bsv_rpc v1.0.0-alpha3 BsvRpc.TransactionOutput View Source
Functions for Bitcoin transaction outputs manipulation.
Link to this section Summary
Functions
Creates transaction outputs from a binary blob.
Creates a single transaction output from a binary blob.
Creates a data (OP_RETURN) output.
Gets the script pubKey to pay to the address.
Gets the binary representation of the transaction output.
Gets the output value in Bitcoins.
Link to this section Types
t()
View Sourcet() :: %BsvRpc.TransactionOutput{ script_pubkey: binary(), value: non_neg_integer() }
A Bitcoin transaction output.
Link to this section Functions
create(tx_out_blob, output_count)
View Sourcecreate(binary(), non_neg_integer()) :: {[BsvRpc.TransactionOutput.t()], binary()}
Creates transaction outputs from a binary blob.
Blob can include multiple outputs.
Returns a tuple with the list of outputs and the remaining of the binary blob.
Arguments
tx_out_blob
- Binary blob to parse transaction outputs from.output_count
- Number of transactions outputs to parse.
Example
iex> tx_out = "D1CA5065020000001976A91437E5CF12EDEC76CC89DA3A731940A1F1932D853F88AC" <> "9504D702000000001976A914B9B9EDB47415C3D6980FEC683C60B8B74754DF9988AC" <> "AABB" iex> tx_out |> Base.decode16!() |> BsvRpc.TransactionOutput.create(2) {[
%BsvRpc.TransactionOutput{
script_pubkey: <<118, 169, 20, 55, 229, 207, 18, 237, 236, 118, 204, 137, 218,
58, 115, 25, 64, 161, 241, 147, 45, 133, 63, 136, 172>>,
value: 10289728209
},
%BsvRpc.TransactionOutput{
script_pubkey: <<118, 169, 20, 185, 185, 237, 180, 116, 21, 195, 214, 152,
15, 236, 104, 60, 96, 184, 183, 71, 84, 223, 153, 136, 172>>,
value: 47645845
}
], <<0xAA, 0xBB>>}
create_single(tx_out_blob)
View Sourcecreate_single(binary()) :: BsvRpc.TransactionOutput.t()
Creates a single transaction output from a binary blob.
Raises MatchError
if the binary includes any more data after the first transaction output.
Example
iex> tx_out = "D1CA5065020000001976A91437E5CF12EDEC76CC89DA3A731940A1F1932D853F88AC" iex> tx_out|> Base.decode16!() |> BsvRpc.TransactionOutput.create_single() %BsvRpc.TransactionOutput{
script_pubkey: <<118, 169, 20, 55, 229, 207, 18, 237, 236, 118, 204, 137, 218,
58, 115, 25, 64, 161, 241, 147, 45, 133, 63, 136, 172>>,
value: 10289728209
} iex> tx_out = tx_out <> "FF" iex> tx_out |> Base.decode16!() |> BsvRpc.TransactionOutput.create_single() ** (MatchError) no match of right hand side value: {[%BsvRpc.TransactionOutput{script_pubkey: <<118, 169, 20, 55, 229, 207, 18, 237, 236, 118, 204, 137, 218, 58, 115, 25, 64, 161, 241, 147, 45, 133, 63, 136, 172>>, value: 10289728209}], <<255>>}
get_data_output(content)
View Sourceget_data_output([String.t() | binary()]) :: BsvRpc.TransactionOutput.t()
Creates a data (OP_RETURN) output.
Examples
iex> BsvRpc.TransactionOutput.get_data_output(["foo", "barbaz", <<0xFF, 0xFF>>]) %BsvRpc.TransactionOutput{
value: 0,
script_pubkey: <<0x00, 0x6A, 3, "foo"::binary, 6, "barbaz"::binary, 2, 0xFF, 0xFF>>
}
Gets the script pubKey to pay to the address.
Examples
iex> {:ok, a} = BsvRpc.Address.create("1KqbPy3xFdHuL6gmWLgzhVz1tUMUgY5xWe") iex> BsvRpc.TransactionOutput.p2pkh_script_pubkey(a) |> Base.encode16() "76A914CEA2F14D4ADB6CCDD185BA6BA45DF49597E409C488AC"
to_binary(tx_out)
View Sourceto_binary(BsvRpc.TransactionOutput.t()) :: binary()
Gets the binary representation of the transaction output.
Examples
iex> tx_out = "D1CA5065020000001976A91437E5CF12EDEC76CC89DA3A731940A1F1932D853F88AC" iex> t = tx_out |> Base.decode16!() |> BsvRpc.TransactionOutput.create_single() iex> t |> BsvRpc.TransactionOutput.to_binary() |> Base.encode16() "D1CA5065020000001976A91437E5CF12EDEC76CC89DA3A731940A1F1932D853F88AC"
Gets the output value in Bitcoins.
Example
iex> tx_out = %BsvRpc.TransactionOutput{script_pubkey: <<0x00, 0x00>>, value: 100_000_000} iex> BsvRpc.TransactionOutput.value(tx_out) 1.0
iex> tx_out = %BsvRpc.TransactionOutput{script_pubkey: <<0x00, 0x00>>, value: 12_345_678_999} iex> BsvRpc.TransactionOutput.value(tx_out) 123.45678999