Page MenuHomePhabricator

[tg bot] create tg messages with parsed token send txs
AbandonedPublic

Authored by bytesofman on Mar 17 2023, 04:50.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

T2972

Depends on D13366

Ended up needing to put a lot into this due to weirdly large variety of etoken txs in the mocks. Functions would fail without some of these patches and they would have been cumbersome to roll back into previous diffs on this stack.

Since this diff is already rebuilt into a stack, and the unit tests are good vs what this app does, I recommend reviewing it as is.

Test Plan

npm test
npm run msgs and check out the parsed tg msgs

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 22546
Build 44712: Build Diff
Build 44711: arc lint + arc unit

Event Timeline

Added some inline comments for clarification.

web/ecash-telegram-bot/chronik.js
28 ↗(On Diff #38654)

This function had to be refactored to return the object needed for the next function, rather than "parsed block with this object already in it"

The previous approach required only one param for getBlockTgMessage(parsedBlock), which was nice. However, better design (and more importantly easier to automate mock generation) if this is split out.

Had to be done here because unit tests failed for getBlockTgMessage on account of mock generation treating parsedBlock and parsedBlockWithTokenInfo as identical objects. JS quirk that is hard to paper over in nodejs.

81 ↗(On Diff #38654)

Function is now called with two parameters instead of the modified parsedBlock.

web/ecash-telegram-bot/parse.js
72 ↗(On Diff #38654)

You need to start tracking this in the inputs. Can't just assume sent amount less change is correct in the outputs, as many token send txs have inputs from multiple addresses.

101 ↗(On Diff #38654)

This weird flag variable was necessary to handle complicated etoken txs with multiple address inputs and outputs

Opportunity for optimization: create an array of input addresses, then determine change by what went to any given input address, added to T2972 master list

web/ecash-telegram-bot/scripts/generateMocks.js
104 ↗(On Diff #38654)

This was, well, dumb. "oh bc js clones things, we'll just unclone one and not the other one"

just impacts them both, same as earlier approach

web/ecash-telegram-bot/test/mocks/templates.js
50 ↗(On Diff #38654)

Added these unit tests bc needed to test a few outputScript results on txs I was debugging.

Correcting function call format for nodejs same file

Need to correct how amounts are parsed here.

Fixing token send tx parsing, extensible to multiple outputs

will rework this in a more organized stack