HomePhabricator

[ecash-lib] Basic primitives for building txs

Description

[ecash-lib] Basic primitives for building txs

Summary:
Add basic primitives for building Bitcoin txs:

  • Tx, TxInput, TxOutput, OutPoint, the basic primitives comprising a tx.
  • Script, currently just a wrapper around Uint8Array of the bytecode, but in the future gives a rich builder for Scripts.
  • SignData: Attached to a TxInput (ignored during serialization), used when signing the input using BIP143.

Unlike the previous draft, this version uses a Writer interface to unify object size calculation and object serialization, significantly simplifying the implementation.

Also, the writer interface abstracts over the messiness of Uint8Array and DataView handling, especially keeping track of the current write/read offset within the data.

Test Plan:
npm install

Unittests

npm run test

Build

npm run build

React app

It's important this works in a React app with typescript, therefore, somewhere in a temp folder:

  1. npx create-react-app my-ecash-app --template typescript
  2. cd my-ecash-app
  3. npm install --save /my/path/to/bitcoin-abc/modules/ecash-lib
  4. Add to App.tsx: import * as ecash from 'ecash-lib'; console.log(ecash);
  5. npm start
  6. In the browser, it should now log a "Module" with "Bytes", "Script", "Tx", ...

Deno

Having deno too work would be great:

  1. mydeno.ts: import * as ecash '/my/path/to/bitcoin-abc/modules/ecash-lib/dist/index.js'; console.log(ecash);
  2. deno run mydeno.ts

Reviewers: bytesofman, #bitcoin_abc

Reviewed By: bytesofman, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D15928

Details

Provenance
tobias_ruckAuthored on Apr 9 2024, 22:44
tobias_ruckPushed on Apr 10 2024, 03:28
Reviewer
Restricted Project
Differential Revision
D15928: [ecash-lib] Basic primitives for building txs
Parents
rABC36c25b73a48e: [Chronik] Add `parse_tx_lokad_ids` to parse LOKAD IDs
Branches
Unknown
Tags
Unknown