libitx / shapeshifter

Shapeshifter is an Elixir library for switching between Bitcoin transaction formats.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shapeshifter

Shapeshifter lets you quickly and simply switch between Bitcoin transaction formats

Hex.pm GitHub Build Status

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.

Sponsors

Supported by:

Coingeek

Your sponsorship will help us continue to release and maintain software that Bitcoin businesses and developers depend on.

Installation

The package can be installed by adding shapeshifter to your list of dependencies in mix.exs:

def deps do
  [
    {:shapeshifter, "~> 0.2"}
  ]
end

Usage

Using 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.

License

Shapeshifter is open source and released under the Apache-2 License.

© Copyright 2020-2021 Chronos Labs Ltd.

About

Shapeshifter is an Elixir library for switching between Bitcoin transaction formats.

License:Apache License 2.0


Languages

Language:Elixir 100.0%