Skip to content

Commit

Permalink
fix: send block hash instead of tx hash for inclusion proof (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab authored Nov 27, 2024
1 parent 1f5a8d5 commit 95049d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/app/hooks/services/useTransactionService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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,
Expand Down
19 changes: 18 additions & 1 deletion src/utils/mempool_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<any> {
export async function getTxInfo(txId: string): Promise<TxInfo> {
const response = await fetch(txInfoUrl(txId));
if (!response.ok) {
const err = await response.text();
Expand Down

0 comments on commit 95049d8

Please sign in to comment.