View Source BitcoinLib.Transaction.Spec (BitcoinLib v0.2.0-pre3)
A simplified version of a %BitcoinLib.Transaction that can be filled with human readable formats
Link to this section Summary
Functions
Adds a human readable input into a transaction spec
Adds a human readable output into a transaction spec
With the help of a privat key, transforms a transaction into a signed binary that can be sent on the network so funds can be spent
Link to this section Functions
@spec add_input(%BitcoinLib.Transaction.Spec{inputs: term(), outputs: term()}, list()) :: %BitcoinLib.Transaction.Spec{inputs: term(), outputs: term()}
Adds a human readable input into a transaction spec
examples
Examples
iex> transaction_spec = %BitcoinLib.Transaction.Spec{} ...> transaction_spec ...> |> BitcoinLib.Transaction.Spec.add_input( ...> txid: "6925062befcf8aafae78de879fec2535ec016e251c19b1c0792993258a6fda26", ...> vout: 1, ...> redeem_script: "76a914c39658833d83f2299416e697af2fb95a998853d388ac" ...> ) %BitcoinLib.Transaction.Spec{
inputs: [
%BitcoinLib.Transaction.Spec.Input{
txid: "6925062befcf8aafae78de879fec2535ec016e251c19b1c0792993258a6fda26",
vout: 1,
redeem_script: [
%BitcoinLib.Script.Opcodes.Stack.Dup{},
%BitcoinLib.Script.Opcodes.Crypto.Hash160{},
%BitcoinLib.Script.Opcodes.Data{value: <<0xc39658833d83f2299416e697af2fb95a998853d3::160>>},
%BitcoinLib.Script.Opcodes.BitwiseLogic.EqualVerify{},
%BitcoinLib.Script.Opcodes.Crypto.CheckSig{script: <<0x76a914c39658833d83f2299416e697af2fb95a998853d388ac::200>>}
]
}
],
outputs: []
}
@spec add_output( %BitcoinLib.Transaction.Spec{inputs: term(), outputs: term()}, binary() | list(), integer() ) :: %BitcoinLib.Transaction.Spec{inputs: term(), outputs: term()}
Adds a human readable output into a transaction spec
examples
Examples
iex> p2pkh_script = BitcoinLib.Script.Types.P2pkh.create(<<0xad6a62e2d23d1c060897cd0cc79c42dad715e4c7::160>>) ...> amount = 1000 ...> transaction_spec = %BitcoinLib.Transaction.Spec{} ...> transaction_spec ...> |> BitcoinLib.Transaction.Spec.add_output(p2pkh_script, amount) %BitcoinLib.Transaction.Spec{
inputs: [],
outputs: [%BitcoinLib.Transaction.Spec.Output{
script_pub_key: [
%BitcoinLib.Script.Opcodes.Stack.Dup{},
%BitcoinLib.Script.Opcodes.Crypto.Hash160{},
%BitcoinLib.Script.Opcodes.Data{value: <<0xad6a62e2d23d1c060897cd0cc79c42dad715e4c7::160>>},
%BitcoinLib.Script.Opcodes.BitwiseLogic.EqualVerify{},
%BitcoinLib.Script.Opcodes.Crypto.CheckSig{}
],
value: 1000
}
]
}
@spec sign_and_encode( %BitcoinLib.Transaction.Spec{inputs: term(), outputs: term()}, %BitcoinLib.Key.PrivateKey{ chain_code: term(), depth: term(), fingerprint: term(), index: term(), key: term(), parent_fingerprint: term() } ) :: binary()
With the help of a privat key, transforms a transaction into a signed binary that can be sent on the network so funds can be spent
examples
Examples
iex> private_key = BitcoinLib.Key.PrivateKey.from_seed_phrase( ...> "rally celery split order almost twenty ignore record legend learn chaos decade" ...> ) ...>%BitcoinLib.Transaction.Spec{ ...> inputs: [ ...> %BitcoinLib.Transaction.Spec.Input{ ...> txid: "6925062befcf8aafae78de879fec2535ec016e251c19b1c0792993258a6fda26", ...> vout: 1, ...> redeem_script: "76a914c39658833d83f2299416e697af2fb95a998853d388ac" ...> } ...> ], ...> outputs: [%BitcoinLib.Transaction.Spec.Output{ ...> script_pub_key: [ ...> %BitcoinLib.Script.Opcodes.Stack.Dup{}, ...> %BitcoinLib.Script.Opcodes.Crypto.Hash160{}, ...> %BitcoinLib.Script.Opcodes.Data{value: <<0xad6a62e2d23d1c060897cd0cc79c42dad715e4c7::160>>}, ...> %BitcoinLib.Script.Opcodes.BitwiseLogic.EqualVerify{}, ...> %BitcoinLib.Script.Opcodes.Crypto.CheckSig{} ...> ], ...> value: 1000 ...> } ...> ] ...>} ...> |> BitcoinLib.Transaction.Spec.sign_and_encode(private_key) "010000000126da6f8a25932979c0b1191c256e01ec3525ec9f87de78aeaf8acfef2b062569010000006a47304402203d219d9ae0cb87ff298ea0d54757abbb8a8a07c724b0d3979476f572178a9c2402203b026acc059654813b5ad6f5ad24422cbc4b92a76193f5765c8d77cb5ad3ec4f012102702ded1cca9816fa1a94787ffc6f3ace62cd3b63164f76d227d0935a33ee48c3ffffffff01e8030000000000001976a914ad6a62e2d23d1c060897cd0cc79c42dad715e4c788ac00000000"