Skip to content

Commit 7143152

Browse files
committed
feat(src): wait the transaction in commit
Wait the transaction and get its receipt in commit.
1 parent 60219be commit 7143152

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/nit.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export async function pull(assetCid: string, blockchainInfo) {
315315
// }
316316
//}
317317

318-
export async function commit(assetCid: string, commitData: string, blockchainInfo) {
318+
export async function commit(assetCid: string, commitData: string, blockchainInfo, confirms: number = 1) {
319319
const commitString = addActionNameInCommit(commitData);
320320
let r;
321321
if (blockchainInfo.gasPrice != null) {
@@ -324,7 +324,9 @@ export async function commit(assetCid: string, commitData: string, blockchainInf
324324
} else {
325325
r = await blockchainInfo.contract.commit(assetCid, commitString, { gasLimit: blockchainInfo.gasLimit });
326326
}
327-
return r;
327+
328+
// Wait for the transaction to be mined
329+
return await r.wait(confirms);
328330
}
329331

330332
export async function log(assetCid: string, blockchainInfo, fromIndex: number, toIndex: number = null) {

src/run.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,11 @@ async function main() {
609609
} else {
610610
commitEventIndexCid = nit.assetCidMock;
611611
}
612-
const commitResult = await nit.commit(commitEventIndexCid, JSON.stringify(commitData), blockchain);
613-
614-
console.log(`Commit Tx: ${commitResult.hash}`);
615-
console.log(`Commit Explorer: ${blockchain.explorerBaseUrl}/${commitResult.hash}`);
616612

617613
try {
618-
// Wait for the transaction to be mined
619-
const transactionReceipt = await commitResult.wait();
620-
console.log(`Block Number: ${transactionReceipt.blockNumber}`);
614+
const transactionReceipt = await nit.commit(commitEventIndexCid, JSON.stringify(commitData), blockchain);
615+
console.log(`Commit Tx: ${transactionReceipt.transactionHash}`);
616+
console.log(`Commit Explorer: ${blockchain.explorerBaseUrl}/${transactionReceipt.transactionHash}`);
621617
} catch (error) {
622618
console.error(`Transaction error: ${error}`);
623619
}

0 commit comments

Comments
 (0)