View Source BitcoinLib.Transaction.Input (BitcoinLib v0.4.3)

Based on https://learnmeabitcoin.com/technical/input

Link to this section Summary

Functions

Encodes an input into a bitstring

Extracts a transaction input from a bitstring

Replaces a potential signature in the input with []

Link to this section Functions

@spec encode(%BitcoinLib.Transaction.Input{
  script_sig: term(),
  sequence: term(),
  txid: term(),
  vout: term()
}) :: bitstring()

Encodes an input into a bitstring

examples

Examples

iex> %BitcoinLib.Transaction.Input{
...>   sequence: 0xFFFFFFFF,
...>   txid: "5e2383defe7efcbdc9fdd6dba55da148b206617bbb49e6bb93fce7bfbb459d44",
...>   vout: 1
...> } |> BitcoinLib.Transaction.Input.encode()
<<0x449d45bbbfe7fc93bbe649bb7b6106b248a15da5dbd6fdc9bdfc7efede83235e0100000000ffffffff::328>>
Link to this function

extract_from(arg, is_coinbase? \\ false)

View Source
@spec extract_from(binary(), bool()) ::
  {:ok,
   %BitcoinLib.Transaction.Input{
     script_sig: term(),
     sequence: term(),
     txid: term(),
     vout: term()
   }, bitstring()}
  | {:error, binary()}

Extracts a transaction input from a bitstring

examples

Examples

iex> <<0x7b1eabe0209b1fe794124575ef807057c77ada2138ae4fa8d6c4de0398a14f3f0000000000ffffffff01f0ca052a010000001976a914cbc20a7664f2f69e5355aa427045bc15e7c6c77288ac00000000::640>>
...> |> BitcoinLib.Transaction.Input.extract_from(false)
{
  :ok,
  %BitcoinLib.Transaction.Input{
    txid: "3f4fa19803dec4d6a84fae3821da7ac7577080ef75451294e71f9b20e0ab1e7b",
    vout: 0,
    script_sig: [],
    sequence: 4294967295
  },
  <<0x01f0ca052a010000001976a914cbc20a7664f2f69e5355aa427045bc15e7c6c77288ac00000000::312>>
}
@spec strip_signature(%BitcoinLib.Transaction.Input{
  script_sig: term(),
  sequence: term(),
  txid: term(),
  vout: term()
}) :: %BitcoinLib.Transaction.Input{
  script_sig: term(),
  sequence: term(),
  txid: term(),
  vout: term()
}

Replaces a potential signature in the input with []

examples

Examples

iex> %BitcoinLib.Transaction.Input{ ...> txid: "77541aeb3c4dac9260b68f74f44c973081a9d4cb2ebe8038b2d70faa201b6bdb", ...> vout: 1, ...> script_sig: [ ...> %BitcoinLib.Script.Opcodes.Data{ ...> value: <<0x001479091972186C449EB1DED22B78E40D009BDF0089::176>> ...> } ...> ], ...> sequence: 4_294_967_294 ...> } ...> |> BitcoinLib.Transaction.Input.strip_signature %BitcoinLib.Transaction.Input{

txid: "77541aeb3c4dac9260b68f74f44c973081a9d4cb2ebe8038b2d70faa201b6bdb",
vout: 1,
script_sig: <<>>,
sequence: 4_294_967_294

}