Recently I’ve been working on new project to bring Bitcoin Core’s functionality to Scala. The project is called bitcoin-s, which aims to be alternative to bitcoinj on the JVM. This first undertaking is mimicking bitcoin core’s functionality inside of the Script interpreter. The script interpreter is responsible for evaluating scripts found in all bitcoin transactions. Bitcoin Core provides a test suite of script signatures & script pubkeys to test against. The theory is that any implementation of Script should pass on all of the tests found in script_valid.json.

Test cases that appear later in the script_valid.json file require transaction signature serialization & hashing to evaluate an OP_CHECKSIG operation. Bitcoin core builds default spending & crediting transaction to check the script signature & script pubkey against. My test cases for bitcoin-s will not succeed unless the transaction is exactly the same as it is built in bitcoin core.

As some one that has beginner knowledge of C++, this obvious question came to me: How do you write an arbitrary bitcoin transaction to stdout in hex format? Thankfully sipa answered my question.

This is really handy when it comes to seeing what bitcoin core is actually doing — especially with beginner level knowledge of C++. Now you can see how I use the code provided by sipa to write the transaction being built by Core here.

Finally, here is the output in practice.