49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import type { MempoolTransaction, TransactionVerificationResult } from './mempoolSpaceTypes'
|
|
import { getTransaction } from './mempoolSpaceApi'
|
|
import { verifySponsoringTransaction } from './mempoolSpaceVerification'
|
|
import { waitForConfirmation } from './mempoolSpaceConfirmation'
|
|
|
|
export type { MempoolTransaction, TransactionVerificationResult } from './mempoolSpaceTypes'
|
|
|
|
/**
|
|
* Mempool.space API service
|
|
* Used to verify Bitcoin mainnet transactions for sponsoring payments
|
|
*/
|
|
/**
|
|
* Mempool.space API service
|
|
* Used to verify Bitcoin mainnet transactions for sponsoring payments
|
|
*/
|
|
export class MempoolSpaceService {
|
|
/**
|
|
* Fetch transaction from mempool.space
|
|
*/
|
|
async getTransaction(txid: string): Promise<MempoolTransaction | null> {
|
|
return await getTransaction(txid)
|
|
}
|
|
|
|
/**
|
|
* Verify sponsoring payment transaction
|
|
* Checks that transaction has correct outputs for both author and platform
|
|
*/
|
|
async verifySponsoringTransaction(
|
|
txid: string,
|
|
authorMainnetAddress: string
|
|
): Promise<TransactionVerificationResult> {
|
|
return await verifySponsoringTransaction(txid, authorMainnetAddress)
|
|
}
|
|
|
|
/**
|
|
* Wait for transaction confirmation
|
|
* Polls mempool.space until transaction is confirmed or timeout
|
|
*/
|
|
async waitForConfirmation(
|
|
txid: string,
|
|
timeout: number = 600000, // 10 minutes
|
|
interval: number = 10000 // 10 seconds
|
|
): Promise<TransactionVerificationResult | null> {
|
|
return await waitForConfirmation(txid, timeout, interval)
|
|
}
|
|
}
|
|
|
|
export const mempoolSpaceService = new MempoolSpaceService()
|