Page MenuHomePhabricator

[ecash-lib] Basic primitives for building txs
ClosedPublic

Authored by tobias_ruck on Apr 9 2024, 13:57.

Details

Reviewers
bytesofman
Group Reviewers
Restricted Project
Commits
rABCaf5be01d095d: [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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

squash with previous commit...

bytesofman requested changes to this revision.Apr 9 2024, 16:08

Re: testplan

Adding integration tests will be complex and should happen in its own diff. So, we should plan to land something first.

What features are available in this version? We could add some simple unit tests to confirm (e.g. can we build a tx and confirm it is the expected hex?)

modules/ecash-lib/src/io/int.ts
6 ↗(On Diff #46960)

bigint and not BigInt ?

This revision now requires changes to proceed.Apr 9 2024, 16:08

add tests, fix build using NodeNext

modules/ecash-lib/src/io/int.ts
6 ↗(On Diff #46960)

BigInt is a function and bigint is a type, just how Number is a function and number is a type

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

Yes, but I do not think we need this to land. Ultimately this will be a dependency in React apps in the monorepo that will be running their tests with this app, so we will have this covered by monorepo CI once we have these apps migrated.

Having deno too work would be great:

Yes, ultimately we will expand and/or replicate the chronik docusaurus to include this lib. But also do not need this rightnow.

no README.md? should have at least a stub so we can publish.

This revision now requires changes to proceed.Apr 10 2024, 00:20
This revision is now accepted and ready to land.Apr 10 2024, 02:02