-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: fail if the tx is dropped #12
Conversation
src/ethereum/txUtils.ts
Outdated
@@ -43,14 +43,22 @@ export namespace txUtils { | |||
* @return {object} data - Current transaction data. See {@link txUtils#getTransaction} | |||
*/ | |||
export async function waitForCompletion(txId: string): Promise<any> { | |||
let retriesOnEmpty = 5 // (5 * TRANSACTION_FETCH_DELAY) seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a configurable function parameter with a default value?
src/ethereum/txUtils.ts
Outdated
@@ -43,14 +43,22 @@ export namespace txUtils { | |||
* @return {object} data - Current transaction data. See {@link txUtils#getTransaction} | |||
*/ | |||
export async function waitForCompletion(txId: string): Promise<any> { | |||
let retriesOnEmpty = 5 // (5 * TRANSACTION_FETCH_DELAY) seconds | |||
|
|||
while (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have a discrete number of amounts to iterate, we could replace the implementation by a for-loop an it would be cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of, because the idea is to wait until the transaction ends or it's dropped. I'm thinking this is a better implementation
export async function waitForCompletion(txId: string, retriesOnEmpty: number = 5): Promise<any> {
const isDropped = await isTxDropped(txId, retriesOnEmpty)
if (isDropped) {
return { hash: txId, status: TRANSACTION_STATUS.failed }
}
while (true) {
const tx = await getTransaction(txId)
if (!isPending(tx) && tx.recepeit) {
return tx
}
await sleep(TRANSACTION_FETCH_DELAY)
}
}
export async function isTxDropped(txId: string, retryAttemps: number = 5) : boolean {
while (retryAttemps > 0) {
const tx = await getTransaction(txId)
if (tx !== null) {
return false
}
retryAttemps -= 1
await sleep(TRANSACTION_FETCH_DELAY)
}
return true
}
what do you think?
f0e8c7f
to
323ed8c
Compare
Let me rebase and squash so it looks cleaner! Edit: Done! |
6a18e8e
to
b83f706
Compare
also removes repeated code for fetching transaction statuses.
The idea is to make
waitForCompletion
aware of dropped transactions, which return asnull
, but give it some time to wait in case there's congestion (hence theretriesOnEmpty
).I'm not in love with the impl, comments are welcomed