Skip to content
A Golang module that helps you answer questions about raw Bitcoin transactions, their inputs, outputs and scripts.
Go Makefile
Branch: master
Clone or download
Latest commit 49c49b9 Sep 28, 2019

README.md

rawtx

A Golang module that helps you answer questions about raw bitcoin transactions, their inputs, outputs and scripts.

Transactions

Transactions can be deserialized from a hex string or from a wire.MsgTx. Based on that following questions can be answered.

Input and Output type

Following is answered:

spends? pays to?
P2PK
P2PKH
P2SH-P2WPKH can't tell
from the rawtx
P2WPKH_V0
P2MS
P2SH
P2SH-P2WSH can't tell
from the rawtx
P2WSH_V0
OP_RETURN can't spend an
OP_RETURN output

Additionally you might ask:

Bitcoin Script

There is a BitcoinScript parser for byte slices build in. A ParsedBitcoinScript is a slice of ParsedOpCodes. It has a String() method which displays the OP codes in a bitcoin developer readable format.

bs1 := BitcoinScript{0x6e, 0x87, 0x91, 0x69, 0xa7, 0x7c, 0xa7, 0x87}
pbs1 := bs1.ParseWithPanic()
fmt.Println(pbs1.String())
// -> OP_2DUP OP_EQUAL OP_NOT OP_VERIFY OP_SHA1 OP_SWAP OP_SHA1 OP_EQUAL
bs2 = BitcoinScript{byte(OpRETURN), byte(OpDATA2), byte(OpCHECKLOCKTIMEVERIFY), byte(OpDATA12)}
pbs2 = bs2.ParseWithPanic()
fmt.Println(pbs2.String())
// -> OP_RETURN OP_DATA_2(b10c)

The actual OpCode behind the ParsedOpCode can, but doesn't have to push data. You can check if a ParsedOpCode is

Running tests

Either normal test suit with coverage report in percent.

$ make test
...
PASS
coverage: 100.0% of statements
ok      github.com/0xB10C/rawtx 0.028s

Or with detailed coverage HTML report opened in your browser.

$ make cover
...
PASS
coverage: 100.0% of statements
ok      github.com/0xB10C/rawtx 0.028s
go tool cover -html=count.out

Discalimer

Do not use in consensus related code!

License

rawTx is licensed under a BSD 3-Clause License.

You can’t perform that action at this time.