Skip to content

Commit f097b29

Browse files
authored
Merge pull request #589 from EdgeApp/sam/failed-txs
Add `'failed'` variant to EdgeTransaction `confirmations` API
2 parents b21026c + f015d51 commit f097b29

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- added: New `'failed'` value to confirmations field on `EdgeTransactions`
6+
57
## 2.3.0 (2024-03-23)
68

79
- added: `EdgeCorePluginOptions.infoPayload`, containing arbitrary JSON provided by the info server.

src/core/currency/wallet/currency-wallet-callbacks.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { emit } from 'yaob'
55

66
import { upgradeCurrencyCode } from '../../../types/type-helpers'
77
import {
8+
EdgeConfirmationState,
89
EdgeCurrencyEngineCallbacks,
910
EdgeStakingStatus,
1011
EdgeTokenId,
@@ -215,15 +216,12 @@ export function makeCurrencyWalletCallbacks(
215216
const { txs } = input.props.walletState
216217
for (const txid of Object.keys(txs)) {
217218
const reduxTx = txs[txid]
218-
if (
219-
reduxTx.confirmations !== 'confirmed' &&
220-
reduxTx.confirmations !== 'dropped'
221-
) {
219+
if (shouldCoreDetermineConfirmations(reduxTx.confirmations)) {
222220
const { requiredConfirmations } =
223221
input.props.walletState.currencyInfo
224222
const { height } = input.props.walletState
225223

226-
reduxTx.confirmations = validateConfirmations(
224+
reduxTx.confirmations = determineConfirmations(
227225
reduxTx,
228226
height,
229227
requiredConfirmations
@@ -318,14 +316,11 @@ export function makeCurrencyWalletCallbacks(
318316
const { txid } = tx
319317

320318
// DEPRECATE: After all currency plugins implement new Confirmations API
321-
if (
322-
tx.confirmations !== 'confirmed' &&
323-
tx.confirmations !== 'dropped'
324-
) {
319+
if (shouldCoreDetermineConfirmations(tx.confirmations)) {
325320
const { requiredConfirmations } = input.props.walletState.currencyInfo
326321
const { height } = input.props.walletState
327322

328-
tx.confirmations = validateConfirmations(
323+
tx.confirmations = determineConfirmations(
329324
tx,
330325
height,
331326
requiredConfirmations
@@ -413,7 +408,23 @@ export function watchCurrencyWallet(input: CurrencyWalletInput): void {
413408
checkChangesLoop()
414409
}
415410

416-
export const validateConfirmations = (
411+
/**
412+
* Returns true if the core needs to calculate the transaction's confirmation state,
413+
* because it still depends on the current block height.
414+
*
415+
* @deprecated Remove once all currency plugins support the new confirmations API.
416+
*/
417+
const shouldCoreDetermineConfirmations = (
418+
confirmations: EdgeConfirmationState | undefined
419+
): boolean => {
420+
return (
421+
confirmations !== 'confirmed' &&
422+
confirmations !== 'dropped' &&
423+
confirmations !== 'failed'
424+
)
425+
}
426+
427+
export const determineConfirmations = (
417428
tx: { blockHeight: number }, // Either EdgeTransaction or MergedTransaction
418429
blockHeight: number,
419430
requiredConfirmations: number = 1 // Default confirmation rule is 1 block

src/types/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,9 @@ export type EdgeConfirmationState =
546546
| 'confirmed'
547547
// Dropped from the network without confirmations:
548548
| 'dropped'
549+
// Confirmed, but failed on-chain execution (exceeded gas limit,
550+
// smart-contract failure, etc):
551+
| 'failed'
549552
// We don't know the chain height yet:
550553
| 'syncing'
551554
// No confirmations yet:

test/core/currency/confirmations.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai'
22
import { describe, it } from 'mocha'
33

4-
import { validateConfirmations } from '../../../src/core/currency/wallet/currency-wallet-callbacks'
4+
import { determineConfirmations } from '../../../src/core/currency/wallet/currency-wallet-callbacks'
55

66
describe('confirmations API', function () {
77
const helper = (
@@ -12,7 +12,7 @@ describe('confirmations API', function () {
1212
): void => {
1313
const tx = { blockHeight: txBlockHeight }
1414
expect(
15-
validateConfirmations(tx, netBlockHeight, required),
15+
determineConfirmations(tx, netBlockHeight, required),
1616
`Expected tx with blockHeight of ${txBlockHeight} to be ${expected} at network blockHeight ${netBlockHeight} with ${required} required confs`
1717
).equals(expected)
1818
}

0 commit comments

Comments
 (0)