Last active
November 15, 2021 16:45
-
-
Save AndreVallestero/b50cbf72598bfc5103bb529f5be5e1e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // timeout in ms | |
| async function checkTxConfirmation(txId, timeout) { | |
| console.log(`Waiting for TX: ${txId}`); | |
| const start = Date.now(); | |
| for (;;) { | |
| const status = (await arweave.transactions.getStatus(txId)).status; | |
| switch (status) { | |
| case 202: | |
| case 404: | |
| break; | |
| case 200: | |
| console.log("Transaction found"); | |
| return true; | |
| default: | |
| console.error(`Status ${status} while checking tx confirmation`); | |
| return false; | |
| } | |
| const elapsed = Date.now() - start; | |
| if (timeout && elapsed > timeout) return false | |
| console.log(Math.round(elapsed / 60000) + "m waiting"); | |
| await new Promise((resolve) => setTimeout(resolve, 60000)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment