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

Transform binaries into Transactions

Link to this section Summary

Functions

Converts a bitstring into a %Transaction{} and the remaining unused data

Link to this section Functions

Link to this function

to_struct(encoded_transaction, is_coinbase? \\ false)

View Source
@spec to_struct(bitstring(), boolean()) ::
  {:ok,
   %BitcoinLib.Transaction{
     coinbase?: term(),
     id: term(),
     inputs: term(),
     locktime: term(),
     outputs: term(),
     segwit?: term(),
     version: term(),
     witness: term()
   }, bitstring()}
  | {:error, binary()}

Converts a bitstring into a %Transaction{} and the remaining unused data

examples

Examples

iex> <<0x01000000017b1eabe0209b1fe794124575ef807057c77ada2138ae4fa8d6c4de0398a14f3f0000000000ffffffff01f0ca052a010000001976a914cbc20a7664f2f69e5355aa427045bc15e7c6c77288ac92040000::680>>
...> |> BitcoinLib.Transaction.Decoder.to_struct(false)
{
  :ok,
  %BitcoinLib.Transaction{
    version: 1,
    inputs: [
      %BitcoinLib.Transaction.Input{
        txid: "3f4fa19803dec4d6a84fae3821da7ac7577080ef75451294e71f9b20e0ab1e7b",
        vout: 0,
        script_sig: [],
        sequence: 4294967295
      }
    ],
    outputs: [
      %BitcoinLib.Transaction.Output{
        value: 4999990000,
        script_pub_key: [
          %BitcoinLib.Script.Opcodes.Stack.Dup{},
          %BitcoinLib.Script.Opcodes.Crypto.Hash160{},
          %BitcoinLib.Script.Opcodes.Data{value: <<0xcbc20a7664f2f69e5355aa427045bc15e7c6c772::160>>},
          %BitcoinLib.Script.Opcodes.BitwiseLogic.EqualVerify{},
          %BitcoinLib.Script.Opcodes.Crypto.CheckSig{script: <<0x76a914cbc20a7664f2f69e5355aa427045bc15e7c6c77288ac::200>>}
        ]
      }
    ],
    locktime: 1170,
    segwit?: false
  },
  <<>>
}