Page MenuHomePhabricator

[ecash-wallet] Add fluent API for building and broadcasting txs
Needs ReviewPublic

Authored by bytesofman on Wed, Mar 19, 04:27.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

We want a powerful and user-friendly API that exposes commonly used steps in tx processing.

Here we initialize such an API with a method that supports non-token XEC txs.

  • We can get the utxos required to build an arbitary tx without actually building the tx by calling wallet.tx(<instructions>).utxos()
  • 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()

    From here,
  • We should add a websocket so the user does not need to remember to call await wallet.sync() before sending every tx
  • Add support for token methods
  • 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

Diff Detail

Repository
rABC Bitcoin ABC
Branch
wallet-txs-regtest
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 32777
Build 65042: Build Diffecash-wallet-tests
Build 65041: arc lint + arc unit

Event Timeline

Improve comments, add tests for fee() and size() methods

tobias_ruck added inline comments.
modules/ecash-wallet/helpers.ts
42 ↗(On Diff #53181)

Careful, this will be incorrect as the signatory is missing, which will add bytes (eg the signature)

modules/ecash-wallet/package.json
7 ↗(On Diff #53181)

There’s something wrong with this. The unit tests should be in one folder (usually src) and the integration tests in another (usually tests), like it’s done for ecash-lib.

Then we can use the wildcard.

Otherwise we’ll have to add new tests here every time we add a new file.

modules/ecash-wallet/wallet.ts
42 ↗(On Diff #53181)

IMO you should change this to Recipient (or Output), and add sats and tokenId and isMintBaton, just like Output in my BIP70 diff.

And then we use that as unified interface for where to send tokens and the wallet just handles it.

Remember ALP allows multiple token IDs per send, I think we should enable this by default, that’s why it should be part of the output.

Also, keep in mind that we also need to enable attaching data in the OP_RETURN. For ALP/eMPP, this will be extra eMPP pushdata, and for non-eMPP, this could be OP_RETURN. Either way it would be an UInt8Array[] (which must be empty for SLP btw)

91 ↗(On Diff #53181)

Event is really not a good name IMO. TransactionsConfig (because you want this to be multiple ones). Recipients might work to. Or just SendConfig.

And I think there should be one unified config for sats only, tokens, and OP_RETURN data

93 ↗(On Diff #53181)

I think you just want one interface which handles all three—remember they can overlap in ALP, eg SENDs and MINTs and BURNs can be in 1 tx .

So you want the outputs as I describe above (with the mint baton Booleans), and the burn amount, and the OP_RETURN data.

  • outputs/recipients (sats and/or tokens, or mint baton)
  • burns (list of tokenId + burn amount)
  • opreturn data

And then the function figures out how to build the tx(s) based on that.

121 ↗(On Diff #53181)

Probably want to use Partial here instead of duplicating types

bytesofman added inline comments.
modules/ecash-wallet/helpers.ts
42 ↗(On Diff #53181)

ok -- added P2PKHSignatory and signing with dummy values

we could completely obscure all of the signing and estimating stuff and just build the tx with inputs signed by the wallet. But I think it's a useful static method to be able to just get the utxos for any arbitary tx, and we would have to convert signed inputs back to utxos to do this (well, I guess we could keep utxos as a class property of the built tx?. Mb that is a better approach...but we would still have to track them separately, we would still have to sign more than once. I like preserving the "just get the utxos sync" --> "just the signed tx and info about it, sync" --> "broadcast the tx, async"

modules/ecash-wallet/package.json
7 ↗(On Diff #53181)

good point, re-organized.

modules/ecash-wallet/wallet.ts
91 ↗(On Diff #53181)

went with somethin else but happy to bikeshed on this one a bit...the point of the class is to make things easier for devs but it's a tricky concept to describe succinctly, and I'm not really sure it's at all readily understandable to someone who hasn't been doing this for years

bytesofman marked 3 inline comments as done.

clean up + unify interfaces, use src/ and test/ directories to preserve test wildcards, add signatory for dummy sigs

bytesofman edited the test plan for this revision. (Show Details)

get rid of getEventUtxos static method, refactor so we get utxos from fluent API