Skip to content

Commit 98075e6

Browse files
committed
fix: bitcoin recipient and amount retrieval
1 parent 9aa5ebb commit 98075e6

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reservoir0x/relay-protocol-sdk",
3-
"version": "0.0.55",
3+
"version": "0.0.56",
44
"description": "Relay protocol SDK",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/messages/v2.1/depository-withdrawal.ts

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -838,20 +838,8 @@ export const getDecodedWithdrawalAmount = (
838838
}
839839

840840
case "bitcoin-vm": {
841-
try {
842-
const psbt = bitcoin.Psbt.fromHex(decodedWithdrawal.withdrawal.psbt);
843-
const tx = psbt.extractTransaction(false);
844-
const totalAmount = tx.outs.reduce((sum, output) => {
845-
return sum + output.value;
846-
}, 0);
847-
return totalAmount.toString();
848-
} catch (error) {
849-
throw new Error(
850-
`Failed to decode PSBT: ${
851-
error instanceof Error ? error.message : String(error)
852-
}`
853-
);
854-
}
841+
const psbt = bitcoin.Psbt.fromHex(decodedWithdrawal.withdrawal.psbt);
842+
return psbt.txOutputs[0].value.toString();
855843
}
856844

857845
case "hyperliquid-vm": {
@@ -902,26 +890,9 @@ export const getDecodedWithdrawalRecipient = (
902890
}
903891

904892
case "bitcoin-vm": {
905-
try {
906-
const psbt = bitcoin.Psbt.fromHex(decodedWithdrawal.withdrawal.psbt);
907-
const tx = psbt.extractTransaction(false);
908-
if (tx.outs.length === 0) {
909-
throw new Error("Transaction has no outputs");
910-
}
911-
// Extract address from the first output
912-
const firstOutput = tx.outs[0];
913-
const address = bitcoin.address.fromOutputScript(
914-
firstOutput.script,
915-
bitcoin.networks.bitcoin
916-
);
917-
return address;
918-
} catch (error) {
919-
throw new Error(
920-
`Failed to decode PSBT: ${
921-
error instanceof Error ? error.message : String(error)
922-
}`
923-
);
924-
}
893+
const psbt = bitcoin.Psbt.fromHex(decodedWithdrawal.withdrawal.psbt);
894+
const firstOutput = psbt.txOutputs[0];
895+
return bitcoin.address.fromOutputScript(firstOutput.script);
925896
}
926897

927898
case "hyperliquid-vm": {

0 commit comments

Comments
 (0)