Skip to content

fix(gamification): decode real payment amounts from XDR, classify don… - #148

Merged
BarryArinze merged 1 commit into
aid-linkk:masterfrom
Martins0152:fix/gamification-xdr-decoded-amounts
Aug 26, 2026
Merged

fix(gamification): decode real payment amounts from XDR, classify don…#148
BarryArinze merged 1 commit into
aid-linkk:masterfrom
Martins0152:fix/gamification-xdr-decoded-amounts

Conversation

@Martins0152

Copy link
Copy Markdown
Contributor

…ation/distribution/claim correctly

Fixes #142

  • transaction-indexer.ts no longer uses fee_charged as the donation amount. It now decodes each transaction's envelope_xdr via the Stellar SDK XDR parser to get the real payment amount and asset code.
  • Introduces src/lib/horizon/envelope-decode.ts: shared low-level XDR primitives (getEnvelopeOperations, decodePaymentOp, decodeInvokeHostFunctionOp, mapSorobanFunctionName, asset code decoding) extracted from decode-horizon-transaction.ts so both the real-time dashboard stream and the gamification indexer decode XDR the same way instead of duplicating the logic.
  • decode-horizon-transaction.ts is refactored to use the shared primitives; its public behavior/output for useRealTimeTransactions is unchanged.
  • TransactionEvent.type is now classified from real operation
    semantics: outgoing payments -> donation, incoming payments ->
    distribution, invokeHostFunction calls matching claim/distribute Soroban function names -> claim/distribution. Soroban 'donate'-style calls are intentionally not counted as donations since no verifiable amount can be recovered from the operation without decoding contract arguments (out of scope).
  • recipient is now the actual payment destination or contract ID, fixing unique_campaigns_supported.
  • Adds resumable cursor support: indexTransactions now honors options.cursor (already persisted via badge-storage.ts's lastSyncedCursor) and issues zero extra Horizon calls when there are no new transactions.
  • TransactionEvent/IndexResult/indexTransactions signature, badge-rules.ts, badge-evaluator.ts, and badge-storage.ts are all unchanged per the issue's constraints.

Tests: src/lib/gamification/tests/transaction-indexer.test.ts covers XDR-decoded amounts, claim classification, fee_charged vs real amount, cursor resumption, AID token currency, undecodable XDR handling, and a badge-evaluator integration scenario.

npm run test and npm run type-check pass with no new regressions (pre-existing unrelated failures on master are unaffected).

…ation/distribution/claim correctly

Fixes aid-linkk#142

- transaction-indexer.ts no longer uses fee_charged as the donation
  amount. It now decodes each transaction's envelope_xdr via the
  Stellar SDK XDR parser to get the real payment amount and asset code.
- Introduces src/lib/horizon/envelope-decode.ts: shared low-level XDR
  primitives (getEnvelopeOperations, decodePaymentOp,
  decodeInvokeHostFunctionOp, mapSorobanFunctionName, asset code
  decoding) extracted from decode-horizon-transaction.ts so both the
  real-time dashboard stream and the gamification indexer decode XDR
  the same way instead of duplicating the logic.
- decode-horizon-transaction.ts is refactored to use the shared
  primitives; its public behavior/output for useRealTimeTransactions is
  unchanged.
- TransactionEvent.type is now classified from real operation
  semantics: outgoing payments -> donation, incoming payments ->
  distribution, invokeHostFunction calls matching claim/distribute
  Soroban function names -> claim/distribution. Soroban 'donate'-style
  calls are intentionally not counted as donations since no verifiable
  amount can be recovered from the operation without decoding contract
  arguments (out of scope).
- recipient is now the actual payment destination or contract ID,
  fixing unique_campaigns_supported.
- Adds resumable cursor support: indexTransactions now honors
  options.cursor (already persisted via badge-storage.ts's
  lastSyncedCursor) and issues zero extra Horizon calls when there are
  no new transactions.
- TransactionEvent/IndexResult/indexTransactions signature, badge-rules.ts,
  badge-evaluator.ts, and badge-storage.ts are all unchanged per the
  issue's constraints.

Tests: src/lib/gamification/__tests__/transaction-indexer.test.ts
covers XDR-decoded amounts, claim classification, fee_charged vs real
amount, cursor resumption, AID token currency, undecodable XDR
handling, and a badge-evaluator integration scenario.

npm run test and npm run type-check pass with no new regressions
(pre-existing unrelated failures on master are unaffected).
@BarryArinze
BarryArinze merged commit d4b6005 into aid-linkk:master Aug 26, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants