HomePhabricator

[ecash-lib] Add `Op`, opcode consts, readOp, writeOp

Description

[ecash-lib] Add Op, opcode consts, readOp, writeOp

Summary:
Basic functionality to read and write opcodes.

Opcode is a number and not an enum for two reasons:

  1. Having to type Opcode.OP_CHECKSIG every time instead of OP_CHECKSIG is much simpler
  2. The opcode list isn't exhaustive, e.g. 0xd0 would be a valid opcode, it would just fail immediately if in an executed branch.

Also, for pushops, the used opcode is explicit and not automatically chosen, this is because there's different usages require different rules:

  1. In executed Bitcoin script, all pushops must be encoded minimally, e.g. the empty string must be pushed using OP_0, not using OP_PUSHDATA1
  2. In SLP, single push opcodes like OP_0 cannot be used, so to push the empty string, OP_PUSHDATAn must be used in this case.

In future diffs, we can add functions to get us minimal Ops for either of these cases.

Test Plan: npm run test && npm run build

Reviewers: bytesofman, #bitcoin_abc

Reviewed By: bytesofman, #bitcoin_abc

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

Details

Provenance
tobias_ruckAuthored on Wed, Apr 10, 20:44
tobias_ruckPushed on Thu, Apr 11, 22:49
Reviewer
Restricted Project
Differential Revision
D15938: [ecash-lib] Add `Op`, opcode consts, readOp, writeOp
Parents
rABC7d5ff29ba399: [chronik] fix ChronikBridge::load_raw_tx and compress_script
Branches
Unknown
Tags
Unknown