Skip to content

Commit

Permalink
Refactor BTC Plugin Validate Unsigned Tx to Call Parse Payments
Browse files Browse the repository at this point in the history
  • Loading branch information
owenkellogg committed Feb 11, 2025
1 parent 128833d commit dcd8b50
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/plugins/btc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,9 @@ export default class BTC extends UTXO_Plugin {
return { txhex: '' } //TODO
}

async validateUnsignedTx(params: ValidateUnsignedTx): Promise<boolean> {
// Parse the transaction
const tx = bitcoin.Transaction.fromHex(params.transactions[0].txhex);

async validateUnsignedTx(params: ValidateUnsignedTx): Promise<boolean> {
// Get outputs from transaction
const txOutputs = tx.outs.map(output => {
try {
const address = bitcoin.address.fromOutputScript(
output.script,
bitcoin.networks.bitcoin
);

return {
address,
amount: output.value
};
} catch(error) {
return null;
}
}).filter((n): n is { address: string, amount: number } => n !== null);
const payments = await this.parsePayments({ txhex: params.transactions[0].txhex })

// Build expected outputs
const buildOutputsParams = {
Expand All @@ -238,7 +221,7 @@ export default class BTC extends UTXO_Plugin {
) :
output.address;

verifyOutput(txOutputs, address, output.amount);
verifyOutput(payments, address, output.amount);
}

return true;
Expand Down

0 comments on commit dcd8b50

Please sign in to comment.