bitcoin-elixir v0.0.1 Bitcoin.Script

Bitcoin Script interpreter.

Opcodes numbers are coming from: https://github.com/bitcoin/bitcoin/blob/master/src/script/script.h

Implemented from the scratch based on the wiki (https://en.bitcoin.it/wiki/Script) and script test cases from bitcoinj/bitcore.

There is still a long road ahead to 100% of valid/invalid scripts test suite (it’s really good). List of issues to remember can be find in the source file with an upcase ‘todo’ tag.

Summary

Functions

Parse binary script into a form consumable by the interpreter (ops list). Parsed script looks like this

Parse script from the string in a format that is outputed by bitcoid

Parse script from a strig form familiar from test cases

Represent parsed script (list of :OP_CODES and binary data), in it’s original binary form

Returns string representation of the provided parsed script in the same form as bitcoind decodescript command

Functions

bin(x)
bool(arg1)
cast_to_bool(arg1)
get_multi(list)
nth_element(stack, n)
parse(binary)

Parse binary script into a form consumable by the interpreter (ops list). Parsed script looks like this:

[:OP_10, :OP_10, :OP_ADD, <<20>>, :OP_EQUAL]
parse_string(string)

Parse script from the string in a format that is outputed by bitcoid.

E.g. “2 OP_IF 0 OP_ELSE 1 OP_ENDIF”

parse_string2(string)

Parse script from a strig form familiar from test cases.

E.g. “128 SIZE 2 EQUAL”

Binaries appear in the 0x form or literaly in single quotes.

run(script, opts \\ [])
run(stack, arg2, opts)
to_binary(script)

Represent parsed script (list of :OP_CODES and binary data), in it’s original binary form.

to_string(script)

Returns string representation of the provided parsed script in the same form as bitcoind decodescript command

validate(script)
verify(script, opts \\ [])
verify_all_signatures(arg1, arg2, opts)
verify_sig_pk(sig_bin, pk_bin, opts \\ [])
verify_signature(sig, pk, opts)