package bitcoinml

  1. Overview
  2. Docs
Bitcoin data-structures library for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

0.3.1.zip
sha256=5399a903489ff80892c57e5e26b301926dccd7017f4cc71cdfcfa10a706ce4c8
md5=db0f5550258f1e5f9a6e8dbe64d352ab

Description

Bitcoin data-structures library for OCaml. Modules documentation is available at https://dakk.github.io/bitcoinml/

Published: 15 Sep 2017

README

BitcoinML

Bitcoin data-structures library for OCaml.

Features

Bitcoinml provides support for the following data-structures:

  • Address (with also bech32 addresses)

  • Block

  • Block_lazy (lazy block evaluation)

  • Hash

  • Merkleroot

  • Script (script execution, common pattern recognizer)

  • Tx (In, Out, Witness)

  • Varint (CompactSize)

  • Params (network parameters for BTC, XTN and BCH)

Segwit

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.

Sexp serialization

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 t_of_sexp and sexp_of_t conversion functions.

Installation

opam install bitcoinml

Documentation

The odoc autogenerated documentation is available here: https://dakk.github.io/bitcoinml/

Examples

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

License

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.

Donations

Feel free to donate bitcoin to the developer: 13TRVwiqLMveg9aPAmZgcAix5ogKVgpe4T

Dependencies (11)

  1. stdint >= "0.3.0-0"
  2. cryptokit >= "1.11"
  3. bignum >= "v0.9.0"
  4. stdio >= "v0.9.0"
  5. bitstring >= "2.1.0"
  6. ppx_bitstring >= "2.0.0"
  7. ppx_jane >= "v0.9.0"
  8. configurator build & >= "v0.9.1"
  9. base build & >= "v0.9.2" & < "v0.11"
  10. jbuilder >= "1.0+beta11"
  11. ocaml

Dev Dependencies (3)

  1. odoc with-test & >= "1.1.1"
  2. ounit with-test & >= "2.0.0"
  3. hex with-test & >= "1.1.1"

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.