BSV.Transaction (bsv_sdk v1.1.0)

Copy Markdown View Source

Bitcoin SV transaction.

Summary

Functions

Append an input to the transaction.

Add an input from hex-encoded txid, vout, locking script, and satoshi amount.

Append an output to the transaction.

Compute the BIP-143 signature hash for the input at input_index using the given sighash flag.

Parse a transaction from raw binary. Returns {:ok, tx, remaining_bytes} on success.

Parse a transaction from a hex-encoded string.

Check if this is a coinbase transaction (null txid input with vout 0xFFFFFFFF).

Create a new empty transaction.

Compute the serialized size of the transaction in bytes.

Serialize the transaction to raw binary (wire format).

Serialize the transaction to a lowercase hex string.

Sum the satoshi values of all source outputs referenced by inputs.

Sum the satoshi values of all outputs.

Compute the 32-byte transaction ID (double-SHA256, internal byte order).

Compute the transaction ID as a hex string in display order (byte-reversed).

Compute the transaction ID as raw 32 bytes (internal byte order).

Types

t()

@type t() :: %BSV.Transaction{
  inputs: [BSV.Transaction.Input.t()],
  lock_time: non_neg_integer(),
  outputs: [BSV.Transaction.Output.t()],
  version: non_neg_integer()
}

Functions

add_input(tx, input)

@spec add_input(t(), BSV.Transaction.Input.t()) :: t()

Append an input to the transaction.

add_input_from(tx, prev_tx_id_hex, vout, prev_locking_script_hex, satoshis)

@spec add_input_from(
  t(),
  String.t(),
  non_neg_integer(),
  String.t(),
  non_neg_integer()
) ::
  {:ok, t()} | {:error, term()}

Add an input from hex-encoded txid, vout, locking script, and satoshi amount.

add_output(tx, output)

@spec add_output(t(), BSV.Transaction.Output.t()) :: t()

Append an output to the transaction.

calc_input_signature_hash(tx, input_index, sighash_flag)

@spec calc_input_signature_hash(t(), non_neg_integer(), non_neg_integer()) ::
  {:ok, <<_::256>>} | {:error, term()}

Compute the BIP-143 signature hash for the input at input_index using the given sighash flag.

from_binary(arg1)

@spec from_binary(binary()) :: {:ok, t(), binary()} | {:error, term()}

Parse a transaction from raw binary. Returns {:ok, tx, remaining_bytes} on success.

from_hex(hex)

@spec from_hex(String.t()) :: {:ok, t()} | {:error, term()}

Parse a transaction from a hex-encoded string.

is_coinbase?(arg1)

@spec is_coinbase?(t()) :: boolean()

Check if this is a coinbase transaction (null txid input with vout 0xFFFFFFFF).

new()

@spec new() :: t()

Create a new empty transaction.

size(tx)

@spec size(t()) :: non_neg_integer()

Compute the serialized size of the transaction in bytes.

to_binary(tx)

@spec to_binary(t()) :: binary()

Serialize the transaction to raw binary (wire format).

to_hex(tx)

@spec to_hex(t()) :: String.t()

Serialize the transaction to a lowercase hex string.

total_input_satoshis(transaction)

@spec total_input_satoshis(t()) :: {:ok, non_neg_integer()} | {:error, term()}

Sum the satoshi values of all source outputs referenced by inputs.

total_output_satoshis(transaction)

@spec total_output_satoshis(t()) :: non_neg_integer()

Sum the satoshi values of all outputs.

tx_id(tx)

@spec tx_id(t()) :: <<_::256>>

Compute the 32-byte transaction ID (double-SHA256, internal byte order).

tx_id_hex(tx)

@spec tx_id_hex(t()) :: String.t()

Compute the transaction ID as a hex string in display order (byte-reversed).

txid_binary(tx)

@spec txid_binary(t()) :: binary()

Compute the transaction ID as raw 32 bytes (internal byte order).