View Source BitcoinLib.Transaction.Encoder (BitcoinLib v0.4.2)

Can convert a Transaction into binary formats

Link to this section Summary

Functions

Specific encoding meant to generate Transaction ID's

Encodes a transaction in binary format from a structure

Link to this section Functions

Specific encoding meant to generate Transaction ID's

examples

Examples

iex> %BitcoinLib.Transaction{
...>   inputs: [
...>     %BitcoinLib.Transaction.Input{
...>       script_sig: nil,
...>       sequence: 0xFFFFFFFF,
...>       txid: "5e2383defe7efcbdc9fdd6dba55da148b206617bbb49e6bb93fce7bfbb459d44",
...>       vout: 1
...>     }
...>   ],
...>   outputs: [
...>     %BitcoinLib.Transaction.Output{
...>       script_pub_key: [
...>         %BitcoinLib.Script.Opcodes.Stack.Dup{},
...>         %BitcoinLib.Script.Opcodes.Crypto.Hash160{},
...>         %BitcoinLib.Script.Opcodes.Data{value: <<0xf86f0bc0a2232970ccdf4569815db500f1268361::160>>},
...>         %BitcoinLib.Script.Opcodes.BitwiseLogic.EqualVerify{},
...>         %BitcoinLib.Script.Opcodes.Crypto.CheckSig{}
...>       ],
...>       value: 129000000
...>     }
...>   ],
...>   locktime: 0,
...>   version: 1
...> }
...> |> BitcoinLib.Transaction.Encoder.for_txid()
<<0x0100000001449d45bbbfe7fc93bbe649bb7b6106b248a15da5dbd6fdc9bdfc7efede83235e0100000000ffffffff014062b007000000001976a914f86f0bc0a2232970ccdf4569815db500f126836188ac00000000::680>>
Link to this function

from_struct(transaction)

View Source
@spec from_struct(%BitcoinLib.Transaction{
  coinbase?: term(),
  id: term(),
  inputs: term(),
  locktime: term(),
  outputs: term(),
  segwit?: term(),
  version: term(),
  witness: term()
}) :: bitstring()

Encodes a transaction in binary format from a structure

examples

Examples

iex> %BitcoinLib.Transaction{
...>   inputs: [
...>     %BitcoinLib.Transaction.Input{
...>       script_sig: nil,
...>       sequence: 0xFFFFFFFF,
...>       txid: "5e2383defe7efcbdc9fdd6dba55da148b206617bbb49e6bb93fce7bfbb459d44",
...>       vout: 1
...>     }
...>   ],
...>   outputs: [
...>     %BitcoinLib.Transaction.Output{
...>       script_pub_key: [
...>         %BitcoinLib.Script.Opcodes.Stack.Dup{},
...>         %BitcoinLib.Script.Opcodes.Crypto.Hash160{},
...>         %BitcoinLib.Script.Opcodes.Data{value: <<0xf86f0bc0a2232970ccdf4569815db500f1268361::160>>},
...>         %BitcoinLib.Script.Opcodes.BitwiseLogic.EqualVerify{},
...>         %BitcoinLib.Script.Opcodes.Crypto.CheckSig{}
...>       ],
...>       value: 129000000
...>     }
...>   ],
...>   locktime: 0,
...>   version: 1
...> }
...> |> BitcoinLib.Transaction.Encoder.from_struct()
<<1, 0, 0, 0>> <> # version
<<1>> <>          # input_count
<<0x449d45bbbfe7fc93bbe649bb7b6106b248a15da5dbd6fdc9bdfc7efede83235e0100000000ffffffff::328>> <> # inputs
<<1>> <>          # output_count
<<0x4062b007000000001976a914f86f0bc0a2232970ccdf4569815db500f126836188ac::272>> <> # outputs
<<0, 0, 0, 0>>    # locktime