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_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.
  • flagsWALLY_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.
  • flagsWALLY_TX_DUMMY_ Flags indicating the type of dummy to set.
Returns:

See Error Codes

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 be WALLY_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_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.

:param satoshi The amount of the output in satoshi. :param script: The scriptPubkey for the output. :param script_len: Size of script in bytes. :param output: Transaction output to initialize. :return: 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.

:param satoshi The amount of the output in satoshi. :param script: The scriptPubkey for the output. :param script_len: Size of script in bytes. :param output: Destination for the resulting transaction output. :return: 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 output.
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 – Flags controlling transaction creation. Must be 0.
  • 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 be WALLY_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 goven 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 be WALLY_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 in bytes. Must be WALLY_TXHASH_LEN.

Note

The txid is expensive to compute.

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.
  • flagsWALLY_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.
  • flagsWALLY_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.
  • flagsWALLY_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.
  • flagsWALLY_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:

See Variable Length Output Buffers

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.
  • flagsWALLY_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)

Create a BTC transaction for signing and return its 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.
  • sighashWALLY_SIGHASH_ flags specifying the type of signature desired.
  • flagsWALLY_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 in bytes. Must be at least SHA256_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)

Create a transaction for signing and return its 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 with 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.
  • sighashWALLY_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 endianess; For normal Bitcoin signing the value of sighash should be given.
  • flagsWALLY_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 in bytes. Must be at least SHA256_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_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 be WALLY_TX_ASSET_TAG_LEN.
  • entropy – Entropy for the asset tag calculation.
  • entropy_len – Size of entropy in bytes. Must be WALLY_TX_ASSET_TAG_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 be WALLY_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 be WALLY_TX_ASSET_TAG_LEN.
  • entropy – Entropy for the asset tag calculation.
  • entropy_len – Size of entropy in bytes. Must be WALLY_TX_ASSET_TAG_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 be WALLY_TX_ASSET_CT_ASSET_LEN.
  • value – The commitment to a possibly blinded value.
  • value_len – Size of value in bytes. Must be WALLY_TX_ASSET_CT_VALUE_LEN or WALLY_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 be WALLY_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 be WALLY_TX_ASSET_CT_ASSET_LEN.
  • value – The commitment to a possibly blinded value.
  • value_len – Size of value in bytes. Must be WALLY_TX_ASSET_CT_VALUE_LEN or WALLY_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 be WALLY_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 be WALLY_TX_ASSET_CT_ASSET_LEN.
  • value – The commitment to a possibly blinded value.
  • value_len – Size of value in bytes. Must be WALLY_TX_ASSET_CT_VALUE_LEN or WALLY_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 be WALLY_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 be WALLY_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 be WALLY_TX_ASSET_TAG_LEN.
  • entropy – Entropy for the asset tag calculation.
  • entropy_len – Size of entropy in bytes. Must be WALLY_TX_ASSET_TAG_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 be WALLY_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 be WALLY_TX_ASSET_TAG_LEN.
  • entropy – Entropy for the asset tag calculation.
  • entropy_len – Size of entropy in bytes. Must be WALLY_TX_ASSET_TAG_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 be WALLY_TX_ASSET_CT_ASSET_LEN.
  • value – The commitment to a possibly blinded value.
  • value_len – Size of value in bytes. Must be WALLY_TX_ASSET_CT_VALUE_LEN or WALLY_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 be WALLY_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 be WALLY_TX_ASSET_CT_ASSET_LEN.
  • value – The commitment to a possibly blinded value.
  • value_len – Size of value in bytes. Must be WALLY_TX_ASSET_CT_VALUE_LEN or WALLY_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 be WALLY_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 in bytes. Must be WALLY_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 be WALLY_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)

Create a Elements transaction for signing and return its 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.
  • sighashWALLY_SIGHASH_ flags specifying the type of signature desired.
  • flagsWALLY_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 in bytes. Must be SHA256_LEN.
Returns:

See Error Codes

int wally_tx_elements_issuance_generate_entropy(const unsigned char *txhash, size_t txhash_len, uint32_t 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 be WALLY_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 be SHA256_LEN.
  • bytes_out – Destination for the asset entropy.
  • len – Size of bytes_out in bytes. Must be SHA256_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 be SHA256_LEN.
  • bytes_out – Destination for the asset tag.
  • len – Size of bytes_out in bytes. Must be SHA256_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 be SHA256_LEN.
  • flagsWALLY_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 in bytes. Must be SHA256_LEN.
Returns:

See Error Codes