Bitcoin data-structures library for OCaml.
Bitcoinml provides support for the following data-structures:
Address (with also bech32 addresses)
Block_lazy (lazy block evaluation)
Script (script execution, common pattern recognizer)
Tx (In, Out, Witness)
Params (network parameters for BTC, XTN and BCH)
The library is now fully compatible with segwit transactions (from version 0.3.0). The parser automatically recognizes
a segwit transaction, and parses/serializes it correctly. For those who want to avoid this behaviour, there are the
*_legacy functions which disable segwit.
For every type of the library, bitcoinml also offers sexp
to_string readable serialization:
( (hash 8139979112e894a14f8370438a471d23984061ff83a9eba0bc7a34433327ec21) (version 1) (txin( ( (out_hash 56f87210814c8baef7068454e517a70da2f2103fc3ac7f687e32a228dc80e115) (out_n 3) (script(((OP_DATA 22 00141d7cd6c75c2e86f4cbf98eaed221b30bd9a0b928))23)) (witness_script( (3045022100f764287d3e99b1474da9bec7f7ed236d6c81e793b20c4b5aa1f3051b9a7daa63022016a198031d5554dbb855bdbe8534776a4be6958bd8d530dc001c32b828f6f0ab01 038262a6c6cec93c2d3ecd6c6072efea86d02ff8e3328bbd0242b20af3425990ac))) (sequence -1)))) (txout( ( (value 99987100) (script((OP_DUP OP_HASH160(OP_DATA 20 1d7cd6c75c2e86f4cbf98eaed221b30bd9a0b928)OP_EQUALVERIFY OP_CHECKSIG)25))))) (locktime 0) (size 108) (vsize 136) (witness(( (hash 6bf4e4dfb860cf0906f49c836700b130ac78cc391c72a0911c94cdec4dcb10ec) (marker 0) (flag 1) (size 110)))) )
This implies that for each type there are the
sexp_of_t conversion functions.
opam install bitcoinml
The odoc autogenerated documentation is available here: https://dakk.github.io/bitcoinml/
You can find some examples in the test/test.ml file.
Block parse/serialize: https://github.com/dakk/bitcoinml/blob/master/test/test.ml#L101
Block header parse/serialize: https://github.com/dakk/bitcoinml/blob/master/test/test.ml#L92
Merkleroot of transcation list: https://github.com/dakk/bitcoinml/blob/master/test/test.ml#L109
Address conversion: https://github.com/dakk/bitcoinml/blob/master/test/test.ml#L130
Transaction parse/serialize: https://github.com/dakk/bitcoinml/blob/master/test/test.ml#L55
Segwit transaction parse/serialize: https://github.com/dakk/bitcoinml/blob/master/test/test.ml#L64
Output script spendable by: https://github.com/dakk/bitcoinml/blob/master/test/test.ml#L50
Script parse: https://github.com/dakk/bitcoinml/blob/master/test/test.ml#L30
Script serialize: https://github.com/dakk/bitcoinml/blob/master/test/test.ml#L41
Copyright (c) 2016-2017 Davide Gessa Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Feel free to donate bitcoin to the developer: 13TRVwiqLMveg9aPAmZgcAix5ogKVgpe4T
with-test & >= "1.3.0"
with-test & >= "2.0.8"
with-test & >= "1.3.0"
>= "3.1.0" & < "4.0.0"