Skip to content

Commit

Permalink
add tx hash to return type
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Apr 16, 2024
1 parent f10d344 commit 4e35c97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/store-sync/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export type SyncOptions<config extends StoreConfig = StoreConfig> = {
};
};

export type WaitForTransactionResult = Pick<TransactionReceipt, "blockNumber" | "status">;
export type WaitForTransactionResult = Pick<TransactionReceipt, "blockNumber" | "status" | "transactionHash">;

export type SyncResult = {
latestBlock$: Observable<Block>;
Expand Down
8 changes: 5 additions & 3 deletions packages/store-sync/src/createStoreSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,17 @@ export async function createStoreSync<config extends StoreConfig = StoreConfig>(
for (const block of blocks) {
const txs = block.logs.map((op) => op.transactionHash);
// If the transaction caused a log, it must have succeeded
if (txs.includes(tx)) return { blockNumber: block.blockNumber, status: "success" as const };
if (txs.includes(tx)) {
return { blockNumber: block.blockNumber, status: "success" as const, transactionHash: tx };
}
}

try {
const lastBlock = blocks[0];
debug("fetching tx receipt for block", lastBlock.blockNumber);
const { status, blockNumber } = await publicClient.getTransactionReceipt({ hash: tx });
const { status, blockNumber, transactionHash } = await publicClient.getTransactionReceipt({ hash: tx });
if (lastBlock.blockNumber >= blockNumber) {
return { status, blockNumber };
return { status, blockNumber, transactionHash };
}
} catch (error) {
if (error instanceof TransactionReceiptNotFoundError) {
Expand Down

0 comments on commit 4e35c97

Please sign in to comment.