Transaction Functions
-
int wally_tx_witness_stack_init_alloc(size_t allocation_len, struct wally_tx_witness_stack **output)
Allocate and initialize a new witness stack.
- Parameters:
allocation_len – The number of items to pre-allocate space for.
output – Destination for the resulting witness stack.
- Returns:
See Error Codes
-
int wally_tx_witness_stack_clone_alloc(const struct wally_tx_witness_stack *stack, struct wally_tx_witness_stack **output)
Create a copy of a witness stack.
- Parameters:
stack – The witness stack to copy.
output – Destination for the resulting copy.
- Returns:
See Error Codes
-
int wally_tx_witness_stack_get_num_items(const struct wally_tx_witness_stack *stack, size_t *written)
Return the number of witness items in a witness stack.
- Parameters:
stack – The witness stack to get the number of items from.
written – Destination for the number of items.
- Returns:
See Error Codes
-
int wally_tx_witness_stack_add(struct wally_tx_witness_stack *stack, const unsigned char *witness, size_t witness_len)
Add a witness to a witness stack.
- Parameters:
stack – The witness stack to add to.
witness – The witness data to add to the stack.
witness_len – Length of
witness
in bytes.
- Returns:
See Error Codes
-
int wally_tx_witness_stack_add_dummy(struct wally_tx_witness_stack *stack, uint32_t flags)
Add a dummy witness item to a witness stack.
- Parameters:
stack – The witness stack to add to.
flags –
WALLY_TX_DUMMY_
Flags indicating the type of dummy to add.
- Returns:
See Error Codes
-
int wally_tx_witness_stack_set(struct wally_tx_witness_stack *stack, size_t index, const unsigned char *witness, size_t witness_len)
Set a witness item to a witness stack.
- Parameters:
stack – The witness stack to add to.
index – Index of the item to set. The stack will grow if needed to this many items.
witness – The witness data to add to the stack.
witness_len – Length of
witness
in bytes.
- Returns:
See Error Codes
-
int wally_tx_witness_stack_set_dummy(struct wally_tx_witness_stack *stack, size_t index, uint32_t flags)
Set a dummy witness item to a witness stack.
- Parameters:
stack – The witness stack to add to.
index – Index of the item to set. The stack will grow if needed to this many items.
flags –
WALLY_TX_DUMMY_
Flags indicating the type of dummy to set.
- Returns:
See Error Codes
-
int wally_tx_witness_stack_from_bytes(const unsigned char *bytes, size_t bytes_len, struct wally_tx_witness_stack **output)
Create a new witness stack from its BIP 144 serialization.
- Parameters:
bytes – Bytes to create the witness stack from.
bytes_len – Length of
bytes
in bytes.output – Destination for the resulting witness stack.
- Returns:
See Error Codes
-
int wally_tx_witness_stack_get_length(const struct wally_tx_witness_stack *stack, size_t *written)
Return the length of a witness stacks BIP 144 serialization.
- Parameters:
stack – The witness stack to find the serialized length of.
written – Destination for the length of the serialized bytes.
- Returns:
See Error Codes
-
int wally_tx_witness_stack_to_bytes(const struct wally_tx_witness_stack *stack, unsigned char *bytes_out, size_t len, size_t *written)
Serialize a witness stack to its BIP 144 serialization.
- Parameters:
stack – The witness stack to serialize.
bytes_out – Destination for the serialized witness stack.
len – Size of
bytes_out
in bytes.written – Destination for the length of the serialized witness stack.
- Returns:
-
int wally_tx_witness_stack_free(struct wally_tx_witness_stack *stack)
Free a transaction witness stack allocated by
wally_tx_witness_stack_init_alloc
.- Parameters:
stack – The transaction witness stack to free.
- Returns:
See Error Codes
-
int wally_tx_input_init_alloc(const unsigned char *txhash, size_t txhash_len, uint32_t utxo_index, uint32_t sequence, const unsigned char *script, size_t script_len, const struct wally_tx_witness_stack *witness, struct wally_tx_input **output)
Allocate and initialize a new transaction input.
- Parameters:
txhash – The transaction hash of the transaction this input comes from.
txhash_len – Size of
txhash
in bytes. Must beWALLY_TXHASH_LEN
.utxo_index – The zero-based index of the transaction output in
txhash
that this input comes from.sequence – The sequence number for the input.
script – The scriptSig for the input.
script_len – Size of
script
in bytes.witness – The witness stack for the input, or NULL if no witness is present.
output – Destination for the resulting transaction input.
- Returns:
See Error Codes
-
int wally_tx_input_clone_alloc(const struct wally_tx_input *tx_input_in, struct wally_tx_input **input)
Create a new copy of a transaction input.
- Parameters:
tx_input_in – The transaction input to clone.
input – Destination for the resulting transaction input copy.
- Returns:
See Error Codes
-
int wally_tx_input_clone(const struct wally_tx_input *tx_input_in, struct wally_tx_input *input)
Create a new copy of a transaction input in place.
- Parameters:
tx_input_in – The transaction input to clone.
input – Destination for the resulting transaction input copy.
Note
input
is overwritten in place, and not cleared first.- Returns:
See Error Codes
-
int wally_tx_input_free(struct wally_tx_input *input)
Free a transaction input allocated by
wally_tx_input_init_alloc
.- Parameters:
input – The transaction input to free.
- Returns:
See Error Codes
-
int wally_tx_output_init(uint64_t satoshi, const unsigned char *script, size_t script_len, struct wally_tx_output *output)
Initialize a new transaction output.
- Parameters:
satoshi – The amount of the output in satoshi.
script – The scriptPubkey for the output.
script_len – Size of
script
in bytes.output – Transaction output to initialize.
- Returns:
See Error Codes
-
int wally_tx_output_init_alloc(uint64_t satoshi, const unsigned char *script, size_t script_len, struct wally_tx_output **output)
Allocate and initialize a new transaction output.
- Parameters:
satoshi – The amount of the output in satoshi.
script – The scriptPubkey for the output.
script_len – Size of
script
in bytes.output – Destination for the resulting transaction output.
- Returns:
See Error Codes
-
int wally_tx_output_clone_alloc(const struct wally_tx_output *tx_output_in, struct wally_tx_output **output)
Create a new copy of a transaction output.
- Parameters:
tx_output_in – The transaction output to clone.
output – Destination for the resulting transaction output copy.
- Returns:
See Error Codes
-
int wally_tx_output_clone(const struct wally_tx_output *tx_output_in, struct wally_tx_output *output)
Create a new copy of a transaction output in place.
- Parameters:
tx_output_in – The transaction output to clone.
output – Destination for the resulting transaction output copy.
Note
output
is overwritten in place, and not cleared first.- Returns:
See Error Codes
-
int wally_tx_output_free(struct wally_tx_output *output)
Free a transaction output allocated by
wally_tx_output_init_alloc
.- Parameters:
output – The transaction output to free.
- Returns:
See Error Codes
-
int wally_tx_init_alloc(uint32_t version, uint32_t locktime, size_t inputs_allocation_len, size_t outputs_allocation_len, struct wally_tx **output)
Allocate and initialize a new transaction.
- Parameters:
version – The version of the transaction.
locktime – The locktime of the transaction.
inputs_allocation_len – The number of inputs to pre-allocate space for.
outputs_allocation_len – The number of outputs to pre-allocate space for.
output – Destination for the resulting transaction.
- Returns:
See Error Codes
-
int wally_tx_clone_alloc(const struct wally_tx *tx, uint32_t flags, struct wally_tx **output)
Create a new copy of a transaction.
- Parameters:
tx – The transaction to clone.
flags – Transaction cloning flags controlling new transaction creation.
output – Destination for the resulting transaction copy.
- Returns:
See Error Codes
-
int wally_tx_add_input(struct wally_tx *tx, const struct wally_tx_input *input)
Add a transaction input to a transaction.
- Parameters:
tx – The transaction to add the input to.
input – The transaction input to add to
tx
.
- Returns:
See Error Codes
-
int wally_tx_add_input_at(struct wally_tx *tx, uint32_t index, const struct wally_tx_input *input)
Add a transaction input to a transaction at a given position.
- Parameters:
tx – The transaction to add the input to.
index – The zero-based index of the position to add the input at.
input – The transaction input to add to
tx
.
- Returns:
See Error Codes
-
int wally_tx_add_raw_input(struct wally_tx *tx, const unsigned char *txhash, size_t txhash_len, uint32_t utxo_index, uint32_t sequence, const unsigned char *script, size_t script_len, const struct wally_tx_witness_stack *witness, uint32_t flags)
Add a transaction input to a transaction.
- Parameters:
tx – The transaction to add the input to.
txhash – The transaction hash of the transaction this input comes from.
txhash_len – Size of
txhash
in bytes. Must beWALLY_TXHASH_LEN
.utxo_index – The zero-based index of the transaction output in
txhash
that this input comes from.sequence – The sequence number for the input.
script – The scriptSig for the input.
script_len – Size of
script
in bytes.witness – The witness stack for the input, or NULL if no witness is present.
flags – Flags controlling input creation. Must be 0.
- Returns:
See Error Codes
-
int wally_tx_add_raw_input_at(struct wally_tx *tx, uint32_t index, const unsigned char *txhash, size_t txhash_len, uint32_t utxo_index, uint32_t sequence, const unsigned char *script, size_t script_len, const struct wally_tx_witness_stack *witness, uint32_t flags)
Add a transaction input to a transaction in a given position.
- Parameters:
tx – The transaction to add the input to.
index – The zero-based index of the position to add the input at.
txhash – The transaction hash of the transaction this input comes from.
txhash_len – Size of
txhash
in bytes. Must beWALLY_TXHASH_LEN
.utxo_index – The zero-based index of the transaction output in
txhash
that this input comes from.sequence – The sequence number for the input.
script – The scriptSig for the input.
script_len – Size of
script
in bytes.witness – The witness stack for the input, or NULL if no witness is present.
flags – Flags controlling input creation. Must be 0.
- Returns:
See Error Codes
-
int wally_tx_remove_input(struct wally_tx *tx, size_t index)
Remove a transaction input from a transaction.
- Parameters:
tx – The transaction to remove the input from.
index – The zero-based index of the input to remove.
- Returns:
See Error Codes
-
int wally_tx_set_input_script(const struct wally_tx *tx, size_t index, const unsigned char *script, size_t script_len)
Set the scriptsig for an input in a transaction.
- Parameters:
tx – The transaction to operate on.
index – The zero-based index of the input to set the script on.
script – The scriptSig for the input.
script_len – Size of
script
in bytes.
- Returns:
See Error Codes
-
int wally_tx_set_input_witness(const struct wally_tx *tx, size_t index, const struct wally_tx_witness_stack *stack)
Set the witness stack for an input in a transaction.
- Parameters:
tx – The transaction to operate on.
index – The zero-based index of the input to set the witness stack on.
stack – The transaction witness stack to set.
- Returns:
See Error Codes
-
int wally_tx_add_output(struct wally_tx *tx, const struct wally_tx_output *output)
Add a transaction output to a transaction.
- Parameters:
tx – The transaction to add the output to.
output – The transaction output to add to
tx
.
- Returns:
See Error Codes
-
int wally_tx_add_output_at(struct wally_tx *tx, uint32_t index, const struct wally_tx_output *output)
Add a transaction output to a transaction at a given position.
- Parameters:
tx – The transaction to add the output to.
index – The zero-based index of the position to add the output at.
output – The transaction output to add to
tx
.
- Returns:
See Error Codes
-
int wally_tx_add_raw_output(struct wally_tx *tx, uint64_t satoshi, const unsigned char *script, size_t script_len, uint32_t flags)
Add a transaction output to a transaction.
- Parameters:
tx – The transaction to add the output to.
satoshi – The amount of the output in satoshi.
script – The scriptPubkey for the output.
script_len – Size of
script
in bytes.flags – Flags controlling output creation. Must be 0.
- Returns:
See Error Codes
-
int wally_tx_add_raw_output_at(struct wally_tx *tx, uint32_t index, uint64_t satoshi, const unsigned char *script, size_t script_len, uint32_t flags)
Add a transaction output to a transaction at a given position.
- Parameters:
tx – The transaction to add the output to.
index – The zero-based index of the position to add the output at.
satoshi – The amount of the output in satoshi.
script – The scriptPubkey for the output.
script_len – Size of
script
in bytes.flags – Flags controlling output creation. Must be 0.
- Returns:
See Error Codes
-
int wally_tx_remove_output(struct wally_tx *tx, size_t index)
Remove a transaction output from a transaction.
- Parameters:
tx – The transaction to remove the output from.
index – The zero-based index of the output to remove.
- Returns:
See Error Codes
-
int wally_tx_get_witness_count(const struct wally_tx *tx, size_t *written)
Get the number of inputs in a transaction that have witness data.
- Parameters:
tx – The transaction to get the witnesses count from.
written – Destination for the number of witness-containing inputs.
- Returns:
See Error Codes
-
int wally_tx_free(struct wally_tx *tx)
Free a transaction allocated by
wally_tx_init_alloc
.- Parameters:
tx – The transaction to free.
- Returns:
See Error Codes
-
int wally_tx_get_txid(const struct wally_tx *tx, unsigned char *bytes_out, size_t len)
Return the txid of a transaction.
- Parameters:
tx – The transaction to compute the txid of.
bytes_out – Destination for the txid.
len – Size of
bytes_out
. Must beWALLY_TXHASH_LEN
.
Note
The txid is expensive to compute.
- Returns:
See Error Codes
-
int wally_get_hash_prevouts(const unsigned char *txhashes, size_t txhashes_len, const uint32_t *utxo_indices, size_t num_utxo_indices, unsigned char *bytes_out, size_t len)
Calculate the BIP 143 hashPrevouts of a list of input txids and output indices.
- Parameters:
txhashes – The input txids to compute the hash from.
txhashes_len – Length of
txhashes
in bytes. Must be a multiple ofWALLY_TXHASH_LEN
.utxo_indices – The output indices of the txids in
txhashes
.num_utxo_indices – The number of output indices in
utxo_indices
. You must pass one index for every txhash intxhashes
.bytes_out – Destination for the hashPrevouts bytes.
len – Size of
bytes_out
. Must beSHA256_LEN
.
- Returns:
See Error Codes
-
int wally_tx_get_hash_prevouts(const struct wally_tx *tx, size_t index, size_t num_inputs, unsigned char *bytes_out, size_t len)
Return the BIP 143 hashPrevouts of a transaction.
- Parameters:
tx – The transaction to compute the hashPrevouts of.
index – The zero-based index of the input to start hashing from. Pass 0 to start from the first input.
num_inputs – The number of inputs to hash starting from the first. If
index
is given as 0, you can pass 0xffffffff to use all inputs.bytes_out – Destination for the hashPrevouts bytes.
len – Size of
bytes_out
. Must beSHA256_LEN
.
Note
The hash is computed without reference to any sighash flags, and so will not match BIP143 for
WALLY_SIGHASH_ANYONECANPAY
.- Returns:
See Error Codes
-
int wally_tx_get_length(const struct wally_tx *tx, uint32_t flags, size_t *written)
Return the length of transaction once serialized into bytes.
- Parameters:
tx – The transaction to find the serialized length of.
flags –
WALLY_TX_FLAG_
Flags controlling serialization options.written – Destination for the length of the serialized bytes.
- Returns:
See Error Codes
-
int wally_tx_from_bytes(const unsigned char *bytes, size_t bytes_len, uint32_t flags, struct wally_tx **output)
Create a transaction from its serialized bytes.
- Parameters:
bytes – Bytes to create the transaction from.
bytes_len – Length of
bytes
in bytes.flags –
WALLY_TX_FLAG_
Flags controlling serialization options.output – Destination for the resulting transaction.
- Returns:
See Error Codes
-
int wally_tx_from_hex(const char *hex, uint32_t flags, struct wally_tx **output)
Create a transaction from its serialized bytes in hexadecimal.
- Parameters:
hex – Hexadecimal string containing the transaction.
flags –
WALLY_TX_FLAG_
Flags controlling serialization options.output – Destination for the resulting transaction.
- Returns:
See Error Codes
-
int wally_tx_to_bytes(const struct wally_tx *tx, uint32_t flags, unsigned char *bytes_out, size_t len, size_t *written)
Serialize a transaction to bytes.
- Parameters:
tx – The transaction to serialize.
flags –
WALLY_TX_FLAG_
Flags controlling serialization options.bytes_out – Destination for the serialized transaction.
len – Size of
bytes_out
in bytes.written – Destination for the length of the serialized transaction.
- Returns:
-
int wally_tx_to_hex(const struct wally_tx *tx, uint32_t flags, char **output)
Serialize a transaction to hex.
- Parameters:
tx – The transaction to serialize.
flags –
WALLY_TX_FLAG_
Flags controlling serialization options.output – Destination for the resulting hexadecimal string.
Note
The string returned should be freed using
wally_free_string
.- Returns:
See Error Codes
-
int wally_tx_get_weight(const struct wally_tx *tx, size_t *written)
Get the weight of a transaction.
- Parameters:
tx – The transaction to get the weight of.
written – Destination for the weight.
- Returns:
See Error Codes
-
int wally_tx_get_vsize(const struct wally_tx *tx, size_t *written)
Get the virtual size of a transaction.
- Parameters:
tx – The transaction to get the virtual size of.
written – Destination for the virtual size.
- Returns:
See Error Codes
-
int wally_tx_vsize_from_weight(size_t weight, size_t *written)
Compute transaction vsize from transaction weight.
- Parameters:
weight – The weight to convert to a virtual size.
written – Destination for the virtual size.
- Returns:
See Error Codes
-
int wally_tx_get_total_output_satoshi(const struct wally_tx *tx, uint64_t *value_out)
Compute the total sum of all outputs in a transaction.
- Parameters:
tx – The transaction to compute the total from.
value_out – Destination for the output total.
- Returns:
See Error Codes
-
int wally_tx_get_btc_signature_hash(const struct wally_tx *tx, size_t index, const unsigned char *script, size_t script_len, uint64_t satoshi, uint32_t sighash, uint32_t flags, unsigned char *bytes_out, size_t len)
Get the hash of the preimage for signing a BTC transaction input.
Deprecated, this call will be removed in a future release. Please use
wally_tx_get_input_signature_hash
.- Parameters:
tx – The transaction to generate the signature hash from.
index – The input index of the input being signed for.
script – The (unprefixed) scriptCode for the input being signed.
script_len – Size of
script
in bytes.satoshi – The amount spent by the input being signed for. Only used if flags includes
WALLY_TX_FLAG_USE_WITNESS
, pass 0 otherwise.sighash –
WALLY_SIGHASH_
flags specifying the type of signature desired.flags –
WALLY_TX_FLAG_USE_WITNESS
to generate a BIP 143 signature, or 0 to generate a pre-segwit Bitcoin signature.bytes_out – Destination for the signature hash.
len – Size of
bytes_out
. Must beSHA256_LEN
.
- Returns:
See Error Codes
-
int wally_tx_get_btc_taproot_signature_hash(const struct wally_tx *tx, size_t index, const struct wally_map *scripts, const uint64_t *values, size_t num_values, const unsigned char *tapleaf_script, size_t tapleaf_script_len, uint32_t key_version, uint32_t codesep_position, const unsigned char *annex, size_t annex_len, uint32_t sighash, uint32_t flags, unsigned char *bytes_out, size_t len)
Get the hash of the preimage for signing a BTC taproot transaction input.
Deprecated, this call will be removed in a future release. Please use
wally_tx_get_input_signature_hash
.- Parameters:
tx – The transaction to generate the signature hash from.
index – The input index of the input being signed for.
scripts – Map of input index to (unprefixed) scriptCodes for each input in
tx
.values – The value in satoshi for each input in
tx
.num_values – The number of elements in
values
.tapleaf_script – BIP342 tapscript being spent.
tapleaf_script_len – Length of
tapleaf_script
in bytes.key_version – Version of pubkey in tapscript. Must be set to 0x00 or 0x01.
codesep_position – BIP342 codeseparator position or
WALLY_NO_CODESEPARATOR
if none.annex – BIP341 annex, or NULL if none.
annex_len – Length of
annex
in bytes.sighash –
WALLY_SIGHASH_
flags specifying the type of signature desired.flags – Flags controlling signature generation. Must be 0.
bytes_out – Destination for the resulting signature hash.
len – Size of
bytes_out
. Must beSHA256_LEN
.
- Returns:
See Error Codes
-
int wally_tx_get_signature_hash(const struct wally_tx *tx, size_t index, const unsigned char *script, size_t script_len, const unsigned char *extra, size_t extra_len, uint32_t extra_offset, uint64_t satoshi, uint32_t sighash, uint32_t tx_sighash, uint32_t flags, unsigned char *bytes_out, size_t len)
Get the hash of the preimage for signing a BTC transaction input.
Deprecated, this call will be removed in a future release. Please use
wally_tx_get_input_signature_hash
.- Parameters:
tx – The transaction to generate the signature hash from.
index – The input index of the input being signed for.
script – The (unprefixed) scriptCode for the input being signed.
script_len – Size of
script
in bytes.extra – Extra bytes to include in the transaction preimage.
extra_len – Size of
extra
in bytes.extra_offset – Offset within the preimage to store
extra
. To store it at the end of the preimage, use 0xffffffff.satoshi – The amount spent by the input being signed for. Only used if flags includes
WALLY_TX_FLAG_USE_WITNESS
, pass 0 otherwise.sighash –
WALLY_SIGHASH_
flags specifying the type of signature desired.tx_sighash – The 32bit sighash value to include in the preimage to hash. This must be given in host CPU endianness; For normal Bitcoin signing the value of
sighash
should be given.flags –
WALLY_TX_FLAG_USE_WITNESS
to generate a BIP 143 signature, or 0 to generate a pre-segwit Bitcoin signature.bytes_out – Destination for the signature hash.
len – Size of
bytes_out
. Must beSHA256_LEN
.
- Returns:
See Error Codes
-
int wally_tx_get_input_signature_hash(const struct wally_tx *tx, size_t index, const struct wally_map *scripts, const struct wally_map *assets, const struct wally_map *values, const unsigned char *script, size_t script_len, uint32_t key_version, uint32_t codesep_position, const unsigned char *annex, size_t annex_len, const unsigned char *genesis_blockhash, size_t genesis_blockhash_len, uint32_t sighash, uint32_t flags, struct wally_map *cache, unsigned char *bytes_out, size_t len)
Get the hash of the preimage for signing a transaction input.
- Parameters:
tx – The transaction to generate the signature hash from.
index – The input index of the input being signed for.
scripts – The scriptpubkeys of each input in the transaction, indexed by their 0-based input index. For non-taproot signing, only the scriptpubkey of
index
is required.assets – The asset commitments of each input in the transaction, or NULL for non-Elements transactions. Ignored for non-taproot signing.
values – The satoshi values(BTC) or value commitments(Elements) of each input in the transaction. BTC values must be stored as bytes with uint64/host endiannes. For non-taproot signing, only the value of
index
is required.script – For segwit v0 signing, the scriptcode of the input to sign for. For taproot, the leaf script to sign with if any. Ignored for pre-segwit signing.
script_len – Length of
script
in bytes.key_version – For taproot signing, the version of the pubkey in
script
when signing with a script path. Currently must be1
for this case. For non-taproot or keypath signing, it must be0
.codesep_position – BIP342 codeseparator position or
WALLY_NO_CODESEPARATOR
if none. Only used for taproot signing.annex – BIP341 annex, or NULL if none.
annex_len – Length of
annex
in bytes. Only used for taproot signing.genesis_blockhash – The genesis blockhash of the chain to sign for, or NULL for non-Elements transactions. Only used for taproot signing.
genesis_blockhash_len – Length of
genesis_blockhash
in bytes. Must beSHA256_LEN
or 0.sighash –
WALLY_SIGHASH_
flags specifying the sighash flags to sign with.flags – Transaction signature hash flags controlling signature hash generation.
cache – An opaque cache for faster generation, or NULL to disable caching. Must be empty on the first call to this function for a given transaction, and only used for signing the inputs of the same
tx
.bytes_out – Destination for the resulting signature hash.
len – Size of
bytes_out
. Must beSHA256_LEN
.
- Returns:
See Error Codes
-
int wally_tx_is_coinbase(const struct wally_tx *tx, size_t *written)
Determine if a transaction is a coinbase transaction.
- Parameters:
tx – The transaction to check.
written – 1 if the transaction is a coinbase transaction, otherwise 0.
- Returns:
See Error Codes
-
int wally_tx_get_elements_weight_discount(const struct wally_tx *tx, uint32_t flags, size_t *written)
Calculate any applicable transaction weight discount for an Elements transaction.
- Parameters:
tx – The transaction to compute the weight discount for.
flags – Unused, must be 0.
written – Destination for the weight discount.
Note
The discount may be 0 if the transaction has no confidential outputs.
- Returns:
See Error Codes
-
int wally_tx_elements_input_issuance_set(struct wally_tx_input *input, const unsigned char *nonce, size_t nonce_len, const unsigned char *entropy, size_t entropy_len, const unsigned char *issuance_amount, size_t issuance_amount_len, const unsigned char *inflation_keys, size_t inflation_keys_len, const unsigned char *issuance_amount_rangeproof, size_t issuance_amount_rangeproof_len, const unsigned char *inflation_keys_rangeproof, size_t inflation_keys_rangeproof_len)
Set issuance data on an input.
- Parameters:
input – The input to add to.
nonce – Asset issuance or revelation blinding factor.
nonce_len – Size of
nonce
in bytes. Must beSHA256_LEN
.entropy – Entropy for the asset tag calculation.
entropy_len – Size of
entropy
in bytes. Must beSHA256_LEN
.issuance_amount – The (blinded) issuance amount.
issuance_amount_len – Size of
issuance_amount
in bytes.inflation_keys – The (blinded) token reissuance amount.
inflation_keys_len – Size of
ìnflation_keys
in bytes.issuance_amount_rangeproof – Issuance amount rangeproof.
issuance_amount_rangeproof_len – Size of
issuance_amount_rangeproof
in bytes.inflation_keys_rangeproof – Inflation keys rangeproof.
inflation_keys_rangeproof_len – Size of
inflation_keys_rangeproof
in bytes.
- Returns:
See Error Codes
-
int wally_tx_elements_input_issuance_free(struct wally_tx_input *input)
Free issuance data on an input.
- Parameters:
input – The input issuance data to free.
- Returns:
See Error Codes
-
int wally_tx_elements_input_init_alloc(const unsigned char *txhash, size_t txhash_len, uint32_t utxo_index, uint32_t sequence, const unsigned char *script, size_t script_len, const struct wally_tx_witness_stack *witness, const unsigned char *nonce, size_t nonce_len, const unsigned char *entropy, size_t entropy_len, const unsigned char *issuance_amount, size_t issuance_amount_len, const unsigned char *inflation_keys, size_t inflation_keys_len, const unsigned char *issuance_amount_rangeproof, size_t issuance_amount_rangeproof_len, const unsigned char *inflation_keys_rangeproof, size_t inflation_keys_rangeproof_len, const struct wally_tx_witness_stack *pegin_witness, struct wally_tx_input **output)
Allocate and initialize a new elements transaction input.
- Parameters:
txhash – The transaction hash of the transaction this input comes from.
txhash_len – Size of
txhash
in bytes. Must beWALLY_TXHASH_LEN
.utxo_index – The zero-based index of the transaction output in
txhash
that this input comes from.sequence – The sequence number for the input.
script – The scriptSig for the input.
script_len – Size of
script
in bytes.witness – The witness stack for the input, or NULL if no witness is present.
nonce – Asset issuance or revelation blinding factor.
nonce_len – Size of
nonce
in bytes. Must beSHA256_LEN
.entropy – Entropy for the asset tag calculation.
entropy_len – Size of
entropy
in bytes. Must beSHA256_LEN
.issuance_amount – The (blinded) issuance amount.
issuance_amount_len – Size of
issuance_amount
in bytes.inflation_keys – The (blinded) token reissuance amount.
inflation_keys_len – Size of
ìnflation_keys
in bytes.issuance_amount_rangeproof – Issuance amount rangeproof.
issuance_amount_rangeproof_len – Size of
issuance_amount_rangeproof
in bytes.inflation_keys_rangeproof – Inflation keys rangeproof.
inflation_keys_rangeproof_len – Size of
inflation_keys_rangeproof
in bytes.pegin_witness – The pegin witness stack for the input, or NULL if no witness is present.
output – Destination for the resulting transaction input.
- Returns:
See Error Codes
-
int wally_tx_elements_input_is_pegin(const struct wally_tx_input *input, size_t *written)
Determine if an input is a pegin.
- Parameters:
input – The input to check.
written – 1 if the input is a pegin, otherwise 0.
- Returns:
See Error Codes
-
int wally_tx_elements_output_commitment_set(struct wally_tx_output *output, const unsigned char *asset, size_t asset_len, const unsigned char *value, size_t value_len, const unsigned char *nonce, size_t nonce_len, const unsigned char *surjectionproof, size_t surjectionproof_len, const unsigned char *rangeproof, size_t rangeproof_len)
Set commitment data on an output.
- Parameters:
output – The output to add to.
asset – The commitment to a possibly blinded asset.
asset_len – Size of
asset
in bytes. Must beWALLY_TX_ASSET_CT_ASSET_LEN
.value – The commitment to a possibly blinded value.
value_len – Size of
value
in bytes. Must beWALLY_TX_ASSET_CT_VALUE_LEN
orWALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN
.nonce – The commitment used to create the nonce (with the blinding key) for the range proof.
nonce_len – Size of
nonce
in bytes. Must beWALLY_TX_ASSET_CT_NONCE_LEN
.surjectionproof – surjection proof.
surjectionproof_len – Size of
surjectionproof
in bytes.rangeproof – rangeproof.
rangeproof_len – Size of
rangeproof
in bytes.
- Returns:
See Error Codes
-
int wally_tx_elements_output_commitment_free(struct wally_tx_output *output)
Free commitment data on an output.
- Parameters:
output – The output with the commitment data to free.
- Returns:
See Error Codes
-
int wally_tx_elements_output_init(const unsigned char *script, size_t script_len, const unsigned char *asset, size_t asset_len, const unsigned char *value, size_t value_len, const unsigned char *nonce, size_t nonce_len, const unsigned char *surjectionproof, size_t surjectionproof_len, const unsigned char *rangeproof, size_t rangeproof_len, struct wally_tx_output *output)
Initialize a new elements transaction output in place.
- Parameters:
script – The scriptPubkey for the output.
script_len – Size of
script
in bytes.asset – The asset tag of the output.
asset_len – Size of
asset
in bytes. Must beWALLY_TX_ASSET_CT_ASSET_LEN
.value – The commitment to a possibly blinded value.
value_len – Size of
value
in bytes. Must beWALLY_TX_ASSET_CT_VALUE_LEN
orWALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN
.nonce – The commitment used to create the nonce (with the blinding key) for the range proof.
nonce_len – Size of
nonce
in bytes. Must beWALLY_TX_ASSET_CT_NONCE_LEN
.surjectionproof – The surjection proof.
surjectionproof_len – Size of
surjectionproof
in bytes.rangeproof – The range proof.
rangeproof_len – Size of
rangeproof
in bytes.output – Destination for the resulting transaction output copy.
Note
output
is overwritten in place, and not cleared first.- Returns:
See Error Codes
-
int wally_tx_elements_output_init_alloc(const unsigned char *script, size_t script_len, const unsigned char *asset, size_t asset_len, const unsigned char *value, size_t value_len, const unsigned char *nonce, size_t nonce_len, const unsigned char *surjectionproof, size_t surjectionproof_len, const unsigned char *rangeproof, size_t rangeproof_len, struct wally_tx_output **output)
Allocate and initialize a new elements transaction output.
- Parameters:
script – The scriptPubkey for the output.
script_len – Size of
script
in bytes.asset – The asset tag of the output.
asset_len – Size of
asset
in bytes. Must beWALLY_TX_ASSET_CT_ASSET_LEN
.value – The commitment to a possibly blinded value.
value_len – Size of
value
in bytes. Must beWALLY_TX_ASSET_CT_VALUE_LEN
orWALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN
.nonce – The commitment used to create the nonce (with the blinding key) for the range proof.
nonce_len – Size of
nonce
in bytes. Must beWALLY_TX_ASSET_CT_NONCE_LEN
.surjectionproof – The surjection proof.
surjectionproof_len – Size of
surjectionproof
in bytes.rangeproof – The range proof.
rangeproof_len – Size of
rangeproof
in bytes.output – Destination for the resulting transaction output.
- Returns:
See Error Codes
-
int wally_tx_add_elements_raw_input(struct wally_tx *tx, const unsigned char *txhash, size_t txhash_len, uint32_t utxo_index, uint32_t sequence, const unsigned char *script, size_t script_len, const struct wally_tx_witness_stack *witness, const unsigned char *nonce, size_t nonce_len, const unsigned char *entropy, size_t entropy_len, const unsigned char *issuance_amount, size_t issuance_amount_len, const unsigned char *inflation_keys, size_t inflation_keys_len, const unsigned char *issuance_amount_rangeproof, size_t issuance_amount_rangeproof_len, const unsigned char *inflation_keys_rangeproof, size_t inflation_keys_rangeproof_len, const struct wally_tx_witness_stack *pegin_witness, uint32_t flags)
Add an elements transaction input to a transaction.
- Parameters:
tx – The transaction to add the input to.
txhash – The transaction hash of the transaction this input comes from.
txhash_len – Size of
txhash
in bytes. Must beWALLY_TXHASH_LEN
.utxo_index – The zero-based index of the transaction output in
txhash
that this input comes from.sequence – The sequence number for the input.
script – The scriptSig for the input.
script_len – Size of
script
in bytes.witness – The witness stack for the input, or NULL if no witness is present.
nonce – Asset issuance or revelation blinding factor.
nonce_len – Size of
nonce
in bytes. Must beSHA256_LEN
.entropy – Entropy for the asset tag calculation.
entropy_len – Size of
entropy
in bytes. Must beSHA256_LEN
.issuance_amount – The (blinded) issuance amount.
issuance_amount_len – Size of
issuance_amount
in bytes.inflation_keys – The (blinded) token reissuance amount.
inflation_keys_len – Size of
ìnflation_keys
in bytes.issuance_amount_rangeproof – Issuance amount rangeproof.
issuance_amount_rangeproof_len – Size of
issuance_amount_rangeproof
in bytes.inflation_keys_rangeproof – Inflation keys rangeproof.
inflation_keys_rangeproof_len – Size of
inflation_keys_rangeproof
in bytes.pegin_witness – The pegin witness stack for the input, or NULL if no witness is present.
flags – Flags controlling input creation. Must be 0.
- Returns:
See Error Codes
-
int wally_tx_add_elements_raw_input_at(struct wally_tx *tx, uint32_t index, const unsigned char *txhash, size_t txhash_len, uint32_t utxo_index, uint32_t sequence, const unsigned char *script, size_t script_len, const struct wally_tx_witness_stack *witness, const unsigned char *nonce, size_t nonce_len, const unsigned char *entropy, size_t entropy_len, const unsigned char *issuance_amount, size_t issuance_amount_len, const unsigned char *inflation_keys, size_t inflation_keys_len, const unsigned char *issuance_amount_rangeproof, size_t issuance_amount_rangeproof_len, const unsigned char *inflation_keys_rangeproof, size_t inflation_keys_rangeproof_len, const struct wally_tx_witness_stack *pegin_witness, uint32_t flags)
Add an elements transaction input to a transaction at a given position.
- Parameters:
tx – The transaction to add the input to.
index – The zero-based index of the position to add the input at.
txhash – The transaction hash of the transaction this input comes from.
txhash_len – Size of
txhash
in bytes. Must beWALLY_TXHASH_LEN
.utxo_index – The zero-based index of the transaction output in
txhash
that this input comes from.sequence – The sequence number for the input.
script – The scriptSig for the input.
script_len – Size of
script
in bytes.witness – The witness stack for the input, or NULL if no witness is present.
nonce – Asset issuance or revelation blinding factor.
nonce_len – Size of
nonce
in bytes. Must beSHA256_LEN
.entropy – Entropy for the asset tag calculation.
entropy_len – Size of
entropy
in bytes. Must beSHA256_LEN
.issuance_amount – The (blinded) issuance amount.
issuance_amount_len – Size of
issuance_amount
in bytes.inflation_keys – The (blinded) token reissuance amount.
inflation_keys_len – Size of
ìnflation_keys
in bytes.issuance_amount_rangeproof – Issuance amount rangeproof.
issuance_amount_rangeproof_len – Size of
issuance_amount_rangeproof
in bytes.inflation_keys_rangeproof – Inflation keys rangeproof.
inflation_keys_rangeproof_len – Size of
inflation_keys_rangeproof
in bytes.pegin_witness – The pegin witness stack for the input, or NULL if no witness is present.
flags – Flags controlling input creation. Must be 0.
- Returns:
See Error Codes
-
int wally_tx_add_elements_raw_output(struct wally_tx *tx, const unsigned char *script, size_t script_len, const unsigned char *asset, size_t asset_len, const unsigned char *value, size_t value_len, const unsigned char *nonce, size_t nonce_len, const unsigned char *surjectionproof, size_t surjectionproof_len, const unsigned char *rangeproof, size_t rangeproof_len, uint32_t flags)
Add a elements transaction output to a transaction.
- Parameters:
tx – The transaction to add the output to.
script – The scriptPubkey for the output.
script_len – Size of
script
in bytes.asset – The asset tag of the output.
asset_len – Size of
asset
in bytes. Must beWALLY_TX_ASSET_CT_ASSET_LEN
.value – The commitment to a possibly blinded value.
value_len – Size of
value
in bytes. Must beWALLY_TX_ASSET_CT_VALUE_LEN
orWALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN
.nonce – The commitment used to create the nonce (with the blinding key) for the range proof.
nonce_len – Size of
nonce
in bytes. Must beWALLY_TX_ASSET_CT_NONCE_LEN
.surjectionproof – The surjection proof.
surjectionproof_len – Size of
surjectionproof
in bytes.rangeproof – The range proof.
rangeproof_len – Size of
rangeproof
in bytes.flags – Flags controlling output creation. Must be 0.
- Returns:
See Error Codes
-
int wally_tx_add_elements_raw_output_at(struct wally_tx *tx, uint32_t index, const unsigned char *script, size_t script_len, const unsigned char *asset, size_t asset_len, const unsigned char *value, size_t value_len, const unsigned char *nonce, size_t nonce_len, const unsigned char *surjectionproof, size_t surjectionproof_len, const unsigned char *rangeproof, size_t rangeproof_len, uint32_t flags)
Add a elements transaction output to a transaction at a given position.
- Parameters:
tx – The transaction to add the output to.
index – The zero-based index of the position to add the output at.
script – The scriptPubkey for the output.
script_len – Size of
script
in bytes.asset – The asset tag of the output.
asset_len – Size of
asset
in bytes. Must beWALLY_TX_ASSET_CT_ASSET_LEN
.value – The commitment to a possibly blinded value.
value_len – Size of
value
in bytes. Must beWALLY_TX_ASSET_CT_VALUE_LEN
orWALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN
.nonce – The commitment used to create the nonce (with the blinding key) for the range proof.
nonce_len – Size of
nonce
in bytes. Must beWALLY_TX_ASSET_CT_NONCE_LEN
.surjectionproof – The surjection proof.
surjectionproof_len – Size of
surjectionproof
in bytes.rangeproof – The range proof.
rangeproof_len – Size of
rangeproof
in bytes.flags – Flags controlling output creation. Must be 0.
- Returns:
See Error Codes
-
int wally_tx_is_elements(const struct wally_tx *tx, size_t *written)
Determine if a transaction is an elements transaction.
- Parameters:
tx – The transaction to check.
written – 1 if the transaction is an elements transaction, otherwise 0.
- Returns:
See Error Codes
-
int wally_tx_confidential_value_from_satoshi(uint64_t satoshi, unsigned char *bytes_out, size_t len)
Convert satoshi to an explicit confidential value representation.
- Parameters:
satoshi – The value in satoshi to convert.
bytes_out – Destination for the confidential value bytes.
len – Size of
bytes_out
. Must beWALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN
.
- Returns:
See Error Codes
-
int wally_tx_confidential_value_to_satoshi(const unsigned char *value, size_t value_len, uint64_t *value_out)
Convert an explicit confidential value representation to satoshi.
- Parameters:
value – The confidential value bytes.
value_len – Size of
value
in bytes. Must beWALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN
.value_out – The converted value in satoshi.
- Returns:
See Error Codes
-
int wally_tx_get_elements_signature_hash(const struct wally_tx *tx, size_t index, const unsigned char *script, size_t script_len, const unsigned char *value, size_t value_len, uint32_t sighash, uint32_t flags, unsigned char *bytes_out, size_t len)
Get the hash of the preimage for signing an Elements transaction input.
Deprecated, this call will be removed in a future release. Please use
wally_tx_get_input_signature_hash
.- Parameters:
tx – The transaction to generate the signature hash from.
index – The input index of the input being signed for.
script – The (unprefixed) scriptCode for the input being signed.
script_len – Size of
script
in bytes.value – The (confidential) value spent by the input being signed for. Only used if flags includes
WALLY_TX_FLAG_USE_WITNESS
, pass NULL otherwise.value_len – Size of
value
in bytes.sighash –
WALLY_SIGHASH_
flags specifying the type of signature desired.flags –
WALLY_TX_FLAG_USE_WITNESS
to generate a BIP 143 signature, or 0 to generate a pre-segwit Bitcoin signature.bytes_out – Destination for the signature hash.
len – Size of
bytes_out
. Must beSHA256_LEN
.
- Returns:
See Error Codes
-
int wally_tx_elements_issuance_generate_entropy(const unsigned char *txhash, size_t txhash_len, uint32_t utxo_index, const unsigned char *contract_hash, size_t contract_hash_len, unsigned char *bytes_out, size_t len)
Calculate the asset entropy from a prevout and the Ricardian contract hash.
- Parameters:
txhash – The prevout transaction hash.
txhash_len – Size of
txhash
in bytes. Must beWALLY_TXHASH_LEN
.utxo_index – The zero-based index of the transaction output in
txhash
to use.contract_hash – The issuer specified Ricardian contract hash.
contract_hash_len – Size of
contract hash
in bytes. Must beSHA256_LEN
.bytes_out – Destination for the asset entropy.
len – Size of
bytes_out
. Must beSHA256_LEN
.
- Returns:
See Error Codes
-
int wally_tx_elements_issuance_calculate_asset(const unsigned char *entropy, size_t entropy_len, unsigned char *bytes_out, size_t len)
Calculate the asset from the entropy.
- Parameters:
entropy – The asset entropy.
entropy_len – Size of
entropy
in bytes. Must beSHA256_LEN
.bytes_out – Destination for the asset tag.
len – Size of
bytes_out
. Must beSHA256_LEN
.
- Returns:
See Error Codes
-
int wally_tx_elements_issuance_calculate_reissuance_token(const unsigned char *entropy, size_t entropy_len, uint32_t flags, unsigned char *bytes_out, size_t len)
Calculate a re-issuance token from an asset’s entropy.
- Parameters:
entropy – The asset entropy.
entropy_len – Size of
entropy
in bytes. Must beSHA256_LEN
.flags –
WALLY_TX_FLAG_BLINDED_INITIAL_ISSUANCE
if initial issuance was blinded, pass 0 otherwise.bytes_out – Destination for the re-issuance token.
len – Size of
bytes_out
. Must beSHA256_LEN
.
- Returns:
See Error Codes
Transaction Constants
-
WALLY_TX_SEQUENCE_FINAL
-
WALLY_TX_VERSION_1
-
WALLY_TX_VERSION_2
-
WALLY_TX_IS_ELEMENTS
-
WALLY_TX_IS_ISSUANCE
-
WALLY_TX_IS_PEGIN
-
WALLY_TX_IS_COINBASE
-
WALLY_SATOSHI_PER_BTC
-
WALLY_BTC_MAX
-
WALLY_TXHASH_LEN
Size of a transaction hash in bytes
-
WALLY_TX_FLAG_USE_WITNESS
-
WALLY_TX_FLAG_USE_ELEMENTS
-
WALLY_TX_FLAG_ALLOW_PARTIAL
-
WALLY_TX_FLAG_PRE_BIP144
-
WALLY_TX_FLAG_BLINDED_INITIAL_ISSUANCE
Transaction cloning flags
-
WALLY_TX_CLONE_FLAG_NON_FINAL
-
WALLY_TX_DUMMY_NULL
-
WALLY_TX_DUMMY_SIG
-
WALLY_TX_DUMMY_SIG_LOW_R
-
WALLY_SIGHASH_DEFAULT
Sighash flags for transaction signing
-
WALLY_SIGHASH_ALL
-
WALLY_SIGHASH_NONE
-
WALLY_SIGHASH_SINGLE
-
WALLY_SIGHASH_FORKID
-
WALLY_SIGHASH_RANGEPROOF
-
WALLY_SIGHASH_ANYPREVOUT
-
WALLY_SIGHASH_ANYPREVOUTANYSCRIPT
-
WALLY_SIGHASH_ANYONECANPAY
-
WALLY_SIGHASH_MASK
-
WALLY_SIGHASH_TR_IN_MASK
Transaction signature hash flags
-
WALLY_SIGTYPE_PRE_SW
-
WALLY_SIGTYPE_SW_V0
-
WALLY_SIGTYPE_SW_V1
-
WALLY_SIGTYPE_MASK
-
WALLY_TX_ASSET_CT_EMPTY_PREFIX
-
WALLY_TX_ASSET_CT_EXPLICIT_PREFIX
-
WALLY_TX_ASSET_CT_VALUE_PREFIX_A
-
WALLY_TX_ASSET_CT_VALUE_PREFIX_B
-
WALLY_TX_ASSET_CT_ASSET_PREFIX_A
-
WALLY_TX_ASSET_CT_ASSET_PREFIX_B
-
WALLY_TX_ASSET_CT_NONCE_PREFIX_A
-
WALLY_TX_ASSET_CT_NONCE_PREFIX_B
-
WALLY_TX_ASSET_TAG_LEN
-
WALLY_TX_ASSET_CT_VALUE_LEN
-
WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN
-
WALLY_TX_ASSET_CT_ASSET_LEN
-
WALLY_TX_ASSET_CT_NONCE_LEN
-
WALLY_TX_ASSET_CT_LEN
-
WALLY_TX_ISSUANCE_FLAG
-
WALLY_TX_PEGIN_FLAG
-
WALLY_TX_INDEX_MASK
-
WALLY_NO_CODESEPARATOR