From 95049d84f703324fa1be3886f3c507459cc4d354 Mon Sep 17 00:00:00 2001 From: Crypto Minion <154598612+jrwbabylonlab@users.noreply.github.com> Date: Thu, 28 Nov 2024 02:09:49 +1100 Subject: [PATCH] fix: send block hash instead of tx hash for inclusion proof (#399) --- .../hooks/services/useTransactionService.tsx | 8 ++++++-- src/utils/mempool_api.ts | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/app/hooks/services/useTransactionService.tsx b/src/app/hooks/services/useTransactionService.tsx index 51ba3310..9280d8f4 100644 --- a/src/app/hooks/services/useTransactionService.tsx +++ b/src/app/hooks/services/useTransactionService.tsx @@ -24,7 +24,7 @@ import { uint8ArrayToHex, } from "@/utils/delegations"; import { getFeeRateFromMempool } from "@/utils/getFeeRateFromMempool"; -import { getTxMerkleProof, MerkleProof } from "@/utils/mempool_api"; +import { getTxInfo, getTxMerkleProof, MerkleProof } from "@/utils/mempool_api"; import { useNetworkFees } from "../api/useNetworkFees"; @@ -736,12 +736,16 @@ const getInclusionProof = async ( // Get the merkle proof let txMerkleProof: MerkleProof; try { + // TODO: Use the hook instead txMerkleProof = await getTxMerkleProof(stakingTx.getId()); } catch (err) { throw new Error("Failed to get the merkle proof", { cause: err }); } + // TODO: Use the hook instead + const txInfo = await getTxInfo(stakingTx.getId()); + const blockHash = txInfo.status.block_hash; - const hash = Uint8Array.from(Buffer.from(stakingTx.getId(), "hex")); + const hash = Uint8Array.from(Buffer.from(blockHash, "hex")); const inclusionProofKey: btccheckpoint.TransactionKey = btccheckpoint.TransactionKey.fromPartial({ index: txMerkleProof.pos, diff --git a/src/utils/mempool_api.ts b/src/utils/mempool_api.ts index 46bcdde9..58c50702 100644 --- a/src/utils/mempool_api.ts +++ b/src/utils/mempool_api.ts @@ -10,6 +10,23 @@ export interface MerkleProof { pos: number; } +interface TxInfo { + txid: string; + version: number; + locktime: number; + vin: string[]; + vout: string[]; + size: number; + weight: number; + fee: number; + status: { + confirmed: boolean; + block_height: number; + block_hash: string; + block_time: number; + }; +} + export class ServerError extends Error { constructor( message: string, @@ -220,7 +237,7 @@ export async function getFundingUTXOs( * @param txId - The transaction ID in string format. * @returns A promise that resolves into the transaction information. */ -export async function getTxInfo(txId: string): Promise { +export async function getTxInfo(txId: string): Promise { const response = await fetch(txInfoUrl(txId)); if (!response.ok) { const err = await response.text();