[ecash-wallet] Add fluent API for building and broadcasting txs
Summary:
We want a powerful and user-friendly API that exposes commonly used steps in tx processing.
Here we initialize such an API. The MVP includes basic support for SLP and ALP txs.
- We can get the utxos required to build an arbitary tx with the exported selectUtxos function, which supports different selection strategies to support Postage protocol
- We can build a tx (and get info about it) without broadcasting it, by calling wallet.tx(<instructions>).build().fee() or wallet.tx(<instructions>).build().size(); or the actual TxBuilder with wallet.tx(<instructions>).build().tx
- We can build and broadcast a tx with one call with await wallet.tx(<instructions>).build().broadcast()
- We can specify the outIdx of token outputs and have extensive validation against token spec about what works / does not work
- We have included a regtest proof of concept for a postage tx
- We have included regtest confirmed behavior for basic XEC, SLP, and ALP txs
This diff ended up piling in many features, as we had to build out a lot of this capability to properly evaluate the API. While the methods in this app do involve some complexity, it is greatly simplified compared to using ecash-lib directly, and the strong typing and validation enhance the developer experience.
From here,
- We should add a websocket so the user does not need to remember to call await wallet.sync() before sending every tx
- Support other token types
- Support Agora actions
- Add support for chained txs, i.e. await wallet.tx(<instructions>).build().broadcast() should "just work" even if the instructions are asking to send more token outputs than a single tx can hold, or more XEC outputs than the tx broadcast limit of 100kb will tolerate.
Test Plan:
npm test
integration tests:
build node in build dir, then, from bitcoin-abc/modules/ecash-wallet/, BUILD_DIR="${PWD}/../../build" npm run integration-tests
Review API, suggest different names, shapes of objects, anything that should go in now before we start to add more features
Reviewers: #bitcoin_abc, tobias_ruck
Reviewed By: #bitcoin_abc, tobias_ruck
Subscribers: alitayin, tobias_ruck
Differential Revision: https://reviews.bitcoinabc.org/D17822