73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { mempoolSpaceService } from './mempoolSpace'
|
|
|
|
export function logVerificationFailure(
|
|
transactionId: string,
|
|
authorPubkey: string,
|
|
authorMainnetAddress: string,
|
|
error: string | undefined
|
|
): void {
|
|
console.error('Sponsoring payment verification failed', {
|
|
transactionId,
|
|
authorPubkey,
|
|
authorAddress: authorMainnetAddress,
|
|
error,
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
}
|
|
|
|
export function logVerificationSuccess(
|
|
transactionId: string,
|
|
authorPubkey: string,
|
|
authorMainnetAddress: string,
|
|
verification: { authorOutput?: { amount: number }; platformOutput?: { amount: number }; confirmed: boolean; confirmations: number }
|
|
): void {
|
|
console.log('Sponsoring payment verified', {
|
|
transactionId,
|
|
authorPubkey,
|
|
authorAddress: authorMainnetAddress,
|
|
authorAmount: verification.authorOutput?.amount,
|
|
platformAmount: verification.platformOutput?.amount,
|
|
confirmed: verification.confirmed,
|
|
confirmations: verification.confirmations,
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
}
|
|
|
|
export async function verifySponsoringPayment(
|
|
transactionId: string,
|
|
authorPubkey: string,
|
|
authorMainnetAddress: string
|
|
): Promise<boolean> {
|
|
try {
|
|
const verification = await mempoolSpaceService.verifySponsoringTransaction(
|
|
transactionId,
|
|
authorMainnetAddress
|
|
)
|
|
|
|
if (!verification.valid) {
|
|
logVerificationFailure(transactionId, authorPubkey, authorMainnetAddress, verification.error)
|
|
return false
|
|
}
|
|
|
|
if (!verification.confirmed) {
|
|
console.warn('Sponsoring payment not yet confirmed', {
|
|
transactionId,
|
|
authorPubkey,
|
|
confirmations: verification.confirmations,
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
}
|
|
|
|
logVerificationSuccess(transactionId, authorPubkey, authorMainnetAddress, verification)
|
|
return true
|
|
} catch (error) {
|
|
console.error('Error verifying sponsoring payment', {
|
|
transactionId,
|
|
authorPubkey,
|
|
error: error instanceof Error ? error.message : 'Unknown error',
|
|
timestamp: new Date().toISOString(),
|
|
})
|
|
return false
|
|
}
|
|
}
|