Skip to content

Commit 8950ddc

Browse files
fix: remove unused sha256Hex import, add fetch error handling for claims
1 parent b71948b commit 8950ddc

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/handlers/pay.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import crypto from 'crypto';
2929
import { getNostrPubkey, pubkeyToDidNostr } from '../auth/nostr.js';
3030
import { readLedger, writeLedger, getBalance, credit, debit } from '../webledger.js';
31-
import { verifyMrc20Deposit, verifyMrc20Anchor, jcs, sha256Hex, btAddress } from '../mrc20.js';
31+
import { verifyMrc20Deposit, verifyMrc20Anchor, jcs, btAddress } from '../mrc20.js';
3232
import { loadTrail, transferToken, buildTransaction, broadcastTx, p2trScript } from '../token.js';
3333
import { secp256k1 } from '@noble/curves/secp256k1';
3434
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
@@ -440,11 +440,16 @@ export function createPayHandler(options = {}) {
440440
const podAddress = btAddress(kp.pubkey, [], network);
441441

442442
// Fetch transaction from mempool
443-
const txResp = await fetch(`${chain.explorer}/tx/${deposit.txid}`);
444-
if (!txResp.ok) {
445-
return reply.code(400).send({ error: 'Transaction not found' });
443+
let txData;
444+
try {
445+
const txResp = await fetch(`${chain.explorer}/tx/${deposit.txid}`);
446+
if (!txResp.ok) {
447+
return reply.code(400).send({ error: 'Transaction not found' });
448+
}
449+
txData = await txResp.json();
450+
} catch (err) {
451+
return reply.code(502).send({ error: `Failed to verify transaction: ${err.message}` });
446452
}
447-
const txData = await txResp.json();
448453
const output = txData.vout?.[deposit.vout];
449454
if (!output) {
450455
return reply.code(400).send({ error: `Output ${deposit.vout} not found` });

0 commit comments

Comments
 (0)