Skip to content

Commit 8de9f44

Browse files
committed
also convert from confidential to satoshi
1 parent 9a283af commit 8de9f44

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

include/wally_transaction.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ WALLY_CORE_API int wally_tx_is_elements(
844844
size_t *written);
845845

846846
/**
847-
* Convert satoshi to an (explicit) confidential value representation.
847+
* Convert satoshi to an explicit confidential value representation.
848848
*
849849
* :param satoshi: The value in satoshi to convert.
850850
* :param bytes_out: Destination for the confidential value bytes.
@@ -855,6 +855,18 @@ WALLY_CORE_API int wally_tx_confidential_value_from_satoshi(
855855
unsigned char *bytes_out,
856856
size_t len);
857857

858+
/**
859+
* Convert an explicit confidential value representation to satoshi.
860+
*
861+
* :param value: The confidential value bytes.
862+
* :param value_len: Size of ``value`` in bytes. Must be ``WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN``.
863+
* :param value_out: The converted value in satoshi.
864+
*/
865+
WALLY_CORE_API int wally_tx_confidential_value_to_satoshi(
866+
const unsigned char *value,
867+
size_t value_len,
868+
uint64_t* value_out);
869+
858870
/**
859871
* Create a Elements transaction for signing and return its hash.
860872
*

src/swig_java/swig.i

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ static jbyteArray create_array(JNIEnv *jenv, const unsigned char* p, size_t len)
448448
%returns_void__(wally_tx_add_output);
449449
%returns_void__(wally_tx_add_raw_output);
450450
%returns_array_(wally_tx_confidential_value_from_satoshi, 2, 3, WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN);
451+
%returns_uint64(wally_tx_confidential_value_to_satoshi);
451452
%returns_struct(wally_tx_elements_input_init_alloc, wally_tx_input);
452453
%rename("_tx_elements_input_is_pegin") wally_tx_elements_input_is_pegin;
453454
%returns_size_t(_tx_elements_input_is_pegin);

src/transaction.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2720,7 +2720,7 @@ int wally_tx_confidential_value_from_satoshi(uint64_t satoshi,
27202720
unsigned char *bytes_out,
27212721
size_t len)
27222722
{
2723-
if (!bytes_out || len < WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN)
2723+
if (!bytes_out || len != WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN)
27242724
return WALLY_EINVAL;
27252725

27262726
*bytes_out = 0x1;
@@ -2729,6 +2729,18 @@ int wally_tx_confidential_value_from_satoshi(uint64_t satoshi,
27292729
return WALLY_OK;
27302730
}
27312731

2732+
int wally_tx_confidential_value_to_satoshi(const unsigned char *value,
2733+
size_t value_len,
2734+
uint64_t* value_out)
2735+
{
2736+
if (!value || value_len != WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN || !value_out || value[0] != 0x1)
2737+
return WALLY_EINVAL;
2738+
2739+
uint64_from_be_bytes(&value[1], value_out);
2740+
2741+
return WALLY_OK;
2742+
}
2743+
27322744
int wally_tx_elements_issuance_generate_entropy(const unsigned char *txhash,
27332745
size_t txhash_len,
27342746
uint32_t index,

0 commit comments

Comments
 (0)