Shapeshifter is an Elixir library for switching between Bitcoin transaction formats. Quickly and simply shift between raw tx binaries, BSV.Tx structs, and TXO and BOB transaction formats.
Supported by:
Your sponsorship will help us continue to release and maintain software that Bitcoin businesses and developers depend on.
The package can be installed by adding shapeshifter to your list of dependencies in mix.exs:
def deps do [ {:shapeshifter, "~> 0.2"} ] endUsing Shapeshifter couldn't be simpler. Under the hood Shapeshifter uses pattern matching to automatically determine the source format, so all you need to do is pass a transaction object of any format to the appropriate function of the format you want to convert to (from: to_raw/2, to_tx/1, to_txo/1 or to_bob/1).
# Convert to raw tx Shapeshifter.to_raw(tx) # => <<1, 0, 0, 0, ...>> # Convert to raw tx with hex encoding Shapeshifter.to_raw(tx, encoding: :hex) # => "01000000..." # Convert to BSV.Tx struct Shapeshifter.to_tx(tx) # => %BSV.Tx{} # Convert to TXO map Shapeshifter.to_txo(tx) # => %{"in" => [...], "out" => [...], ...} # Convert to BOB map Shapeshifter.to_bob(tx) # => %{"in" => [...], "out" => [...], ...}For more advanced use, Shapeshifter can also be used to convert individual inputs and outputs between the supported formats.
For more examples, refer to the full documentation.
Shapeshifter is open source and released under the Apache-2 License.
© Copyright 2020-2021 Chronos Labs Ltd.
