Bitcoin Processing Unit
Transform Bitcoin Transactions into Virtual Procedure Call Units.
Transforms raw transactions to BOB format. Port from the original bpu library bu unwriter
Since this is intended to be used by low level transactoin parsers dependencies are kept to a bare minimum. It does not include the RPC client functionality that connects to a node to get a raw tx. Its designed to be a fast raw tx to BOB processor.
There is also a Typescript version which does include the originally RPC functionality.
var seperator = "|"
var l = bpu.IncludeL
var opReturn = uint8(106)
var opFalse = uint8(0)
var splitConfig = []SplitConfig{
{
Token: &Token{
Op: &opReturn,
},
Include: &l,
},
{
Token: &Token{
Op: &opFalse,
},
Include: &l,
},
{
Token: &Token{
S: &seperator,
},
Require: &opFalse,
},
}
bpuTx, err := Parse(ParseConfig{RawTxHex: &sampleTx, SplitConfig: splitConfig})
if err != nil {
fmt.Println(err)
}
You can either use SplitConfig.RawTxHex and set by hex string, or use SplitConfig.Tx to set by bt.Tx.
You can pass an optional Transform function to bpu.Parse. Function should look something like this:
var splitTransform Transform = func(o Cell, c string) (to *Cell, e error) {
// if the buffer is larger than 512 bytes,
// replace the key with "l" prepended attribute
to = &o
bytes, err := hex.DecodeString(c)
if err != nil {
return nil, err
}
if len(bytes) > 512 {
to.LS = to.S
to.LB = to.B
to.S = nil
to.B = nil
}
return to, nil
}
See the Typescript library README for more examples of split configuration options, transformation, and a look at the output.
The original BPU library used bsv (javascript) v1.5 to determine if a script chunk was a valid opcode. At the time, the bsv library supported a limited number of OP codes (inherited from limitations uimposed by Bitcoin core). In this version all opcodes are recognized which surfaces a new issue where fields previously available would be missing if the data is now recognized as an opcode.
Previously, BPU would omit the op and ops fields for non opcode data, while recognized opcodes would omit the s, b and h fields. To solve the issue of missing fields that happen to be opcodes, all keys are included if the recognized pushdata is also in the Printable ASCII range.