Page MenuHomePhabricator

[xec-js] Initial baseline for npm publication
AbandonedPublic

Authored by emack on May 28 2022, 02:35.

Details

Reviewers
bytesofman
deadalnix
Group Reviewers
Restricted Project
Summary

As per T2455, this is an initial baseline of xec-js, which is a light-weight fork of bch-js.

It's also intended to serve as a wrapper library to bridge the gap between what eCash web apps may need vs what the chronik-client is not designed for (e.g. hash160 public key hash conversion prior to interacting with chronik, eCash native TransactionBuilder without needing to convert into bitcoincash addresses first...)

Key eCash specific updates in this baseline

  • Library instantiates to an eCash REST API by default rather than BCHN.
  • Primary library is now instantiated as an XECJS object
  • transaction-builder can now directly take in an eCash address as part of adding tx outputs without the need for bitcoincash: address conversion beforehand (see buildXecTx.js example)
  • Address.toHash160() can now directly take in an eCash address for conversion to a hash160 public key hash (see addrToHash160.js example)
  • Address.toCashAddress() can now directly take in an eCash address for conversion to a cash address
  • Updated README with references to the new eCash features and default xec-api rest url
  • Library has been trimmed of the following legacy bch-js modules as most are catered via Chronik or not relevant to XEC:
    • Blockchain
    • Crypto
    • Control
    • Generating
    • Mining
    • RawTransactions
    • Price
    • Schnorr
    • Encryption
    • Utxo
    • DSProof
    • Transaction
    • Electrum
    • PsfSlpIndexer
Test Plan
  • before npm publication, import library via:

const XECJS = require('../src/xec-js')
let xecjs = new XECJS() // Defaults to the XEC network.

  • after npm publication, import library via:

const XECJS = require('xec-js')
let xecjs = new XECJS() // Defaults to the XEC network.

  • run the XEC native transaction builder and hash160 conversion sample code in the /examples/ folder and ensure it executes successfully

Diff Detail

Repository
rABC Bitcoin ABC
Branch
xecJsBaseline
Lint
Lint Errors
SeverityLocationCodeMessage
Errorweb/xec-js/deploy-production.sh:BASH_SHEBANG1Missing or unexpected shebang.
Errorweb/xec-js/deploy-production.sh:SHELL_LOCALE1`export LC_ALL=C` or `export LC_ALL=C.UTF-8` should be the first statement.
Errorweb/xec-js/deploy-production.sh:3SC1128ShellCheck found an issue:
Warningweb/xec-js/deploy-production.sh:8SC2089ShellCheck found an issue:
Warningweb/xec-js/deploy-production.sh:12SC2090ShellCheck found an issue:
Unit
No Test Coverage
Build Status
Buildable 19172
Build 38092: Build Diff
Build 38091: arc lint + arc unit

Event Timeline

emack requested review of this revision.May 28 2022, 02:35
deadalnix requested changes to this revision.May 29 2022, 23:54
deadalnix added a subscriber: deadalnix.

I had a quick look. Didn't review everything in there as it is quite big, but the little I review is quite worrying. This cealry doesn't match the kind of quality we want to put out there.

web/xec-js/examples/addrToHash160.js
22

Why do you swallow all errors? Why is this function async? This code is very questionable.

web/xec-js/src/address.js
4

Use imports.

17–31

Use a ternary within the obejct instead of duplicating half the universe.

61

WAT?

124

WATWAT?

This revision now requires changes to proceed.May 29 2022, 23:54

This cealry doesn't match the kind of quality we want to put out there.

Agreed.

We are looking to replace bch-api with chronik, with the ultimate goal of integrating chronik as the ABC node indexer.

We also need a basic JS library that covers XEC functions. Cashtab has been working with bch-js for this purpose. While there are some code quality questions with bch-js overall, the fundamental libraries and functions it offers perform well in a React wallet.

Some work has already happened to bring in XEC-specific features to bch-js outside of phab (support for accepting xec addresses). Since these types of patches will likely continue, I think pulling it into phab to track them is the best policy.

The ultimate destiny of xec-js is a lite XEC-focused javascript library to support XEC-specific calculations that are not related to chronik indexing. Alternatively, we could build this new -- but I think it is more straightforward to start with what is already being used and pare it down / improve it.

bytesofman requested changes to this revision.Jun 1 2022, 00:03

We'll take a different approach on this -- see T2465

This diff can be abandoned.