From 38a00e653a8b17f86cef0c3459fb9a2104ce3499 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:16:58 +1200 Subject: [PATCH 01/26] add wally_get_build_version and associated constants for the wally version --- include/wally.hpp | 5 +++++ include/wally_core.h | 15 +++++++++++++++ src/internal.c | 7 +++++++ src/swig_java/swig.i | 1 + src/test/util.py | 1 + src/wasm_package/src/const.js | 4 ++++ src/wasm_package/src/functions.js | 1 + src/wasm_package/src/index.d.ts | 1 + tools/wasm_exports.sh | 1 + 9 files changed, 36 insertions(+) diff --git a/include/wally.hpp b/include/wally.hpp index 193bf4705..0dda137b5 100644 --- a/include/wally.hpp +++ b/include/wally.hpp @@ -722,6 +722,11 @@ inline int free_string(char* str) { return ret; } +inline int get_build_version(uint32_t* value) { + int ret = ::wally_get_build_version(value); + return ret; +} + template inline int get_hash_prevouts(const TXHASHES& txhashes, const UTXO_INDICES& utxo_indices, BYTES_OUT& bytes_out) { int ret = ::wally_get_hash_prevouts(txhashes.data(), txhashes.size(), utxo_indices.data(), utxo_indices.size(), bytes_out.data(), bytes_out.size()); diff --git a/include/wally_core.h b/include/wally_core.h index d2d2b9e58..4338f679f 100644 --- a/include/wally_core.h +++ b/include/wally_core.h @@ -28,6 +28,12 @@ extern "C" { #define WALLY_EINVAL -2 /** Invalid argument */ #define WALLY_ENOMEM -3 /** malloc() failed */ +/** Library version */ +#define WALLY_MAJOR_VER 0 +#define WALLY_MINOR_VER 9 +#define WALLY_PATCH_VER 2 +#define WALLY_BUILD_VER 0x902 + /** * Initialize wally. * @@ -44,6 +50,15 @@ WALLY_CORE_API int wally_init(uint32_t flags); */ WALLY_CORE_API int wally_cleanup(uint32_t flags); +/** + * Get the version number of the library. + * + * :param value: Destination for the library build version. This is the + *| value of `WALLY_BUILD_VER` when the library was compiled. + */ +WALLY_CORE_API int wally_get_build_version( + uint32_t *value); + #ifndef SWIG /** * Fetch the wally internal secp256k1 context object. diff --git a/src/internal.c b/src/internal.c index 857a1b23d..0e9cb78d3 100644 --- a/src/internal.c +++ b/src/internal.c @@ -18,6 +18,13 @@ /* Caller is responsible for thread safety */ static secp256k1_context *global_ctx = NULL; +int wally_get_build_version(uint32_t *value) +{ + if (value) + *value = WALLY_BUILD_VER; + return value ? WALLY_OK : WALLY_EINVAL; +} + int pubkey_combine(secp256k1_pubkey *pubnonce, const secp256k1_pubkey *const *pubnonces, size_t n) { return secp256k1_ec_pubkey_combine(secp256k1_context_no_precomp, pubnonce, pubnonces, n); diff --git a/src/swig_java/swig.i b/src/swig_java/swig.i index b36c2cbbd..a5537d8bf 100644 --- a/src/swig_java/swig.i +++ b/src/swig_java/swig.i @@ -598,6 +598,7 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) { %returns_array_(wally_explicit_surjectionproof, 7, 8, ASSET_EXPLICIT_SURJECTIONPROOF_LEN); %returns_void__(wally_explicit_surjectionproof_verify); %returns_size_t(wally_format_bitcoin_message); +%returns_size_t(wally_get_build_version) %returns_array_(wally_get_hash_prevouts, 5, 6, SHA256_LEN); %returns_array_(wally_hash160, 3, 4, HASH160_LEN); %returns_string(wally_hex_from_bytes); diff --git a/src/test/util.py b/src/test/util.py index edfe9ff5b..bfe67ebaf 100755 --- a/src/test/util.py +++ b/src/test/util.py @@ -357,6 +357,7 @@ class wally_psbt(Structure): ('wally_explicit_surjectionproof_verify', c_int, [c_void_p, c_size_t, c_void_p, c_size_t, c_void_p, c_size_t]), ('wally_format_bitcoin_message', c_int, [c_void_p, c_size_t, c_uint32, c_void_p, c_size_t, c_size_t_p]), ('wally_free_string', c_int, [c_char_p]), + ('wally_get_build_version', c_int, [c_uint32_p]), ('wally_get_hash_prevouts', c_int, [c_void_p, c_size_t, POINTER(c_uint32), c_size_t, c_void_p, c_size_t]), ('wally_get_operations', c_int, [POINTER(wally_operations)]), ('wally_hash160', c_int, [c_void_p, c_size_t, c_void_p, c_size_t]), diff --git a/src/wasm_package/src/const.js b/src/wasm_package/src/const.js index f8eb3545b..1d65a81fa 100755 --- a/src/wasm_package/src/const.js +++ b/src/wasm_package/src/const.js @@ -109,6 +109,7 @@ export const WALLY_ADDRESS_VERSION_WIF_TESTNET = 0xEF; /** Wallet Import Format export const WALLY_BIP32_CHAIN_CODE_LEN = 32; export const WALLY_BIP32_TWEAK_SUM_LEN = 32; export const WALLY_BTC_MAX = 21000000; +export const WALLY_BUILD_VER = 0x902; export const WALLY_CA_PREFIX_LIQUID = 0x0c; /** Liquid v1 confidential address prefix */ export const WALLY_CA_PREFIX_LIQUID_REGTEST = 0x04; /** Liquid v1 confidential address prefix for regtest */ export const WALLY_CA_PREFIX_LIQUID_TESTNET = 0x17; /** Liquid v1 confidential address prefix for testnet */ @@ -117,12 +118,14 @@ export const WALLY_EINVAL = -2; /** Invalid argument */ export const WALLY_ENOMEM = -3; /** malloc() failed */ export const WALLY_ERROR = -1; /** General error */ export const WALLY_HOST_COMMITMENT_LEN = 32; +export const WALLY_MAJOR_VER = 0; export const WALLY_MAX_OP_RETURN_LEN = 80; /* Maximum length of OP_RETURN data push */ export const WALLY_MINISCRIPT_DEPTH_MASK = 0xffff0000; /** Mask for limiting maximum depth */ export const WALLY_MINISCRIPT_DEPTH_SHIFT = 16; /** Shift to convert maximum depth to flags */ export const WALLY_MINISCRIPT_ONLY = 0x02; /** Only allow miniscript (not descriptor) expressions */ export const WALLY_MINISCRIPT_REQUIRE_CHECKSUM = 0x04; /** Require a checksum to be present */ export const WALLY_MINISCRIPT_TAPSCRIPT = 0x01; /** Tapscript, use x-only pubkeys */ +export const WALLY_MINOR_VER = 9; export const WALLY_MS_CANONICAL_NO_CHECKSUM = 0x01; /** Do not include a checksum */ export const WALLY_MS_IS_DESCRIPTOR = 0x20; /** Contains only descriptor expressions (no miniscript) */ export const WALLY_MS_IS_MULTIPATH = 0x02; /** Allows multiple paths via ```` */ @@ -139,6 +142,7 @@ export const WALLY_NETWORK_LIQUID_TESTNET = 0x05; /** Liquid v1 testnet */ export const WALLY_NETWORK_NONE = 0x00; /** Used for miniscript parsing only */ export const WALLY_NO_CODESEPARATOR = 0xffffffff; /* No BIP342 code separator position */ export const WALLY_OK = 0; /** Success */ +export const WALLY_PATCH_VER = 2; export const WALLY_PSBT_EXTRACT_NON_FINAL = 0x1; /* Extract without final scriptsig and witness */ export const WALLY_PSBT_FINALIZE_NO_CLEAR = 0x1; /* Finalize without clearing redeem/witness scripts etc */ export const WALLY_PSBT_FLAG_NON_FINAL = 0x1; diff --git a/src/wasm_package/src/functions.js b/src/wasm_package/src/functions.js index 2b7557126..e14725d83 100644 --- a/src/wasm_package/src/functions.js +++ b/src/wasm_package/src/functions.js @@ -209,6 +209,7 @@ export const explicit_surjectionproof = wrap('wally_explicit_surjectionproof', [ export const explicit_surjectionproof_verify = wrap('wally_explicit_surjectionproof_verify', [T.Bytes, T.Bytes, T.Bytes]); export const format_bitcoin_message = wrap('wally_format_bitcoin_message', [T.Bytes, T.Int32, T.DestPtrVarLen(T.Bytes, format_bitcoin_message_len, true)]); export const free_string = wrap('wally_free_string', [T.OpaqueRef]); +export const get_build_version = wrap('wally_get_build_version', [T.DestPtr(T.Int32)]); export const get_hash_prevouts = wrap('wally_get_hash_prevouts', [T.Bytes, T.Uint32Array, T.DestPtrSized(T.Bytes, C.SHA256_LEN)]); export const get_operations = wrap('wally_get_operations', [T.OpaqueRef]); export const hash160 = wrap('wally_hash160', [T.Bytes, T.DestPtrSized(T.Bytes, C.HASH160_LEN)]); diff --git a/src/wasm_package/src/index.d.ts b/src/wasm_package/src/index.d.ts index 121b9566b..830fa855b 100644 --- a/src/wasm_package/src/index.d.ts +++ b/src/wasm_package/src/index.d.ts @@ -161,6 +161,7 @@ export function explicit_surjectionproof(output_asset: Buffer|Uint8Array, output export function explicit_surjectionproof_verify(surjectionproof: Buffer|Uint8Array, output_asset: Buffer|Uint8Array, output_generator: Buffer|Uint8Array): void; export function format_bitcoin_message(bytes: Buffer|Uint8Array, flags: number): Buffer; export function free_string(str: Ref): void; +export function get_build_version(): number; export function get_hash_prevouts(txhashes: Buffer|Uint8Array, utxo_indices: Uint32Array|number[]): Buffer; export function get_operations(output: Ref_wally_operations): void; export function hash160(bytes: Buffer|Uint8Array): Buffer; diff --git a/tools/wasm_exports.sh b/tools/wasm_exports.sh index bf18a3edb..3191be732 100644 --- a/tools/wasm_exports.sh +++ b/tools/wasm_exports.sh @@ -114,6 +114,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \ ,'_wally_ecdh' \ ,'_wally_format_bitcoin_message' \ ,'_wally_free_string' \ +,'_wally_get_build_version' \ ,'_wally_get_hash_prevouts' \ ,'_wally_get_operations' \ ,'_wally_hash160' \ From a04eba12acdb8ba40d8b2c61165f9348bf3c995b Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:17:22 +1200 Subject: [PATCH 02/26] build: add a hacky maintainer script to update the version when releasing --- README.md | 2 +- tools/update_version.sh | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 tools/update_version.sh diff --git a/README.md b/README.md index 0855aba61..c786c5980 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ You can also install the binary [wally releases](https://github.com/ElementsProj using the released wheel files without having to compile the library, e.g.: ``` -pip install wallycore-0.9.2-cp39-cp39m-linux_x86_64.whl +pip install wallycore-.whl ``` The script `tools/build_python_manylinux_wheels.sh` builds the Linux release files diff --git a/tools/update_version.sh b/tools/update_version.sh new file mode 100755 index 000000000..95aafbe8b --- /dev/null +++ b/tools/update_version.sh @@ -0,0 +1,22 @@ +#! /usr/bin/env bash +# Update the library version in dependent source files. + +# The master source of the version numbers is the wally_core.h header +MAJOR=$(grep '#define WALLY_MAJOR_VER ' include/wally_core.h | cut -d' ' -f 3) +MINOR=$(grep '#define WALLY_MINOR_VER ' include/wally_core.h | cut -d' ' -f 3) +PATCH=$(grep '#define WALLY_PATCH_VER ' include/wally_core.h | cut -d' ' -f 3) +# Compute the build version from the sub versions +BUILD=$(($MAJOR * 256 * 256 + $MINOR * 256 + $PATCH)); +BUILD=$(printf '0x%x' $BUILD) +sed -i "s/BUILD_VER .*$/BUILD_VER $BUILD/g" include/wally_core.h + +DOTTED="$MAJOR.$MINOR.$PATCH" +sed -i "s/^AC_INIT.*$/AC_INIT\(\[libwallycore],\[$DOTTED\]\)/g" configure.ac +sed -i "s/wallycore==.*$/wallycore==$DOTTED/g" README.md +sed -i "s/^ VERSION .*$/ VERSION $DOTTED/g" _CMakeLists.txt +sed -i "s/^version = .*$/version = u'$DOTTED'/g" docs/source/conf.py +sed -i "s/^ 'version': .*$/ 'version': '$DOTTED',/g" setup.py +sed -i "s/^ \"version\": .*$/ \"version\": \"$DOTTED\",/g" src/wasm_package/package.json src/wasm_package/package-lock.json +jq --arg dotted "$DOTTED" '(.packages."".version) = $dotted' src/wasm_package/package-lock.json > src/wasm_package/package-lock.json.tmp +mv src/wasm_package/package-lock.json.tmp src/wasm_package/package-lock.json +./tools/update_generated.sh From 104d03ba96cba93994666d993552f792fb6a55fe Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:17:26 +1200 Subject: [PATCH 03/26] abi: enable Elements by default, force users to explicitly opt-out of ABI compliance As wally is now being installed as a global shared library by at least one distro (Gentoo), update how the ABI is handled to ensure that elements and non-elements builds are compatible at the C structure level: 1. By default, Elements support is now enabled. 2. By default, if Elements support is disabled, the C structs defining library types retain the extra Elements members. 3. Allow removing the extra members by configuring with --disable-elements --disable-elements-abi. The caller must define WALLY_ABI_NO_ELEMENTS before including any wally headers. This configuration can be used for Bitcoin-only embedded environments, but must not be used when installing wally as a system shared library. Currently elements specific functions remain undefined in the wally headers unless BUILD_ELEMENTS is defined by the caller. Note that the Python and Javascript wrappers are unaffected as these releases always enabled elements. Callers can determine if the library was compiled with elements support by calling wally_is_elements_build(). --- README.md | 10 ++++++++-- configure.ac | 14 ++++++++++++-- include/wally_bip32.h | 4 ++-- include/wally_psbt.h | 12 ++++++------ include/wally_script.h | 2 +- include/wally_transaction.h | 8 ++++---- src/transaction.c | 10 +++++----- 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c786c5980..9ffca6c18 100644 --- a/README.md +++ b/README.md @@ -79,8 +79,14 @@ $ brew install swig - `--enable-swig-java`. Enable the [SWIG](http://www.swig.org/) Java (JNI) interface. After building, see `src/swig_java/src/com/blockstream/libwally/Wally.java` for the Java interface definition (default: no). -- `--enable-elements`. Enables support for [Elements](https://elementsproject.org/) - features, including [Liquid](https://blockstream.com/liquid/) support. +- `--disable-elements`. Disables support for [Elements](https://elementsproject.org/) + features, including [Liquid](https://blockstream.com/liquid/) support (default: no). + Note that to use Elements API calls from C/C++, the caller must define `BUILD_ELEMENTS` + when including the wally header files. +- `--disable-elements-abi`. Ensures that exposed library structures maintain the same ABI + regardless of `--disable-elements`. If disabled, elements support must be disabled and + the user must define `WALLY_ABI_NO_ELEMENTS` before including all wally header files. + This option *must be set if wally is being installed as a system/shared library*. (default: no). - `--enabled-standard-secp`. Excludes support for features that are unavailable in the standard [libsecp256k1 library](https://github.com/bitcoin-core/secp256k1). - `--enable-mbed-tls`. Use mbed-tls hashing functions if available. This typically diff --git a/configure.ac b/configure.ac index 05e10e868..338cd6d30 100644 --- a/configure.ac +++ b/configure.ac @@ -65,8 +65,11 @@ AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests],[enable code tests (default: yes)]), [tests=$enableval], [tests=yes]) AC_ARG_ENABLE(elements, - AS_HELP_STRING([--enable-elements],[enable elements tx code (default: no)]), - [elements=$enableval], [elements=no]) + AS_HELP_STRING([--enable-elements],[enable support for elements (default: yes)]), + [elements=$enableval], [elements=yes]) +AC_ARG_ENABLE(elements_abi, + AS_HELP_STRING([--enable-elements-abi],[enable ABI compatibility when elements is disabled (default: yes)]), + [elements_abi=$enableval], [elements_abi=yes]) AC_ARG_ENABLE(standard-secp, AS_HELP_STRING([--enable-standard-secp],[enable compiling with standard libsecp256k1 (default: no)]), [standard_secp=$enableval], [standard_secp=no]) @@ -87,6 +90,7 @@ AC_ARG_ENABLE(asm, [asm=$enableval], [asm=yes]) AM_CONDITIONAL([RUN_TESTS], [test "x$tests" == "xyes"]) AM_CONDITIONAL([BUILD_ELEMENTS], [test "x$elements" == "xyes"]) +AM_CONDITIONAL([WALLY_ABI_NO_ELEMENTS], [test "x$elements_abi" == "xno"]) AM_CONDITIONAL([BUILD_STANDARD_SECP], [test "x$standard_secp" == "xyes"]) AM_CONDITIONAL([BUILD_MINIMAL], [test "x$minimal" == "xyes"]) @@ -128,6 +132,12 @@ fi if test "x$elements" == "xyes"; then AX_CHECK_COMPILE_FLAG([-DBUILD_ELEMENTS=1], [AM_CFLAGS="$AM_CFLAGS -DBUILD_ELEMENTS=1"]) fi +if test "x$elements_abi" == "xno"; then + if test "x$elements" == "xyes"; then + AC_MSG_FAILURE([ERROR: Elements ABI cannot be disabled when elements is enabled]) + fi + AX_CHECK_COMPILE_FLAG([-DWALLY_ABI_NO_ELEMENTS=1], [AM_CFLAGS="$AM_CFLAGS -DWALLY_ABI_NO_ELEMENTS=1"]) +fi if test "x$standard_secp" == "xyes"; then if test "x$elements" == "xyes"; then AC_MSG_FAILURE([ERROR: Elements cannot be enabled with standard libsecp256k1]) diff --git a/include/wally_bip32.h b/include/wally_bip32.h index f6cd0f825..38cd3df7c 100644 --- a/include/wally_bip32.h +++ b/include/wally_bip32.h @@ -90,9 +90,9 @@ struct ext_key { unsigned char pad2[3]; /** The public key with prefix byte 0x2 or 0x3 */ unsigned char pub_key[33]; -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS unsigned char pub_key_tweak_sum[32]; -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ }; #endif /* SWIG */ diff --git a/include/wally_psbt.h b/include/wally_psbt.h index f95a456ed..6a0ed0ca2 100644 --- a/include/wally_psbt.h +++ b/include/wally_psbt.h @@ -82,7 +82,7 @@ struct wally_psbt_input { /* Hashes and paths for taproot bip32 derivation path */ struct wally_map taproot_leaf_hashes; struct wally_map taproot_leaf_paths; -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS uint64_t issuance_amount; /* Issuance amount, or 0 if not given */ uint64_t inflation_keys; /* Number of reissuance tokens, or 0 if none given */ uint64_t pegin_amount; /* Peg-in amount, or 0 if none given */ @@ -91,7 +91,7 @@ struct wally_psbt_input { struct wally_map pset_fields; /* Commitments/scripts/proofs etc keyed by PSET keytype*/ uint64_t amount; /* Explicit amount (not normally present, used for mixed-creator txs) */ uint32_t has_amount; -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ }; /** A PSBT output */ @@ -109,11 +109,11 @@ struct wally_psbt_output { /* Hashes and paths for taproot bip32 derivation path */ struct wally_map taproot_leaf_hashes; struct wally_map taproot_leaf_paths; -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS uint32_t blinder_index; /* Index of the input whose owner should blind this output */ uint32_t has_blinder_index; struct wally_map pset_fields; /* Commitments/pubkeys/proofs etc keyed by PSET keytype*/ -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ }; /** A partially signed bitcoin transaction */ @@ -133,10 +133,10 @@ struct wally_psbt { uint32_t fallback_locktime; uint32_t has_fallback_locktime; uint32_t tx_modifiable_flags; -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS struct wally_map global_scalars; uint32_t pset_modifiable_flags; -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ }; #endif /* SWIG */ diff --git a/include/wally_script.h b/include/wally_script.h index 980558f0a..99c4f168a 100644 --- a/include/wally_script.h +++ b/include/wally_script.h @@ -649,7 +649,7 @@ WALLY_CORE_API int wally_elements_pegin_contract_script_from_bytes( unsigned char *bytes_out, size_t len, size_t *written); -#endif +#endif /* BUILD_ELEMENTS */ #ifdef __cplusplus } diff --git a/include/wally_transaction.h b/include/wally_transaction.h index 118a9f109..151e9cb53 100644 --- a/include/wally_transaction.h +++ b/include/wally_transaction.h @@ -101,7 +101,7 @@ struct wally_tx_input { size_t script_len; struct wally_tx_witness_stack *witness; uint8_t features; -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS unsigned char blinding_nonce[SHA256_LEN]; unsigned char entropy[SHA256_LEN]; unsigned char *issuance_amount; @@ -113,7 +113,7 @@ struct wally_tx_input { unsigned char *inflation_keys_rangeproof; size_t inflation_keys_rangeproof_len; struct wally_tx_witness_stack *pegin_witness; -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ }; /** A transaction output */ @@ -122,7 +122,7 @@ struct wally_tx_output { unsigned char *script; size_t script_len; uint8_t features; -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS unsigned char *asset; size_t asset_len; unsigned char *value; @@ -133,7 +133,7 @@ struct wally_tx_output { size_t surjectionproof_len; unsigned char *rangeproof; size_t rangeproof_len; -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ }; /** A parsed bitcoin transaction */ diff --git a/src/transaction.c b/src/transaction.c index 0bb1e3ccf..7aaacd1f7 100644 --- a/src/transaction.c +++ b/src/transaction.c @@ -1269,7 +1269,7 @@ static int tx_add_elements_raw_input_at( (unsigned char *)script, script_len, (struct wally_tx_witness_stack *) witness, is_elements ? WALLY_TX_IS_ELEMENTS : 0, -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS { 0 }, { 0 }, (unsigned char *) issuance_amount, issuance_amount_len, (unsigned char *) inflation_keys, @@ -1279,11 +1279,11 @@ static int tx_add_elements_raw_input_at( (unsigned char *) inflation_keys_rangeproof, inflation_keys_rangeproof_len, (struct wally_tx_witness_stack *) pegin_witness -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ }; bool is_coinbase; int ret; -#ifndef BUILD_ELEMENTS +#ifdef WALLY_ABI_NO_ELEMENTS (void)pegin_witness; #endif @@ -1491,11 +1491,11 @@ static int tx_add_elements_raw_output_at( struct wally_tx_output output = { satoshi, (unsigned char *)script, script_len, is_elements ? WALLY_TX_IS_ELEMENTS : 0, -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS (unsigned char *)asset, asset_len, (unsigned char *)value, value_len, (unsigned char *)nonce, nonce_len, (unsigned char *)surjectionproof, surjectionproof_len, (unsigned char *)rangeproof, rangeproof_len, -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ }; int ret; From 5fae2bd18ffc03dc1e76d381c22c54d4ce777f43 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:18:05 +1200 Subject: [PATCH 04/26] build: switch other build infra to enable elements by default --- .gitlab-ci.yml | 2 +- README.md | 4 ++-- setup.py | 2 +- src/wasm_package/build.sh | 4 ++-- tools/android_helpers.sh | 2 +- tools/build_wasm.sh | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d9f9cbf00..25e4c500b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,7 +22,7 @@ bullseye_release: - tar cvf wally_dist/wallycore-android-jni.tar wallycore-android-jni - gzip -9 wally_dist/wallycore-android-jni.tar - source /opt/emsdk/emsdk_env.sh - - tools/build_wasm.sh --enable-elements + - tools/build_wasm.sh - cd wally_dist && tar cvf wallycore-wasm.tar --remove-files wallycore.html wallycore.js wallycore.wasm - gzip -9 wallycore-wasm.tar diff --git a/README.md b/README.md index 9ffca6c18..5cb1b92dd 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ $ source $HOME/emsdk/emsdk_env.sh $ export EXPORTED_FUNCTIONS="['_malloc','_free','_wally_init','_wally_cleanup',...]" # Build -$ ./tools/build_wasm.sh [--enable-elements] +$ ./tools/build_wasm.sh [--disable-elements] ``` Note that emsdk v3.1.27 or later is required. @@ -243,7 +243,7 @@ To generate an HTML coverage report, install `lcov` and use: ``` $ ./tools/cleanup.sh $ ./tools/autogen.sh -$ ./configure --enable-debug --enable-export-all --enable-swig-python --enable-swig-java --enable-coverage --enable-elements +$ ./configure --enable-debug --enable-export-all --enable-swig-python --enable-swig-java --enable-coverage $ make $ ./tools/coverage.sh clean $ make check diff --git a/setup.py b/setup.py index 350a5b316..e403ed81a 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ import copy, os, platform, shutil import distutils.sysconfig -CONFIGURE_ARGS = '--enable-swig-python --enable-python-manylinux --enable-elements' +CONFIGURE_ARGS = '--enable-swig-python --enable-python-manylinux' CONFIGURE_ARGS += ' --disable-swig-java --disable-tests --disable-dependency-tracking' distutils_env = distutils.sysconfig.get_config_vars() diff --git a/src/wasm_package/build.sh b/src/wasm_package/build.sh index 74032954a..3267a73e4 100755 --- a/src/wasm_package/build.sh +++ b/src/wasm_package/build.sh @@ -7,8 +7,8 @@ set -xeo pipefail # Update WASM package constants and version to match libwally (cd ../.. && ./tools/update_wasm_package.sh) -# Build WASM (Elements is always enabled) -(cd ../.. && ./tools/build_wasm.sh --enable-elements) +# Build WASM (Note Elements is always enabled) +(cd ../.. && ./tools/build_wasm.sh) mkdir -p libwally_wasm && cp ../../wally_dist/wallycore.{js,wasm} libwally_wasm/ touch libwally_wasm/index # necessary for webpack to work (fixes "Can't resolve './' in 'wasm_package/libwally_wasm'") diff --git a/tools/android_helpers.sh b/tools/android_helpers.sh index 23a4b252f..31681cbc6 100755 --- a/tools/android_helpers.sh +++ b/tools/android_helpers.sh @@ -71,7 +71,7 @@ function android_build_wally() { RANLIB=$toolsdir/bin/llvm-ranlib \ STRIP=$toolsdir/bin/llvm-strip \ ./configure --host=$(android_get_cross_compile_triplet $arch $api) \ - --enable-swig-java --disable-swig-python --enable-elements $useropts + --enable-swig-java --disable-swig-python $useropts local num_jobs=4 if [ -f /proc/cpuinfo ]; then num_jobs=$(grep ^processor /proc/cpuinfo | wc -l) diff --git a/tools/build_wasm.sh b/tools/build_wasm.sh index 190da56f0..371d89eed 100755 --- a/tools/build_wasm.sh +++ b/tools/build_wasm.sh @@ -2,9 +2,9 @@ set -e -ENABLE_ELEMENTS="" -if [ "$1" = "--enable-elements" ]; then - ENABLE_ELEMENTS="$1" +DISABLE_ELEMENTS="" +if [ "$1" = "--disable-elements" ]; then + DISABLE_ELEMENTS="--disable-elements --disable-elements-abi" fi num_jobs=4 @@ -26,7 +26,7 @@ $PWD/tools/cleanup.sh && $PWD/tools/autogen.sh #sed -i 's/WALLY_CORE_API/EMSCRIPTEN_KEEPALIVE/g' include/*.h src/*.h export CFLAGS="-fno-stack-protector" -emconfigure ./configure --build=$HOST_OS ac_cv_c_bigendian=no --disable-swig-python --disable-swig-java $ENABLE_ELEMENTS --disable-tests --enable-export-all --enable-wasm-interface +emconfigure ./configure --build=$HOST_OS ac_cv_c_bigendian=no --disable-swig-python --disable-swig-java $DISABLE_ELEMENTS --disable-tests --enable-export-all --enable-wasm-interface emmake make -j $num_jobs EMCC_OPTIONS="$EMCC_OPTIONS -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME=InitWally -s WASM_BIGINT" From f19718353eb951db84ac5bc44610bb3f818f1eff Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:18:14 +1200 Subject: [PATCH 05/26] tx: expose accessors for non-SWIG builds, move internal header to wally_transaction_members.h --- docs/source/conf.py | 4 ++-- .../wally_transaction_members.h | 14 +++++++------- src/swig_java/swig.i | 4 ++-- src/swig_python/swig.i | 4 ++-- src/transaction.c | 5 +---- tools/build_wrappers.py | 2 +- 6 files changed, 15 insertions(+), 18 deletions(-) rename src/transaction_int.h => include/wally_transaction_members.h (97%) diff --git a/docs/source/conf.py b/docs/source/conf.py index ee16c4440..61da01509 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -120,9 +120,9 @@ def extract_docs(infile, outfile): # Generate the documentation source files if DUMP_INTERNAL: - for m in ['bip32_int', 'transaction_int']: - extract_docs('../../src/%s.h' % m, '%s.rst' % m) + extract_docs('../../src/bip32_int.h', 'bip32_int.rst') extract_docs('../../include/wally_psbt_members.h', 'psbt_members.rst') + extract_docs('../../include/wally_transaction_members.h', 'transaction_members.rst') else: for m in [ 'address', 'anti_exfil', 'bip32', 'bip38', 'bip39', 'bip85', diff --git a/src/transaction_int.h b/include/wally_transaction_members.h similarity index 97% rename from src/transaction_int.h rename to include/wally_transaction_members.h index dc0a52451..2960fdd81 100644 --- a/src/transaction_int.h +++ b/include/wally_transaction_members.h @@ -1,7 +1,7 @@ -#ifndef LIBWALLY_CORE_TRANSACTION_INT_H -#define LIBWALLY_CORE_TRANSACTION_INT_H 1 +#ifndef LIBWALLY_CORE_TRANSACTION_MEMBERS_H +#define LIBWALLY_CORE_TRANSACTION_MEMBERS_H 1 -#if defined(SWIG) || defined (SWIG_JAVA_BUILD) || defined (SWIG_PYTHON_BUILD) || defined(SWIG_JAVASCRIPT_BUILD) || defined(WASM_BUILD) +/* Accessors for Transaction members */ #ifdef __cplusplus extern "C" { @@ -173,11 +173,11 @@ WALLY_CORE_API int wally_tx_set_output_value(const struct wally_tx *tx_in, size_ WALLY_CORE_API int wally_tx_set_output_nonce(const struct wally_tx *tx_in, size_t index, const unsigned char *nonce, size_t nonce_len); WALLY_CORE_API int wally_tx_set_output_surjectionproof(const struct wally_tx *tx_in, size_t index, const unsigned char *surjectionproof, size_t surjectionproof_len); WALLY_CORE_API int wally_tx_set_output_rangeproof(const struct wally_tx *tx_in, size_t index, const unsigned char *rangeproof, size_t rangeproof_len); -#endif +#endif /* BUILD_ELEMENTS */ + + #ifdef __cplusplus } #endif -#endif /* SWIG/SWIG_JAVA_BUILD/SWIG_PYTHON_BUILD/SWIG_JAVASCRIPT_BUILD/WASM_BUILD */ - -#endif /* LIBWALLY_CORE_TRANSACTION_INT_H */ +#endif /* LIBWALLY_CORE_TRANSACTION_MEMBERS_H */ diff --git a/src/swig_java/swig.i b/src/swig_java/swig.i index a5537d8bf..ccdc7a99c 100644 --- a/src/swig_java/swig.i +++ b/src/swig_java/swig.i @@ -17,7 +17,7 @@ #include "../include/wally_script.h" #include "../include/wally_symmetric.h" #include "../include/wally_transaction.h" -#include "transaction_int.h" +#include "../include/wally_transaction_members.h" #include "../include/wally_elements.h" #include "../internal.h" #include @@ -1342,5 +1342,5 @@ static jobjectArray create_jstringArray(JNIEnv *jenv, char **p, size_t len) { %include "../include/wally_script.h" %include "../include/wally_symmetric.h" %include "../include/wally_transaction.h" -%include "transaction_int.h" +%include "../include/wally_transaction_members.h" %include "../include/wally_elements.h" diff --git a/src/swig_python/swig.i b/src/swig_python/swig.i index 91ef0dcd1..f60847965 100644 --- a/src/swig_python/swig.i +++ b/src/swig_python/swig.i @@ -38,7 +38,7 @@ del swig_import_helper #include "../include/wally_script.h" #include "../include/wally_symmetric.h" #include "../include/wally_transaction.h" -#include "transaction_int.h" +#include "../include/wally_transaction_members.h" #include "../include/wally_elements.h" #include "../internal.h" @@ -456,5 +456,5 @@ static void destroy_words(PyObject *obj) { (void)obj; } %include "../include/wally_script.h" %include "../include/wally_symmetric.h" %include "../include/wally_transaction.h" -%include "transaction_int.h" +%include "../include/wally_transaction_members.h" %include "../include/wally_elements.h" diff --git a/src/transaction.c b/src/transaction.c index 7aaacd1f7..41b901aad 100644 --- a/src/transaction.c +++ b/src/transaction.c @@ -4,13 +4,13 @@ #include #include +#include #include #include #include #include "pullpush.h" #include "script_int.h" -#include "transaction_int.h" #define WALLY_TX_ALL_FLAGS \ (WALLY_TX_FLAG_USE_WITNESS | WALLY_TX_FLAG_USE_ELEMENTS | \ @@ -3493,8 +3493,6 @@ static struct wally_tx_input *tx_get_input(const struct wally_tx *tx, size_t ind return wally_tx_ ## typ ## _set_ ## name(tx_get_ ## typ(tx, index), name, name ## _len); \ } -#if defined (SWIG_JAVA_BUILD) || defined (SWIG_PYTHON_BUILD) || defined (SWIG_JAVASCRIPT_BUILD) || defined(WASM_BUILD) - /* Getters for wally_tx_input/wally_tx_output/wally_tx values */ static int tx_getb_impl(const void *input, @@ -3831,7 +3829,6 @@ TX_SET_B(output, nonce) TX_SET_B(output, surjectionproof) TX_SET_B(output, rangeproof) #endif -#endif /* SWIG_JAVA_BUILD/SWIG_PYTHON_BUILD/SWIG_JAVASCRIPT_BUILD/WASM_BUILD */ int wally_tx_input_set_witness(struct wally_tx_input *input, const struct wally_tx_witness_stack *stack) diff --git a/tools/build_wrappers.py b/tools/build_wrappers.py index 7aea69e2f..34e4b7ab4 100755 --- a/tools/build_wrappers.py +++ b/tools/build_wrappers.py @@ -52,7 +52,7 @@ def replace_text(filename, text, delims): def get_non_elements_functions(): # SWIG_PYTHON_BUILD=1 used to include internal functions too - cmd = "-E -DSWIG_PYTHON_BUILD=1 include/*.h src/bip32_int.h src/transaction_int.h |" \ + cmd = "-E -DSWIG_PYTHON_BUILD=1 include/*.h src/bip32_int.h |" \ "sort | uniq | sed 's/^ *WALLY_CORE_API//' | grep '^ *int ' | grep '(' | sed -e 's/^ *int //g' -e 's/(.*//g' | egrep '^wally_|^bip'" try: funcs = subprocess.check_output(u'gcc ' + cmd, shell=True) From 463533143c06b6b8316b67deb2c2f2ee59d162f2 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:18:43 +1200 Subject: [PATCH 06/26] cpp: update generated header to new ABI --- include/wally.hpp | 6 ++---- tools/build_wrappers.py | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/wally.hpp b/include/wally.hpp index 0dda137b5..bedc42064 100644 --- a/include/wally.hpp +++ b/include/wally.hpp @@ -18,9 +18,7 @@ #include #include #include -#ifdef BUILD_ELEMENTS #include -#endif /* These wrappers allow passing containers such as std::vector, std::array, * std::string and custom classes as input/output buffers to wally functions. @@ -2097,7 +2095,7 @@ inline int witness_program_from_bytes_and_version(const BYTES& bytes, uint32_t v return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; } -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS template inline int bip32_key_with_tweak_from_parent_path(const HDKEY& hdkey, const CHILD_PATH& child_path, uint32_t flags, struct ext_key* output) { int ret = ::bip32_key_with_tweak_from_parent_path(detail::get_p(hdkey), child_path.data(), child_path.size(), flags, output); @@ -3096,7 +3094,7 @@ inline int tx_is_elements(const TX& tx, size_t* written) { int ret = ::wally_tx_is_elements(detail::get_p(tx), written); return ret; } -#endif // BUILD_ELEMENTS +#endif // WALLY_ABI_NO_ELEMENTS /* END AUTOGENERATED */ inline struct secp256k1_context_struct *get_secp_context() { diff --git a/tools/build_wrappers.py b/tools/build_wrappers.py index 34e4b7ab4..5635df8c5 100755 --- a/tools/build_wrappers.py +++ b/tools/build_wrappers.py @@ -345,16 +345,15 @@ def gen_wally_hpp(funcs, all_funcs): else: impl.append(f' return ret;') impl.extend([u'}', u'']) - # FIXME: sort (cpp_elements if func.is_elements else cpp)[func.name] = impl text = [] for f in sorted(cpp.keys()): text.extend(cpp[f]) - text.append(u'#ifdef BUILD_ELEMENTS') + text.append(u'#ifndef WALLY_ABI_NO_ELEMENTS') for f in sorted(cpp_elements.keys()): text.extend(cpp_elements[f]) - text[-1] = u'#endif // BUILD_ELEMENTS' + text[-1] = u'#endif // WALLY_ABI_NO_ELEMENTS' replace_text(u'include/wally.hpp', text, [u'/* BEGIN AUTOGENERATED */', u'/* END AUTOGENERATED */']) From 14c36c5353d5cf6c7b94e3e8b308bb7ee2bddc69 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:18:56 +1200 Subject: [PATCH 07/26] cpp: force the user to provide an error handler for wally calls Also add missing coin selection header. --- include/wally.hpp | 1099 +++++++++++++++++++++------------------ tools/build_wrappers.py | 5 +- 2 files changed, 596 insertions(+), 508 deletions(-) diff --git a/include/wally.hpp b/include/wally.hpp index bedc42064..560cc0cb9 100644 --- a/include/wally.hpp +++ b/include/wally.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,11 @@ namespace wally { namespace detail { + +// Caller must provide an implementation of this call for error checking. +// It may either throw an exception when ret != WALLY_OK or return the error code. +int check_ret(const char* func_name, int ret); + template inline auto get_p(const P& p, std::false_type, std::true_type) { return &p[0]; } @@ -49,3050 +55,3133 @@ template <> inline auto get_p(const std::nullptr_t& p) { /* BEGIN AUTOGENERATED */ inline int bip32_key_free(const struct ext_key* hdkey) { int ret = ::bip32_key_free(hdkey); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_base58(const BASE58& base58, struct ext_key* output) { int ret = ::bip32_key_from_base58(detail::get_p(base58), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_base58_alloc(const BASE58& base58, struct ext_key** output) { int ret = ::bip32_key_from_base58_alloc(detail::get_p(base58), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_base58_n(const BASE58& base58, size_t base58_len, struct ext_key* output) { int ret = ::bip32_key_from_base58_n(detail::get_p(base58), base58_len, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_base58_n_alloc(const BASE58& base58, size_t base58_len, struct ext_key** output) { int ret = ::bip32_key_from_base58_n_alloc(detail::get_p(base58), base58_len, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_parent(const HDKEY& hdkey, uint32_t child_num, uint32_t flags, struct ext_key* output) { int ret = ::bip32_key_from_parent(detail::get_p(hdkey), child_num, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_parent_alloc(const HDKEY& hdkey, uint32_t child_num, uint32_t flags, struct ext_key** output) { int ret = ::bip32_key_from_parent_alloc(detail::get_p(hdkey), child_num, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_parent_path(const HDKEY& hdkey, const CHILD_PATH& child_path, uint32_t flags, struct ext_key* output) { int ret = ::bip32_key_from_parent_path(detail::get_p(hdkey), child_path.data(), child_path.size(), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_parent_path_alloc(const HDKEY& hdkey, const CHILD_PATH& child_path, uint32_t flags, struct ext_key** output) { int ret = ::bip32_key_from_parent_path_alloc(detail::get_p(hdkey), child_path.data(), child_path.size(), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_parent_path_str(const HDKEY& hdkey, const PATH_STR& path_str, uint32_t child_num, uint32_t flags, struct ext_key* output) { int ret = ::bip32_key_from_parent_path_str(detail::get_p(hdkey), detail::get_p(path_str), child_num, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_parent_path_str_alloc(const HDKEY& hdkey, const PATH_STR& path_str, uint32_t child_num, uint32_t flags, struct ext_key** output) { int ret = ::bip32_key_from_parent_path_str_alloc(detail::get_p(hdkey), detail::get_p(path_str), child_num, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_parent_path_str_n(const HDKEY& hdkey, const PATH_STR& path_str, size_t path_str_len, uint32_t child_num, uint32_t flags, struct ext_key* output) { int ret = ::bip32_key_from_parent_path_str_n(detail::get_p(hdkey), detail::get_p(path_str), path_str_len, child_num, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_parent_path_str_n_alloc(const HDKEY& hdkey, const PATH_STR& path_str, size_t path_str_len, uint32_t child_num, uint32_t flags, struct ext_key** output) { int ret = ::bip32_key_from_parent_path_str_n_alloc(detail::get_p(hdkey), detail::get_p(path_str), path_str_len, child_num, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_seed(const BYTES& bytes, uint32_t version, uint32_t flags, struct ext_key* output) { int ret = ::bip32_key_from_seed(bytes.data(), bytes.size(), version, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_seed_alloc(const BYTES& bytes, uint32_t version, uint32_t flags, struct ext_key** output) { int ret = ::bip32_key_from_seed_alloc(bytes.data(), bytes.size(), version, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_seed_custom(const BYTES& bytes, uint32_t version, const HMAC_KEY& hmac_key, uint32_t flags, struct ext_key* output) { int ret = ::bip32_key_from_seed_custom(bytes.data(), bytes.size(), version, hmac_key.data(), hmac_key.size(), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_from_seed_custom_alloc(const BYTES& bytes, uint32_t version, const HMAC_KEY& hmac_key, uint32_t flags, struct ext_key** output) { int ret = ::bip32_key_from_seed_custom_alloc(bytes.data(), bytes.size(), version, hmac_key.data(), hmac_key.size(), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_get_fingerprint(const HDKEY& hdkey, BYTES_OUT& bytes_out) { int ret = ::bip32_key_get_fingerprint(detail::get_p(hdkey), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_init(uint32_t version, uint32_t depth, uint32_t child_num, const CHAIN_CODE& chain_code, const PUB_KEY& pub_key, const PRIV_KEY& priv_key, const HASH160& hash160, const PARENT160& parent160, struct ext_key* output) { int ret = ::bip32_key_init(version, depth, child_num, chain_code.data(), chain_code.size(), pub_key.data(), pub_key.size(), priv_key.data(), priv_key.size(), hash160.data(), hash160.size(), parent160.data(), parent160.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_init_alloc(uint32_t version, uint32_t depth, uint32_t child_num, const CHAIN_CODE& chain_code, const PUB_KEY& pub_key, const PRIV_KEY& priv_key, const HASH160& hash160, const PARENT160& parent160, struct ext_key** output) { int ret = ::bip32_key_init_alloc(version, depth, child_num, chain_code.data(), chain_code.size(), pub_key.data(), pub_key.size(), priv_key.data(), priv_key.size(), hash160.data(), hash160.size(), parent160.data(), parent160.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_serialize(const HDKEY& hdkey, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::bip32_key_serialize(detail::get_p(hdkey), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int bip32_key_strip_private_key(struct ext_key* hdkey) { int ret = ::bip32_key_strip_private_key(hdkey); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_to_base58(const HDKEY& hdkey, uint32_t flags, char** output) { int ret = ::bip32_key_to_base58(detail::get_p(hdkey), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_unserialize(const BYTES& bytes, struct ext_key* output) { int ret = ::bip32_key_unserialize(bytes.data(), bytes.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_unserialize_alloc(const BYTES& bytes, struct ext_key** output) { int ret = ::bip32_key_unserialize_alloc(bytes.data(), bytes.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_path_from_str(const PATH_STR& path_str, uint32_t child_num, uint32_t multi_index, uint32_t flags, uint32_t* child_path_out, uint32_t child_path_out_len, size_t* written) { int ret = ::bip32_path_from_str(detail::get_p(path_str), child_num, multi_index, flags, child_path_out, child_path_out_len, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_path_from_str_n(const PATH_STR& path_str, size_t path_str_len, uint32_t child_num, uint32_t multi_index, uint32_t flags, uint32_t* child_path_out, uint32_t child_path_out_len, size_t* written) { int ret = ::bip32_path_from_str_n(detail::get_p(path_str), path_str_len, child_num, multi_index, flags, child_path_out, child_path_out_len, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_path_str_get_features(const PATH_STR& path_str, uint32_t* value_out) { int ret = ::bip32_path_str_get_features(detail::get_p(path_str), value_out); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_path_str_n_get_features(const PATH_STR& path_str, size_t path_str_len, uint32_t* value_out) { int ret = ::bip32_path_str_n_get_features(detail::get_p(path_str), path_str_len, value_out); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip38_from_private_key(const BYTES& bytes, const PASS& pass, uint32_t flags, char** output) { int ret = ::bip38_from_private_key(bytes.data(), bytes.size(), pass.data(), pass.size(), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip38_get_flags(const BIP38& bip38, size_t* written) { int ret = ::bip38_get_flags(detail::get_p(bip38), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip38_raw_from_private_key(const BYTES& bytes, const PASS& pass, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::bip38_raw_from_private_key(bytes.data(), bytes.size(), pass.data(), pass.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip38_raw_get_flags(const BYTES& bytes, size_t* written = 0) { size_t n; int ret = ::bip38_raw_get_flags(bytes.data(), bytes.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip38_raw_to_private_key(const BYTES& bytes, const PASS& pass, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::bip38_raw_to_private_key(bytes.data(), bytes.size(), pass.data(), pass.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip38_to_private_key(const BIP38& bip38, const PASS& pass, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::bip38_to_private_key(detail::get_p(bip38), pass.data(), pass.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int bip39_get_languages(char** output) { int ret = ::bip39_get_languages(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip39_get_word(const W& w, size_t index, char** output) { int ret = ::bip39_get_word(detail::get_p(w), index, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip39_get_wordlist(const LANG& lang, struct words** output) { int ret = ::bip39_get_wordlist(detail::get_p(lang), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip39_mnemonic_from_bytes(const W& w, const BYTES& bytes, char** output) { int ret = ::bip39_mnemonic_from_bytes(detail::get_p(w), bytes.data(), bytes.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip39_mnemonic_to_bytes(const W& w, const MNEMONIC& mnemonic, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::bip39_mnemonic_to_bytes(detail::get_p(w), detail::get_p(mnemonic), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip39_mnemonic_to_seed(const MNEMONIC& mnemonic, const PASSPHRASE& passphrase, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::bip39_mnemonic_to_seed(detail::get_p(mnemonic), detail::get_p(passphrase), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip39_mnemonic_to_seed512(const MNEMONIC& mnemonic, const PASSPHRASE& passphrase, BYTES_OUT& bytes_out) { int ret = ::bip39_mnemonic_to_seed512(detail::get_p(mnemonic), detail::get_p(passphrase), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip39_mnemonic_validate(const W& w, const char* mnemonic) { int ret = ::bip39_mnemonic_validate(detail::get_p(w), mnemonic); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip85_get_bip39_entropy(const HDKEY& hdkey, const LANG& lang, uint32_t num_words, uint32_t index, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::bip85_get_bip39_entropy(detail::get_p(hdkey), detail::get_p(lang), num_words, index, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } inline int bip85_get_languages(char** output) { int ret = ::bip85_get_languages(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int addr_segwit_from_bytes(const BYTES& bytes, const ADDR_FAMILY& addr_family, uint32_t flags, char** output) { int ret = ::wally_addr_segwit_from_bytes(bytes.data(), bytes.size(), detail::get_p(addr_family), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int addr_segwit_get_version(const ADDR& addr, const ADDR_FAMILY& addr_family, uint32_t flags, size_t* written) { int ret = ::wally_addr_segwit_get_version(detail::get_p(addr), detail::get_p(addr_family), flags, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int addr_segwit_n_get_version(const ADDR& addr, size_t addr_len, const ADDR_FAMILY& addr_family, size_t addr_family_len, uint32_t flags, size_t* written) { int ret = ::wally_addr_segwit_n_get_version(detail::get_p(addr), addr_len, detail::get_p(addr_family), addr_family_len, flags, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int addr_segwit_n_to_bytes(const ADDR& addr, size_t addr_len, const ADDR_FAMILY& addr_family, size_t addr_family_len, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_addr_segwit_n_to_bytes(detail::get_p(addr), addr_len, detail::get_p(addr_family), addr_family_len, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int addr_segwit_to_bytes(const ADDR& addr, const ADDR_FAMILY& addr_family, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_addr_segwit_to_bytes(detail::get_p(addr), detail::get_p(addr_family), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int address_to_scriptpubkey(const ADDR& addr, uint32_t network, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_address_to_scriptpubkey(detail::get_p(addr), network, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int ae_host_commit_from_bytes(const ENTROPY& entropy, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_ae_host_commit_from_bytes(entropy.data(), entropy.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ae_sig_from_bytes(const PRIV_KEY& priv_key, const BYTES& bytes, const ENTROPY& entropy, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_ae_sig_from_bytes(priv_key.data(), priv_key.size(), bytes.data(), bytes.size(), entropy.data(), entropy.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ae_signer_commit_from_bytes(const PRIV_KEY& priv_key, const BYTES& bytes, const COMMITMENT& commitment, uint32_t flags, S2C_OPENING_OUT& s2c_opening_out) { int ret = ::wally_ae_signer_commit_from_bytes(priv_key.data(), priv_key.size(), bytes.data(), bytes.size(), commitment.data(), commitment.size(), flags, s2c_opening_out.data(), s2c_opening_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ae_verify(const PUB_KEY& pub_key, const BYTES& bytes, const ENTROPY& entropy, const S2C_OPENING& s2c_opening, uint32_t flags, const SIG& sig) { int ret = ::wally_ae_verify(pub_key.data(), pub_key.size(), bytes.data(), bytes.size(), entropy.data(), entropy.size(), s2c_opening.data(), s2c_opening.size(), flags, sig.data(), sig.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int aes(const KEY& key, const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_aes(key.data(), key.size(), bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int aes_cbc(const KEY& key, const IV& iv, const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_aes_cbc(key.data(), key.size(), iv.data(), iv.size(), bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int base58_from_bytes(const BYTES& bytes, uint32_t flags, char** output) { int ret = ::wally_base58_from_bytes(bytes.data(), bytes.size(), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int base58_get_length(const STR_IN& str_in, size_t* written) { int ret = ::wally_base58_get_length(detail::get_p(str_in), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int base58_n_get_length(const STR_IN& str_in, size_t str_len, size_t* written) { int ret = ::wally_base58_n_get_length(detail::get_p(str_in), str_len, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int base58_n_to_bytes(const STR_IN& str_in, size_t str_len, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_base58_n_to_bytes(detail::get_p(str_in), str_len, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int base58_to_bytes(const STR_IN& str_in, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_base58_to_bytes(detail::get_p(str_in), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int base64_from_bytes(const BYTES& bytes, uint32_t flags, char** output) { int ret = ::wally_base64_from_bytes(bytes.data(), bytes.size(), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int base64_get_maximum_length(const STR_IN& str_in, uint32_t flags, size_t* written) { int ret = ::wally_base64_get_maximum_length(detail::get_p(str_in), flags, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int base64_to_bytes(const STR_IN& str_in, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_base64_to_bytes(detail::get_p(str_in), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_to_addr_segwit(const HDKEY& hdkey, const ADDR_FAMILY& addr_family, uint32_t flags, char** output) { int ret = ::wally_bip32_key_to_addr_segwit(detail::get_p(hdkey), detail::get_p(addr_family), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_to_address(const HDKEY& hdkey, uint32_t flags, uint32_t version, char** output) { int ret = ::wally_bip32_key_to_address(detail::get_p(hdkey), flags, version, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip340_tagged_hash(const BYTES& bytes, const TAG& tag, BYTES_OUT& bytes_out) { int ret = ::wally_bip340_tagged_hash(bytes.data(), bytes.size(), detail::get_p(tag), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bzero(const BYTES& bytes, size_t bytes_len) { int ret = ::wally_bzero(detail::get_p(bytes), bytes_len); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int cleanup(uint32_t flags) { int ret = ::wally_cleanup(flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_canonicalize(const DESCRIPTOR& descriptor, uint32_t flags, char** output) { int ret = ::wally_descriptor_canonicalize(detail::get_p(descriptor), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int descriptor_free(struct wally_descriptor* descriptor) { int ret = ::wally_descriptor_free(descriptor); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_get_checksum(const DESCRIPTOR& descriptor, uint32_t flags, char** output) { int ret = ::wally_descriptor_get_checksum(detail::get_p(descriptor), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_get_depth(const DESCRIPTOR& descriptor, uint32_t* value_out) { int ret = ::wally_descriptor_get_depth(detail::get_p(descriptor), value_out); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_get_features(const DESCRIPTOR& descriptor, uint32_t* value_out) { int ret = ::wally_descriptor_get_features(detail::get_p(descriptor), value_out); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_get_network(const DESCRIPTOR& descriptor, uint32_t* value_out) { int ret = ::wally_descriptor_get_network(detail::get_p(descriptor), value_out); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_get_num_paths(const DESCRIPTOR& descriptor, uint32_t* value_out) { int ret = ::wally_descriptor_get_num_paths(detail::get_p(descriptor), value_out); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_get_num_variants(const DESCRIPTOR& descriptor, uint32_t* value_out) { int ret = ::wally_descriptor_get_num_variants(detail::get_p(descriptor), value_out); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_parse(const DESCRIPTOR& descriptor, const VARS_IN& vars_in, uint32_t network, uint32_t flags, struct wally_descriptor** output) { int ret = ::wally_descriptor_parse(detail::get_p(descriptor), detail::get_p(vars_in), network, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_set_network(const DESCRIPTOR& descriptor, uint32_t network) { int ret = ::wally_descriptor_set_network(detail::get_p(descriptor), network); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_to_address(const DESCRIPTOR& descriptor, uint32_t variant, uint32_t multi_index, uint32_t child_num, uint32_t flags, char** output) { int ret = ::wally_descriptor_to_address(detail::get_p(descriptor), variant, multi_index, child_num, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_to_addresses(const DESCRIPTOR& descriptor, uint32_t variant, uint32_t multi_index, uint32_t child_num, uint32_t flags, char** output, size_t num_outputs) { int ret = ::wally_descriptor_to_addresses(detail::get_p(descriptor), variant, multi_index, child_num, flags, output, num_outputs); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_to_script(const DESCRIPTOR& descriptor, uint32_t depth, uint32_t index, uint32_t variant, uint32_t multi_index, uint32_t child_num, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_descriptor_to_script(detail::get_p(descriptor), depth, index, variant, multi_index, child_num, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int descriptor_to_script_get_maximum_length(const DESCRIPTOR& descriptor, uint32_t depth, uint32_t index, uint32_t variant, uint32_t multi_index, uint32_t child_num, uint32_t flags, size_t* written) { int ret = ::wally_descriptor_to_script_get_maximum_length(detail::get_p(descriptor), depth, index, variant, multi_index, child_num, flags, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_private_key_bip341_tweak(const PRIV_KEY& priv_key, const MERKLE_ROOT& merkle_root, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_ec_private_key_bip341_tweak(priv_key.data(), priv_key.size(), merkle_root.data(), merkle_root.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_private_key_verify(const PRIV_KEY& priv_key) { int ret = ::wally_ec_private_key_verify(priv_key.data(), priv_key.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_public_key_bip341_tweak(const PUB_KEY& pub_key, const MERKLE_ROOT& merkle_root, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_ec_public_key_bip341_tweak(pub_key.data(), pub_key.size(), merkle_root.data(), merkle_root.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_public_key_decompress(const PUB_KEY& pub_key, BYTES_OUT& bytes_out) { int ret = ::wally_ec_public_key_decompress(pub_key.data(), pub_key.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_public_key_from_private_key(const PRIV_KEY& priv_key, BYTES_OUT& bytes_out) { int ret = ::wally_ec_public_key_from_private_key(priv_key.data(), priv_key.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_public_key_negate(const PUB_KEY& pub_key, BYTES_OUT& bytes_out) { int ret = ::wally_ec_public_key_negate(pub_key.data(), pub_key.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_public_key_verify(const PUB_KEY& pub_key) { int ret = ::wally_ec_public_key_verify(pub_key.data(), pub_key.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_scalar_add(const SCALAR& scalar, const OPERAND& operand, BYTES_OUT& bytes_out) { int ret = ::wally_ec_scalar_add(scalar.data(), scalar.size(), operand.data(), operand.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_scalar_add_to(SCALAR& scalar, const OPERAND& operand) { int ret = ::wally_ec_scalar_add_to(scalar.data(), scalar.size(), operand.data(), operand.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_scalar_multiply(const SCALAR& scalar, const OPERAND& operand, BYTES_OUT& bytes_out) { int ret = ::wally_ec_scalar_multiply(scalar.data(), scalar.size(), operand.data(), operand.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_scalar_multiply_by(SCALAR& scalar, const OPERAND& operand) { int ret = ::wally_ec_scalar_multiply_by(scalar.data(), scalar.size(), operand.data(), operand.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_scalar_subtract(const SCALAR& scalar, const OPERAND& operand, BYTES_OUT& bytes_out) { int ret = ::wally_ec_scalar_subtract(scalar.data(), scalar.size(), operand.data(), operand.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_scalar_subtract_from(SCALAR& scalar, const OPERAND& operand) { int ret = ::wally_ec_scalar_subtract_from(scalar.data(), scalar.size(), operand.data(), operand.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_scalar_verify(const SCALAR& scalar) { int ret = ::wally_ec_scalar_verify(scalar.data(), scalar.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_sig_from_bytes(const PRIV_KEY& priv_key, const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_ec_sig_from_bytes(priv_key.data(), priv_key.size(), bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_sig_from_bytes_aux(const PRIV_KEY& priv_key, const BYTES& bytes, const AUX_RAND& aux_rand, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_ec_sig_from_bytes_aux(priv_key.data(), priv_key.size(), bytes.data(), bytes.size(), aux_rand.data(), aux_rand.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_sig_from_bytes_aux_len(const PRIV_KEY& priv_key, const BYTES& bytes, const AUX_RAND& aux_rand, uint32_t flags, size_t* written) { int ret = ::wally_ec_sig_from_bytes_aux_len(priv_key.data(), priv_key.size(), bytes.data(), bytes.size(), aux_rand.data(), aux_rand.size(), flags, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_sig_from_bytes_len(const PRIV_KEY& priv_key, const BYTES& bytes, uint32_t flags, size_t* written) { int ret = ::wally_ec_sig_from_bytes_len(priv_key.data(), priv_key.size(), bytes.data(), bytes.size(), flags, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_sig_from_der(const BYTES& bytes, BYTES_OUT& bytes_out) { int ret = ::wally_ec_sig_from_der(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_sig_normalize(const SIG& sig, BYTES_OUT& bytes_out) { int ret = ::wally_ec_sig_normalize(sig.data(), sig.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_sig_to_der(const SIG& sig, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_ec_sig_to_der(sig.data(), sig.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_sig_to_public_key(const BYTES& bytes, const SIG& sig, BYTES_OUT& bytes_out) { int ret = ::wally_ec_sig_to_public_key(bytes.data(), bytes.size(), sig.data(), sig.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_sig_verify(const PUB_KEY& pub_key, const BYTES& bytes, uint32_t flags, const SIG& sig) { int ret = ::wally_ec_sig_verify(pub_key.data(), pub_key.size(), bytes.data(), bytes.size(), flags, sig.data(), sig.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ec_xonly_public_key_verify(const PUB_KEY& pub_key) { int ret = ::wally_ec_xonly_public_key_verify(pub_key.data(), pub_key.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ecdh(const PUB_KEY& pub_key, const PRIV_KEY& priv_key, BYTES_OUT& bytes_out) { int ret = ::wally_ecdh(pub_key.data(), pub_key.size(), priv_key.data(), priv_key.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int format_bitcoin_message(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_format_bitcoin_message(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } inline int free_string(char* str) { int ret = ::wally_free_string(str); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int get_build_version(uint32_t* value) { int ret = ::wally_get_build_version(value); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int get_hash_prevouts(const TXHASHES& txhashes, const UTXO_INDICES& utxo_indices, BYTES_OUT& bytes_out) { int ret = ::wally_get_hash_prevouts(txhashes.data(), txhashes.size(), utxo_indices.data(), utxo_indices.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int get_operations(struct wally_operations* output) { int ret = ::wally_get_operations(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int hash160(const BYTES& bytes, BYTES_OUT& bytes_out) { int ret = ::wally_hash160(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int hex_from_bytes(const BYTES& bytes, char** output) { int ret = ::wally_hex_from_bytes(bytes.data(), bytes.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int hex_n_to_bytes(const HEX& hex, size_t hex_len, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_hex_n_to_bytes(detail::get_p(hex), hex_len, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int hex_n_verify(const HEX& hex, size_t hex_len) { int ret = ::wally_hex_n_verify(detail::get_p(hex), hex_len); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int hex_to_bytes(const HEX& hex, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_hex_to_bytes(detail::get_p(hex), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } inline int hex_verify(const char* hex) { int ret = ::wally_hex_verify(hex); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int hmac_sha256(const KEY& key, const BYTES& bytes, BYTES_OUT& bytes_out) { int ret = ::wally_hmac_sha256(key.data(), key.size(), bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int hmac_sha512(const KEY& key, const BYTES& bytes, BYTES_OUT& bytes_out) { int ret = ::wally_hmac_sha512(key.data(), key.size(), bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int init(uint32_t flags) { int ret = ::wally_init(flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int is_elements_build(size_t* written) { int ret = ::wally_is_elements_build(written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int keypath_bip32_verify(const KEY& key, const VAL& val) { int ret = ::wally_keypath_bip32_verify(key.data(), key.size(), val.data(), val.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int keypath_get_fingerprint(const VAL& val, BYTES_OUT& bytes_out) { int ret = ::wally_keypath_get_fingerprint(val.data(), val.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int keypath_get_path(const VAL& val, uint32_t* child_path_out, size_t child_path_out_len, size_t* written) { int ret = ::wally_keypath_get_path(val.data(), val.size(), child_path_out, child_path_out_len, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int keypath_get_path_len(const VAL& val, size_t* written = 0) { size_t n; int ret = ::wally_keypath_get_path_len(val.data(), val.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(val.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(val.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int keypath_public_key_verify(const KEY& key, const VAL& val) { int ret = ::wally_keypath_public_key_verify(key.data(), key.size(), val.data(), val.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int keypath_xonly_public_key_verify(const KEY& key, const VAL& val) { int ret = ::wally_keypath_xonly_public_key_verify(key.data(), key.size(), val.data(), val.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_add(const MAP_IN& map_in, const KEY& key, const VALUE& value) { int ret = ::wally_map_add(detail::get_p(map_in), key.data(), key.size(), value.data(), value.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_add_integer(const MAP_IN& map_in, uint32_t key, const VALUE& value) { int ret = ::wally_map_add_integer(detail::get_p(map_in), key, value.data(), value.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_assign(const MAP_IN& map_in, const struct wally_map* source) { int ret = ::wally_map_assign(detail::get_p(map_in), source); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int map_clear(struct wally_map* map_in) { int ret = ::wally_map_clear(map_in); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_combine(const MAP_IN& map_in, const struct wally_map* source) { int ret = ::wally_map_combine(detail::get_p(map_in), source); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_find(const MAP_IN& map_in, const KEY& key, size_t* written = 0) { size_t n; int ret = ::wally_map_find(detail::get_p(map_in), key.data(), key.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(key.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(key.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_find_bip32_public_key_from(const MAP_IN& map_in, size_t index, const HDKEY& hdkey, size_t* written) { int ret = ::wally_map_find_bip32_public_key_from(detail::get_p(map_in), index, detail::get_p(hdkey), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_find_from(const MAP_IN& map_in, size_t index, const KEY& key, size_t* written = 0) { size_t n; int ret = ::wally_map_find_from(detail::get_p(map_in), index, key.data(), key.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(key.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(key.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_find_integer(const MAP_IN& map_in, uint32_t key, size_t* written) { int ret = ::wally_map_find_integer(detail::get_p(map_in), key, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int map_free(struct wally_map* map_in) { int ret = ::wally_map_free(map_in); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_get_item(const MAP_IN& map_in, size_t index, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_map_get_item(detail::get_p(map_in), index, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_get_item_integer_key(const MAP_IN& map_in, size_t index, size_t* written) { int ret = ::wally_map_get_item_integer_key(detail::get_p(map_in), index, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_get_item_key(const MAP_IN& map_in, size_t index, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_map_get_item_key(detail::get_p(map_in), index, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_get_item_key_length(const MAP_IN& map_in, size_t index, size_t* written) { int ret = ::wally_map_get_item_key_length(detail::get_p(map_in), index, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_get_item_length(const MAP_IN& map_in, size_t index, size_t* written) { int ret = ::wally_map_get_item_length(detail::get_p(map_in), index, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_get_num_items(const MAP_IN& map_in, size_t* written) { int ret = ::wally_map_get_num_items(detail::get_p(map_in), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_hash_preimage_verify(const KEY& key, const VAL& val) { int ret = ::wally_map_hash_preimage_verify(key.data(), key.size(), val.data(), val.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int map_init(size_t allocation_len, wally_map_verify_fn_t verify_fn, struct wally_map* output) { int ret = ::wally_map_init(allocation_len, verify_fn, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int map_init_alloc(size_t allocation_len, wally_map_verify_fn_t verify_fn, struct wally_map** output) { int ret = ::wally_map_init_alloc(allocation_len, verify_fn, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_keypath_add(const MAP_IN& map_in, const PUB_KEY& pub_key, const FINGERPRINT& fingerprint, const CHILD_PATH& child_path) { int ret = ::wally_map_keypath_add(detail::get_p(map_in), pub_key.data(), pub_key.size(), fingerprint.data(), fingerprint.size(), child_path.data(), child_path.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int map_keypath_bip32_init_alloc(size_t allocation_len, struct wally_map** output) { int ret = ::wally_map_keypath_bip32_init_alloc(allocation_len, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_keypath_get_bip32_key_from_alloc(const MAP_IN& map_in, size_t index, const HDKEY& hdkey, struct ext_key** output) { int ret = ::wally_map_keypath_get_bip32_key_from_alloc(detail::get_p(map_in), index, detail::get_p(hdkey), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_keypath_get_item_fingerprint(const MAP_IN& map_in, size_t index, BYTES_OUT& bytes_out) { int ret = ::wally_map_keypath_get_item_fingerprint(detail::get_p(map_in), index, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_keypath_get_item_path(const MAP_IN& map_in, size_t index, uint32_t* child_path_out, size_t child_path_out_len, size_t* written) { int ret = ::wally_map_keypath_get_item_path(detail::get_p(map_in), index, child_path_out, child_path_out_len, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_keypath_get_item_path_len(const MAP_IN& map_in, size_t index, size_t* written) { int ret = ::wally_map_keypath_get_item_path_len(detail::get_p(map_in), index, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int map_keypath_public_key_init_alloc(size_t allocation_len, struct wally_map** output) { int ret = ::wally_map_keypath_public_key_init_alloc(allocation_len, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_merkle_path_add(const MAP_IN& map_in, const PUB_KEY& pub_key, const MERKLE_HASHES& merkle_hashes) { int ret = ::wally_map_merkle_path_add(detail::get_p(map_in), pub_key.data(), pub_key.size(), merkle_hashes.data(), merkle_hashes.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_preimage_hash160_add(const MAP_IN& map_in, const VALUE& value) { int ret = ::wally_map_preimage_hash160_add(detail::get_p(map_in), value.data(), value.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int map_preimage_init_alloc(size_t allocation_len, struct wally_map** output) { int ret = ::wally_map_preimage_init_alloc(allocation_len, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_preimage_ripemd160_add(const MAP_IN& map_in, const VALUE& value) { int ret = ::wally_map_preimage_ripemd160_add(detail::get_p(map_in), value.data(), value.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_preimage_sha256_add(const MAP_IN& map_in, const VALUE& value) { int ret = ::wally_map_preimage_sha256_add(detail::get_p(map_in), value.data(), value.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_preimage_sha256d_add(const MAP_IN& map_in, const VALUE& value) { int ret = ::wally_map_preimage_sha256d_add(detail::get_p(map_in), value.data(), value.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_remove(const MAP_IN& map_in, const KEY& key) { int ret = ::wally_map_remove(detail::get_p(map_in), key.data(), key.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_remove_integer(const MAP_IN& map_in, uint32_t key) { int ret = ::wally_map_remove_integer(detail::get_p(map_in), key); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_replace(const MAP_IN& map_in, const KEY& key, const VALUE& value) { int ret = ::wally_map_replace(detail::get_p(map_in), key.data(), key.size(), value.data(), value.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_replace_integer(const MAP_IN& map_in, uint32_t key, const VALUE& value) { int ret = ::wally_map_replace_integer(detail::get_p(map_in), key, value.data(), value.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int map_sort(const MAP_IN& map_in, uint32_t flags) { int ret = ::wally_map_sort(detail::get_p(map_in), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int merkle_path_xonly_public_key_verify(const KEY& key, const VAL& val) { int ret = ::wally_merkle_path_xonly_public_key_verify(key.data(), key.size(), val.data(), val.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int pbkdf2_hmac_sha256(const PASS& pass, const SALT& salt, uint32_t flags, uint32_t cost, BYTES_OUT& bytes_out) { int ret = ::wally_pbkdf2_hmac_sha256(pass.data(), pass.size(), salt.data(), salt.size(), flags, cost, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int pbkdf2_hmac_sha512(const PASS& pass, const SALT& salt, uint32_t flags, uint32_t cost, BYTES_OUT& bytes_out) { int ret = ::wally_pbkdf2_hmac_sha512(pass.data(), pass.size(), salt.data(), salt.size(), flags, cost, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_add_input_taproot_keypath(const PSBT& psbt, uint32_t index, uint32_t flags, const PUB_KEY& pub_key, const TAPLEAF_HASHES& tapleaf_hashes, const FINGERPRINT& fingerprint, const CHILD_PATH& child_path) { int ret = ::wally_psbt_add_input_taproot_keypath(detail::get_p(psbt), index, flags, pub_key.data(), pub_key.size(), tapleaf_hashes.data(), tapleaf_hashes.size(), fingerprint.data(), fingerprint.size(), child_path.data(), child_path.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_add_output_taproot_keypath(const PSBT& psbt, uint32_t index, uint32_t flags, const PUB_KEY& pub_key, const TAPLEAF_HASHES& tapleaf_hashes, const FINGERPRINT& fingerprint, const CHILD_PATH& child_path) { int ret = ::wally_psbt_add_output_taproot_keypath(detail::get_p(psbt), index, flags, pub_key.data(), pub_key.size(), tapleaf_hashes.data(), tapleaf_hashes.size(), fingerprint.data(), fingerprint.size(), child_path.data(), child_path.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_add_tx_input_at(const PSBT& psbt, uint32_t index, uint32_t flags, const struct wally_tx_input* input) { int ret = ::wally_psbt_add_tx_input_at(detail::get_p(psbt), index, flags, input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_add_tx_output_at(const PSBT& psbt, uint32_t index, uint32_t flags, const struct wally_tx_output* output) { int ret = ::wally_psbt_add_tx_output_at(detail::get_p(psbt), index, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_blind(const PSBT& psbt, const VALUES& values, const VBFS& vbfs, const ASSETS& assets, const ABFS& abfs, const ENTROPY& entropy, uint32_t output_index, uint32_t flags, struct wally_map* output) { int ret = ::wally_psbt_blind(detail::get_p(psbt), detail::get_p(values), detail::get_p(vbfs), detail::get_p(assets), detail::get_p(abfs), entropy.data(), entropy.size(), output_index, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_blind_alloc(const PSBT& psbt, const VALUES& values, const VBFS& vbfs, const ASSETS& assets, const ABFS& abfs, const ENTROPY& entropy, uint32_t output_index, uint32_t flags, struct wally_map** output) { int ret = ::wally_psbt_blind_alloc(detail::get_p(psbt), detail::get_p(values), detail::get_p(vbfs), detail::get_p(assets), detail::get_p(abfs), entropy.data(), entropy.size(), output_index, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_clear_fallback_locktime(struct wally_psbt* psbt) { int ret = ::wally_psbt_clear_fallback_locktime(psbt); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_clone_alloc(const PSBT& psbt, uint32_t flags, struct wally_psbt** output) { int ret = ::wally_psbt_clone_alloc(detail::get_p(psbt), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_combine(const PSBT& psbt, const struct wally_psbt* source) { int ret = ::wally_psbt_combine(detail::get_p(psbt), source); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_extract(const PSBT& psbt, uint32_t flags, struct wally_tx** output) { int ret = ::wally_psbt_extract(detail::get_p(psbt), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_finalize(const PSBT& psbt, uint32_t flags) { int ret = ::wally_psbt_finalize(detail::get_p(psbt), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_finalize_input(const PSBT& psbt, size_t index, uint32_t flags) { int ret = ::wally_psbt_finalize_input(detail::get_p(psbt), index, flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_find_input_spending_utxo(const PSBT& psbt, const TXHASH& txhash, uint32_t utxo_index, size_t* written) { int ret = ::wally_psbt_find_input_spending_utxo(detail::get_p(psbt), txhash.data(), txhash.size(), utxo_index, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_free(struct wally_psbt* psbt) { int ret = ::wally_psbt_free(psbt); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_from_base64(const BASE64& base64, uint32_t flags, struct wally_psbt** output) { int ret = ::wally_psbt_from_base64(detail::get_p(base64), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_from_bytes(const BYTES& bytes, uint32_t flags, struct wally_psbt** output) { int ret = ::wally_psbt_from_bytes(bytes.data(), bytes.size(), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_from_tx(const TX& tx, uint32_t version, uint32_t flags, struct wally_psbt** output) { int ret = ::wally_psbt_from_tx(detail::get_p(tx), version, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_get_id(const PSBT& psbt, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_psbt_get_id(detail::get_p(psbt), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_get_input_bip32_key_from_alloc(const PSBT& psbt, size_t index, size_t subindex, uint32_t flags, const HDKEY& hdkey, struct ext_key** output) { int ret = ::wally_psbt_get_input_bip32_key_from_alloc(detail::get_p(psbt), index, subindex, flags, detail::get_p(hdkey), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_get_input_scriptcode(const PSBT& psbt, size_t index, const SCRIPT& script, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_get_input_scriptcode(detail::get_p(psbt), index, script.data(), script.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_get_input_scriptcode_len(const PSBT& psbt, size_t index, const SCRIPT& script, size_t* written = 0) { size_t n; int ret = ::wally_psbt_get_input_scriptcode_len(detail::get_p(psbt), index, script.data(), script.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(script.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(script.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_get_input_signature_hash(const PSBT& psbt, size_t index, const TX& tx, const SCRIPT& script, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_psbt_get_input_signature_hash(detail::get_p(psbt), index, detail::get_p(tx), script.data(), script.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_get_input_signing_script(const PSBT& psbt, size_t index, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_get_input_signing_script(detail::get_p(psbt), index, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_get_input_signing_script_len(const PSBT& psbt, size_t index, size_t* written) { int ret = ::wally_psbt_get_input_signing_script_len(detail::get_p(psbt), index, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_get_length(const PSBT& psbt, uint32_t flags, size_t* written) { int ret = ::wally_psbt_get_length(detail::get_p(psbt), flags, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_get_locktime(const PSBT& psbt, size_t* written) { int ret = ::wally_psbt_get_locktime(detail::get_p(psbt), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_get_tx_version(const PSBT& psbt, size_t* written) { int ret = ::wally_psbt_get_tx_version(detail::get_p(psbt), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_init_alloc(uint32_t version, size_t inputs_allocation_len, size_t outputs_allocation_len, size_t global_unknowns_allocation_len, uint32_t flags, struct wally_psbt** output) { int ret = ::wally_psbt_init_alloc(version, inputs_allocation_len, outputs_allocation_len, global_unknowns_allocation_len, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_add_signature(const INPUT& input, const PUB_KEY& pub_key, const SIG& sig) { int ret = ::wally_psbt_input_add_signature(detail::get_p(input), pub_key.data(), pub_key.size(), sig.data(), sig.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_required_lockheight(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_required_lockheight(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_required_locktime(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_required_locktime(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_sequence(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_sequence(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_find_keypath(const INPUT& input, const PUB_KEY& pub_key, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_find_keypath(detail::get_p(input), pub_key.data(), pub_key.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(pub_key.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(pub_key.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_find_signature(const INPUT& input, const PUB_KEY& pub_key, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_find_signature(detail::get_p(input), pub_key.data(), pub_key.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(pub_key.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(pub_key.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_find_unknown(const INPUT& input, const KEY& key, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_find_unknown(detail::get_p(input), key.data(), key.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(key.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(key.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_is_finalized(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_is_finalized(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_keypath_add(const INPUT& input, const PUB_KEY& pub_key, const FINGERPRINT& fingerprint, const CHILD_PATH& child_path) { int ret = ::wally_psbt_input_keypath_add(detail::get_p(input), pub_key.data(), pub_key.size(), fingerprint.data(), fingerprint.size(), child_path.data(), child_path.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_final_scriptsig(const INPUT& input, const FINAL_SCRIPTSIG& final_scriptsig) { int ret = ::wally_psbt_input_set_final_scriptsig(detail::get_p(input), final_scriptsig.data(), final_scriptsig.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_final_witness(const INPUT& input, const struct wally_tx_witness_stack* witness) { int ret = ::wally_psbt_input_set_final_witness(detail::get_p(input), witness); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_keypaths(const INPUT& input, const struct wally_map* map_in) { int ret = ::wally_psbt_input_set_keypaths(detail::get_p(input), map_in); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_output_index(const INPUT& input, uint32_t index) { int ret = ::wally_psbt_input_set_output_index(detail::get_p(input), index); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_previous_txid(const INPUT& input, const TXHASH& txhash) { int ret = ::wally_psbt_input_set_previous_txid(detail::get_p(input), txhash.data(), txhash.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_redeem_script(const INPUT& input, const SCRIPT& script) { int ret = ::wally_psbt_input_set_redeem_script(detail::get_p(input), script.data(), script.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_required_lockheight(const INPUT& input, uint32_t required_lockheight) { int ret = ::wally_psbt_input_set_required_lockheight(detail::get_p(input), required_lockheight); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_required_locktime(const INPUT& input, uint32_t required_locktime) { int ret = ::wally_psbt_input_set_required_locktime(detail::get_p(input), required_locktime); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_sequence(const INPUT& input, uint32_t sequence) { int ret = ::wally_psbt_input_set_sequence(detail::get_p(input), sequence); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_sighash(const INPUT& input, uint32_t sighash) { int ret = ::wally_psbt_input_set_sighash(detail::get_p(input), sighash); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_signatures(const INPUT& input, const struct wally_map* map_in) { int ret = ::wally_psbt_input_set_signatures(detail::get_p(input), map_in); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_taproot_signature(const INPUT& input, const TAP_SIG& tap_sig) { int ret = ::wally_psbt_input_set_taproot_signature(detail::get_p(input), tap_sig.data(), tap_sig.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_unknowns(const INPUT& input, const struct wally_map* map_in) { int ret = ::wally_psbt_input_set_unknowns(detail::get_p(input), map_in); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_utxo(const INPUT& input, const struct wally_tx* utxo) { int ret = ::wally_psbt_input_set_utxo(detail::get_p(input), utxo); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_witness_script(const INPUT& input, const SCRIPT& script) { int ret = ::wally_psbt_input_set_witness_script(detail::get_p(input), script.data(), script.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_witness_utxo(const INPUT& input, const struct wally_tx_output* witness_utxo) { int ret = ::wally_psbt_input_set_witness_utxo(detail::get_p(input), witness_utxo); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_witness_utxo_from_tx(const INPUT& input, const UTXO& utxo, uint32_t index) { int ret = ::wally_psbt_input_set_witness_utxo_from_tx(detail::get_p(input), detail::get_p(utxo), index); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_taproot_keypath_add(const INPUT& input, const PUB_KEY& pub_key, const TAPLEAF_HASHES& tapleaf_hashes, const FINGERPRINT& fingerprint, const CHILD_PATH& child_path) { int ret = ::wally_psbt_input_taproot_keypath_add(detail::get_p(input), pub_key.data(), pub_key.size(), tapleaf_hashes.data(), tapleaf_hashes.size(), fingerprint.data(), fingerprint.size(), child_path.data(), child_path.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_is_elements(const PSBT& psbt, size_t* written) { int ret = ::wally_psbt_is_elements(detail::get_p(psbt), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_is_finalized(const PSBT& psbt, size_t* written) { int ret = ::wally_psbt_is_finalized(detail::get_p(psbt), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_is_input_finalized(const PSBT& psbt, size_t index, size_t* written) { int ret = ::wally_psbt_is_input_finalized(detail::get_p(psbt), index, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_output_clear_amount(struct wally_psbt_output* output) { int ret = ::wally_psbt_output_clear_amount(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_find_keypath(const OUTPUT& output, const PUB_KEY& pub_key, size_t* written = 0) { size_t n; int ret = ::wally_psbt_output_find_keypath(detail::get_p(output), pub_key.data(), pub_key.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(pub_key.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(pub_key.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_find_unknown(const OUTPUT& output, const KEY& key, size_t* written = 0) { size_t n; int ret = ::wally_psbt_output_find_unknown(detail::get_p(output), key.data(), key.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(key.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(key.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_keypath_add(const OUTPUT& output, const PUB_KEY& pub_key, const FINGERPRINT& fingerprint, const CHILD_PATH& child_path) { int ret = ::wally_psbt_output_keypath_add(detail::get_p(output), pub_key.data(), pub_key.size(), fingerprint.data(), fingerprint.size(), child_path.data(), child_path.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_amount(const OUTPUT& output, uint64_t amount) { int ret = ::wally_psbt_output_set_amount(detail::get_p(output), amount); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_keypaths(const OUTPUT& output, const struct wally_map* map_in) { int ret = ::wally_psbt_output_set_keypaths(detail::get_p(output), map_in); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_redeem_script(const OUTPUT& output, const SCRIPT& script) { int ret = ::wally_psbt_output_set_redeem_script(detail::get_p(output), script.data(), script.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_script(const OUTPUT& output, const SCRIPT& script) { int ret = ::wally_psbt_output_set_script(detail::get_p(output), script.data(), script.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_unknowns(const OUTPUT& output, const struct wally_map* map_in) { int ret = ::wally_psbt_output_set_unknowns(detail::get_p(output), map_in); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_witness_script(const OUTPUT& output, const SCRIPT& script) { int ret = ::wally_psbt_output_set_witness_script(detail::get_p(output), script.data(), script.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_taproot_keypath_add(const OUTPUT& output, const PUB_KEY& pub_key, const TAPLEAF_HASHES& tapleaf_hashes, const FINGERPRINT& fingerprint, const CHILD_PATH& child_path) { int ret = ::wally_psbt_output_taproot_keypath_add(detail::get_p(output), pub_key.data(), pub_key.size(), tapleaf_hashes.data(), tapleaf_hashes.size(), fingerprint.data(), fingerprint.size(), child_path.data(), child_path.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_remove_input(const PSBT& psbt, uint32_t index) { int ret = ::wally_psbt_remove_input(detail::get_p(psbt), index); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_remove_output(const PSBT& psbt, uint32_t index) { int ret = ::wally_psbt_remove_output(detail::get_p(psbt), index); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_set_fallback_locktime(const PSBT& psbt, uint32_t locktime) { int ret = ::wally_psbt_set_fallback_locktime(detail::get_p(psbt), locktime); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_set_global_tx(const PSBT& psbt, const struct wally_tx* tx) { int ret = ::wally_psbt_set_global_tx(detail::get_p(psbt), tx); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_set_tx_modifiable_flags(const PSBT& psbt, uint32_t flags) { int ret = ::wally_psbt_set_tx_modifiable_flags(detail::get_p(psbt), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_set_tx_version(const PSBT& psbt, uint32_t version) { int ret = ::wally_psbt_set_tx_version(detail::get_p(psbt), version); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_set_version(const PSBT& psbt, uint32_t flags, uint32_t version) { int ret = ::wally_psbt_set_version(detail::get_p(psbt), flags, version); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_sign(const PSBT& psbt, const KEY& key, uint32_t flags) { int ret = ::wally_psbt_sign(detail::get_p(psbt), key.data(), key.size(), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_sign_bip32(const PSBT& psbt, const HDKEY& hdkey, uint32_t flags) { int ret = ::wally_psbt_sign_bip32(detail::get_p(psbt), detail::get_p(hdkey), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_sign_input_bip32(const PSBT& psbt, size_t index, size_t subindex, const TXHASH& txhash, const HDKEY& hdkey, uint32_t flags) { int ret = ::wally_psbt_sign_input_bip32(detail::get_p(psbt), index, subindex, txhash.data(), txhash.size(), detail::get_p(hdkey), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_to_base64(const PSBT& psbt, uint32_t flags, char** output) { int ret = ::wally_psbt_to_base64(detail::get_p(psbt), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_to_bytes(const PSBT& psbt, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_to_bytes(detail::get_p(psbt), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int ripemd160(const BYTES& bytes, BYTES_OUT& bytes_out) { int ret = ::wally_ripemd160(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int s2c_commitment_verify(const SIG& sig, const S2C_DATA& s2c_data, const S2C_OPENING& s2c_opening, uint32_t flags) { int ret = ::wally_s2c_commitment_verify(sig.data(), sig.size(), s2c_data.data(), s2c_data.size(), s2c_opening.data(), s2c_opening.size(), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int s2c_sig_from_bytes(const PRIV_KEY& priv_key, const BYTES& bytes, const S2C_DATA& s2c_data, uint32_t flags, S2C_OPENING_OUT& s2c_opening_out, BYTES_OUT& bytes_out) { int ret = ::wally_s2c_sig_from_bytes(priv_key.data(), priv_key.size(), bytes.data(), bytes.size(), s2c_data.data(), s2c_data.size(), flags, s2c_opening_out.data(), s2c_opening_out.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int script_push_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_script_push_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int scriptpubkey_csv_2of2_then_1_from_bytes(const BYTES& bytes, uint32_t csv_blocks, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_scriptpubkey_csv_2of2_then_1_from_bytes(bytes.data(), bytes.size(), csv_blocks, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int scriptpubkey_csv_2of2_then_1_from_bytes_opt(const BYTES& bytes, uint32_t csv_blocks, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_scriptpubkey_csv_2of2_then_1_from_bytes_opt(bytes.data(), bytes.size(), csv_blocks, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int scriptpubkey_get_type(const BYTES& bytes, size_t* written = 0) { size_t n; int ret = ::wally_scriptpubkey_get_type(bytes.data(), bytes.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int scriptpubkey_multisig_from_bytes(const BYTES& bytes, uint32_t threshold, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_scriptpubkey_multisig_from_bytes(bytes.data(), bytes.size(), threshold, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int scriptpubkey_op_return_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_scriptpubkey_op_return_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int scriptpubkey_p2pkh_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_scriptpubkey_p2pkh_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int scriptpubkey_p2sh_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_scriptpubkey_p2sh_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int scriptpubkey_to_address(const SCRIPTPUBKEY& scriptpubkey, uint32_t network, char** output) { int ret = ::wally_scriptpubkey_to_address(scriptpubkey.data(), scriptpubkey.size(), network, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int scriptsig_multisig_from_bytes(const SCRIPT& script, const BYTES& bytes, const SIGHASH& sighash, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_scriptsig_multisig_from_bytes(script.data(), script.size(), bytes.data(), bytes.size(), sighash.data(), sighash.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int scriptsig_p2pkh_from_der(const PUB_KEY& pub_key, const SIG& sig, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_scriptsig_p2pkh_from_der(pub_key.data(), pub_key.size(), sig.data(), sig.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int scriptsig_p2pkh_from_sig(const PUB_KEY& pub_key, const SIG& sig, uint32_t sighash, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_scriptsig_p2pkh_from_sig(pub_key.data(), pub_key.size(), sig.data(), sig.size(), sighash, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int scrypt(const PASS& pass, const SALT& salt, uint32_t cost, uint32_t block_size, uint32_t parallelism, BYTES_OUT& bytes_out) { int ret = ::wally_scrypt(pass.data(), pass.size(), salt.data(), salt.size(), cost, block_size, parallelism, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int secp_randomize(const BYTES& bytes) { int ret = ::wally_secp_randomize(bytes.data(), bytes.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int set_operations(const struct wally_operations* ops) { int ret = ::wally_set_operations(ops); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int sha256(const BYTES& bytes, BYTES_OUT& bytes_out) { int ret = ::wally_sha256(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int sha256_midstate(const BYTES& bytes, BYTES_OUT& bytes_out) { int ret = ::wally_sha256_midstate(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int sha256d(const BYTES& bytes, BYTES_OUT& bytes_out) { int ret = ::wally_sha256d(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int sha512(const BYTES& bytes, BYTES_OUT& bytes_out) { int ret = ::wally_sha512(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int symmetric_key_from_parent(const BYTES& bytes, uint32_t version, const LABEL& label, BYTES_OUT& bytes_out) { int ret = ::wally_symmetric_key_from_parent(bytes.data(), bytes.size(), version, label.data(), label.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int symmetric_key_from_seed(const BYTES& bytes, BYTES_OUT& bytes_out) { int ret = ::wally_symmetric_key_from_seed(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_input(const TX& tx, const struct wally_tx_input* input) { int ret = ::wally_tx_add_input(detail::get_p(tx), input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_input_at(const TX& tx, uint32_t index, const struct wally_tx_input* input) { int ret = ::wally_tx_add_input_at(detail::get_p(tx), index, input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_output(const TX& tx, const struct wally_tx_output* output) { int ret = ::wally_tx_add_output(detail::get_p(tx), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_output_at(const TX& tx, uint32_t index, const struct wally_tx_output* output) { int ret = ::wally_tx_add_output_at(detail::get_p(tx), index, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_raw_input(const TX& tx, const TXHASH& txhash, uint32_t utxo_index, uint32_t sequence, const SCRIPT& script, const WITNESS& witness, uint32_t flags) { int ret = ::wally_tx_add_raw_input(detail::get_p(tx), txhash.data(), txhash.size(), utxo_index, sequence, script.data(), script.size(), detail::get_p(witness), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_raw_input_at(const TX& tx, uint32_t index, const TXHASH& txhash, uint32_t utxo_index, uint32_t sequence, const SCRIPT& script, const WITNESS& witness, uint32_t flags) { int ret = ::wally_tx_add_raw_input_at(detail::get_p(tx), index, txhash.data(), txhash.size(), utxo_index, sequence, script.data(), script.size(), detail::get_p(witness), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_raw_output(const TX& tx, uint64_t satoshi, const SCRIPT& script, uint32_t flags) { int ret = ::wally_tx_add_raw_output(detail::get_p(tx), satoshi, script.data(), script.size(), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_raw_output_at(const TX& tx, uint32_t index, uint64_t satoshi, const SCRIPT& script, uint32_t flags) { int ret = ::wally_tx_add_raw_output_at(detail::get_p(tx), index, satoshi, script.data(), script.size(), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_clone_alloc(const TX& tx, uint32_t flags, struct wally_tx** output) { int ret = ::wally_tx_clone_alloc(detail::get_p(tx), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int tx_free(struct wally_tx* tx) { int ret = ::wally_tx_free(tx); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_from_bytes(const BYTES& bytes, uint32_t flags, struct wally_tx** output) { int ret = ::wally_tx_from_bytes(bytes.data(), bytes.size(), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_from_hex(const HEX& hex, uint32_t flags, struct wally_tx** output) { int ret = ::wally_tx_from_hex(detail::get_p(hex), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_get_btc_signature_hash(const TX& tx, size_t index, const SCRIPT& script, uint64_t satoshi, uint32_t sighash, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_tx_get_btc_signature_hash(detail::get_p(tx), index, script.data(), script.size(), satoshi, sighash, flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_get_btc_taproot_signature_hash(const TX& tx, size_t index, const SCRIPTS& scripts, const VALUES& values, const TAPLEAF_SCRIPT& tapleaf_script, uint32_t key_version, uint32_t codesep_position, const ANNEX& annex, uint32_t sighash, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_tx_get_btc_taproot_signature_hash(detail::get_p(tx), index, detail::get_p(scripts), values.data(), values.size(), tapleaf_script.data(), tapleaf_script.size(), key_version, codesep_position, annex.data(), annex.size(), sighash, flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_get_hash_prevouts(const TX& tx, size_t index, size_t num_inputs, BYTES_OUT& bytes_out) { int ret = ::wally_tx_get_hash_prevouts(detail::get_p(tx), index, num_inputs, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_get_length(const TX& tx, uint32_t flags, size_t* written) { int ret = ::wally_tx_get_length(detail::get_p(tx), flags, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_get_signature_hash(const TX& tx, size_t index, const SCRIPT& script, const EXTRA& extra, uint32_t extra_offset, uint64_t satoshi, uint32_t sighash, uint32_t tx_sighash, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_tx_get_signature_hash(detail::get_p(tx), index, script.data(), script.size(), extra.data(), extra.size(), extra_offset, satoshi, sighash, tx_sighash, flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_get_total_output_satoshi(const TX& tx, uint64_t* value_out) { int ret = ::wally_tx_get_total_output_satoshi(detail::get_p(tx), value_out); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_get_txid(const TX& tx, BYTES_OUT& bytes_out) { int ret = ::wally_tx_get_txid(detail::get_p(tx), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_get_vsize(const TX& tx, size_t* written) { int ret = ::wally_tx_get_vsize(detail::get_p(tx), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_get_weight(const TX& tx, size_t* written) { int ret = ::wally_tx_get_weight(detail::get_p(tx), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_get_witness_count(const TX& tx, size_t* written) { int ret = ::wally_tx_get_witness_count(detail::get_p(tx), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int tx_init_alloc(uint32_t version, uint32_t locktime, size_t inputs_allocation_len, size_t outputs_allocation_len, struct wally_tx** output) { int ret = ::wally_tx_init_alloc(version, locktime, inputs_allocation_len, outputs_allocation_len, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int tx_input_free(struct wally_tx_input* input) { int ret = ::wally_tx_input_free(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_input_init_alloc(const TXHASH& txhash, uint32_t utxo_index, uint32_t sequence, const SCRIPT& script, const WITNESS& witness, struct wally_tx_input** output) { int ret = ::wally_tx_input_init_alloc(txhash.data(), txhash.size(), utxo_index, sequence, script.data(), script.size(), detail::get_p(witness), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_is_coinbase(const TX& tx, size_t* written) { int ret = ::wally_tx_is_coinbase(detail::get_p(tx), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_output_clone(const TX_OUTPUT_IN& tx_output_in, struct wally_tx_output* output) { int ret = ::wally_tx_output_clone(detail::get_p(tx_output_in), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_output_clone_alloc(const TX_OUTPUT_IN& tx_output_in, struct wally_tx_output** output) { int ret = ::wally_tx_output_clone_alloc(detail::get_p(tx_output_in), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int tx_output_free(struct wally_tx_output* output) { int ret = ::wally_tx_output_free(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_output_init(uint64_t satoshi, const SCRIPT& script, struct wally_tx_output* output) { int ret = ::wally_tx_output_init(satoshi, script.data(), script.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_output_init_alloc(uint64_t satoshi, const SCRIPT& script, struct wally_tx_output** output) { int ret = ::wally_tx_output_init_alloc(satoshi, script.data(), script.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_remove_input(const TX& tx, size_t index) { int ret = ::wally_tx_remove_input(detail::get_p(tx), index); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_remove_output(const TX& tx, size_t index) { int ret = ::wally_tx_remove_output(detail::get_p(tx), index); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_set_input_script(const TX& tx, size_t index, const SCRIPT& script) { int ret = ::wally_tx_set_input_script(detail::get_p(tx), index, script.data(), script.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_set_input_witness(const TX& tx, size_t index, const struct wally_tx_witness_stack* stack) { int ret = ::wally_tx_set_input_witness(detail::get_p(tx), index, stack); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_to_bytes(const TX& tx, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_tx_to_bytes(detail::get_p(tx), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_to_hex(const TX& tx, uint32_t flags, char** output) { int ret = ::wally_tx_to_hex(detail::get_p(tx), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int tx_vsize_from_weight(size_t weight, size_t* written) { int ret = ::wally_tx_vsize_from_weight(weight, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_witness_stack_add(const STACK& stack, const WITNESS& witness) { int ret = ::wally_tx_witness_stack_add(detail::get_p(stack), witness.data(), witness.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_witness_stack_add_dummy(const STACK& stack, uint32_t flags) { int ret = ::wally_tx_witness_stack_add_dummy(detail::get_p(stack), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_witness_stack_clone_alloc(const STACK& stack, struct wally_tx_witness_stack** output) { int ret = ::wally_tx_witness_stack_clone_alloc(detail::get_p(stack), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int tx_witness_stack_free(struct wally_tx_witness_stack* stack) { int ret = ::wally_tx_witness_stack_free(stack); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_witness_stack_from_bytes(const BYTES& bytes, struct wally_tx_witness_stack** output) { int ret = ::wally_tx_witness_stack_from_bytes(bytes.data(), bytes.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_witness_stack_get_length(const STACK& stack, size_t* written) { int ret = ::wally_tx_witness_stack_get_length(detail::get_p(stack), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_witness_stack_get_num_items(const STACK& stack, size_t* written) { int ret = ::wally_tx_witness_stack_get_num_items(detail::get_p(stack), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int tx_witness_stack_init_alloc(size_t allocation_len, struct wally_tx_witness_stack** output) { int ret = ::wally_tx_witness_stack_init_alloc(allocation_len, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_witness_stack_set(const STACK& stack, size_t index, const WITNESS& witness) { int ret = ::wally_tx_witness_stack_set(detail::get_p(stack), index, witness.data(), witness.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_witness_stack_set_dummy(const STACK& stack, size_t index, uint32_t flags) { int ret = ::wally_tx_witness_stack_set_dummy(detail::get_p(stack), index, flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_witness_stack_to_bytes(const STACK& stack, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_tx_witness_stack_to_bytes(detail::get_p(stack), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int varbuff_get_length(const BYTES& bytes, size_t* written = 0) { size_t n; int ret = ::wally_varbuff_get_length(bytes.data(), bytes.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int varbuff_to_bytes(const BYTES& bytes, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_varbuff_to_bytes(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } inline int varint_get_length(uint64_t value, size_t* written) { int ret = ::wally_varint_get_length(value, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int varint_to_bytes(uint64_t value, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_varint_to_bytes(value, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int wif_from_bytes(const PRIV_KEY& priv_key, uint32_t prefix, uint32_t flags, char** output) { int ret = ::wally_wif_from_bytes(priv_key.data(), priv_key.size(), prefix, flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int wif_is_uncompressed(const WIF& wif, size_t* written) { int ret = ::wally_wif_is_uncompressed(detail::get_p(wif), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int wif_to_address(const WIF& wif, uint32_t prefix, uint32_t version, char** output) { int ret = ::wally_wif_to_address(detail::get_p(wif), prefix, version, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int wif_to_bytes(const WIF& wif, uint32_t prefix, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_wif_to_bytes(detail::get_p(wif), prefix, flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int wif_to_public_key(const WIF& wif, uint32_t prefix, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_wif_to_public_key(detail::get_p(wif), prefix, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int witness_multisig_from_bytes(const SCRIPT& script, const BYTES& bytes, const SIGHASH& sighash, uint32_t flags, struct wally_tx_witness_stack** witness) { int ret = ::wally_witness_multisig_from_bytes(script.data(), script.size(), bytes.data(), bytes.size(), sighash.data(), sighash.size(), flags, witness); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int witness_p2tr_from_sig(const SIG& sig, struct wally_tx_witness_stack** witness) { int ret = ::wally_witness_p2tr_from_sig(sig.data(), sig.size(), witness); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int witness_p2wpkh_from_der(const PUB_KEY& pub_key, const SIG& sig, struct wally_tx_witness_stack** witness) { int ret = ::wally_witness_p2wpkh_from_der(pub_key.data(), pub_key.size(), sig.data(), sig.size(), witness); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int witness_p2wpkh_from_sig(const PUB_KEY& pub_key, const SIG& sig, uint32_t sighash, struct wally_tx_witness_stack** witness) { int ret = ::wally_witness_p2wpkh_from_sig(pub_key.data(), pub_key.size(), sig.data(), sig.size(), sighash, witness); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int witness_program_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_witness_program_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int witness_program_from_bytes_and_version(const BYTES& bytes, uint32_t version, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_witness_program_from_bytes_and_version(bytes.data(), bytes.size(), version, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } #ifndef WALLY_ABI_NO_ELEMENTS template inline int bip32_key_with_tweak_from_parent_path(const HDKEY& hdkey, const CHILD_PATH& child_path, uint32_t flags, struct ext_key* output) { int ret = ::bip32_key_with_tweak_from_parent_path(detail::get_p(hdkey), child_path.data(), child_path.size(), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int bip32_key_with_tweak_from_parent_path_alloc(const HDKEY& hdkey, const CHILD_PATH& child_path, uint32_t flags, struct ext_key** output) { int ret = ::bip32_key_with_tweak_from_parent_path_alloc(detail::get_p(hdkey), child_path.data(), child_path.size(), flags, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_blinding_key_from_seed(const BYTES& bytes, BYTES_OUT& bytes_out) { int ret = ::wally_asset_blinding_key_from_seed(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_blinding_key_to_abf(const BYTES& bytes, const HASH_PREVOUTS& hash_prevouts, uint32_t output_index, BYTES_OUT& bytes_out) { int ret = ::wally_asset_blinding_key_to_abf(bytes.data(), bytes.size(), hash_prevouts.data(), hash_prevouts.size(), output_index, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_blinding_key_to_abf_vbf(const BYTES& bytes, const HASH_PREVOUTS& hash_prevouts, uint32_t output_index, BYTES_OUT& bytes_out) { int ret = ::wally_asset_blinding_key_to_abf_vbf(bytes.data(), bytes.size(), hash_prevouts.data(), hash_prevouts.size(), output_index, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_blinding_key_to_ec_private_key(const BYTES& bytes, const SCRIPT& script, BYTES_OUT& bytes_out) { int ret = ::wally_asset_blinding_key_to_ec_private_key(bytes.data(), bytes.size(), script.data(), script.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_blinding_key_to_vbf(const BYTES& bytes, const HASH_PREVOUTS& hash_prevouts, uint32_t output_index, BYTES_OUT& bytes_out) { int ret = ::wally_asset_blinding_key_to_vbf(bytes.data(), bytes.size(), hash_prevouts.data(), hash_prevouts.size(), output_index, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_final_vbf(const VALUES& values, size_t num_inputs, const ABF& abf, const VBF& vbf, BYTES_OUT& bytes_out) { int ret = ::wally_asset_final_vbf(values.data(), values.size(), num_inputs, abf.data(), abf.size(), vbf.data(), vbf.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_generator_from_bytes(const ASSET& asset, const ABF& abf, BYTES_OUT& bytes_out) { int ret = ::wally_asset_generator_from_bytes(asset.data(), asset.size(), abf.data(), abf.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_pak_whitelistproof(const ONLINE_KEYS& online_keys, const OFFLINE_KEYS& offline_keys, size_t key_index, const SUB_PUBKEY& sub_pubkey, const ONLINE_PRIV_KEY& online_priv_key, const SUMMED_KEY& summed_key, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_asset_pak_whitelistproof(online_keys.data(), online_keys.size(), offline_keys.data(), offline_keys.size(), key_index, sub_pubkey.data(), sub_pubkey.size(), online_priv_key.data(), online_priv_key.size(), summed_key.data(), summed_key.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_pak_whitelistproof_len(const ONLINE_KEYS& online_keys, const OFFLINE_KEYS& offline_keys, size_t key_index, const SUB_PUBKEY& sub_pubkey, const ONLINE_PRIV_KEY& online_priv_key, const SUMMED_KEY& summed_key, size_t* written = 0) { size_t n; int ret = ::wally_asset_pak_whitelistproof_len(online_keys.data(), online_keys.size(), offline_keys.data(), offline_keys.size(), key_index, sub_pubkey.data(), sub_pubkey.size(), online_priv_key.data(), online_priv_key.size(), summed_key.data(), summed_key.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(summed_key.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(summed_key.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } inline int asset_pak_whitelistproof_size(size_t num_keys, size_t* written) { int ret = ::wally_asset_pak_whitelistproof_size(num_keys, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_rangeproof(uint64_t value, const PUB_KEY& pub_key, const PRIV_KEY& priv_key, const ASSET& asset, const ABF& abf, const VBF& vbf, const COMMITMENT& commitment, const EXTRA& extra, const GENERATOR& generator, uint64_t min_value, int exp, int min_bits, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_asset_rangeproof(value, pub_key.data(), pub_key.size(), priv_key.data(), priv_key.size(), asset.data(), asset.size(), abf.data(), abf.size(), vbf.data(), vbf.size(), commitment.data(), commitment.size(), extra.data(), extra.size(), generator.data(), generator.size(), min_value, exp, min_bits, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } inline int asset_rangeproof_get_maximum_len(uint64_t value, int min_bits, size_t* written) { int ret = ::wally_asset_rangeproof_get_maximum_len(value, min_bits, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_rangeproof_with_nonce(uint64_t value, const NONCE_HASH& nonce_hash, const ASSET& asset, const ABF& abf, const VBF& vbf, const COMMITMENT& commitment, const EXTRA& extra, const GENERATOR& generator, uint64_t min_value, int exp, int min_bits, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_asset_rangeproof_with_nonce(value, nonce_hash.data(), nonce_hash.size(), asset.data(), asset.size(), abf.data(), abf.size(), vbf.data(), vbf.size(), commitment.data(), commitment.size(), extra.data(), extra.size(), generator.data(), generator.size(), min_value, exp, min_bits, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_scalar_offset(uint64_t value, const ABF& abf, const VBF& vbf, BYTES_OUT& bytes_out) { int ret = ::wally_asset_scalar_offset(value, abf.data(), abf.size(), vbf.data(), vbf.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_surjectionproof(const OUTPUT_ASSET& output_asset, const OUTPUT_ABF& output_abf, const OUTPUT_GENERATOR& output_generator, const BYTES& bytes, const ASSET& asset, const ABF& abf, const GENERATOR& generator, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_asset_surjectionproof(output_asset.data(), output_asset.size(), output_abf.data(), output_abf.size(), output_generator.data(), output_generator.size(), bytes.data(), bytes.size(), asset.data(), asset.size(), abf.data(), abf.size(), generator.data(), generator.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_surjectionproof_len(const OUTPUT_ASSET& output_asset, const OUTPUT_ABF& output_abf, const OUTPUT_GENERATOR& output_generator, const BYTES& bytes, const ASSET& asset, const ABF& abf, const GENERATOR& generator, size_t* written = 0) { size_t n; int ret = ::wally_asset_surjectionproof_len(output_asset.data(), output_asset.size(), output_abf.data(), output_abf.size(), output_generator.data(), output_generator.size(), bytes.data(), bytes.size(), asset.data(), asset.size(), abf.data(), abf.size(), generator.data(), generator.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(generator.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(generator.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } inline int asset_surjectionproof_size(size_t num_inputs, size_t* written) { int ret = ::wally_asset_surjectionproof_size(num_inputs, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_unblind(const PUB_KEY& pub_key, const PRIV_KEY& priv_key, const PROOF& proof, const COMMITMENT& commitment, const EXTRA& extra, const GENERATOR& generator, ASSET_OUT& asset_out, ABF_OUT& abf_out, VBF_OUT& vbf_out, uint64_t* value_out) { int ret = ::wally_asset_unblind(pub_key.data(), pub_key.size(), priv_key.data(), priv_key.size(), proof.data(), proof.size(), commitment.data(), commitment.size(), extra.data(), extra.size(), generator.data(), generator.size(), asset_out.data(), asset_out.size(), abf_out.data(), abf_out.size(), vbf_out.data(), vbf_out.size(), value_out); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_unblind_with_nonce(const NONCE_HASH& nonce_hash, const PROOF& proof, const COMMITMENT& commitment, const EXTRA& extra, const GENERATOR& generator, ASSET_OUT& asset_out, ABF_OUT& abf_out, VBF_OUT& vbf_out, uint64_t* value_out) { int ret = ::wally_asset_unblind_with_nonce(nonce_hash.data(), nonce_hash.size(), proof.data(), proof.size(), commitment.data(), commitment.size(), extra.data(), extra.size(), generator.data(), generator.size(), asset_out.data(), asset_out.size(), abf_out.data(), abf_out.size(), vbf_out.data(), vbf_out.size(), value_out); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int asset_value_commitment(uint64_t value, const VBF& vbf, const GENERATOR& generator, BYTES_OUT& bytes_out) { int ret = ::wally_asset_value_commitment(value, vbf.data(), vbf.size(), generator.data(), generator.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int coinselect_assets(const VALUES& values, uint64_t target, uint64_t attempts, uint32_t io_ratio, uint32_t* indices_out, size_t indices_out_len, size_t* written) { int ret = ::wally_coinselect_assets(values.data(), values.size(), target, attempts, io_ratio, indices_out, indices_out_len, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int confidential_addr_from_addr(const ADDRESS& address, uint32_t prefix, const PUB_KEY& pub_key, char** output) { int ret = ::wally_confidential_addr_from_addr(detail::get_p(address), prefix, pub_key.data(), pub_key.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int confidential_addr_from_addr_segwit(const ADDRESS& address, const ADDR_FAMILY& addr_family, const CONFIDENTIAL_ADDR_FAMILY& confidential_addr_family, const PUB_KEY& pub_key, char** output) { int ret = ::wally_confidential_addr_from_addr_segwit(detail::get_p(address), detail::get_p(addr_family), detail::get_p(confidential_addr_family), pub_key.data(), pub_key.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int confidential_addr_segwit_to_ec_public_key(const ADDRESS& address, const CONFIDENTIAL_ADDR_FAMILY& confidential_addr_family, BYTES_OUT& bytes_out) { int ret = ::wally_confidential_addr_segwit_to_ec_public_key(detail::get_p(address), detail::get_p(confidential_addr_family), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int confidential_addr_to_addr(const ADDRESS& address, uint32_t prefix, char** output) { int ret = ::wally_confidential_addr_to_addr(detail::get_p(address), prefix, output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int confidential_addr_to_addr_segwit(const ADDRESS& address, const CONFIDENTIAL_ADDR_FAMILY& confidential_addr_family, const ADDR_FAMILY& addr_family, char** output) { int ret = ::wally_confidential_addr_to_addr_segwit(detail::get_p(address), detail::get_p(confidential_addr_family), detail::get_p(addr_family), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int confidential_addr_to_ec_public_key(const ADDRESS& address, uint32_t prefix, BYTES_OUT& bytes_out) { int ret = ::wally_confidential_addr_to_ec_public_key(detail::get_p(address), prefix, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int ecdh_nonce_hash(const PUB_KEY& pub_key, const PRIV_KEY& priv_key, BYTES_OUT& bytes_out) { int ret = ::wally_ecdh_nonce_hash(pub_key.data(), pub_key.size(), priv_key.data(), priv_key.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int elements_pegin_contract_script_from_bytes(const REDEEM_SCRIPT& redeem_script, const SCRIPT& script, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_elements_pegin_contract_script_from_bytes(redeem_script.data(), redeem_script.size(), script.data(), script.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int elements_pegout_script_from_bytes(const GENESIS_BLOCKHASH& genesis_blockhash, const MAINCHAIN_SCRIPT& mainchain_script, const SUB_PUBKEY& sub_pubkey, const WHITELISTPROOF& whitelistproof, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_elements_pegout_script_from_bytes(genesis_blockhash.data(), genesis_blockhash.size(), mainchain_script.data(), mainchain_script.size(), sub_pubkey.data(), sub_pubkey.size(), whitelistproof.data(), whitelistproof.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } inline int elements_pegout_script_size(size_t genesis_blockhash_len, size_t mainchain_script_len, size_t sub_pubkey_len, size_t whitelistproof_len, size_t* written) { int ret = ::wally_elements_pegout_script_size(genesis_blockhash_len, mainchain_script_len, sub_pubkey_len, whitelistproof_len, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int explicit_rangeproof(uint64_t value, const NONCE& nonce, const VBF& vbf, const COMMITMENT& commitment, const GENERATOR& generator, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_explicit_rangeproof(value, nonce.data(), nonce.size(), vbf.data(), vbf.size(), commitment.data(), commitment.size(), generator.data(), generator.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int explicit_rangeproof_verify(const RANGEPROOF& rangeproof, uint64_t value, const COMMITMENT& commitment, const GENERATOR& generator) { int ret = ::wally_explicit_rangeproof_verify(rangeproof.data(), rangeproof.size(), value, commitment.data(), commitment.size(), generator.data(), generator.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int explicit_surjectionproof(const OUTPUT_ASSET& output_asset, const OUTPUT_ABF& output_abf, const OUTPUT_GENERATOR& output_generator, BYTES_OUT& bytes_out) { int ret = ::wally_explicit_surjectionproof(output_asset.data(), output_asset.size(), output_abf.data(), output_abf.size(), output_generator.data(), output_generator.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int explicit_surjectionproof_verify(const SURJECTIONPROOF& surjectionproof, const OUTPUT_ASSET& output_asset, const OUTPUT_GENERATOR& output_generator) { int ret = ::wally_explicit_surjectionproof_verify(surjectionproof.data(), surjectionproof.size(), output_asset.data(), output_asset.size(), output_generator.data(), output_generator.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_add_global_scalar(const PSBT& psbt, const SCALAR& scalar) { int ret = ::wally_psbt_add_global_scalar(detail::get_p(psbt), scalar.data(), scalar.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_find_global_scalar(const PSBT& psbt, const SCALAR& scalar, size_t* written = 0) { size_t n; int ret = ::wally_psbt_find_global_scalar(detail::get_p(psbt), scalar.data(), scalar.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(scalar.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(scalar.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_amount_rangeproof(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_amount_rangeproof(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_asset(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_asset(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_asset_surjectionproof(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_asset_surjectionproof(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_inflation_keys_blinding_rangeproof(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_inflation_keys_blinding_rangeproof(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_inflation_keys_commitment(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_inflation_keys_commitment(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_inflation_keys_rangeproof(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_inflation_keys_rangeproof(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_issuance_amount_blinding_rangeproof(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_issuance_amount_blinding_rangeproof(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_issuance_amount_commitment(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_issuance_amount_commitment(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_issuance_amount_rangeproof(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_issuance_amount_rangeproof(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_issuance_asset_entropy(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_issuance_asset_entropy(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_issuance_blinding_nonce(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_issuance_blinding_nonce(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_pegin_claim_script(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_pegin_claim_script(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_pegin_genesis_blockhash(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_pegin_genesis_blockhash(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_pegin_txout_proof(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_pegin_txout_proof(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_input_clear_utxo_rangeproof(struct wally_psbt_input* input) { int ret = ::wally_psbt_input_clear_utxo_rangeproof(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_generate_explicit_proofs(const INPUT& input, uint64_t satoshi, const ASSET& asset, const ABF& abf, const VBF& vbf, const ENTROPY& entropy) { int ret = ::wally_psbt_input_generate_explicit_proofs(detail::get_p(input), satoshi, asset.data(), asset.size(), abf.data(), abf.size(), vbf.data(), vbf.size(), entropy.data(), entropy.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_amount_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_amount_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_amount_rangeproof_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_amount_rangeproof_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_asset(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_asset(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_asset_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_asset_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_asset_surjectionproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_asset_surjectionproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_asset_surjectionproof_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_asset_surjectionproof_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_inflation_keys_blinding_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_inflation_keys_blinding_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_inflation_keys_blinding_rangeproof_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_inflation_keys_blinding_rangeproof_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_inflation_keys_commitment(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_inflation_keys_commitment(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_inflation_keys_commitment_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_inflation_keys_commitment_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_inflation_keys_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_inflation_keys_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_inflation_keys_rangeproof_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_inflation_keys_rangeproof_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_issuance_amount_blinding_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_issuance_amount_blinding_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_issuance_amount_blinding_rangeproof_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_issuance_amount_blinding_rangeproof_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_issuance_amount_commitment(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_issuance_amount_commitment(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_issuance_amount_commitment_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_issuance_amount_commitment_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_issuance_amount_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_issuance_amount_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_issuance_amount_rangeproof_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_issuance_amount_rangeproof_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_issuance_asset_entropy(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_issuance_asset_entropy(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_issuance_asset_entropy_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_issuance_asset_entropy_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_issuance_blinding_nonce(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_issuance_blinding_nonce(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_issuance_blinding_nonce_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_issuance_blinding_nonce_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_pegin_claim_script(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_pegin_claim_script(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_pegin_claim_script_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_pegin_claim_script_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_pegin_genesis_blockhash(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_pegin_genesis_blockhash(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_pegin_genesis_blockhash_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_pegin_genesis_blockhash_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_pegin_txout_proof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_pegin_txout_proof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_pegin_txout_proof_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_pegin_txout_proof_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_utxo_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_input_get_utxo_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_get_utxo_rangeproof_len(const INPUT& input, size_t* written) { int ret = ::wally_psbt_input_get_utxo_rangeproof_len(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_amount(const INPUT& input, uint64_t amount) { int ret = ::wally_psbt_input_set_amount(detail::get_p(input), amount); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_amount_rangeproof(const INPUT& input, const RANGEPROOF& rangeproof) { int ret = ::wally_psbt_input_set_amount_rangeproof(detail::get_p(input), rangeproof.data(), rangeproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_asset(const INPUT& input, const ASSET& asset) { int ret = ::wally_psbt_input_set_asset(detail::get_p(input), asset.data(), asset.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_asset_surjectionproof(const INPUT& input, const SURJECTIONPROOF& surjectionproof) { int ret = ::wally_psbt_input_set_asset_surjectionproof(detail::get_p(input), surjectionproof.data(), surjectionproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_inflation_keys(const INPUT& input, uint64_t value) { int ret = ::wally_psbt_input_set_inflation_keys(detail::get_p(input), value); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_inflation_keys_blinding_rangeproof(const INPUT& input, const RANGEPROOF& rangeproof) { int ret = ::wally_psbt_input_set_inflation_keys_blinding_rangeproof(detail::get_p(input), rangeproof.data(), rangeproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_inflation_keys_commitment(const INPUT& input, const COMMITMENT& commitment) { int ret = ::wally_psbt_input_set_inflation_keys_commitment(detail::get_p(input), commitment.data(), commitment.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_inflation_keys_rangeproof(const INPUT& input, const RANGEPROOF& rangeproof) { int ret = ::wally_psbt_input_set_inflation_keys_rangeproof(detail::get_p(input), rangeproof.data(), rangeproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_issuance_amount(const INPUT& input, uint64_t amount) { int ret = ::wally_psbt_input_set_issuance_amount(detail::get_p(input), amount); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_issuance_amount_blinding_rangeproof(const INPUT& input, const RANGEPROOF& rangeproof) { int ret = ::wally_psbt_input_set_issuance_amount_blinding_rangeproof(detail::get_p(input), rangeproof.data(), rangeproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_issuance_amount_commitment(const INPUT& input, const COMMITMENT& commitment) { int ret = ::wally_psbt_input_set_issuance_amount_commitment(detail::get_p(input), commitment.data(), commitment.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_issuance_amount_rangeproof(const INPUT& input, const RANGEPROOF& rangeproof) { int ret = ::wally_psbt_input_set_issuance_amount_rangeproof(detail::get_p(input), rangeproof.data(), rangeproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_issuance_asset_entropy(const INPUT& input, const ENTROPY& entropy) { int ret = ::wally_psbt_input_set_issuance_asset_entropy(detail::get_p(input), entropy.data(), entropy.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_issuance_blinding_nonce(const INPUT& input, const NONCE& nonce) { int ret = ::wally_psbt_input_set_issuance_blinding_nonce(detail::get_p(input), nonce.data(), nonce.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_pegin_amount(const INPUT& input, uint64_t amount) { int ret = ::wally_psbt_input_set_pegin_amount(detail::get_p(input), amount); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_pegin_claim_script(const INPUT& input, const SCRIPT& script) { int ret = ::wally_psbt_input_set_pegin_claim_script(detail::get_p(input), script.data(), script.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_pegin_genesis_blockhash(const INPUT& input, const GENESIS_BLOCKHASH& genesis_blockhash) { int ret = ::wally_psbt_input_set_pegin_genesis_blockhash(detail::get_p(input), genesis_blockhash.data(), genesis_blockhash.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_pegin_tx(const INPUT& input, const struct wally_tx* tx) { int ret = ::wally_psbt_input_set_pegin_tx(detail::get_p(input), tx); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_pegin_txout_proof(const INPUT& input, const TXOUT_PROOF& txout_proof) { int ret = ::wally_psbt_input_set_pegin_txout_proof(detail::get_p(input), txout_proof.data(), txout_proof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_pegin_witness(const INPUT& input, const struct wally_tx_witness_stack* witness) { int ret = ::wally_psbt_input_set_pegin_witness(detail::get_p(input), witness); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_input_set_utxo_rangeproof(const INPUT& input, const RANGEPROOF& rangeproof) { int ret = ::wally_psbt_input_set_utxo_rangeproof(detail::get_p(input), rangeproof.data(), rangeproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_output_clear_asset(struct wally_psbt_output* output) { int ret = ::wally_psbt_output_clear_asset(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_output_clear_asset_blinding_surjectionproof(struct wally_psbt_output* output) { int ret = ::wally_psbt_output_clear_asset_blinding_surjectionproof(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_output_clear_asset_commitment(struct wally_psbt_output* output) { int ret = ::wally_psbt_output_clear_asset_commitment(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_output_clear_asset_surjectionproof(struct wally_psbt_output* output) { int ret = ::wally_psbt_output_clear_asset_surjectionproof(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_output_clear_blinder_index(struct wally_psbt_output* output) { int ret = ::wally_psbt_output_clear_blinder_index(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_output_clear_blinding_public_key(struct wally_psbt_output* output) { int ret = ::wally_psbt_output_clear_blinding_public_key(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_output_clear_ecdh_public_key(struct wally_psbt_output* output) { int ret = ::wally_psbt_output_clear_ecdh_public_key(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_output_clear_value_blinding_rangeproof(struct wally_psbt_output* output) { int ret = ::wally_psbt_output_clear_value_blinding_rangeproof(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_output_clear_value_commitment(struct wally_psbt_output* output) { int ret = ::wally_psbt_output_clear_value_commitment(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int psbt_output_clear_value_rangeproof(struct wally_psbt_output* output) { int ret = ::wally_psbt_output_clear_value_rangeproof(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_asset(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_output_get_asset(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_asset_blinding_surjectionproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_output_get_asset_blinding_surjectionproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_asset_blinding_surjectionproof_len(const OUTPUT& output, size_t* written) { int ret = ::wally_psbt_output_get_asset_blinding_surjectionproof_len(detail::get_p(output), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_asset_commitment(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_output_get_asset_commitment(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_asset_commitment_len(const OUTPUT& output, size_t* written) { int ret = ::wally_psbt_output_get_asset_commitment_len(detail::get_p(output), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_asset_len(const OUTPUT& output, size_t* written) { int ret = ::wally_psbt_output_get_asset_len(detail::get_p(output), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_asset_surjectionproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_output_get_asset_surjectionproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_asset_surjectionproof_len(const OUTPUT& output, size_t* written) { int ret = ::wally_psbt_output_get_asset_surjectionproof_len(detail::get_p(output), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_blinding_public_key(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_output_get_blinding_public_key(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_blinding_public_key_len(const OUTPUT& output, size_t* written) { int ret = ::wally_psbt_output_get_blinding_public_key_len(detail::get_p(output), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_blinding_status(const OUTPUT& output, uint32_t flags, size_t* written) { int ret = ::wally_psbt_output_get_blinding_status(detail::get_p(output), flags, written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_ecdh_public_key(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_output_get_ecdh_public_key(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_ecdh_public_key_len(const OUTPUT& output, size_t* written) { int ret = ::wally_psbt_output_get_ecdh_public_key_len(detail::get_p(output), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_value_blinding_rangeproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_output_get_value_blinding_rangeproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_value_blinding_rangeproof_len(const OUTPUT& output, size_t* written) { int ret = ::wally_psbt_output_get_value_blinding_rangeproof_len(detail::get_p(output), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_value_commitment(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_output_get_value_commitment(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_value_commitment_len(const OUTPUT& output, size_t* written) { int ret = ::wally_psbt_output_get_value_commitment_len(detail::get_p(output), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_value_rangeproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { size_t n; int ret = ::wally_psbt_output_get_value_rangeproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - return written || ret != WALLY_OK ? ret : n == static_cast(bytes_out.size()) ? WALLY_OK : WALLY_EINVAL; + if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_get_value_rangeproof_len(const OUTPUT& output, size_t* written) { int ret = ::wally_psbt_output_get_value_rangeproof_len(detail::get_p(output), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_asset(const OUTPUT& output, const ASSET& asset) { int ret = ::wally_psbt_output_set_asset(detail::get_p(output), asset.data(), asset.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_asset_blinding_surjectionproof(const OUTPUT& output, const SURJECTIONPROOF& surjectionproof) { int ret = ::wally_psbt_output_set_asset_blinding_surjectionproof(detail::get_p(output), surjectionproof.data(), surjectionproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_asset_commitment(const OUTPUT& output, const COMMITMENT& commitment) { int ret = ::wally_psbt_output_set_asset_commitment(detail::get_p(output), commitment.data(), commitment.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_asset_surjectionproof(const OUTPUT& output, const SURJECTIONPROOF& surjectionproof) { int ret = ::wally_psbt_output_set_asset_surjectionproof(detail::get_p(output), surjectionproof.data(), surjectionproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_blinder_index(const OUTPUT& output, uint32_t index) { int ret = ::wally_psbt_output_set_blinder_index(detail::get_p(output), index); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_blinding_public_key(const OUTPUT& output, const PUB_KEY& pub_key) { int ret = ::wally_psbt_output_set_blinding_public_key(detail::get_p(output), pub_key.data(), pub_key.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_ecdh_public_key(const OUTPUT& output, const PUB_KEY& pub_key) { int ret = ::wally_psbt_output_set_ecdh_public_key(detail::get_p(output), pub_key.data(), pub_key.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_value_blinding_rangeproof(const OUTPUT& output, const RANGEPROOF& rangeproof) { int ret = ::wally_psbt_output_set_value_blinding_rangeproof(detail::get_p(output), rangeproof.data(), rangeproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_value_commitment(const OUTPUT& output, const COMMITMENT& commitment) { int ret = ::wally_psbt_output_set_value_commitment(detail::get_p(output), commitment.data(), commitment.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_output_set_value_rangeproof(const OUTPUT& output, const RANGEPROOF& rangeproof) { int ret = ::wally_psbt_output_set_value_rangeproof(detail::get_p(output), rangeproof.data(), rangeproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_set_global_scalars(const PSBT& psbt, const struct wally_map* map_in) { int ret = ::wally_psbt_set_global_scalars(detail::get_p(psbt), map_in); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int psbt_set_pset_modifiable_flags(const PSBT& psbt, uint32_t flags) { int ret = ::wally_psbt_set_pset_modifiable_flags(detail::get_p(psbt), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_elements_raw_input(const TX& tx, const TXHASH& txhash, uint32_t utxo_index, uint32_t sequence, const SCRIPT& script, const WITNESS& witness, const NONCE& nonce, const ENTROPY& entropy, const ISSUANCE_AMOUNT& issuance_amount, const INFLATION_KEYS& inflation_keys, const ISSUANCE_AMOUNT_RANGEPROOF& issuance_amount_rangeproof, const INFLATION_KEYS_RANGEPROOF& inflation_keys_rangeproof, const PEGIN_WITNESS& pegin_witness, uint32_t flags) { int ret = ::wally_tx_add_elements_raw_input(detail::get_p(tx), txhash.data(), txhash.size(), utxo_index, sequence, script.data(), script.size(), detail::get_p(witness), nonce.data(), nonce.size(), entropy.data(), entropy.size(), issuance_amount.data(), issuance_amount.size(), inflation_keys.data(), inflation_keys.size(), issuance_amount_rangeproof.data(), issuance_amount_rangeproof.size(), inflation_keys_rangeproof.data(), inflation_keys_rangeproof.size(), detail::get_p(pegin_witness), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_elements_raw_input_at(const TX& tx, uint32_t index, const TXHASH& txhash, uint32_t utxo_index, uint32_t sequence, const SCRIPT& script, const WITNESS& witness, const NONCE& nonce, const ENTROPY& entropy, const ISSUANCE_AMOUNT& issuance_amount, const INFLATION_KEYS& inflation_keys, const ISSUANCE_AMOUNT_RANGEPROOF& issuance_amount_rangeproof, const INFLATION_KEYS_RANGEPROOF& inflation_keys_rangeproof, const PEGIN_WITNESS& pegin_witness, uint32_t flags) { int ret = ::wally_tx_add_elements_raw_input_at(detail::get_p(tx), index, txhash.data(), txhash.size(), utxo_index, sequence, script.data(), script.size(), detail::get_p(witness), nonce.data(), nonce.size(), entropy.data(), entropy.size(), issuance_amount.data(), issuance_amount.size(), inflation_keys.data(), inflation_keys.size(), issuance_amount_rangeproof.data(), issuance_amount_rangeproof.size(), inflation_keys_rangeproof.data(), inflation_keys_rangeproof.size(), detail::get_p(pegin_witness), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_elements_raw_output(const TX& tx, const SCRIPT& script, const ASSET& asset, const VALUE& value, const NONCE& nonce, const SURJECTIONPROOF& surjectionproof, const RANGEPROOF& rangeproof, uint32_t flags) { int ret = ::wally_tx_add_elements_raw_output(detail::get_p(tx), script.data(), script.size(), asset.data(), asset.size(), value.data(), value.size(), nonce.data(), nonce.size(), surjectionproof.data(), surjectionproof.size(), rangeproof.data(), rangeproof.size(), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_add_elements_raw_output_at(const TX& tx, uint32_t index, const SCRIPT& script, const ASSET& asset, const VALUE& value, const NONCE& nonce, const SURJECTIONPROOF& surjectionproof, const RANGEPROOF& rangeproof, uint32_t flags) { int ret = ::wally_tx_add_elements_raw_output_at(detail::get_p(tx), index, script.data(), script.size(), asset.data(), asset.size(), value.data(), value.size(), nonce.data(), nonce.size(), surjectionproof.data(), surjectionproof.size(), rangeproof.data(), rangeproof.size(), flags); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_confidential_value_from_satoshi(uint64_t satoshi, BYTES_OUT& bytes_out) { int ret = ::wally_tx_confidential_value_from_satoshi(satoshi, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_confidential_value_to_satoshi(const VALUE& value, uint64_t* value_out) { int ret = ::wally_tx_confidential_value_to_satoshi(value.data(), value.size(), value_out); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_elements_input_init_alloc(const TXHASH& txhash, uint32_t utxo_index, uint32_t sequence, const SCRIPT& script, const WITNESS& witness, const NONCE& nonce, const ENTROPY& entropy, const ISSUANCE_AMOUNT& issuance_amount, const INFLATION_KEYS& inflation_keys, const ISSUANCE_AMOUNT_RANGEPROOF& issuance_amount_rangeproof, const INFLATION_KEYS_RANGEPROOF& inflation_keys_rangeproof, const PEGIN_WITNESS& pegin_witness, struct wally_tx_input** output) { int ret = ::wally_tx_elements_input_init_alloc(txhash.data(), txhash.size(), utxo_index, sequence, script.data(), script.size(), detail::get_p(witness), nonce.data(), nonce.size(), entropy.data(), entropy.size(), issuance_amount.data(), issuance_amount.size(), inflation_keys.data(), inflation_keys.size(), issuance_amount_rangeproof.data(), issuance_amount_rangeproof.size(), inflation_keys_rangeproof.data(), inflation_keys_rangeproof.size(), detail::get_p(pegin_witness), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_elements_input_is_pegin(const INPUT& input, size_t* written) { int ret = ::wally_tx_elements_input_is_pegin(detail::get_p(input), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int tx_elements_input_issuance_free(struct wally_tx_input* input) { int ret = ::wally_tx_elements_input_issuance_free(input); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_elements_input_issuance_set(const INPUT& input, const NONCE& nonce, const ENTROPY& entropy, const ISSUANCE_AMOUNT& issuance_amount, const INFLATION_KEYS& inflation_keys, const ISSUANCE_AMOUNT_RANGEPROOF& issuance_amount_rangeproof, const INFLATION_KEYS_RANGEPROOF& inflation_keys_rangeproof) { int ret = ::wally_tx_elements_input_issuance_set(detail::get_p(input), nonce.data(), nonce.size(), entropy.data(), entropy.size(), issuance_amount.data(), issuance_amount.size(), inflation_keys.data(), inflation_keys.size(), issuance_amount_rangeproof.data(), issuance_amount_rangeproof.size(), inflation_keys_rangeproof.data(), inflation_keys_rangeproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_elements_issuance_calculate_asset(const ENTROPY& entropy, BYTES_OUT& bytes_out) { int ret = ::wally_tx_elements_issuance_calculate_asset(entropy.data(), entropy.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_elements_issuance_calculate_reissuance_token(const ENTROPY& entropy, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_tx_elements_issuance_calculate_reissuance_token(entropy.data(), entropy.size(), flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_elements_issuance_generate_entropy(const TXHASH& txhash, uint32_t utxo_index, const CONTRACT_HASH& contract_hash, BYTES_OUT& bytes_out) { int ret = ::wally_tx_elements_issuance_generate_entropy(txhash.data(), txhash.size(), utxo_index, contract_hash.data(), contract_hash.size(), bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } inline int tx_elements_output_commitment_free(struct wally_tx_output* output) { int ret = ::wally_tx_elements_output_commitment_free(output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_elements_output_commitment_set(const OUTPUT& output, const ASSET& asset, const VALUE& value, const NONCE& nonce, const SURJECTIONPROOF& surjectionproof, const RANGEPROOF& rangeproof) { int ret = ::wally_tx_elements_output_commitment_set(detail::get_p(output), asset.data(), asset.size(), value.data(), value.size(), nonce.data(), nonce.size(), surjectionproof.data(), surjectionproof.size(), rangeproof.data(), rangeproof.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_elements_output_init(const SCRIPT& script, const ASSET& asset, const VALUE& value, const NONCE& nonce, const SURJECTIONPROOF& surjectionproof, const RANGEPROOF& rangeproof, struct wally_tx_output* output) { int ret = ::wally_tx_elements_output_init(script.data(), script.size(), asset.data(), asset.size(), value.data(), value.size(), nonce.data(), nonce.size(), surjectionproof.data(), surjectionproof.size(), rangeproof.data(), rangeproof.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_elements_output_init_alloc(const SCRIPT& script, const ASSET& asset, const VALUE& value, const NONCE& nonce, const SURJECTIONPROOF& surjectionproof, const RANGEPROOF& rangeproof, struct wally_tx_output** output) { int ret = ::wally_tx_elements_output_init_alloc(script.data(), script.size(), asset.data(), asset.size(), value.data(), value.size(), nonce.data(), nonce.size(), surjectionproof.data(), surjectionproof.size(), rangeproof.data(), rangeproof.size(), output); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_get_elements_signature_hash(const TX& tx, size_t index, const SCRIPT& script, const VALUE& value, uint32_t sighash, uint32_t flags, BYTES_OUT& bytes_out) { int ret = ::wally_tx_get_elements_signature_hash(detail::get_p(tx), index, script.data(), script.size(), value.data(), value.size(), sighash, flags, bytes_out.data(), bytes_out.size()); - return ret; + return detail::check_ret(__FUNCTION__, ret); } template inline int tx_is_elements(const TX& tx, size_t* written) { int ret = ::wally_tx_is_elements(detail::get_p(tx), written); - return ret; + return detail::check_ret(__FUNCTION__, ret); } #endif // WALLY_ABI_NO_ELEMENTS /* END AUTOGENERATED */ diff --git a/tools/build_wrappers.py b/tools/build_wrappers.py index 5635df8c5..6ec1768ec 100755 --- a/tools/build_wrappers.py +++ b/tools/build_wrappers.py @@ -341,9 +341,8 @@ def gen_wally_hpp(funcs, all_funcs): impl.append(f' int ret = ::{func.name}({", ".join(call_args)});') if vardecl: prev = func.args[-3] - impl.append(f' return written || ret != WALLY_OK ? ret : n == static_cast({prev.name}.size()) ? WALLY_OK : WALLY_EINVAL;') - else: - impl.append(f' return ret;') + impl.append(f' if (ret == WALLY_OK && n != static_cast({prev.name}.size())) ret = WALLY_EINVAL;') + impl.append(f' return detail::check_ret(__FUNCTION__, ret);') impl.extend([u'}', u'']) (cpp_elements if func.is_elements else cpp)[func.name] = impl From 850cb0491376ead0e695cf6b700bb5dcbd22f7cc Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:19:05 +1200 Subject: [PATCH 08/26] cpp: remove written parameter defaulting --- include/wally.hpp | 498 ++++++++++++++-------------------------- tools/build_wrappers.py | 5 - 2 files changed, 166 insertions(+), 337 deletions(-) diff --git a/include/wally.hpp b/include/wally.hpp index 560cc0cb9..a94fb93b0 100644 --- a/include/wally.hpp +++ b/include/wally.hpp @@ -244,10 +244,8 @@ inline int bip38_raw_from_private_key(const BYTES& bytes, const PASS& pass, uint } template -inline int bip38_raw_get_flags(const BYTES& bytes, size_t* written = 0) { - size_t n; - int ret = ::bip38_raw_get_flags(bytes.data(), bytes.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes.size())) ret = WALLY_EINVAL; +inline int bip38_raw_get_flags(const BYTES& bytes, size_t* written) { + int ret = ::bip38_raw_get_flags(bytes.data(), bytes.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -287,18 +285,14 @@ inline int bip39_mnemonic_from_bytes(const W& w, const BYTES& bytes, char** outp } template -inline int bip39_mnemonic_to_bytes(const W& w, const MNEMONIC& mnemonic, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::bip39_mnemonic_to_bytes(detail::get_p(w), detail::get_p(mnemonic), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int bip39_mnemonic_to_bytes(const W& w, const MNEMONIC& mnemonic, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::bip39_mnemonic_to_bytes(detail::get_p(w), detail::get_p(mnemonic), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int bip39_mnemonic_to_seed(const MNEMONIC& mnemonic, const PASSPHRASE& passphrase, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::bip39_mnemonic_to_seed(detail::get_p(mnemonic), detail::get_p(passphrase), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int bip39_mnemonic_to_seed(const MNEMONIC& mnemonic, const PASSPHRASE& passphrase, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::bip39_mnemonic_to_seed(detail::get_p(mnemonic), detail::get_p(passphrase), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -315,10 +309,8 @@ inline int bip39_mnemonic_validate(const W& w, const char* mnemonic) { } template -inline int bip85_get_bip39_entropy(const HDKEY& hdkey, const LANG& lang, uint32_t num_words, uint32_t index, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::bip85_get_bip39_entropy(detail::get_p(hdkey), detail::get_p(lang), num_words, index, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int bip85_get_bip39_entropy(const HDKEY& hdkey, const LANG& lang, uint32_t num_words, uint32_t index, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::bip85_get_bip39_entropy(detail::get_p(hdkey), detail::get_p(lang), num_words, index, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -346,26 +338,20 @@ inline int addr_segwit_n_get_version(const ADDR& addr, size_t addr_len, const AD } template -inline int addr_segwit_n_to_bytes(const ADDR& addr, size_t addr_len, const ADDR_FAMILY& addr_family, size_t addr_family_len, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_addr_segwit_n_to_bytes(detail::get_p(addr), addr_len, detail::get_p(addr_family), addr_family_len, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int addr_segwit_n_to_bytes(const ADDR& addr, size_t addr_len, const ADDR_FAMILY& addr_family, size_t addr_family_len, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_addr_segwit_n_to_bytes(detail::get_p(addr), addr_len, detail::get_p(addr_family), addr_family_len, flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int addr_segwit_to_bytes(const ADDR& addr, const ADDR_FAMILY& addr_family, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_addr_segwit_to_bytes(detail::get_p(addr), detail::get_p(addr_family), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int addr_segwit_to_bytes(const ADDR& addr, const ADDR_FAMILY& addr_family, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_addr_segwit_to_bytes(detail::get_p(addr), detail::get_p(addr_family), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int address_to_scriptpubkey(const ADDR& addr, uint32_t network, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_address_to_scriptpubkey(detail::get_p(addr), network, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int address_to_scriptpubkey(const ADDR& addr, uint32_t network, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_address_to_scriptpubkey(detail::get_p(addr), network, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -400,10 +386,8 @@ inline int aes(const KEY& key, const BYTES& bytes, uint32_t flags, BYTES_OUT& by } template -inline int aes_cbc(const KEY& key, const IV& iv, const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_aes_cbc(key.data(), key.size(), iv.data(), iv.size(), bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int aes_cbc(const KEY& key, const IV& iv, const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_aes_cbc(key.data(), key.size(), iv.data(), iv.size(), bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -426,18 +410,14 @@ inline int base58_n_get_length(const STR_IN& str_in, size_t str_len, size_t* wri } template -inline int base58_n_to_bytes(const STR_IN& str_in, size_t str_len, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_base58_n_to_bytes(detail::get_p(str_in), str_len, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int base58_n_to_bytes(const STR_IN& str_in, size_t str_len, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_base58_n_to_bytes(detail::get_p(str_in), str_len, flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int base58_to_bytes(const STR_IN& str_in, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_base58_to_bytes(detail::get_p(str_in), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int base58_to_bytes(const STR_IN& str_in, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_base58_to_bytes(detail::get_p(str_in), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -454,10 +434,8 @@ inline int base64_get_maximum_length(const STR_IN& str_in, uint32_t flags, size_ } template -inline int base64_to_bytes(const STR_IN& str_in, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_base64_to_bytes(detail::get_p(str_in), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int base64_to_bytes(const STR_IN& str_in, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_base64_to_bytes(detail::get_p(str_in), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -562,10 +540,8 @@ inline int descriptor_to_addresses(const DESCRIPTOR& descriptor, uint32_t varian } template -inline int descriptor_to_script(const DESCRIPTOR& descriptor, uint32_t depth, uint32_t index, uint32_t variant, uint32_t multi_index, uint32_t child_num, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_descriptor_to_script(detail::get_p(descriptor), depth, index, variant, multi_index, child_num, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int descriptor_to_script(const DESCRIPTOR& descriptor, uint32_t depth, uint32_t index, uint32_t variant, uint32_t multi_index, uint32_t child_num, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_descriptor_to_script(detail::get_p(descriptor), depth, index, variant, multi_index, child_num, flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -696,10 +672,8 @@ inline int ec_sig_normalize(const SIG& sig, BYTES_OUT& bytes_out) { } template -inline int ec_sig_to_der(const SIG& sig, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_ec_sig_to_der(sig.data(), sig.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int ec_sig_to_der(const SIG& sig, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_ec_sig_to_der(sig.data(), sig.size(), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -728,10 +702,8 @@ inline int ecdh(const PUB_KEY& pub_key, const PRIV_KEY& priv_key, BYTES_OUT& byt } template -inline int format_bitcoin_message(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_format_bitcoin_message(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int format_bitcoin_message(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_format_bitcoin_message(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -769,10 +741,8 @@ inline int hex_from_bytes(const BYTES& bytes, char** output) { } template -inline int hex_n_to_bytes(const HEX& hex, size_t hex_len, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_hex_n_to_bytes(detail::get_p(hex), hex_len, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int hex_n_to_bytes(const HEX& hex, size_t hex_len, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_hex_n_to_bytes(detail::get_p(hex), hex_len, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -783,10 +753,8 @@ inline int hex_n_verify(const HEX& hex, size_t hex_len) { } template -inline int hex_to_bytes(const HEX& hex, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_hex_to_bytes(detail::get_p(hex), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int hex_to_bytes(const HEX& hex, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_hex_to_bytes(detail::get_p(hex), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -836,10 +804,8 @@ inline int keypath_get_path(const VAL& val, uint32_t* child_path_out, size_t chi } template -inline int keypath_get_path_len(const VAL& val, size_t* written = 0) { - size_t n; - int ret = ::wally_keypath_get_path_len(val.data(), val.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(val.size())) ret = WALLY_EINVAL; +inline int keypath_get_path_len(const VAL& val, size_t* written) { + int ret = ::wally_keypath_get_path_len(val.data(), val.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -885,10 +851,8 @@ inline int map_combine(const MAP_IN& map_in, const struct wally_map* source) { } template -inline int map_find(const MAP_IN& map_in, const KEY& key, size_t* written = 0) { - size_t n; - int ret = ::wally_map_find(detail::get_p(map_in), key.data(), key.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(key.size())) ret = WALLY_EINVAL; +inline int map_find(const MAP_IN& map_in, const KEY& key, size_t* written) { + int ret = ::wally_map_find(detail::get_p(map_in), key.data(), key.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -899,10 +863,8 @@ inline int map_find_bip32_public_key_from(const MAP_IN& map_in, size_t index, co } template -inline int map_find_from(const MAP_IN& map_in, size_t index, const KEY& key, size_t* written = 0) { - size_t n; - int ret = ::wally_map_find_from(detail::get_p(map_in), index, key.data(), key.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(key.size())) ret = WALLY_EINVAL; +inline int map_find_from(const MAP_IN& map_in, size_t index, const KEY& key, size_t* written) { + int ret = ::wally_map_find_from(detail::get_p(map_in), index, key.data(), key.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -918,10 +880,8 @@ inline int map_free(struct wally_map* map_in) { } template -inline int map_get_item(const MAP_IN& map_in, size_t index, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_map_get_item(detail::get_p(map_in), index, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int map_get_item(const MAP_IN& map_in, size_t index, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_map_get_item(detail::get_p(map_in), index, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -932,10 +892,8 @@ inline int map_get_item_integer_key(const MAP_IN& map_in, size_t index, size_t* } template -inline int map_get_item_key(const MAP_IN& map_in, size_t index, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_map_get_item_key(detail::get_p(map_in), index, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int map_get_item_key(const MAP_IN& map_in, size_t index, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_map_get_item_key(detail::get_p(map_in), index, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -1209,18 +1167,14 @@ inline int psbt_get_input_bip32_key_from_alloc(const PSBT& psbt, size_t index, s } template -inline int psbt_get_input_scriptcode(const PSBT& psbt, size_t index, const SCRIPT& script, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_get_input_scriptcode(detail::get_p(psbt), index, script.data(), script.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_get_input_scriptcode(const PSBT& psbt, size_t index, const SCRIPT& script, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_get_input_scriptcode(detail::get_p(psbt), index, script.data(), script.size(), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int psbt_get_input_scriptcode_len(const PSBT& psbt, size_t index, const SCRIPT& script, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_get_input_scriptcode_len(detail::get_p(psbt), index, script.data(), script.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(script.size())) ret = WALLY_EINVAL; +inline int psbt_get_input_scriptcode_len(const PSBT& psbt, size_t index, const SCRIPT& script, size_t* written) { + int ret = ::wally_psbt_get_input_scriptcode_len(detail::get_p(psbt), index, script.data(), script.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -1231,10 +1185,8 @@ inline int psbt_get_input_signature_hash(const PSBT& psbt, size_t index, const T } template -inline int psbt_get_input_signing_script(const PSBT& psbt, size_t index, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_get_input_signing_script(detail::get_p(psbt), index, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_get_input_signing_script(const PSBT& psbt, size_t index, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_get_input_signing_script(detail::get_p(psbt), index, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -1289,26 +1241,20 @@ inline int psbt_input_clear_sequence(struct wally_psbt_input* input) { } template -inline int psbt_input_find_keypath(const INPUT& input, const PUB_KEY& pub_key, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_find_keypath(detail::get_p(input), pub_key.data(), pub_key.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(pub_key.size())) ret = WALLY_EINVAL; +inline int psbt_input_find_keypath(const INPUT& input, const PUB_KEY& pub_key, size_t* written) { + int ret = ::wally_psbt_input_find_keypath(detail::get_p(input), pub_key.data(), pub_key.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int psbt_input_find_signature(const INPUT& input, const PUB_KEY& pub_key, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_find_signature(detail::get_p(input), pub_key.data(), pub_key.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(pub_key.size())) ret = WALLY_EINVAL; +inline int psbt_input_find_signature(const INPUT& input, const PUB_KEY& pub_key, size_t* written) { + int ret = ::wally_psbt_input_find_signature(detail::get_p(input), pub_key.data(), pub_key.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int psbt_input_find_unknown(const INPUT& input, const KEY& key, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_find_unknown(detail::get_p(input), key.data(), key.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(key.size())) ret = WALLY_EINVAL; +inline int psbt_input_find_unknown(const INPUT& input, const KEY& key, size_t* written) { + int ret = ::wally_psbt_input_find_unknown(detail::get_p(input), key.data(), key.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -1456,18 +1402,14 @@ inline int psbt_output_clear_amount(struct wally_psbt_output* output) { } template -inline int psbt_output_find_keypath(const OUTPUT& output, const PUB_KEY& pub_key, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_output_find_keypath(detail::get_p(output), pub_key.data(), pub_key.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(pub_key.size())) ret = WALLY_EINVAL; +inline int psbt_output_find_keypath(const OUTPUT& output, const PUB_KEY& pub_key, size_t* written) { + int ret = ::wally_psbt_output_find_keypath(detail::get_p(output), pub_key.data(), pub_key.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int psbt_output_find_unknown(const OUTPUT& output, const KEY& key, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_output_find_unknown(detail::get_p(output), key.data(), key.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(key.size())) ret = WALLY_EINVAL; +inline int psbt_output_find_unknown(const OUTPUT& output, const KEY& key, size_t* written) { + int ret = ::wally_psbt_output_find_unknown(detail::get_p(output), key.data(), key.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -1586,10 +1528,8 @@ inline int psbt_to_base64(const PSBT& psbt, uint32_t flags, char** output) { } template -inline int psbt_to_bytes(const PSBT& psbt, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_to_bytes(detail::get_p(psbt), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_to_bytes(const PSBT& psbt, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_to_bytes(detail::get_p(psbt), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -1612,66 +1552,50 @@ inline int s2c_sig_from_bytes(const PRIV_KEY& priv_key, const BYTES& bytes, cons } template -inline int script_push_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_script_push_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int script_push_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_script_push_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int scriptpubkey_csv_2of2_then_1_from_bytes(const BYTES& bytes, uint32_t csv_blocks, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_scriptpubkey_csv_2of2_then_1_from_bytes(bytes.data(), bytes.size(), csv_blocks, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int scriptpubkey_csv_2of2_then_1_from_bytes(const BYTES& bytes, uint32_t csv_blocks, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_scriptpubkey_csv_2of2_then_1_from_bytes(bytes.data(), bytes.size(), csv_blocks, flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int scriptpubkey_csv_2of2_then_1_from_bytes_opt(const BYTES& bytes, uint32_t csv_blocks, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_scriptpubkey_csv_2of2_then_1_from_bytes_opt(bytes.data(), bytes.size(), csv_blocks, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int scriptpubkey_csv_2of2_then_1_from_bytes_opt(const BYTES& bytes, uint32_t csv_blocks, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_scriptpubkey_csv_2of2_then_1_from_bytes_opt(bytes.data(), bytes.size(), csv_blocks, flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int scriptpubkey_get_type(const BYTES& bytes, size_t* written = 0) { - size_t n; - int ret = ::wally_scriptpubkey_get_type(bytes.data(), bytes.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes.size())) ret = WALLY_EINVAL; +inline int scriptpubkey_get_type(const BYTES& bytes, size_t* written) { + int ret = ::wally_scriptpubkey_get_type(bytes.data(), bytes.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int scriptpubkey_multisig_from_bytes(const BYTES& bytes, uint32_t threshold, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_scriptpubkey_multisig_from_bytes(bytes.data(), bytes.size(), threshold, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int scriptpubkey_multisig_from_bytes(const BYTES& bytes, uint32_t threshold, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_scriptpubkey_multisig_from_bytes(bytes.data(), bytes.size(), threshold, flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int scriptpubkey_op_return_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_scriptpubkey_op_return_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int scriptpubkey_op_return_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_scriptpubkey_op_return_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int scriptpubkey_p2pkh_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_scriptpubkey_p2pkh_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int scriptpubkey_p2pkh_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_scriptpubkey_p2pkh_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int scriptpubkey_p2sh_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_scriptpubkey_p2sh_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int scriptpubkey_p2sh_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_scriptpubkey_p2sh_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -1682,26 +1606,20 @@ inline int scriptpubkey_to_address(const SCRIPTPUBKEY& scriptpubkey, uint32_t ne } template -inline int scriptsig_multisig_from_bytes(const SCRIPT& script, const BYTES& bytes, const SIGHASH& sighash, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_scriptsig_multisig_from_bytes(script.data(), script.size(), bytes.data(), bytes.size(), sighash.data(), sighash.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int scriptsig_multisig_from_bytes(const SCRIPT& script, const BYTES& bytes, const SIGHASH& sighash, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_scriptsig_multisig_from_bytes(script.data(), script.size(), bytes.data(), bytes.size(), sighash.data(), sighash.size(), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int scriptsig_p2pkh_from_der(const PUB_KEY& pub_key, const SIG& sig, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_scriptsig_p2pkh_from_der(pub_key.data(), pub_key.size(), sig.data(), sig.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int scriptsig_p2pkh_from_der(const PUB_KEY& pub_key, const SIG& sig, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_scriptsig_p2pkh_from_der(pub_key.data(), pub_key.size(), sig.data(), sig.size(), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int scriptsig_p2pkh_from_sig(const PUB_KEY& pub_key, const SIG& sig, uint32_t sighash, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_scriptsig_p2pkh_from_sig(pub_key.data(), pub_key.size(), sig.data(), sig.size(), sighash, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int scriptsig_p2pkh_from_sig(const PUB_KEY& pub_key, const SIG& sig, uint32_t sighash, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_scriptsig_p2pkh_from_sig(pub_key.data(), pub_key.size(), sig.data(), sig.size(), sighash, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -1965,10 +1883,8 @@ inline int tx_set_input_witness(const TX& tx, size_t index, const struct wally_t } template -inline int tx_to_bytes(const TX& tx, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_tx_to_bytes(detail::get_p(tx), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int tx_to_bytes(const TX& tx, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_tx_to_bytes(detail::get_p(tx), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2042,26 +1958,20 @@ inline int tx_witness_stack_set_dummy(const STACK& stack, size_t index, uint32_t } template -inline int tx_witness_stack_to_bytes(const STACK& stack, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_tx_witness_stack_to_bytes(detail::get_p(stack), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int tx_witness_stack_to_bytes(const STACK& stack, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_tx_witness_stack_to_bytes(detail::get_p(stack), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int varbuff_get_length(const BYTES& bytes, size_t* written = 0) { - size_t n; - int ret = ::wally_varbuff_get_length(bytes.data(), bytes.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes.size())) ret = WALLY_EINVAL; +inline int varbuff_get_length(const BYTES& bytes, size_t* written) { + int ret = ::wally_varbuff_get_length(bytes.data(), bytes.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int varbuff_to_bytes(const BYTES& bytes, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_varbuff_to_bytes(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int varbuff_to_bytes(const BYTES& bytes, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_varbuff_to_bytes(bytes.data(), bytes.size(), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2071,10 +1981,8 @@ inline int varint_get_length(uint64_t value, size_t* written) { } template -inline int varint_to_bytes(uint64_t value, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_varint_to_bytes(value, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int varint_to_bytes(uint64_t value, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_varint_to_bytes(value, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2103,10 +2011,8 @@ inline int wif_to_bytes(const WIF& wif, uint32_t prefix, uint32_t flags, BYTES_O } template -inline int wif_to_public_key(const WIF& wif, uint32_t prefix, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_wif_to_public_key(detail::get_p(wif), prefix, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int wif_to_public_key(const WIF& wif, uint32_t prefix, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_wif_to_public_key(detail::get_p(wif), prefix, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2135,18 +2041,14 @@ inline int witness_p2wpkh_from_sig(const PUB_KEY& pub_key, const SIG& sig, uint3 } template -inline int witness_program_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_witness_program_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int witness_program_from_bytes(const BYTES& bytes, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_witness_program_from_bytes(bytes.data(), bytes.size(), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int witness_program_from_bytes_and_version(const BYTES& bytes, uint32_t version, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_witness_program_from_bytes_and_version(bytes.data(), bytes.size(), version, flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int witness_program_from_bytes_and_version(const BYTES& bytes, uint32_t version, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_witness_program_from_bytes_and_version(bytes.data(), bytes.size(), version, flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2206,18 +2108,14 @@ inline int asset_generator_from_bytes(const ASSET& asset, const ABF& abf, BYTES_ } template -inline int asset_pak_whitelistproof(const ONLINE_KEYS& online_keys, const OFFLINE_KEYS& offline_keys, size_t key_index, const SUB_PUBKEY& sub_pubkey, const ONLINE_PRIV_KEY& online_priv_key, const SUMMED_KEY& summed_key, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_asset_pak_whitelistproof(online_keys.data(), online_keys.size(), offline_keys.data(), offline_keys.size(), key_index, sub_pubkey.data(), sub_pubkey.size(), online_priv_key.data(), online_priv_key.size(), summed_key.data(), summed_key.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int asset_pak_whitelistproof(const ONLINE_KEYS& online_keys, const OFFLINE_KEYS& offline_keys, size_t key_index, const SUB_PUBKEY& sub_pubkey, const ONLINE_PRIV_KEY& online_priv_key, const SUMMED_KEY& summed_key, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_asset_pak_whitelistproof(online_keys.data(), online_keys.size(), offline_keys.data(), offline_keys.size(), key_index, sub_pubkey.data(), sub_pubkey.size(), online_priv_key.data(), online_priv_key.size(), summed_key.data(), summed_key.size(), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int asset_pak_whitelistproof_len(const ONLINE_KEYS& online_keys, const OFFLINE_KEYS& offline_keys, size_t key_index, const SUB_PUBKEY& sub_pubkey, const ONLINE_PRIV_KEY& online_priv_key, const SUMMED_KEY& summed_key, size_t* written = 0) { - size_t n; - int ret = ::wally_asset_pak_whitelistproof_len(online_keys.data(), online_keys.size(), offline_keys.data(), offline_keys.size(), key_index, sub_pubkey.data(), sub_pubkey.size(), online_priv_key.data(), online_priv_key.size(), summed_key.data(), summed_key.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(summed_key.size())) ret = WALLY_EINVAL; +inline int asset_pak_whitelistproof_len(const ONLINE_KEYS& online_keys, const OFFLINE_KEYS& offline_keys, size_t key_index, const SUB_PUBKEY& sub_pubkey, const ONLINE_PRIV_KEY& online_priv_key, const SUMMED_KEY& summed_key, size_t* written) { + int ret = ::wally_asset_pak_whitelistproof_len(online_keys.data(), online_keys.size(), offline_keys.data(), offline_keys.size(), key_index, sub_pubkey.data(), sub_pubkey.size(), online_priv_key.data(), online_priv_key.size(), summed_key.data(), summed_key.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2227,10 +2125,8 @@ inline int asset_pak_whitelistproof_size(size_t num_keys, size_t* written) { } template -inline int asset_rangeproof(uint64_t value, const PUB_KEY& pub_key, const PRIV_KEY& priv_key, const ASSET& asset, const ABF& abf, const VBF& vbf, const COMMITMENT& commitment, const EXTRA& extra, const GENERATOR& generator, uint64_t min_value, int exp, int min_bits, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_asset_rangeproof(value, pub_key.data(), pub_key.size(), priv_key.data(), priv_key.size(), asset.data(), asset.size(), abf.data(), abf.size(), vbf.data(), vbf.size(), commitment.data(), commitment.size(), extra.data(), extra.size(), generator.data(), generator.size(), min_value, exp, min_bits, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int asset_rangeproof(uint64_t value, const PUB_KEY& pub_key, const PRIV_KEY& priv_key, const ASSET& asset, const ABF& abf, const VBF& vbf, const COMMITMENT& commitment, const EXTRA& extra, const GENERATOR& generator, uint64_t min_value, int exp, int min_bits, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_asset_rangeproof(value, pub_key.data(), pub_key.size(), priv_key.data(), priv_key.size(), asset.data(), asset.size(), abf.data(), abf.size(), vbf.data(), vbf.size(), commitment.data(), commitment.size(), extra.data(), extra.size(), generator.data(), generator.size(), min_value, exp, min_bits, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2240,10 +2136,8 @@ inline int asset_rangeproof_get_maximum_len(uint64_t value, int min_bits, size_t } template -inline int asset_rangeproof_with_nonce(uint64_t value, const NONCE_HASH& nonce_hash, const ASSET& asset, const ABF& abf, const VBF& vbf, const COMMITMENT& commitment, const EXTRA& extra, const GENERATOR& generator, uint64_t min_value, int exp, int min_bits, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_asset_rangeproof_with_nonce(value, nonce_hash.data(), nonce_hash.size(), asset.data(), asset.size(), abf.data(), abf.size(), vbf.data(), vbf.size(), commitment.data(), commitment.size(), extra.data(), extra.size(), generator.data(), generator.size(), min_value, exp, min_bits, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int asset_rangeproof_with_nonce(uint64_t value, const NONCE_HASH& nonce_hash, const ASSET& asset, const ABF& abf, const VBF& vbf, const COMMITMENT& commitment, const EXTRA& extra, const GENERATOR& generator, uint64_t min_value, int exp, int min_bits, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_asset_rangeproof_with_nonce(value, nonce_hash.data(), nonce_hash.size(), asset.data(), asset.size(), abf.data(), abf.size(), vbf.data(), vbf.size(), commitment.data(), commitment.size(), extra.data(), extra.size(), generator.data(), generator.size(), min_value, exp, min_bits, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2254,18 +2148,14 @@ inline int asset_scalar_offset(uint64_t value, const ABF& abf, const VBF& vbf, B } template -inline int asset_surjectionproof(const OUTPUT_ASSET& output_asset, const OUTPUT_ABF& output_abf, const OUTPUT_GENERATOR& output_generator, const BYTES& bytes, const ASSET& asset, const ABF& abf, const GENERATOR& generator, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_asset_surjectionproof(output_asset.data(), output_asset.size(), output_abf.data(), output_abf.size(), output_generator.data(), output_generator.size(), bytes.data(), bytes.size(), asset.data(), asset.size(), abf.data(), abf.size(), generator.data(), generator.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int asset_surjectionproof(const OUTPUT_ASSET& output_asset, const OUTPUT_ABF& output_abf, const OUTPUT_GENERATOR& output_generator, const BYTES& bytes, const ASSET& asset, const ABF& abf, const GENERATOR& generator, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_asset_surjectionproof(output_asset.data(), output_asset.size(), output_abf.data(), output_abf.size(), output_generator.data(), output_generator.size(), bytes.data(), bytes.size(), asset.data(), asset.size(), abf.data(), abf.size(), generator.data(), generator.size(), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int asset_surjectionproof_len(const OUTPUT_ASSET& output_asset, const OUTPUT_ABF& output_abf, const OUTPUT_GENERATOR& output_generator, const BYTES& bytes, const ASSET& asset, const ABF& abf, const GENERATOR& generator, size_t* written = 0) { - size_t n; - int ret = ::wally_asset_surjectionproof_len(output_asset.data(), output_asset.size(), output_abf.data(), output_abf.size(), output_generator.data(), output_generator.size(), bytes.data(), bytes.size(), asset.data(), asset.size(), abf.data(), abf.size(), generator.data(), generator.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(generator.size())) ret = WALLY_EINVAL; +inline int asset_surjectionproof_len(const OUTPUT_ASSET& output_asset, const OUTPUT_ABF& output_abf, const OUTPUT_GENERATOR& output_generator, const BYTES& bytes, const ASSET& asset, const ABF& abf, const GENERATOR& generator, size_t* written) { + int ret = ::wally_asset_surjectionproof_len(output_asset.data(), output_asset.size(), output_abf.data(), output_abf.size(), output_generator.data(), output_generator.size(), bytes.data(), bytes.size(), asset.data(), asset.size(), abf.data(), abf.size(), generator.data(), generator.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2341,18 +2231,14 @@ inline int ecdh_nonce_hash(const PUB_KEY& pub_key, const PRIV_KEY& priv_key, BYT } template -inline int elements_pegin_contract_script_from_bytes(const REDEEM_SCRIPT& redeem_script, const SCRIPT& script, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_elements_pegin_contract_script_from_bytes(redeem_script.data(), redeem_script.size(), script.data(), script.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int elements_pegin_contract_script_from_bytes(const REDEEM_SCRIPT& redeem_script, const SCRIPT& script, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_elements_pegin_contract_script_from_bytes(redeem_script.data(), redeem_script.size(), script.data(), script.size(), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int elements_pegout_script_from_bytes(const GENESIS_BLOCKHASH& genesis_blockhash, const MAINCHAIN_SCRIPT& mainchain_script, const SUB_PUBKEY& sub_pubkey, const WHITELISTPROOF& whitelistproof, uint32_t flags, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_elements_pegout_script_from_bytes(genesis_blockhash.data(), genesis_blockhash.size(), mainchain_script.data(), mainchain_script.size(), sub_pubkey.data(), sub_pubkey.size(), whitelistproof.data(), whitelistproof.size(), flags, bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int elements_pegout_script_from_bytes(const GENESIS_BLOCKHASH& genesis_blockhash, const MAINCHAIN_SCRIPT& mainchain_script, const SUB_PUBKEY& sub_pubkey, const WHITELISTPROOF& whitelistproof, uint32_t flags, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_elements_pegout_script_from_bytes(genesis_blockhash.data(), genesis_blockhash.size(), mainchain_script.data(), mainchain_script.size(), sub_pubkey.data(), sub_pubkey.size(), whitelistproof.data(), whitelistproof.size(), flags, bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2362,10 +2248,8 @@ inline int elements_pegout_script_size(size_t genesis_blockhash_len, size_t main } template -inline int explicit_rangeproof(uint64_t value, const NONCE& nonce, const VBF& vbf, const COMMITMENT& commitment, const GENERATOR& generator, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_explicit_rangeproof(value, nonce.data(), nonce.size(), vbf.data(), vbf.size(), commitment.data(), commitment.size(), generator.data(), generator.size(), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int explicit_rangeproof(uint64_t value, const NONCE& nonce, const VBF& vbf, const COMMITMENT& commitment, const GENERATOR& generator, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_explicit_rangeproof(value, nonce.data(), nonce.size(), vbf.data(), vbf.size(), commitment.data(), commitment.size(), generator.data(), generator.size(), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2394,10 +2278,8 @@ inline int psbt_add_global_scalar(const PSBT& psbt, const SCALAR& scalar) { } template -inline int psbt_find_global_scalar(const PSBT& psbt, const SCALAR& scalar, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_find_global_scalar(detail::get_p(psbt), scalar.data(), scalar.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(scalar.size())) ret = WALLY_EINVAL; +inline int psbt_find_global_scalar(const PSBT& psbt, const SCALAR& scalar, size_t* written) { + int ret = ::wally_psbt_find_global_scalar(detail::get_p(psbt), scalar.data(), scalar.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2483,10 +2365,8 @@ inline int psbt_input_generate_explicit_proofs(const INPUT& input, uint64_t sato } template -inline int psbt_input_get_amount_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_amount_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_amount_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_amount_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2497,10 +2377,8 @@ inline int psbt_input_get_amount_rangeproof_len(const INPUT& input, size_t* writ } template -inline int psbt_input_get_asset(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_asset(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_asset(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_asset(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2511,10 +2389,8 @@ inline int psbt_input_get_asset_len(const INPUT& input, size_t* written) { } template -inline int psbt_input_get_asset_surjectionproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_asset_surjectionproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_asset_surjectionproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_asset_surjectionproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2525,10 +2401,8 @@ inline int psbt_input_get_asset_surjectionproof_len(const INPUT& input, size_t* } template -inline int psbt_input_get_inflation_keys_blinding_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_inflation_keys_blinding_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_inflation_keys_blinding_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_inflation_keys_blinding_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2539,10 +2413,8 @@ inline int psbt_input_get_inflation_keys_blinding_rangeproof_len(const INPUT& in } template -inline int psbt_input_get_inflation_keys_commitment(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_inflation_keys_commitment(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_inflation_keys_commitment(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_inflation_keys_commitment(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2553,10 +2425,8 @@ inline int psbt_input_get_inflation_keys_commitment_len(const INPUT& input, size } template -inline int psbt_input_get_inflation_keys_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_inflation_keys_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_inflation_keys_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_inflation_keys_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2567,10 +2437,8 @@ inline int psbt_input_get_inflation_keys_rangeproof_len(const INPUT& input, size } template -inline int psbt_input_get_issuance_amount_blinding_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_issuance_amount_blinding_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_issuance_amount_blinding_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_issuance_amount_blinding_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2581,10 +2449,8 @@ inline int psbt_input_get_issuance_amount_blinding_rangeproof_len(const INPUT& i } template -inline int psbt_input_get_issuance_amount_commitment(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_issuance_amount_commitment(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_issuance_amount_commitment(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_issuance_amount_commitment(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2595,10 +2461,8 @@ inline int psbt_input_get_issuance_amount_commitment_len(const INPUT& input, siz } template -inline int psbt_input_get_issuance_amount_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_issuance_amount_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_issuance_amount_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_issuance_amount_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2609,10 +2473,8 @@ inline int psbt_input_get_issuance_amount_rangeproof_len(const INPUT& input, siz } template -inline int psbt_input_get_issuance_asset_entropy(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_issuance_asset_entropy(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_issuance_asset_entropy(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_issuance_asset_entropy(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2623,10 +2485,8 @@ inline int psbt_input_get_issuance_asset_entropy_len(const INPUT& input, size_t* } template -inline int psbt_input_get_issuance_blinding_nonce(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_issuance_blinding_nonce(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_issuance_blinding_nonce(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_issuance_blinding_nonce(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2637,10 +2497,8 @@ inline int psbt_input_get_issuance_blinding_nonce_len(const INPUT& input, size_t } template -inline int psbt_input_get_pegin_claim_script(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_pegin_claim_script(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_pegin_claim_script(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_pegin_claim_script(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2651,10 +2509,8 @@ inline int psbt_input_get_pegin_claim_script_len(const INPUT& input, size_t* wri } template -inline int psbt_input_get_pegin_genesis_blockhash(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_pegin_genesis_blockhash(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_pegin_genesis_blockhash(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_pegin_genesis_blockhash(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2665,10 +2521,8 @@ inline int psbt_input_get_pegin_genesis_blockhash_len(const INPUT& input, size_t } template -inline int psbt_input_get_pegin_txout_proof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_pegin_txout_proof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_pegin_txout_proof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_pegin_txout_proof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2679,10 +2533,8 @@ inline int psbt_input_get_pegin_txout_proof_len(const INPUT& input, size_t* writ } template -inline int psbt_input_get_utxo_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_input_get_utxo_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_input_get_utxo_rangeproof(const INPUT& input, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_input_get_utxo_rangeproof(detail::get_p(input), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2869,18 +2721,14 @@ inline int psbt_output_clear_value_rangeproof(struct wally_psbt_output* output) } template -inline int psbt_output_get_asset(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_output_get_asset(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_output_get_asset(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_output_get_asset(detail::get_p(output), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } template -inline int psbt_output_get_asset_blinding_surjectionproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_output_get_asset_blinding_surjectionproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_output_get_asset_blinding_surjectionproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_output_get_asset_blinding_surjectionproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2891,10 +2739,8 @@ inline int psbt_output_get_asset_blinding_surjectionproof_len(const OUTPUT& outp } template -inline int psbt_output_get_asset_commitment(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_output_get_asset_commitment(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_output_get_asset_commitment(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_output_get_asset_commitment(detail::get_p(output), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2911,10 +2757,8 @@ inline int psbt_output_get_asset_len(const OUTPUT& output, size_t* written) { } template -inline int psbt_output_get_asset_surjectionproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_output_get_asset_surjectionproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_output_get_asset_surjectionproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_output_get_asset_surjectionproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2925,10 +2769,8 @@ inline int psbt_output_get_asset_surjectionproof_len(const OUTPUT& output, size_ } template -inline int psbt_output_get_blinding_public_key(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_output_get_blinding_public_key(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_output_get_blinding_public_key(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_output_get_blinding_public_key(detail::get_p(output), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2945,10 +2787,8 @@ inline int psbt_output_get_blinding_status(const OUTPUT& output, uint32_t flags, } template -inline int psbt_output_get_ecdh_public_key(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_output_get_ecdh_public_key(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_output_get_ecdh_public_key(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_output_get_ecdh_public_key(detail::get_p(output), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2959,10 +2799,8 @@ inline int psbt_output_get_ecdh_public_key_len(const OUTPUT& output, size_t* wri } template -inline int psbt_output_get_value_blinding_rangeproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_output_get_value_blinding_rangeproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_output_get_value_blinding_rangeproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_output_get_value_blinding_rangeproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2973,10 +2811,8 @@ inline int psbt_output_get_value_blinding_rangeproof_len(const OUTPUT& output, s } template -inline int psbt_output_get_value_commitment(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_output_get_value_commitment(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_output_get_value_commitment(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_output_get_value_commitment(detail::get_p(output), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } @@ -2987,10 +2823,8 @@ inline int psbt_output_get_value_commitment_len(const OUTPUT& output, size_t* wr } template -inline int psbt_output_get_value_rangeproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written = 0) { - size_t n; - int ret = ::wally_psbt_output_get_value_rangeproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written ? written : &n); - if (ret == WALLY_OK && n != static_cast(bytes_out.size())) ret = WALLY_EINVAL; +inline int psbt_output_get_value_rangeproof(const OUTPUT& output, BYTES_OUT& bytes_out, size_t* written) { + int ret = ::wally_psbt_output_get_value_rangeproof(detail::get_p(output), bytes_out.data(), bytes_out.size(), written); return detail::check_ret(__FUNCTION__, ret); } diff --git a/tools/build_wrappers.py b/tools/build_wrappers.py index 6ec1768ec..755e4c607 100755 --- a/tools/build_wrappers.py +++ b/tools/build_wrappers.py @@ -310,11 +310,6 @@ def gen_wally_hpp(funcs, all_funcs): cpp_args.append(f'{const}{arg.name.upper()}& {arg.name}') call_args.extend([f'{arg.name}.data()', f'{arg.name}.size()']) skip = True - elif arg.type == u'size_t*' and arg.name == u'written' and \ - n >= 2 and is_buffer(func, func.args[n-2], n-2, num_args): - vardecl = u' size_t n;' - cpp_args.append(f'{arg.type} {arg.name} = 0') - call_args.append(f'{arg.name} ? {arg.name} : &n') elif arg.type in [u'int', u'size_t', u'uint32_t', u'uint64_t', u'int*', u'size_t*', u'uint32_t*', u'uint64_t*', u'wally_map_verify_fn_t']: From 59b70670f67fc55fecbb5b5df84449df488fffcc Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:19:13 +1200 Subject: [PATCH 09/26] cpp: fix verify functions to ignore errors --- include/wally.hpp | 64 ++++++++++++++++++++--------------------- tools/build_wrappers.py | 9 ++++-- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/include/wally.hpp b/include/wally.hpp index a94fb93b0..acd3627c8 100644 --- a/include/wally.hpp +++ b/include/wally.hpp @@ -374,9 +374,9 @@ inline int ae_signer_commit_from_bytes(const PRIV_KEY& priv_key, const BYTES& by } template -inline int ae_verify(const PUB_KEY& pub_key, const BYTES& bytes, const ENTROPY& entropy, const S2C_OPENING& s2c_opening, uint32_t flags, const SIG& sig) { +inline bool ae_verify(const PUB_KEY& pub_key, const BYTES& bytes, const ENTROPY& entropy, const S2C_OPENING& s2c_opening, uint32_t flags, const SIG& sig) { int ret = ::wally_ae_verify(pub_key.data(), pub_key.size(), bytes.data(), bytes.size(), entropy.data(), entropy.size(), s2c_opening.data(), s2c_opening.size(), flags, sig.data(), sig.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -558,9 +558,9 @@ inline int ec_private_key_bip341_tweak(const PRIV_KEY& priv_key, const MERKLE_RO } template -inline int ec_private_key_verify(const PRIV_KEY& priv_key) { +inline bool ec_private_key_verify(const PRIV_KEY& priv_key) { int ret = ::wally_ec_private_key_verify(priv_key.data(), priv_key.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -588,9 +588,9 @@ inline int ec_public_key_negate(const PUB_KEY& pub_key, BYTES_OUT& bytes_out) { } template -inline int ec_public_key_verify(const PUB_KEY& pub_key) { +inline bool ec_public_key_verify(const PUB_KEY& pub_key) { int ret = ::wally_ec_public_key_verify(pub_key.data(), pub_key.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -630,9 +630,9 @@ inline int ec_scalar_subtract_from(SCALAR& scalar, const OPERAND& operand) { } template -inline int ec_scalar_verify(const SCALAR& scalar) { +inline bool ec_scalar_verify(const SCALAR& scalar) { int ret = ::wally_ec_scalar_verify(scalar.data(), scalar.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -684,15 +684,15 @@ inline int ec_sig_to_public_key(const BYTES& bytes, const SIG& sig, BYTES_OUT& b } template -inline int ec_sig_verify(const PUB_KEY& pub_key, const BYTES& bytes, uint32_t flags, const SIG& sig) { +inline bool ec_sig_verify(const PUB_KEY& pub_key, const BYTES& bytes, uint32_t flags, const SIG& sig) { int ret = ::wally_ec_sig_verify(pub_key.data(), pub_key.size(), bytes.data(), bytes.size(), flags, sig.data(), sig.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template -inline int ec_xonly_public_key_verify(const PUB_KEY& pub_key) { +inline bool ec_xonly_public_key_verify(const PUB_KEY& pub_key) { int ret = ::wally_ec_xonly_public_key_verify(pub_key.data(), pub_key.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -747,9 +747,9 @@ inline int hex_n_to_bytes(const HEX& hex, size_t hex_len, BYTES_OUT& bytes_out, } template -inline int hex_n_verify(const HEX& hex, size_t hex_len) { +inline bool hex_n_verify(const HEX& hex, size_t hex_len) { int ret = ::wally_hex_n_verify(detail::get_p(hex), hex_len); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -758,9 +758,9 @@ inline int hex_to_bytes(const HEX& hex, BYTES_OUT& bytes_out, size_t* written) { return detail::check_ret(__FUNCTION__, ret); } -inline int hex_verify(const char* hex) { +inline bool hex_verify(const char* hex) { int ret = ::wally_hex_verify(hex); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -786,9 +786,9 @@ inline int is_elements_build(size_t* written) { } template -inline int keypath_bip32_verify(const KEY& key, const VAL& val) { +inline bool keypath_bip32_verify(const KEY& key, const VAL& val) { int ret = ::wally_keypath_bip32_verify(key.data(), key.size(), val.data(), val.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -810,15 +810,15 @@ inline int keypath_get_path_len(const VAL& val, size_t* written) { } template -inline int keypath_public_key_verify(const KEY& key, const VAL& val) { +inline bool keypath_public_key_verify(const KEY& key, const VAL& val) { int ret = ::wally_keypath_public_key_verify(key.data(), key.size(), val.data(), val.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template -inline int keypath_xonly_public_key_verify(const KEY& key, const VAL& val) { +inline bool keypath_xonly_public_key_verify(const KEY& key, const VAL& val) { int ret = ::wally_keypath_xonly_public_key_verify(key.data(), key.size(), val.data(), val.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -916,9 +916,9 @@ inline int map_get_num_items(const MAP_IN& map_in, size_t* written) { } template -inline int map_hash_preimage_verify(const KEY& key, const VAL& val) { +inline bool map_hash_preimage_verify(const KEY& key, const VAL& val) { int ret = ::wally_map_hash_preimage_verify(key.data(), key.size(), val.data(), val.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } inline int map_init(size_t allocation_len, wally_map_verify_fn_t verify_fn, struct wally_map* output) { @@ -1037,9 +1037,9 @@ inline int map_sort(const MAP_IN& map_in, uint32_t flags) { } template -inline int merkle_path_xonly_public_key_verify(const KEY& key, const VAL& val) { +inline bool merkle_path_xonly_public_key_verify(const KEY& key, const VAL& val) { int ret = ::wally_merkle_path_xonly_public_key_verify(key.data(), key.size(), val.data(), val.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -1540,9 +1540,9 @@ inline int ripemd160(const BYTES& bytes, BYTES_OUT& bytes_out) { } template -inline int s2c_commitment_verify(const SIG& sig, const S2C_DATA& s2c_data, const S2C_OPENING& s2c_opening, uint32_t flags) { +inline bool s2c_commitment_verify(const SIG& sig, const S2C_DATA& s2c_data, const S2C_OPENING& s2c_opening, uint32_t flags) { int ret = ::wally_s2c_commitment_verify(sig.data(), sig.size(), s2c_data.data(), s2c_data.size(), s2c_opening.data(), s2c_opening.size(), flags); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -2254,9 +2254,9 @@ inline int explicit_rangeproof(uint64_t value, const NONCE& nonce, const VBF& vb } template -inline int explicit_rangeproof_verify(const RANGEPROOF& rangeproof, uint64_t value, const COMMITMENT& commitment, const GENERATOR& generator) { +inline bool explicit_rangeproof_verify(const RANGEPROOF& rangeproof, uint64_t value, const COMMITMENT& commitment, const GENERATOR& generator) { int ret = ::wally_explicit_rangeproof_verify(rangeproof.data(), rangeproof.size(), value, commitment.data(), commitment.size(), generator.data(), generator.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template @@ -2266,9 +2266,9 @@ inline int explicit_surjectionproof(const OUTPUT_ASSET& output_asset, const OUTP } template -inline int explicit_surjectionproof_verify(const SURJECTIONPROOF& surjectionproof, const OUTPUT_ASSET& output_asset, const OUTPUT_GENERATOR& output_generator) { +inline bool explicit_surjectionproof_verify(const SURJECTIONPROOF& surjectionproof, const OUTPUT_ASSET& output_asset, const OUTPUT_GENERATOR& output_generator) { int ret = ::wally_explicit_surjectionproof_verify(surjectionproof.data(), surjectionproof.size(), output_asset.data(), output_asset.size(), output_generator.data(), output_generator.size()); - return detail::check_ret(__FUNCTION__, ret); + return ret == WALLY_OK; } template diff --git a/tools/build_wrappers.py b/tools/build_wrappers.py index 755e4c607..b5fd60d83 100755 --- a/tools/build_wrappers.py +++ b/tools/build_wrappers.py @@ -304,6 +304,7 @@ def gen_wally_hpp(funcs, all_funcs): if skip: skip = False continue + is_verify_function = func.name.endswith('_verify') if is_buffer(func, arg, n, num_args) or is_int_buffer(func, arg, n, num_args): t_types.append(f'class {arg.name.upper()}') const = u'const ' if arg.is_const else '' @@ -330,14 +331,18 @@ def gen_wally_hpp(funcs, all_funcs): if len(t_types): impl.append(f'template <{", ".join(t_types)}>') func_name = strip_wally_prefix(func.name) - impl.append(f'inline int {func_name}({", ".join(cpp_args)}) {{') + return_type = 'bool' if is_verify_function else 'int' + impl.append(f'inline {return_type} {func_name}({", ".join(cpp_args)}) {{') if vardecl: impl.append(vardecl) impl.append(f' int ret = ::{func.name}({", ".join(call_args)});') if vardecl: prev = func.args[-3] impl.append(f' if (ret == WALLY_OK && n != static_cast({prev.name}.size())) ret = WALLY_EINVAL;') - impl.append(f' return detail::check_ret(__FUNCTION__, ret);') + if is_verify_function: + impl.append(f' return ret == WALLY_OK;') + else: + impl.append(f' return detail::check_ret(__FUNCTION__, ret);') impl.extend([u'}', u'']) (cpp_elements if func.is_elements else cpp)[func.name] = impl From c5b8a5a622b3eb408c9b1f558c88457e71e37dec Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:19:44 +1200 Subject: [PATCH 10/26] abi: add set and get error calls to the operations struct Future error handling will support extended error codes via these functions which are user-overridable in order to support thread safety. Make the structure changes now without using them so we can avoid an ABI version bump once implemented. --- include/wally_core.h | 13 ++++++++++--- src/internal.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/include/wally_core.h b/include/wally_core.h index 4338f679f..e5d6a958e 100644 --- a/include/wally_core.h +++ b/include/wally_core.h @@ -350,6 +350,13 @@ typedef int (*wally_ec_nonce_t)( typedef struct secp256k1_context_struct *(*secp_context_t)( void); +/** The type of an overridable function to get the last extended error code */ +typedef int (*wally_get_error_t)(void); + +/** The type of an overridable function to set the last extended error code */ +typedef int (*wally_set_error_t)( + int error_code); + /** Structure holding function pointers for overridable wally operations */ struct wally_operations { uintptr_t struct_size; /* Must be initialised to sizeof(wally_operations) */ @@ -358,9 +365,9 @@ struct wally_operations { wally_bzero_t bzero_fn; wally_ec_nonce_t ec_nonce_fn; secp_context_t secp_context_fn; - void *reserved_1; /* reserved_ pointers are reserved for future use */ - void *reserved_2; - void *reserved_3; + wally_get_error_t get_error_fn; + wally_set_error_t set_error_fn; + void *reserved_3; /* reserved_ pointers are reserved for future use */ void *reserved_4; }; diff --git a/src/internal.c b/src/internal.c index 0e9cb78d3..1a4e53d0d 100644 --- a/src/internal.c +++ b/src/internal.c @@ -17,6 +17,8 @@ /* Caller is responsible for thread safety */ static secp256k1_context *global_ctx = NULL; +/* Global extended error code. Not thread-safe unless caller-overridden */ +static int global_error = WALLY_OK; int wally_get_build_version(uint32_t *value) { @@ -378,6 +380,16 @@ struct secp256k1_context_struct *wally_internal_secp_context(void) return global_ctx; } +int wally_internal_get_error(void) { + return global_error; +} + +int wally_internal_set_error(int error_code) +{ + global_error = error_code; + return error_code; +} + static struct wally_operations _ops = { sizeof(struct wally_operations), wally_internal_malloc, @@ -385,8 +397,8 @@ static struct wally_operations _ops = { wally_internal_bzero, wally_internal_ec_nonce_fn, wally_internal_secp_context, - NULL, - NULL, + wally_internal_get_error, + wally_internal_set_error, NULL, NULL }; @@ -428,6 +440,15 @@ char *wally_strdup(const char *str) return wally_strdup_n(str, strlen(str)); } +int wally_get_error(void) { + return _ops.get_error_fn(); +} + +int wally_set_error(int error_code) +{ + return _ops.set_error_fn(error_code); +} + const struct wally_operations *wally_ops(void) { return &_ops; @@ -447,7 +468,7 @@ int wally_set_operations(const struct wally_operations *ops) return WALLY_EINVAL; /* Null or invalid version of ops */ /* Reserved pointers must be null so they can be enabled in the * future without breaking back compatibility */ - if (ops->reserved_1 || ops->reserved_2 || ops->reserved_3 || ops->reserved_4) + if (ops->reserved_3 || ops->reserved_4) return WALLY_EINVAL; #define COPY_FN_PTR(name) if (ops->name) _ops.name = ops->name @@ -456,6 +477,8 @@ int wally_set_operations(const struct wally_operations *ops) COPY_FN_PTR (bzero_fn); COPY_FN_PTR (ec_nonce_fn); COPY_FN_PTR (secp_context_fn); + COPY_FN_PTR (get_error_fn); + COPY_FN_PTR (set_error_fn); #undef COPY_FN_PTR return WALLY_OK; } From b98e0b20b7f64cfacd376f1403564695d8d2f090 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:20:01 +1200 Subject: [PATCH 11/26] abi: force users to explicitly opt-out of exporting Elements functions (1) Part 1, header changes. As with the previous c-struct change, by default Elements is enabled and elements functions are exported from the library. Using --disable-elements now leaves the Elements functions available, but calling them will always return WALLY_ERROR. This behaviour allows installing a system-wide wally built without Elements support which applications can gracefully detect at runtime via wally_is_elements_build() and handle by degrading functionality or failing to start. To compile the Elements functions out completely, the user must configure with --disable-elements-abi and define WALLY_ABI_NO_ELEMENTS when including library headers. This allows e.g. embeddeded/static builds to eliminate all Elements code entirely. As before, WALLY_ABI_NO_ELEMENTS builds must not be installed as system-wide shared libraries. Doing so may result in either memory corruption at runtime (if no Elements code is used) or linker errors on startup due to missing Elements calls. --- include/wally_address.h | 4 ++-- include/wally_bip32.h | 4 ++-- include/wally_coinselection.h | 4 ++-- include/wally_elements.h | 5 ++--- include/wally_psbt.h | 12 ++++++------ include/wally_psbt_members.h | 12 ++++++------ include/wally_script.h | 4 ++-- include/wally_transaction.h | 4 ++-- include/wally_transaction_members.h | 16 ++++++++-------- src/internal.h | 6 ++++++ 10 files changed, 38 insertions(+), 33 deletions(-) diff --git a/include/wally_address.h b/include/wally_address.h index 68e965dfb..98061a954 100644 --- a/include/wally_address.h +++ b/include/wally_address.h @@ -274,7 +274,7 @@ WALLY_CORE_API int wally_wif_to_address( uint32_t version, char **output); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * Extract the address from a confidential address. * @@ -366,7 +366,7 @@ WALLY_CORE_API int wally_confidential_addr_from_addr_segwit( const unsigned char *pub_key, size_t pub_key_len, char **output); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ #ifdef __cplusplus } diff --git a/include/wally_bip32.h b/include/wally_bip32.h index 38cd3df7c..703b64350 100644 --- a/include/wally_bip32.h +++ b/include/wally_bip32.h @@ -360,7 +360,7 @@ WALLY_CORE_API int bip32_key_from_parent_path_str_n_alloc( uint32_t flags, struct ext_key **output); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * Derive the pub tweak from a parent extended key and a path. * @@ -387,7 +387,7 @@ WALLY_CORE_API int bip32_key_with_tweak_from_parent_path_alloc( size_t child_path_len, uint32_t flags, struct ext_key **output); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ /** * Convert an extended key to base58. diff --git a/include/wally_coinselection.h b/include/wally_coinselection.h index 2be6ac2c7..d1833ae03 100644 --- a/include/wally_coinselection.h +++ b/include/wally_coinselection.h @@ -10,7 +10,7 @@ extern "C" { /** The maximum number of asset values that can be returned in a coin selection */ #define WALLY_CS_MAX_ASSETS 256 -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * Select input asset values to meet a given payment target. @@ -47,7 +47,7 @@ WALLY_CORE_API int wally_coinselect_assets( size_t indices_out_len, size_t *written); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ #ifdef __cplusplus } diff --git a/include/wally_elements.h b/include/wally_elements.h index 4b1ef6e5c..85a0c641d 100644 --- a/include/wally_elements.h +++ b/include/wally_elements.h @@ -7,8 +7,6 @@ extern "C" { #endif -#ifdef BUILD_ELEMENTS - #define ASSET_TAG_LEN 32 /** Length of an Asset Tag */ #define BLINDING_FACTOR_LEN 32 /** Length of a Blinding Factor (or blinder) */ @@ -24,6 +22,7 @@ extern "C" { #define ASSET_SURJECTIONPROOF_MAX_LEN 162 /** Maximum length of a wally-produced Asset Surjection Proof */ #define ASSET_EXPLICIT_SURJECTIONPROOF_LEN 67 /** Length of an Explicit Asset Surjection Proof */ +#ifndef WALLY_ABI_NO_ELEMENTS /** * Create an Asset Generator from an either an asset commitment or asset tag plus blinding factor. * @@ -657,7 +656,7 @@ WALLY_CORE_API int wally_asset_pak_whitelistproof_len( size_t summed_key_len, size_t *written); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ #ifdef __cplusplus } diff --git a/include/wally_psbt.h b/include/wally_psbt.h index 6a0ed0ca2..0e7ae2a90 100644 --- a/include/wally_psbt.h +++ b/include/wally_psbt.h @@ -453,7 +453,7 @@ WALLY_CORE_API int wally_psbt_input_set_required_lockheight( WALLY_CORE_API int wally_psbt_input_clear_required_lockheight( struct wally_psbt_input *input); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * Set the unblinded amount in an input. * @@ -1254,7 +1254,7 @@ WALLY_CORE_API int wally_psbt_input_generate_explicit_proofs( size_t vbf_len, const unsigned char *entropy, size_t entropy_len); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ /** * Determine if a PSBT input is finalized. @@ -1416,7 +1416,7 @@ WALLY_CORE_API int wally_psbt_output_set_script( const unsigned char *script, size_t script_len); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * Set the input blinder index in an output. * @@ -1875,7 +1875,7 @@ WALLY_CORE_API int wally_psbt_output_get_blinding_status( const struct wally_psbt_output *output, uint32_t flags, size_t *written); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ /** * Allocate and initialize a new PSBT. @@ -2037,7 +2037,7 @@ WALLY_CORE_API int wally_psbt_set_tx_modifiable_flags( struct wally_psbt *psbt, uint32_t flags); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * Set the scalar offsets in a PSBT. * @@ -2084,7 +2084,7 @@ WALLY_CORE_API int wally_psbt_find_global_scalar( WALLY_CORE_API int wally_psbt_set_pset_modifiable_flags( struct wally_psbt *psbt, uint32_t flags); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ /** * Find the index of the PSBT input that spends a given UTXO. diff --git a/include/wally_psbt_members.h b/include/wally_psbt_members.h index 2b34ba3bd..8ffb0fb8c 100644 --- a/include/wally_psbt_members.h +++ b/include/wally_psbt_members.h @@ -16,7 +16,7 @@ WALLY_CORE_API int wally_psbt_get_num_outputs(const struct wally_psbt *psbt, siz WALLY_CORE_API int wally_psbt_get_fallback_locktime(const struct wally_psbt *psbt, size_t *written); WALLY_CORE_API int wally_psbt_has_fallback_locktime(const struct wally_psbt *psbt, size_t *written); WALLY_CORE_API int wally_psbt_get_tx_modifiable_flags(const struct wally_psbt *psbt, size_t *written); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS WALLY_CORE_API int wally_psbt_get_global_scalars_size(const struct wally_psbt *psbt, size_t *written); /** @@ -25,7 +25,7 @@ WALLY_CORE_API int wally_psbt_get_global_scalars_size(const struct wally_psbt *p WALLY_CORE_API int wally_psbt_get_global_scalar(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len); WALLY_CORE_API int wally_psbt_get_pset_modifiable_flags(const struct wally_psbt *psbt, size_t *written); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ /* Inputs */ WALLY_CORE_API int wally_psbt_get_input_utxo_alloc(const struct wally_psbt *psbt, size_t index, struct wally_tx **output); @@ -92,7 +92,7 @@ WALLY_CORE_API int wally_psbt_has_input_required_locktime(const struct wally_psb WALLY_CORE_API int wally_psbt_set_input_required_lockheight(struct wally_psbt *psbt, size_t index, uint32_t lockheight); WALLY_CORE_API int wally_psbt_clear_input_required_lockheight(struct wally_psbt *psbt, size_t index); WALLY_CORE_API int wally_psbt_has_input_required_lockheight(const struct wally_psbt *psbt, size_t index, size_t *written); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS WALLY_CORE_API int wally_psbt_get_input_amount(const struct wally_psbt *psbt, size_t index, uint64_t *value_out); WALLY_CORE_API int wally_psbt_get_input_amount_rangeproof(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len, size_t *written); WALLY_CORE_API int wally_psbt_get_input_amount_rangeproof_len(const struct wally_psbt *psbt, size_t index, size_t *written); @@ -164,7 +164,7 @@ WALLY_CORE_API int wally_psbt_clear_input_inflation_keys_blinding_rangeproof(str WALLY_CORE_API int wally_psbt_set_input_utxo_rangeproof(struct wally_psbt *psbt, size_t index, const unsigned char *rangeproof, size_t rangeproof_len); WALLY_CORE_API int wally_psbt_clear_input_utxo_rangeproof(struct wally_psbt *psbt, size_t index); WALLY_CORE_API int wally_psbt_generate_input_explicit_proofs(struct wally_psbt *psbt, size_t index, uint64_t satoshi, const unsigned char *asset, size_t asset_len, const unsigned char *abf, size_t abf_len, const unsigned char *vbf, size_t vbf_len, const unsigned char *entropy, size_t entropy_len); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ /* Outputs */ WALLY_CORE_API int wally_psbt_get_output_redeem_script(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len, size_t *written); @@ -192,7 +192,7 @@ WALLY_CORE_API int wally_psbt_set_output_script(struct wally_psbt *psbt, size_t WALLY_CORE_API int wally_psbt_set_output_amount(struct wally_psbt *psbt, size_t index, uint64_t amount); WALLY_CORE_API int wally_psbt_clear_output_amount(struct wally_psbt *psbt, size_t index); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS WALLY_CORE_API int wally_psbt_get_output_blinder_index(const struct wally_psbt *psbt, size_t index, uint32_t *value_out); WALLY_CORE_API int wally_psbt_has_output_blinder_index(const struct wally_psbt *psbt, size_t index, size_t *written); WALLY_CORE_API int wally_psbt_get_output_value_commitment(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len, size_t *written); @@ -236,7 +236,7 @@ WALLY_CORE_API int wally_psbt_clear_output_value_blinding_rangeproof(struct wall WALLY_CORE_API int wally_psbt_set_output_asset_blinding_surjectionproof(struct wally_psbt *psbt, size_t index, const unsigned char *surjectionproof, size_t surjectionproof_len); WALLY_CORE_API int wally_psbt_clear_output_asset_blinding_surjectionproof(struct wally_psbt *psbt, size_t index); WALLY_CORE_API int wally_psbt_get_output_blinding_status(const struct wally_psbt *output, size_t index, uint32_t flags, size_t *written); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ #ifdef __cplusplus } #endif diff --git a/include/wally_script.h b/include/wally_script.h index 99c4f168a..d84126401 100644 --- a/include/wally_script.h +++ b/include/wally_script.h @@ -581,7 +581,7 @@ WALLY_CORE_API int wally_witness_program_from_bytes_and_version( size_t len, size_t *written); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * Get the pegout script size. * @@ -649,7 +649,7 @@ WALLY_CORE_API int wally_elements_pegin_contract_script_from_bytes( unsigned char *bytes_out, size_t len, size_t *written); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ #ifdef __cplusplus } diff --git a/include/wally_transaction.h b/include/wally_transaction.h index 151e9cb53..6aa23c2a3 100644 --- a/include/wally_transaction.h +++ b/include/wally_transaction.h @@ -850,7 +850,7 @@ WALLY_CORE_API int wally_tx_is_coinbase( const struct wally_tx *tx, size_t *written); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * Set issuance data on an input. * @@ -1340,7 +1340,7 @@ WALLY_CORE_API int wally_tx_elements_issuance_calculate_reissuance_token( unsigned char *bytes_out, size_t len); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ #ifdef __cplusplus } diff --git a/include/wally_transaction_members.h b/include/wally_transaction_members.h index 2960fdd81..e7d121e10 100644 --- a/include/wally_transaction_members.h +++ b/include/wally_transaction_members.h @@ -27,7 +27,7 @@ WALLY_CORE_API int wally_tx_input_set_witness(struct wally_tx_input *tx_input, c WALLY_CORE_API int wally_tx_input_set_index(struct wally_tx_input *tx_input, uint32_t index); WALLY_CORE_API int wally_tx_input_set_sequence(struct wally_tx_input *tx_input, uint32_t sequence); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * FIXED_SIZED_OUTPUT(len, bytes_out, SHA256_LEN) @@ -54,7 +54,7 @@ WALLY_CORE_API int wally_tx_input_set_inflation_keys(struct wally_tx_input *tx_i WALLY_CORE_API int wally_tx_input_set_inflation_keys_rangeproof(struct wally_tx_input *tx_input_in, const unsigned char *inflation_keys_rangeproof, size_t inflation_keys_rangeproof_len); WALLY_CORE_API int wally_tx_input_set_issuance_amount(struct wally_tx_input *tx_input_in, const unsigned char *issuance_amount, size_t issuance_amount_len); WALLY_CORE_API int wally_tx_input_set_issuance_amount_rangeproof(struct wally_tx_input *tx_input_in, const unsigned char *issuance_amount_rangeproof, size_t issuance_amount_rangeproof_len); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ /* Output */ WALLY_CORE_API int wally_tx_output_get_script(const struct wally_tx_output *tx_output_in, unsigned char *bytes_out, size_t len, size_t *written); @@ -64,7 +64,7 @@ WALLY_CORE_API int wally_tx_output_get_satoshi(const struct wally_tx_output *tx_ WALLY_CORE_API int wally_tx_output_set_script(struct wally_tx_output *tx_output_in, const unsigned char *script, size_t script_len); WALLY_CORE_API int wally_tx_output_set_satoshi(struct wally_tx_output *tx_output_in, uint64_t satoshi); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS WALLY_CORE_API int wally_tx_output_get_asset(const struct wally_tx_output *tx_output_in, unsigned char *bytes_out, size_t len); WALLY_CORE_API int wally_tx_output_get_asset_len(const struct wally_tx_output *tx_output_in, size_t *written); WALLY_CORE_API int wally_tx_output_get_value(const struct wally_tx_output *tx_output_in, unsigned char *bytes_out, size_t len, size_t *written); @@ -81,7 +81,7 @@ WALLY_CORE_API int wally_tx_output_set_value(struct wally_tx_output *tx_output_i WALLY_CORE_API int wally_tx_output_set_nonce(struct wally_tx_output *tx_output_in, const unsigned char *nonce, size_t nonce_len); WALLY_CORE_API int wally_tx_output_set_surjectionproof(struct wally_tx_output *tx_output_in, const unsigned char *surjectionproof, size_t surjectionproof_len); WALLY_CORE_API int wally_tx_output_set_rangeproof(struct wally_tx_output *tx_output_in, const unsigned char *rangeproof, size_t rangeproof_len); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ /* Transaction */ WALLY_CORE_API int wally_tx_get_version(const struct wally_tx *tx_in, size_t *written); @@ -107,7 +107,7 @@ WALLY_CORE_API int wally_tx_set_input_index(const struct wally_tx *tx_in, size_t WALLY_CORE_API int wally_tx_set_input_sequence(const struct wally_tx *tx_in, size_t index, uint32_t sequence); WALLY_CORE_API int wally_tx_set_input_txhash(const struct wally_tx *tx_in, size_t index, const unsigned char *txhash, size_t txhash_len); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * FIXED_SIZED_OUTPUT(len, bytes_out, SHA256_LEN) @@ -134,7 +134,7 @@ WALLY_CORE_API int wally_tx_set_input_inflation_keys(const struct wally_tx *tx_i WALLY_CORE_API int wally_tx_set_input_inflation_keys_rangeproof(const struct wally_tx *tx_in, size_t index, const unsigned char *inflation_keys_rangeproof, size_t inflation_keys_rangeproof_len); WALLY_CORE_API int wally_tx_set_input_issuance_amount(const struct wally_tx *tx_in, size_t index, const unsigned char *issuance_amount, size_t issuance_amount_len); WALLY_CORE_API int wally_tx_set_input_issuance_amount_rangeproof(const struct wally_tx *tx_in, size_t index, const unsigned char *issuance_amount_rangeproof, size_t issuance_amount_rangeproof_len); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ /* Transaction Outputs */ WALLY_CORE_API int wally_tx_get_output_script(const struct wally_tx *tx_in, size_t index, unsigned char *bytes_out, size_t len, size_t *written); @@ -144,7 +144,7 @@ WALLY_CORE_API int wally_tx_get_output_satoshi(const struct wally_tx *tx_in, siz WALLY_CORE_API int wally_tx_set_output_script(const struct wally_tx *tx_in, size_t index, const unsigned char *script, size_t script_len); WALLY_CORE_API int wally_tx_set_output_satoshi(const struct wally_tx *tx_in, size_t index, uint64_t satoshi); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * FIXED_SIZED_OUTPUT(len, bytes_out, WALLY_TX_ASSET_CT_ASSET_LEN) @@ -173,7 +173,7 @@ WALLY_CORE_API int wally_tx_set_output_value(const struct wally_tx *tx_in, size_ WALLY_CORE_API int wally_tx_set_output_nonce(const struct wally_tx *tx_in, size_t index, const unsigned char *nonce, size_t nonce_len); WALLY_CORE_API int wally_tx_set_output_surjectionproof(const struct wally_tx *tx_in, size_t index, const unsigned char *surjectionproof, size_t surjectionproof_len); WALLY_CORE_API int wally_tx_set_output_rangeproof(const struct wally_tx *tx_in, size_t index, const unsigned char *rangeproof, size_t rangeproof_len); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ #ifdef __cplusplus diff --git a/src/internal.h b/src/internal.h index e73d187d3..8672d0f01 100644 --- a/src/internal.h +++ b/src/internal.h @@ -2,6 +2,12 @@ #define LIBWALLY_INTERNAL_H #include + +#ifdef BUILD_ELEMENTS +#ifdef WALLY_ABI_NO_ELEMENTS +#error "WALLY_ABI_NO_ELEMENTS cannot be defined if BUILD_ELEMENTS is defined" +#endif +#endif #include "secp256k1/include/secp256k1.h" #include "secp256k1/include/secp256k1_recovery.h" #include "secp256k1/include/secp256k1_extrakeys.h" From 6ce492665d52efe35338faa174767e4c4d442b0f Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 14:20:12 +1200 Subject: [PATCH 12/26] abi: force users to explicitly opt-out of exporting Elements functions (2) Part 2, source changes. --- README.md | 19 ++- include/wally_psbt.h | 2 + src/bip32.c | 20 ++- src/bip32_int.h | 4 +- src/blech32.c | 18 ++- src/elements.c | 114 +++++++++++++- src/internal.h | 9 +- src/psbt.c | 367 +++++++++++++++++++++++++++++++------------ src/transaction.c | 203 +++++++++++++++--------- 9 files changed, 562 insertions(+), 194 deletions(-) diff --git a/README.md b/README.md index 5cb1b92dd..c1aa4a3e9 100644 --- a/README.md +++ b/README.md @@ -80,13 +80,12 @@ $ brew install swig interface. After building, see `src/swig_java/src/com/blockstream/libwally/Wally.java` for the Java interface definition (default: no). - `--disable-elements`. Disables support for [Elements](https://elementsproject.org/) - features, including [Liquid](https://blockstream.com/liquid/) support (default: no). - Note that to use Elements API calls from C/C++, the caller must define `BUILD_ELEMENTS` - when including the wally header files. -- `--disable-elements-abi`. Ensures that exposed library structures maintain the same ABI - regardless of `--disable-elements`. If disabled, elements support must be disabled and - the user must define `WALLY_ABI_NO_ELEMENTS` before including all wally header files. - This option *must be set if wally is being installed as a system/shared library*. (default: no). + features, including [Liquid](https://blockstream.com/liquid/) support. Elements + functions exported by the library will always return WALLY_ERROR (default: no). +- `--disable-elements-abi`. Changes the exposed library ABI to completely remove Elements + structure members and exported functions. When configured, elements support must be + disabled and the user must define `WALLY_ABI_NO_ELEMENTS` before including all wally + header files. This option *must not be given if wally is being installed as a system/shared library*. (default: no). - `--enabled-standard-secp`. Excludes support for features that are unavailable in the standard [libsecp256k1 library](https://github.com/bitcoin-core/secp256k1). - `--enable-mbed-tls`. Use mbed-tls hashing functions if available. This typically @@ -97,10 +96,10 @@ $ brew install swig need [lcov](http://ltp.sourceforge.net/coverage/lcov.php) installed to build with this option enabled and generate coverage reports. - `--disable-shared`. Disables building a shared library and builds a static - library instead. -- `--disable-tests`. Disables building library tests. + library instead. (default: no) +- `--disable-tests`. Disables building library tests. (default: no) - `--disable-clear-tests`. Disables just the test_clear test (required to pass - the test suite with some compilers). + the test suite with some compilers). (default: no) ### Recommended development configure options diff --git a/include/wally_psbt.h b/include/wally_psbt.h index 0e7ae2a90..ef133c9cb 100644 --- a/include/wally_psbt.h +++ b/include/wally_psbt.h @@ -2419,6 +2419,7 @@ WALLY_CORE_API int wally_psbt_clone_alloc( uint32_t flags, struct wally_psbt **output); +#ifndef WALLY_ABI_NO_ELEMENTS /** * Blind a PSBT. * @@ -2464,6 +2465,7 @@ WALLY_CORE_API int wally_psbt_blind_alloc( uint32_t output_index, uint32_t flags, struct wally_map **output); +#endif /* WALLY_ABI_NO_ELEMENTS */ /** * Sign PSBT inputs corresponding to a given private key. diff --git a/src/bip32.c b/src/bip32.c index 823ae24c0..e18cc9ea4 100644 --- a/src/bip32.c +++ b/src/bip32.c @@ -837,13 +837,16 @@ int bip32_key_from_parent_path_alloc(const struct ext_key *hdkey, return ret; } -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS int bip32_key_with_tweak_from_parent_path(const struct ext_key *hdkey, const uint32_t *child_path, size_t child_path_len, uint32_t flags, struct ext_key *output) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const secp256k1_context *ctx; secp256k1_pubkey pub_key; size_t len = EC_PUBLIC_KEY_LEN; @@ -865,6 +868,7 @@ int bip32_key_with_tweak_from_parent_path(const struct ext_key *hdkey, return wipe_key_fail(output); return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } int bip32_key_with_tweak_from_parent_path_alloc(const struct ext_key *hdkey, @@ -872,6 +876,9 @@ int bip32_key_with_tweak_from_parent_path_alloc(const struct ext_key *hdkey, uint32_t flags, struct ext_key **output) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else int ret; ALLOC_KEY(); @@ -882,8 +889,9 @@ int bip32_key_with_tweak_from_parent_path_alloc(const struct ext_key *hdkey, *output = NULL; } return ret; -} #endif /* BUILD_ELEMENTS */ +} +#endif /* WALLY_ABI_NO_ELEMENTS */ int bip32_key_from_parent_path_str_n(const struct ext_key *hdkey, const char *str, size_t str_len, @@ -1137,9 +1145,15 @@ GET_B(chain_code) GET_B(parent160) GET_B(hash160) GET_B(pub_key) -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS +#ifndef BUILD_ELEMENTS +int bip32_key_get_pub_key_tweak_sum(const struct ext_key *hdkey, unsigned char *bytes_out, size_t len) { + return WALLY_ERROR; +} +#else GET_B(pub_key_tweak_sum) #endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ int bip32_key_get_priv_key(const struct ext_key *hdkey, unsigned char *bytes_out, size_t len) { return getb_impl(hdkey, hdkey->priv_key + 1, sizeof(hdkey->priv_key) - 1, bytes_out, len); diff --git a/src/bip32_int.h b/src/bip32_int.h index 7e8178dd7..bdb025df1 100644 --- a/src/bip32_int.h +++ b/src/bip32_int.h @@ -32,14 +32,14 @@ WALLY_CORE_API int bip32_key_get_hash160(const struct ext_key *hdkey, unsigned c */ WALLY_CORE_API int bip32_key_get_pub_key(const struct ext_key *hdkey, unsigned char *bytes_out, size_t len); -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS /** * FIXED_SIZED_OUTPUT(len, bytes_out, WALLY_BIP32_TWEAK_SUM_LEN) */ WALLY_CORE_API int bip32_key_get_pub_key_tweak_sum(const struct ext_key *hdkey, unsigned char *bytes_out, size_t len); -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ WALLY_CORE_API int bip32_key_get_depth(const struct ext_key *hdkey, size_t *written); WALLY_CORE_API int bip32_key_get_child_num(const struct ext_key *hdkey, size_t *written); diff --git a/src/blech32.c b/src/blech32.c index a472d9e1c..6baae2a52 100644 --- a/src/blech32.c +++ b/src/blech32.c @@ -27,7 +27,6 @@ #include "script.h" #ifdef BUILD_ELEMENTS - #define CHECKSUM_BLECH32 0x1 #define CHECKSUM_BLECH32M 0x455972a3350f7a1ull @@ -208,13 +207,18 @@ static int blech32_addr_decode(uint8_t *witver, uint8_t *witdata, size_t *witdat wally_clear_2(data, sizeof(data), hrp_actual, sizeof(hrp_actual)); return 0; } +#endif /* BUILD_ELEMENTS */ +#ifndef WALLY_ABI_NO_ELEMENTS int wally_confidential_addr_to_addr_segwit( const char *address, const char *confidential_addr_family, const char *addr_family, char **output) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char buf[WALLY_BLECH32_MAXLEN]; unsigned char *hash_bytes_p = &buf[EC_PUBLIC_KEY_LEN - 2]; size_t written = 0; @@ -241,6 +245,7 @@ int wally_confidential_addr_to_addr_segwit( wally_clear(buf, sizeof(buf)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_confidential_addr_segwit_to_ec_public_key( @@ -249,6 +254,9 @@ int wally_confidential_addr_segwit_to_ec_public_key( unsigned char *bytes_out, size_t len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char buf[WALLY_BLECH32_MAXLEN]; size_t written = 0; int ret = WALLY_OK; @@ -266,6 +274,7 @@ int wally_confidential_addr_segwit_to_ec_public_key( wally_clear(buf, sizeof(buf)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_confidential_addr_from_addr_segwit( @@ -276,6 +285,9 @@ int wally_confidential_addr_from_addr_segwit( size_t pub_key_len, char **output) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else char result[WALLY_BLECH32_MAXLEN + 1]; unsigned char buf[EC_PUBLIC_KEY_LEN + SHA256_LEN]; unsigned char *hash_bytes_p = &buf[EC_PUBLIC_KEY_LEN - 2]; @@ -320,6 +332,6 @@ int wally_confidential_addr_from_addr_segwit( wally_clear(buf, sizeof(buf)); wally_clear(result, sizeof(result)); return ret; -} - #endif /* BUILD_ELEMENTS */ +} +#endif /* WALLY_ABI_NO_ELEMENTS */ diff --git a/src/elements.c b/src/elements.c index 1d2371e70..9edb58ca8 100644 --- a/src/elements.c +++ b/src/elements.c @@ -36,11 +36,16 @@ static int parse_commitment(const secp256k1_context *ctx, return WALLY_EINVAL; return WALLY_OK; } +#endif /* BUILD_ELEMENTS */ +#ifndef WALLY_ABI_NO_ELEMENTS int wally_ecdh_nonce_hash(const unsigned char *pub_key, size_t pub_key_len, const unsigned char *priv_key, size_t priv_key_len, unsigned char *bytes_out, size_t len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char nonce[SHA256_LEN]; int ret; @@ -50,12 +55,16 @@ int wally_ecdh_nonce_hash(const unsigned char *pub_key, size_t pub_key_len, ret = wally_sha256(nonce, sizeof(nonce), bytes_out, len); wally_clear(nonce, sizeof(nonce)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_asset_generator_from_bytes(const unsigned char *asset, size_t asset_len, const unsigned char *abf, size_t abf_len, unsigned char *bytes_out, size_t len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const secp256k1_context *ctx = secp_ctx(); secp256k1_generator gen; int secp_ret; @@ -99,6 +108,7 @@ int wally_asset_generator_from_bytes(const unsigned char *asset, size_t asset_le secp256k1_generator_serialize(ctx, bytes_out, &gen); /* Never fails */ wally_clear(&gen, sizeof(gen)); return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } int wally_asset_final_vbf(const uint64_t *values, size_t num_values, size_t num_inputs, @@ -106,6 +116,9 @@ int wally_asset_final_vbf(const uint64_t *values, size_t num_values, size_t num_ const unsigned char *vbf, size_t vbf_len, unsigned char *bytes_out, size_t len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const secp256k1_context *ctx = secp_ctx(); const unsigned char **abf_p = NULL, **vbf_p = NULL; size_t i; @@ -145,6 +158,7 @@ int wally_asset_final_vbf(const uint64_t *values, size_t num_values, size_t num_ clear_and_free(abf_p, num_values * sizeof(unsigned char *)); clear_and_free(vbf_p, num_values * sizeof(unsigned char *)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_asset_scalar_offset(uint64_t value, @@ -152,6 +166,9 @@ int wally_asset_scalar_offset(uint64_t value, const unsigned char *vbf, size_t vbf_len, unsigned char *bytes_out, size_t len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else beint64_t tweak[4] = { 0, 0, 0, cpu_to_be64(value) }; unsigned char tmp[EC_SCALAR_LEN]; int ret; @@ -165,6 +182,7 @@ int wally_asset_scalar_offset(uint64_t value, if (ret == WALLY_OK) ret = wally_ec_scalar_add(tmp, sizeof(tmp), vbf, vbf_len, bytes_out, len); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_asset_value_commitment(uint64_t value, @@ -172,6 +190,9 @@ int wally_asset_value_commitment(uint64_t value, const unsigned char *generator, size_t generator_len, unsigned char *bytes_out, size_t len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const secp256k1_context *ctx = secp_ctx(); secp256k1_generator gen; secp256k1_pedersen_commitment commit; @@ -189,10 +210,14 @@ int wally_asset_value_commitment(uint64_t value, wally_clear_2(&gen, sizeof(gen), &commit, sizeof(commit)); return ok ? WALLY_OK : WALLY_EINVAL; +#endif /* BUILD_ELEMENTS */ } int wally_asset_rangeproof_get_maximum_len(uint64_t value, int min_bits, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const secp256k1_context *ctx = secp_ctx(); if (!written) return WALLY_EINVAL; @@ -201,6 +226,7 @@ int wally_asset_rangeproof_get_maximum_len(uint64_t value, int min_bits, size_t return WALLY_ENOMEM; *written = secp256k1_rangeproof_max_size(ctx, value, min_bits); return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } int wally_asset_rangeproof_with_nonce(uint64_t value, @@ -215,6 +241,9 @@ int wally_asset_rangeproof_with_nonce(uint64_t value, unsigned char *bytes_out, size_t len, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const secp256k1_context *ctx = secp_ctx(); secp256k1_generator gen; secp256k1_pedersen_commitment commit; @@ -271,6 +300,7 @@ int wally_asset_rangeproof_with_nonce(uint64_t value, wally_clear_3(&gen, sizeof(gen), &commit, sizeof(commit), message, sizeof(message)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_asset_rangeproof(uint64_t value, @@ -286,6 +316,9 @@ int wally_asset_rangeproof(uint64_t value, unsigned char *bytes_out, size_t len, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char nonce_hash[SHA256_LEN]; int ret; @@ -305,6 +338,7 @@ int wally_asset_rangeproof(uint64_t value, wally_clear(nonce_hash, sizeof(nonce_hash)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_explicit_rangeproof(uint64_t value, @@ -314,10 +348,14 @@ int wally_explicit_rangeproof(uint64_t value, const unsigned char *generator, size_t generator_len, unsigned char *bytes_out, size_t len, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else return wally_asset_rangeproof_with_nonce(value, nonce, nonce_len, NULL, 0, NULL, 0, vbf, vbf_len, commitment, commitment_len, NULL, 0, generator, generator_len, value, -1, 0, bytes_out, len, written); +#endif /* BUILD_ELEMENTS */ } int wally_explicit_rangeproof_verify(const unsigned char *rangeproof, size_t rangeproof_len, @@ -325,6 +363,9 @@ int wally_explicit_rangeproof_verify(const unsigned char *rangeproof, size_t ran const unsigned char *commitment, size_t commitment_len, const unsigned char *generator, size_t generator_len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const secp256k1_context *ctx = secp_ctx(); secp256k1_pedersen_commitment commit; secp256k1_generator gen; @@ -339,6 +380,7 @@ int wally_explicit_rangeproof_verify(const unsigned char *rangeproof, size_t ran rangeproof, rangeproof_len, NULL, 0, &gen)) return WALLY_EINVAL; return value == min_v ? WALLY_OK : WALLY_EINVAL; +#endif /* BUILD_ELEMENTS */ } int wally_asset_unblind_with_nonce(const unsigned char *nonce_hash, size_t nonce_hash_len, @@ -351,6 +393,9 @@ int wally_asset_unblind_with_nonce(const unsigned char *nonce_hash, size_t nonce unsigned char *vbf_out, size_t vbf_out_len, uint64_t *value_out) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const secp256k1_context *ctx = secp_ctx(); secp256k1_generator gen; secp256k1_pedersen_commitment commit; @@ -392,6 +437,7 @@ int wally_asset_unblind_with_nonce(const unsigned char *nonce_hash, size_t nonce wally_clear_3(&gen, sizeof(gen), &commit, sizeof(commit), message, sizeof(message)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_asset_unblind(const unsigned char *pub_key, size_t pub_key_len, @@ -405,6 +451,9 @@ int wally_asset_unblind(const unsigned char *pub_key, size_t pub_key_len, unsigned char *vbf_out, size_t vbf_out_len, uint64_t *value_out) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char nonce_hash[SHA256_LEN]; int ret; @@ -423,10 +472,14 @@ int wally_asset_unblind(const unsigned char *pub_key, size_t pub_key_len, wally_clear(nonce_hash, sizeof(nonce_hash)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_asset_surjectionproof_size(size_t num_inputs, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else size_t num_used = num_inputs > 3 ? 3 : num_inputs; if (written) *written = 0; @@ -434,8 +487,10 @@ int wally_asset_surjectionproof_size(size_t num_inputs, size_t *written) return WALLY_EINVAL; *written = SECP256K1_SURJECTIONPROOF_SERIALIZATION_BYTES(num_inputs, num_used); return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } +#ifdef BUILD_ELEMENTS static int surjproof_impl(const unsigned char *output_asset, size_t output_asset_len, const unsigned char *output_abf, size_t output_abf_len, const unsigned char *output_generator, size_t output_generator_len, @@ -522,6 +577,7 @@ static int surjproof_impl(const unsigned char *output_asset, size_t output_asset clear_and_free(generators, num_inputs * sizeof(secp256k1_generator)); return ret; } +#endif /* BUILD_ELEMENTS */ int wally_asset_surjectionproof_len(const unsigned char *output_asset, size_t output_asset_len, const unsigned char *output_abf, size_t output_abf_len, @@ -532,11 +588,15 @@ int wally_asset_surjectionproof_len(const unsigned char *output_asset, size_t ou const unsigned char *generator, size_t generator_len, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char buff[1]; return surjproof_impl(output_asset, output_asset_len, output_abf, output_abf_len, output_generator, output_generator_len, bytes, bytes_len, asset, asset_len, abf, abf_len, generator, generator_len, buff, sizeof(buff), written, 100); +#endif /* BUILD_ELEMENTS */ } int wally_asset_surjectionproof(const unsigned char *output_asset, size_t output_asset_len, @@ -549,10 +609,14 @@ int wally_asset_surjectionproof(const unsigned char *output_asset, size_t output unsigned char *bytes_out, size_t len, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else return surjproof_impl(output_asset, output_asset_len, output_abf, output_abf_len, output_generator, output_generator_len, bytes, bytes_len, asset, asset_len, abf, abf_len, generator, generator_len, bytes_out, len, written, 100); +#endif /* BUILD_ELEMENTS */ } int wally_explicit_surjectionproof(const unsigned char *output_asset, size_t output_asset_len, @@ -560,6 +624,9 @@ int wally_explicit_surjectionproof(const unsigned char *output_asset, size_t out const unsigned char *output_generator, size_t output_generator_len, unsigned char *bytes_out, size_t len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const secp256k1_context *ctx = secp_ctx(); const unsigned char dummy_entropy[32] = { 0 }; unsigned char asset_generator[ASSET_GENERATOR_LEN]; @@ -586,6 +653,7 @@ int wally_explicit_surjectionproof(const unsigned char *output_asset, size_t out wally_clear(asset_generator, sizeof(asset_generator)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_explicit_surjectionproof_verify( @@ -593,6 +661,9 @@ int wally_explicit_surjectionproof_verify( const unsigned char *output_asset, size_t output_asset_len, const unsigned char *output_generator, size_t output_generator_len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const secp256k1_context *ctx = secp_ctx(); secp256k1_surjectionproof sjp; secp256k1_generator asset_gen, blinded_asset_gen; @@ -611,6 +682,7 @@ int wally_explicit_surjectionproof_verify( wally_clear_3(&sjp, sizeof(sjp), &asset_gen, sizeof(asset_gen), &blinded_asset_gen, sizeof(blinded_asset_gen)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_confidential_addr_to_addr( @@ -618,6 +690,9 @@ int wally_confidential_addr_to_addr( uint32_t prefix, char **output) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char buf[2 + EC_PUBLIC_KEY_LEN + HASH160_LEN + BASE58_CHECKSUM_LEN]; unsigned char *addr_bytes_p = &buf[EC_PUBLIC_KEY_LEN + 1]; size_t written; @@ -643,6 +718,7 @@ int wally_confidential_addr_to_addr( wally_clear(buf, sizeof(buf)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_confidential_addr_to_ec_public_key( @@ -651,6 +727,9 @@ int wally_confidential_addr_to_ec_public_key( unsigned char *bytes_out, size_t len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char buf[2 + EC_PUBLIC_KEY_LEN + HASH160_LEN + BASE58_CHECKSUM_LEN]; size_t written; int ret; @@ -670,6 +749,7 @@ int wally_confidential_addr_to_ec_public_key( wally_clear(buf, sizeof(buf)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_confidential_addr_from_addr( @@ -679,6 +759,9 @@ int wally_confidential_addr_from_addr( size_t pub_key_len, char **output) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char buf[2 + EC_PUBLIC_KEY_LEN + HASH160_LEN + BASE58_CHECKSUM_LEN]; unsigned char *addr_bytes_p = &buf[EC_PUBLIC_KEY_LEN + 1]; size_t written; @@ -708,6 +791,7 @@ int wally_confidential_addr_from_addr( wally_clear(buf, sizeof(buf)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_asset_blinding_key_from_seed( @@ -716,6 +800,9 @@ int wally_asset_blinding_key_from_seed( unsigned char *bytes_out, size_t len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char root[HMAC_SHA512_LEN]; int ret; @@ -727,8 +814,10 @@ int wally_asset_blinding_key_from_seed( } return ret; +#endif /* BUILD_ELEMENTS */ } +#ifdef BUILD_ELEMENTS static int asset_blinding_key_hash( const unsigned char *bytes, size_t bytes_len, const unsigned char *data, size_t data_len, @@ -744,12 +833,16 @@ static int asset_blinding_key_hash( return WALLY_EINVAL; return wally_hmac_sha256(bytes, bytes_len, data, data_len, bytes_out, len); } +#endif /* BUILD_ELEMENTS */ int wally_asset_blinding_key_to_ec_private_key( const unsigned char *bytes, size_t bytes_len, const unsigned char *script, size_t script_len, unsigned char *bytes_out, size_t len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else int ret = asset_blinding_key_hash(bytes, bytes_len, script, script_len, bytes_out, len); if (ret == WALLY_OK) { ret = wally_ec_private_key_verify(bytes_out, len); @@ -757,16 +850,20 @@ int wally_asset_blinding_key_to_ec_private_key( wally_clear(bytes_out, len); } return ret; +#endif /* BUILD_ELEMENTS */ } #define BK_ABF 0x1 #define BK_VBF 0x2 -int bk_to_abf_vbf_impl( +static int bk_to_abf_vbf_impl( const unsigned char *bytes, size_t bytes_len, const unsigned char *hash_prevouts, size_t hash_prevouts_len, uint32_t output_index, unsigned char *bytes_out, size_t len, uint32_t flags) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char buff[SHA256_LEN]; unsigned char msg[7] = { 0x00, 'B', 'F', 0x00, 0x00, 0x00, 0x00 }; size_t i; @@ -790,6 +887,7 @@ int bk_to_abf_vbf_impl( } wally_clear(buff, sizeof(buff)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_asset_blinding_key_to_abf_vbf( @@ -823,12 +921,16 @@ int wally_asset_blinding_key_to_vbf( int wally_asset_pak_whitelistproof_size(size_t num_keys, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (written) *written = 0; if (!written || num_keys > SECP256K1_WHITELIST_MAX_N_KEYS) return WALLY_EINVAL; *written = 1 + 32 * (1 + num_keys); return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } int wally_asset_pak_whitelistproof( @@ -840,6 +942,9 @@ int wally_asset_pak_whitelistproof( const unsigned char *summed_key, size_t summed_key_len, unsigned char *bytes_out, size_t len, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const secp256k1_context *ctx = secp_ctx(); secp256k1_pubkey online_secp_keys[SECP256K1_WHITELIST_MAX_N_KEYS]; secp256k1_pubkey offline_secp_keys[SECP256K1_WHITELIST_MAX_N_KEYS]; @@ -894,6 +999,7 @@ int wally_asset_pak_whitelistproof( offline_secp_keys, (sizeof(offline_secp_keys)), &pubkey, sizeof(pubkey)); return ret; +#endif /* BUILD_ELEMENTS */ } int wally_asset_pak_whitelistproof_len( @@ -905,6 +1011,9 @@ int wally_asset_pak_whitelistproof_len( const unsigned char *summed_key, size_t summed_key_len, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else unsigned char buff[1]; /* Undersized: we only want the length */ return wally_asset_pak_whitelistproof(online_keys, online_keys_len, offline_keys, offline_keys_len, @@ -913,5 +1022,6 @@ int wally_asset_pak_whitelistproof_len( online_priv_key, online_priv_key_len, summed_key, summed_key_len, buff, sizeof(buff), written); -} #endif /* BUILD_ELEMENTS */ +} +#endif /* WALLY_ABI_NO_ELEMENTS */ diff --git a/src/internal.h b/src/internal.h index 8672d0f01..f99087b31 100644 --- a/src/internal.h +++ b/src/internal.h @@ -3,11 +3,16 @@ #include -#ifdef BUILD_ELEMENTS #ifdef WALLY_ABI_NO_ELEMENTS +#ifdef BUILD_ELEMENTS #error "WALLY_ABI_NO_ELEMENTS cannot be defined if BUILD_ELEMENTS is defined" #endif -#endif +#else +#ifndef BUILD_ELEMENTS +#pragma clang diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ #include "secp256k1/include/secp256k1.h" #include "secp256k1/include/secp256k1_recovery.h" #include "secp256k1/include/secp256k1_extrakeys.h" diff --git a/src/psbt.c b/src/psbt.c index 88ee130f4..fbdfea67a 100644 --- a/src/psbt.c +++ b/src/psbt.c @@ -56,6 +56,16 @@ static int scalar_verify(const unsigned char *key, size_t key_len, { return !val && !val_len ? wally_ec_scalar_verify(key, key_len) : WALLY_EINVAL; } + +static bool utxo_has_explicit_value(const struct wally_tx_output *utxo) +{ + return utxo && utxo->value && utxo->value_len && utxo->value[0] == 1u; +} + +static bool utxo_has_explicit_asset(const struct wally_tx_output *utxo) +{ + return utxo && utxo->asset && utxo->asset_len && utxo->asset[0] == 1u; +} #endif /* BUILD_ELEMENTS */ static int tx_clone_alloc(const struct wally_tx *src, struct wally_tx **dst) { @@ -101,18 +111,6 @@ static bool psbt_can_modify(const struct wally_psbt *psbt, uint32_t flags) return psbt && (psbt->version == PSBT_0 || ((psbt->tx_modifiable_flags & flags) == flags)); } -#ifdef BUILD_ELEMENTS -static bool utxo_has_explicit_value(const struct wally_tx_output *utxo) -{ - return utxo && utxo->value && utxo->value_len && utxo->value[0] == 1u; -} - -static bool utxo_has_explicit_asset(const struct wally_tx_output *utxo) -{ - return utxo && utxo->asset && utxo->asset_len && utxo->asset[0] == 1u; -} -#endif /* BUILD_ELEMENTS */ - static struct wally_psbt_input *psbt_get_input(const struct wally_psbt *psbt, size_t index) { if (!psbt || index >= psbt->num_inputs || @@ -191,6 +189,14 @@ static bool is_taproot_input(const struct wally_psbt *psbt, parent->NAME = new_p; \ return ret; \ } +#ifdef BUILD_ELEMENTS +#define SET_STRUCT_PSET(PARENT, NAME, STRUCT_TYPE, CLONE_FN, FREE_FN) SET_STRUCT(PARENT, NAME, STRUCT_TYPE, CLONE_FN, FREE_FN) +#else +#define SET_STRUCT_PSET(PARENT, NAME, STRUCT_TYPE, CLONE_FN, FREE_FN) \ + int PARENT ## _set_ ## NAME(struct PARENT *parent, const struct STRUCT_TYPE *p) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ /* Set/find in and add a map value member on a parent struct */ #define SET_MAP(PARENT, NAME, ADD_POST) \ @@ -295,7 +301,7 @@ static int map_field_set(struct wally_map *map_in, uint32_t type, return wally_map_replace_integer(map_in, type, val, val_len); } -/* Methods for a binary buffer field from a PSET input/output */ +/* Methods for a binary buffer field from a PSBT input/output */ #define MAP_INNER_FIELD(typ, name, FT, mapname) \ int wally_psbt_ ## typ ## _get_ ## name ## _len(const struct wally_psbt_ ## typ *p, \ size_t * written) { \ @@ -313,6 +319,27 @@ static int map_field_set(struct wally_map *map_in, uint32_t type, return map_field_set(p ? &p->mapname : NULL, FT, value, value_len); \ } +#ifdef BUILD_ELEMENTS +#define MAP_INNER_FIELD_PSET(typ, name, FT) MAP_INNER_FIELD(typ, name, FT, pset_fields) +#else +#define MAP_INNER_FIELD_PSET(typ, name, FT) \ + int wally_psbt_ ## typ ## _get_ ## name ## _len(const struct wally_psbt_ ## typ *p, \ + size_t * written) { \ + return WALLY_ERROR; \ + } \ + int wally_psbt_ ## typ ## _get_ ## name(const struct wally_psbt_ ## typ *p, \ + unsigned char *bytes_out, size_t len, size_t * written) { \ + return WALLY_ERROR; \ + } \ + int wally_psbt_ ## typ ## _clear_ ## name(struct wally_psbt_ ## typ *p) { \ + return WALLY_ERROR; \ + } \ + int wally_psbt_ ## typ ## _set_ ## name(struct wally_psbt_ ## typ *p, \ + const unsigned char *value, size_t value_len) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ + int wally_psbt_input_is_finalized(const struct wally_psbt_input *input, size_t *written) { @@ -326,8 +353,8 @@ int wally_psbt_input_is_finalized(const struct wally_psbt_input *input, return WALLY_OK; } -SET_STRUCT(wally_psbt_input, utxo, wally_tx, - tx_clone_alloc, wally_tx_free) +SET_STRUCT(wally_psbt_input, utxo, wally_tx, tx_clone_alloc, wally_tx_free) + int wally_psbt_input_set_witness_utxo(struct wally_psbt_input *input, const struct wally_tx_output *utxo) { int ret = WALLY_OK; @@ -643,9 +670,14 @@ static int pset_map_output_field_verify(const unsigned char *key, size_t key_len { return key ? WALLY_EINVAL : pset_output_field_verify(key_len, val, val_len); } +#endif /* BUILD_ELEMENTS */ +#ifndef WALLY_ABI_NO_ELEMENTS int wally_psbt_input_set_amount(struct wally_psbt_input *input, uint64_t amount) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!input) return WALLY_EINVAL; if (utxo_has_explicit_value(input->witness_utxo)) @@ -653,9 +685,9 @@ int wally_psbt_input_set_amount(struct wally_psbt_input *input, uint64_t amount) input->amount = amount; input->has_amount = 1u; return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } -#ifdef BUILD_ELEMENTS int wally_psbt_input_generate_explicit_proofs( struct wally_psbt_input *input, uint64_t satoshi, @@ -664,6 +696,9 @@ int wally_psbt_input_generate_explicit_proofs( const unsigned char *vbf, size_t vbf_len, const unsigned char *entropy, size_t entropy_len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else const struct wally_tx_output *utxo = input ? input->witness_utxo : 0; unsigned char proof[ASSET_SURJECTIONPROOF_MAX_LEN]; /* > ASSET_EXPLICIT_RANGEPROOF_MAX_LEN */ size_t proof_len; @@ -708,64 +743,80 @@ int wally_psbt_input_generate_explicit_proofs( } wally_clear(proof, sizeof(proof)); return ret; -} #endif /* BUILD_ELEMENTS */ +} int wally_psbt_input_clear_amount(struct wally_psbt_input *input) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!input) return WALLY_EINVAL; input->amount = 0; input->has_amount = 0; return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } int wally_psbt_input_set_issuance_amount(struct wally_psbt_input *input, uint64_t amount) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!input) return WALLY_EINVAL; input->issuance_amount = amount; return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } int wally_psbt_input_set_inflation_keys(struct wally_psbt_input *input, uint64_t amount) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!input) return WALLY_EINVAL; input->inflation_keys = amount; return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } int wally_psbt_input_set_pegin_amount(struct wally_psbt_input *input, uint64_t amount) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!input) return WALLY_EINVAL; input->pegin_amount = amount; return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } -SET_STRUCT(wally_psbt_input, pegin_tx, wally_tx, tx_clone_alloc, wally_tx_free) -SET_STRUCT(wally_psbt_input, pegin_witness, wally_tx_witness_stack, - wally_tx_witness_stack_clone_alloc, wally_tx_witness_stack_free) - -MAP_INNER_FIELD(input, issuance_amount_commitment, PSET_IN_ISSUANCE_VALUE_COMMITMENT, pset_fields) -MAP_INNER_FIELD(input, issuance_amount_rangeproof, PSET_IN_ISSUANCE_VALUE_RANGEPROOF, pset_fields) -MAP_INNER_FIELD(input, issuance_blinding_nonce, PSET_IN_ISSUANCE_BLINDING_NONCE, pset_fields) -MAP_INNER_FIELD(input, issuance_asset_entropy, PSET_IN_ISSUANCE_ASSET_ENTROPY, pset_fields) -MAP_INNER_FIELD(input, issuance_amount_blinding_rangeproof, PSET_IN_ISSUANCE_BLIND_VALUE_PROOF, pset_fields) -MAP_INNER_FIELD(input, pegin_claim_script, PSET_IN_PEG_IN_CLAIM_SCRIPT, pset_fields) -MAP_INNER_FIELD(input, pegin_genesis_blockhash, PSET_IN_PEG_IN_GENESIS_HASH, pset_fields) -MAP_INNER_FIELD(input, pegin_txout_proof, PSET_IN_PEG_IN_TXOUT_PROOF, pset_fields) -MAP_INNER_FIELD(input, inflation_keys_commitment, PSET_IN_ISSUANCE_INFLATION_KEYS_COMMITMENT, pset_fields) -MAP_INNER_FIELD(input, inflation_keys_rangeproof, PSET_IN_ISSUANCE_INFLATION_KEYS_RANGEPROOF, pset_fields) -MAP_INNER_FIELD(input, inflation_keys_blinding_rangeproof, PSET_IN_ISSUANCE_BLIND_INFLATION_KEYS_PROOF, pset_fields) -MAP_INNER_FIELD(input, amount_rangeproof, PSET_IN_VALUE_PROOF, pset_fields) -MAP_INNER_FIELD(input, asset, PSET_IN_EXPLICIT_ASSET, pset_fields) -MAP_INNER_FIELD(input, asset_surjectionproof, PSET_IN_ASSET_PROOF, pset_fields) -MAP_INNER_FIELD(input, utxo_rangeproof, PSET_IN_UTXO_RANGEPROOF, pset_fields) -#endif /* BUILD_ELEMENTS */ +SET_STRUCT_PSET(wally_psbt_input, pegin_tx, wally_tx, tx_clone_alloc, wally_tx_free) +SET_STRUCT_PSET(wally_psbt_input, pegin_witness, wally_tx_witness_stack, + wally_tx_witness_stack_clone_alloc, wally_tx_witness_stack_free) + +MAP_INNER_FIELD_PSET(input, issuance_amount_commitment, PSET_IN_ISSUANCE_VALUE_COMMITMENT) +MAP_INNER_FIELD_PSET(input, issuance_amount_rangeproof, PSET_IN_ISSUANCE_VALUE_RANGEPROOF) +MAP_INNER_FIELD_PSET(input, issuance_blinding_nonce, PSET_IN_ISSUANCE_BLINDING_NONCE) +MAP_INNER_FIELD_PSET(input, issuance_asset_entropy, PSET_IN_ISSUANCE_ASSET_ENTROPY) +MAP_INNER_FIELD_PSET(input, issuance_amount_blinding_rangeproof, PSET_IN_ISSUANCE_BLIND_VALUE_PROOF) +MAP_INNER_FIELD_PSET(input, pegin_claim_script, PSET_IN_PEG_IN_CLAIM_SCRIPT) +MAP_INNER_FIELD_PSET(input, pegin_genesis_blockhash, PSET_IN_PEG_IN_GENESIS_HASH) +MAP_INNER_FIELD_PSET(input, pegin_txout_proof, PSET_IN_PEG_IN_TXOUT_PROOF) +MAP_INNER_FIELD_PSET(input, inflation_keys_commitment, PSET_IN_ISSUANCE_INFLATION_KEYS_COMMITMENT) +MAP_INNER_FIELD_PSET(input, inflation_keys_rangeproof, PSET_IN_ISSUANCE_INFLATION_KEYS_RANGEPROOF) +MAP_INNER_FIELD_PSET(input, inflation_keys_blinding_rangeproof, PSET_IN_ISSUANCE_BLIND_INFLATION_KEYS_PROOF) +MAP_INNER_FIELD_PSET(input, amount_rangeproof, PSET_IN_VALUE_PROOF) +MAP_INNER_FIELD_PSET(input, asset, PSET_IN_EXPLICIT_ASSET) +MAP_INNER_FIELD_PSET(input, asset_surjectionproof, PSET_IN_ASSET_PROOF) +MAP_INNER_FIELD_PSET(input, utxo_rangeproof, PSET_IN_UTXO_RANGEPROOF) +#endif /* WALLY_ABI_NO_ELEMENTS */ static void psbt_input_init(struct wally_psbt_input *input) { @@ -818,6 +869,14 @@ ADD_KEYPATH(wally_psbt_output) ADD_TAP_KEYPATH(wally_psbt_output) SET_MAP(wally_psbt_output, unknown,) +int wally_psbt_output_set_script(struct wally_psbt_output *output, + const unsigned char *bytes, size_t len) +{ + if (!output) + return WALLY_EINVAL; + return replace_bytes(bytes, len, &output->script, &output->script_len); +} + int wally_psbt_output_set_amount(struct wally_psbt_output *output, uint64_t amount) { if (!output) @@ -836,44 +895,44 @@ int wally_psbt_output_clear_amount(struct wally_psbt_output *output) return WALLY_OK; } -int wally_psbt_output_set_script(struct wally_psbt_output *output, - const unsigned char *bytes, size_t len) -{ - if (!output) - return WALLY_EINVAL; - return replace_bytes(bytes, len, &output->script, &output->script_len); -} - - -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS int wally_psbt_output_set_blinder_index(struct wally_psbt_output *output, uint32_t index) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!output) return WALLY_EINVAL; output->blinder_index = index; output->has_blinder_index = 1u; return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } int wally_psbt_output_clear_blinder_index(struct wally_psbt_output *output) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!output) return WALLY_EINVAL; output->blinder_index = 0; output->has_blinder_index = 0; return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } -MAP_INNER_FIELD(output, value_commitment, PSET_OUT_VALUE_COMMITMENT, pset_fields) -MAP_INNER_FIELD(output, asset, PSET_OUT_ASSET, pset_fields) -MAP_INNER_FIELD(output, asset_commitment, PSET_OUT_ASSET_COMMITMENT, pset_fields) -MAP_INNER_FIELD(output, value_rangeproof, PSET_OUT_VALUE_RANGEPROOF, pset_fields) -MAP_INNER_FIELD(output, asset_surjectionproof, PSET_OUT_ASSET_SURJECTION_PROOF, pset_fields) -MAP_INNER_FIELD(output, blinding_public_key, PSET_OUT_BLINDING_PUBKEY, pset_fields) -MAP_INNER_FIELD(output, ecdh_public_key, PSET_OUT_ECDH_PUBKEY, pset_fields) -MAP_INNER_FIELD(output, value_blinding_rangeproof, PSET_OUT_BLIND_VALUE_PROOF, pset_fields) -MAP_INNER_FIELD(output, asset_blinding_surjectionproof, PSET_OUT_BLIND_ASSET_PROOF, pset_fields) +MAP_INNER_FIELD_PSET(output, value_commitment, PSET_OUT_VALUE_COMMITMENT) +MAP_INNER_FIELD_PSET(output, asset, PSET_OUT_ASSET) +MAP_INNER_FIELD_PSET(output, asset_commitment, PSET_OUT_ASSET_COMMITMENT) +MAP_INNER_FIELD_PSET(output, value_rangeproof, PSET_OUT_VALUE_RANGEPROOF) +MAP_INNER_FIELD_PSET(output, asset_surjectionproof, PSET_OUT_ASSET_SURJECTION_PROOF) +MAP_INNER_FIELD_PSET(output, blinding_public_key, PSET_OUT_BLINDING_PUBKEY) +MAP_INNER_FIELD_PSET(output, ecdh_public_key, PSET_OUT_ECDH_PUBKEY) +MAP_INNER_FIELD_PSET(output, value_blinding_rangeproof, PSET_OUT_BLIND_VALUE_PROOF) +MAP_INNER_FIELD_PSET(output, asset_blinding_surjectionproof, PSET_OUT_BLIND_ASSET_PROOF) +#ifdef BUILD_ELEMENTS static int psbt_output_get_blinding_state(const struct wally_psbt_output *output, uint64_t *written) { const struct wally_map_item *p; @@ -892,10 +951,14 @@ static int psbt_output_get_blinding_state(const struct wally_psbt_output *output } return WALLY_OK; } +#endif /* BUILD_ELEMENTS */ int wally_psbt_output_get_blinding_status(const struct wally_psbt_output *output, uint32_t flags, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else uint64_t state; if (written) @@ -915,8 +978,10 @@ int wally_psbt_output_get_blinding_status(const struct wally_psbt_output *output *written = WALLY_PSET_BLINDED_REQUIRED; } return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } +#ifdef BUILD_ELEMENTS /* Verify that unblinded values, their commitment, and commitment proof * are provided/elided where required, and proofs are valid if provided. */ @@ -1041,6 +1106,7 @@ static bool pset_check_proof(const struct wally_psbt *psbt, return ret == WALLY_OK; } #endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ static void psbt_output_init(struct wally_psbt_output *output) { @@ -1260,6 +1326,15 @@ int wally_psbt_get_global_tx_alloc(const struct wally_psbt *psbt, struct wally_t return WALLY_OK; \ } +#ifdef BUILD_ELEMENTS +#define PSBT_GET_PSET(name, v) PSBT_GET(name, v) +#else +#define PSBT_GET_PSET(name, v) \ + int wally_psbt_get_ ## name(const struct wally_psbt *psbt, size_t *written) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ + PSBT_GET(version, PSBT_0) PSBT_GET(num_inputs, PSBT_0) PSBT_GET(num_outputs, PSBT_0) @@ -1336,62 +1411,86 @@ int wally_psbt_find_input_spending_utxo(const struct wally_psbt *psbt, return WALLY_OK; /* Not found, return 0 */ } -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS int wally_psbt_get_global_scalars_size(const struct wally_psbt *psbt, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (written) *written = 0; if (!psbt_is_valid(psbt) || psbt->version == PSBT_0 || !written) return WALLY_EINVAL; *written = psbt->global_scalars.num_items; return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } int wally_psbt_find_global_scalar(struct wally_psbt *psbt, const unsigned char *scalar, size_t scalar_len, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (written) *written = 0; if (!psbt_is_valid(psbt) || psbt->version == PSBT_0) return WALLY_EINVAL; return wally_map_find(&psbt->global_scalars, scalar, scalar_len, written); +#endif /* BUILD_ELEMENTS */ } int wally_psbt_get_global_scalar(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!psbt_is_valid(psbt) || psbt->version == PSBT_0 || index >= psbt->global_scalars.num_items || !bytes_out || len != WALLY_SCALAR_OFFSET_LEN) return WALLY_EINVAL; memcpy(bytes_out, psbt->global_scalars.items[index].key, len); return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } int wally_psbt_add_global_scalar(struct wally_psbt *psbt, const unsigned char *scalar, size_t scalar_len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!psbt_is_valid(psbt) || psbt->version == PSBT_0) return WALLY_EINVAL; return wally_map_add(&psbt->global_scalars, scalar, scalar_len, NULL, 0); +#endif /* BUILD_ELEMENTS */ } int wally_psbt_set_global_scalars(struct wally_psbt *psbt, const struct wally_map *map_in) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!psbt_is_valid(psbt) || psbt->version == PSBT_0) return WALLY_EINVAL; return wally_map_assign(&psbt->global_scalars, map_in); +#endif /* BUILD_ELEMENTS */ } int wally_psbt_set_pset_modifiable_flags(struct wally_psbt *psbt, uint32_t flags) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!psbt_is_valid(psbt) || psbt->version == PSBT_0 || flags & ~PSET_TXMOD_ALL_FLAGS) return WALLY_EINVAL; psbt->pset_modifiable_flags = flags & ~WALLY_PSET_TXMOD_RESERVED; return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } -PSBT_GET(pset_modifiable_flags, PSBT_2) -#endif /* BUILD_ELEMENTS */ +PSBT_GET_PSET(pset_modifiable_flags, PSBT_2) +#endif /* WALLY_ABI_NO_ELEMENTS */ int wally_psbt_is_finalized(const struct wally_psbt *psbt, size_t *written) @@ -4848,6 +4947,7 @@ static int compute_final_vbf(struct wally_psbt *psbt, } #endif /* BUILD_ELEMENTS */ +#ifndef WALLY_ABI_NO_ELEMENTS int wally_psbt_blind(struct wally_psbt *psbt, const struct wally_map *values, const struct wally_map *vbfs, @@ -5157,6 +5257,7 @@ int wally_psbt_blind_alloc(struct wally_psbt *psbt, } return ret; } +#endif /* WALLY_ABI_NO_ELEMENTS */ int wally_psbt_is_elements(const struct wally_psbt *psbt, size_t *written) { @@ -5244,6 +5345,15 @@ int wally_psbt_is_elements(const struct wally_psbt *psbt, size_t *written) if (!psbt || (v && psbt->version != v)) return WALLY_EINVAL; \ return wally_psbt_ ## typ ## _set_ ## name(psbt_get_ ## typ(psbt, index), name, name ## _len); \ } +#ifdef BUILD_ELEMENTS +#define PSBT_SET_B_PSET(typ, name, v) PSBT_SET_B(typ, name, v) +#else +#define PSBT_SET_B_PSET(typ, name, v) \ + int wally_psbt_set_ ## typ ## _ ## name(struct wally_psbt *psbt, size_t index, \ + const unsigned char *name, size_t name ## _len) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ /* Get an integer value from an input/output */ #define PSBT_GET_I(typ, name, inttyp, v) \ @@ -5256,6 +5366,16 @@ int wally_psbt_is_elements(const struct wally_psbt *psbt, size_t *written) return WALLY_OK; \ } +#ifdef BUILD_ELEMENTS +#define PSBT_GET_I_PSET(typ, name, inttyp, v) PSBT_GET_I(typ, name, inttyp, v) +#else +#define PSBT_GET_I_PSET(typ, name, inttyp, v) \ + int wally_psbt_get_ ## typ ## _ ## name(const struct wally_psbt *psbt, size_t index, \ + inttyp *written) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ + /* Set an integer value on an input/output */ #define PSBT_SET_I(typ, name, inttyp, v) \ int wally_psbt_set_ ## typ ## _ ## name(struct wally_psbt *psbt, size_t index, \ @@ -5264,6 +5384,16 @@ int wally_psbt_is_elements(const struct wally_psbt *psbt, size_t *written) return wally_psbt_ ## typ ## _set_ ## name(psbt_get_ ## typ(psbt, index), val); \ } +#ifdef BUILD_ELEMENTS +#define PSBT_SET_I_PSET(typ, name, inttyp, v) PSBT_SET_I(typ, name, inttyp, v) +#else +#define PSBT_SET_I_PSET(typ, name, inttyp, v) \ + int wally_psbt_set_ ## typ ## _ ## name(struct wally_psbt *psbt, size_t index, \ + inttyp val) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ + /* Get a struct from an input/output */ #define PSBT_GET_S(typ, name, structtyp, clonefn) \ int wally_psbt_get_ ## typ ## _ ## name ## _alloc(const struct wally_psbt *psbt, size_t index, \ @@ -5304,9 +5434,27 @@ int wally_psbt_is_elements(const struct wally_psbt *psbt, size_t *written) } \ PSBT_SET_B(typ, name, ver) +#ifdef BUILD_ELEMENTS +#define PSBT_FIELD_PSET(typ, name, ver) PSBT_FIELD(typ, name, ver) +#else +#define PSBT_FIELD_PSET(typ, name, ver) \ + int wally_psbt_get_ ## typ ## _ ## name ## _len(const struct wally_psbt *psbt, \ + size_t index, size_t *written) { \ + return WALLY_ERROR; \ + } \ + int wally_psbt_get_ ## typ ## _ ## name(const struct wally_psbt *psbt, size_t index, \ + unsigned char *bytes_out, size_t len, size_t *written) { \ + return WALLY_ERROR; \ + } \ + int wally_psbt_clear_ ## typ ## _ ## name(struct wally_psbt *psbt, size_t index) { \ + return WALLY_ERROR; \ + } \ + PSBT_SET_B_PSET(typ, name, ver) +#endif /* BUILD_ELEMENTS */ PSBT_GET_S(input, utxo, wally_tx, tx_clone_alloc) PSBT_GET_S(input, witness_utxo, wally_tx_output, wally_tx_output_clone_alloc) + int wally_psbt_get_input_best_utxo(const struct wally_psbt *psbt, size_t index, const struct wally_tx_output **output) { @@ -5326,6 +5474,7 @@ int wally_psbt_get_input_best_utxo_alloc(const struct wally_psbt *psbt, size_t i ret = *output ? wally_tx_output_clone_alloc(*output, output) : WALLY_OK; return ret; } + PSBT_FIELD(input, redeem_script, PSBT_0) PSBT_FIELD(input, witness_script, PSBT_0) PSBT_FIELD(input, final_scriptsig, PSBT_0) @@ -5335,6 +5484,7 @@ PSBT_GET_M(input, keypath) PSBT_GET_M(input, signature) PSBT_GET_M(input, unknown) PSBT_GET_I(input, sighash, size_t, PSBT_0) + int wally_psbt_get_input_previous_txid(const struct wally_psbt *psbt, size_t index, unsigned char *bytes_out, size_t len) { @@ -5466,36 +5616,37 @@ int wally_psbt_clear_input_required_lockheight(struct wally_psbt *psbt, size_t i return wally_psbt_input_clear_required_lockheight(psbt_get_input(psbt, index)); } -#ifdef BUILD_ELEMENTS -PSBT_GET_I(input, amount, uint64_t, PSBT_2) +#ifndef WALLY_ABI_NO_ELEMENTS +PSBT_GET_I_PSET(input, amount, uint64_t, PSBT_2) int wally_psbt_clear_input_amount(struct wally_psbt *psbt, size_t index) { if (!psbt || psbt->version != PSBT_2) return WALLY_EINVAL; return wally_psbt_input_clear_amount(psbt_get_input(psbt, index)); } -PSBT_GET_I(input, issuance_amount, uint64_t, PSBT_2) -PSBT_GET_I(input, inflation_keys, uint64_t, PSBT_2) -PSBT_GET_I(input, pegin_amount, uint64_t, PSBT_2) - -PSBT_SET_I(input, amount, uint64_t, PSBT_2) -PSBT_SET_I(input, issuance_amount, uint64_t, PSBT_2) -PSBT_SET_I(input, inflation_keys, uint64_t, PSBT_2) -PSBT_SET_I(input, pegin_amount, uint64_t, PSBT_2) - -PSBT_FIELD(input, amount_rangeproof, PSBT_2) -PSBT_FIELD(input, asset, PSBT_2) -PSBT_FIELD(input, asset_surjectionproof, PSBT_2) -PSBT_FIELD(input, issuance_amount_commitment, PSBT_2) -PSBT_FIELD(input, issuance_amount_rangeproof, PSBT_2) -PSBT_FIELD(input, issuance_blinding_nonce, PSBT_2) -PSBT_FIELD(input, issuance_asset_entropy, PSBT_2) -PSBT_FIELD(input, issuance_amount_blinding_rangeproof, PSBT_2) -PSBT_FIELD(input, pegin_claim_script, PSBT_2) -PSBT_FIELD(input, pegin_genesis_blockhash, PSBT_2) -PSBT_FIELD(input, pegin_txout_proof, PSBT_2) -PSBT_FIELD(input, inflation_keys_commitment, PSBT_2) -PSBT_FIELD(input, inflation_keys_rangeproof, PSBT_2) -PSBT_FIELD(input, inflation_keys_blinding_rangeproof, PSBT_2) -PSBT_FIELD(input, utxo_rangeproof, PSBT_2) +PSBT_GET_I_PSET(input, issuance_amount, uint64_t, PSBT_2) +PSBT_GET_I_PSET(input, inflation_keys, uint64_t, PSBT_2) +PSBT_GET_I_PSET(input, pegin_amount, uint64_t, PSBT_2) + +PSBT_SET_I_PSET(input, amount, uint64_t, PSBT_2) +PSBT_SET_I_PSET(input, issuance_amount, uint64_t, PSBT_2) +PSBT_SET_I_PSET(input, inflation_keys, uint64_t, PSBT_2) +PSBT_SET_I_PSET(input, pegin_amount, uint64_t, PSBT_2) + +PSBT_FIELD_PSET(input, amount_rangeproof, PSBT_2) +PSBT_FIELD_PSET(input, asset, PSBT_2) +PSBT_FIELD_PSET(input, asset_surjectionproof, PSBT_2) +PSBT_FIELD_PSET(input, issuance_amount_commitment, PSBT_2) +PSBT_FIELD_PSET(input, issuance_amount_rangeproof, PSBT_2) +PSBT_FIELD_PSET(input, issuance_blinding_nonce, PSBT_2) +PSBT_FIELD_PSET(input, issuance_asset_entropy, PSBT_2) +PSBT_FIELD_PSET(input, issuance_amount_blinding_rangeproof, PSBT_2) +PSBT_FIELD_PSET(input, pegin_claim_script, PSBT_2) +PSBT_FIELD_PSET(input, pegin_genesis_blockhash, PSBT_2) +PSBT_FIELD_PSET(input, pegin_txout_proof, PSBT_2) +PSBT_FIELD_PSET(input, inflation_keys_commitment, PSBT_2) +PSBT_FIELD_PSET(input, inflation_keys_rangeproof, PSBT_2) +PSBT_FIELD_PSET(input, inflation_keys_blinding_rangeproof, PSBT_2) +PSBT_FIELD_PSET(input, utxo_rangeproof, PSBT_2) + int wally_psbt_generate_input_explicit_proofs( struct wally_psbt *psbt, size_t index, uint64_t satoshi, @@ -5504,14 +5655,18 @@ int wally_psbt_generate_input_explicit_proofs( const unsigned char *vbf, size_t vbf_len, const unsigned char *entropy, size_t entropy_len) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!psbt || psbt->version != PSBT_2) return WALLY_EINVAL; return wally_psbt_input_generate_explicit_proofs(psbt_get_input(psbt, index), satoshi, asset, asset_len, abf, abf_len, vbf, vbf_len, entropy, entropy_len); +#endif } -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ PSBT_FIELD(output, redeem_script, PSBT_0) PSBT_FIELD(output, witness_script, PSBT_0) @@ -5561,38 +5716,52 @@ int wally_psbt_clear_output_amount(struct wally_psbt *psbt, size_t index) { } PSBT_SET_B(output, script, PSBT_2) +#ifndef WALLY_ABI_NO_ELEMENTS +PSBT_GET_I_PSET(output, blinder_index, uint32_t, PSBT_2) -#ifdef BUILD_ELEMENTS -PSBT_GET_I(output, blinder_index, uint32_t, PSBT_2) int wally_psbt_has_output_blinder_index(const struct wally_psbt *psbt, size_t index, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else struct wally_psbt_output *p = psbt_get_output(psbt, index); if (written) *written = 0; if (!p || !written || psbt->version != PSBT_2) return WALLY_EINVAL; *written = p->has_blinder_index ? 1 : 0; return WALLY_OK; +#endif /* BUILD_ELEMENTS */ } -PSBT_SET_I(output, blinder_index, uint32_t, PSBT_2) +PSBT_SET_I_PSET(output, blinder_index, uint32_t, PSBT_2) + int wally_psbt_clear_output_blinder_index(struct wally_psbt *psbt, size_t index) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else if (!psbt || psbt->version != PSBT_2) return WALLY_EINVAL; return wally_psbt_output_clear_blinder_index(psbt_get_output(psbt, index)); +#endif /* BUILD_ELEMENTS */ } -PSBT_FIELD(output, value_commitment, PSBT_2) -PSBT_FIELD(output, asset, PSBT_2) -PSBT_FIELD(output, asset_commitment, PSBT_2) -PSBT_FIELD(output, value_rangeproof, PSBT_2) -PSBT_FIELD(output, asset_surjectionproof, PSBT_2) -PSBT_FIELD(output, blinding_public_key, PSBT_2) -PSBT_FIELD(output, ecdh_public_key, PSBT_2) -PSBT_FIELD(output, value_blinding_rangeproof, PSBT_2) -PSBT_FIELD(output, asset_blinding_surjectionproof, PSBT_2) +PSBT_FIELD_PSET(output, value_commitment, PSBT_2) +PSBT_FIELD_PSET(output, asset, PSBT_2) +PSBT_FIELD_PSET(output, asset_commitment, PSBT_2) +PSBT_FIELD_PSET(output, value_rangeproof, PSBT_2) +PSBT_FIELD_PSET(output, asset_surjectionproof, PSBT_2) +PSBT_FIELD_PSET(output, blinding_public_key, PSBT_2) +PSBT_FIELD_PSET(output, ecdh_public_key, PSBT_2) +PSBT_FIELD_PSET(output, value_blinding_rangeproof, PSBT_2) +PSBT_FIELD_PSET(output, asset_blinding_surjectionproof, PSBT_2) + int wally_psbt_get_output_blinding_status(const struct wally_psbt *psbt, size_t index, uint32_t flags, size_t *written) { +#ifndef BUILD_ELEMENTS + return WALLY_ERROR; +#else struct wally_psbt_output *p = psbt_get_output(psbt, index); if (written) *written = WALLY_PSET_BLINDED_NONE; if (!p || !written || psbt->version != PSBT_2) return WALLY_EINVAL; return wally_psbt_output_get_blinding_status(p, flags, written); +#endif /* BUILD_ELEMENTS */ } #undef MAX_INVALID_SATOSHI -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ diff --git a/src/transaction.c b/src/transaction.c index 41b901aad..fc65250a4 100644 --- a/src/transaction.c +++ b/src/transaction.c @@ -3487,12 +3487,6 @@ static struct wally_tx_input *tx_get_input(const struct wally_tx *tx, size_t ind return is_valid_tx(tx) && index < tx->num_inputs ? &tx->inputs[index] : NULL; } -#define TX_SET_B(typ, name) \ - int wally_tx_set_ ## typ ## _ ## name(const struct wally_tx *tx, size_t index, \ - const unsigned char *name, size_t name ## _len) { \ - return wally_tx_ ## typ ## _set_ ## name(tx_get_ ## typ(tx, index), name, name ## _len); \ - } - /* Getters for wally_tx_input/wally_tx_output/wally_tx values */ static int tx_getb_impl(const void *input, @@ -3518,14 +3512,6 @@ static int tx_getb_impl(const void *input, return tx_getb_impl(input, input->name, siz, bytes_out, len, &written); \ } - -GET_TX_B_FIXED(tx_input, txhash, WALLY_TXHASH_LEN, WALLY_TXHASH_LEN) -#ifdef BUILD_ELEMENTS -GET_TX_B_FIXED(tx_input, blinding_nonce, SHA256_LEN, SHA256_LEN) -GET_TX_B_FIXED(tx_input, entropy, SHA256_LEN, SHA256_LEN) -#endif /* BUILD_ELEMENTS */ - - #define GET_TX_B(typ, name, siz) \ int wally_ ## typ ## _get_ ## name(const struct wally_ ## typ *input, \ unsigned char *bytes_out, size_t len, size_t * written) { \ @@ -3534,6 +3520,22 @@ GET_TX_B_FIXED(tx_input, entropy, SHA256_LEN, SHA256_LEN) return tx_getb_impl(input, input->name, siz, bytes_out, len, written); \ } +#define TX_SET_B(typ, name) \ + int wally_tx_set_ ## typ ## _ ## name(const struct wally_tx *tx, size_t index, \ + const unsigned char *name, size_t name ## _len) { \ + return wally_tx_ ## typ ## _set_ ## name(tx_get_ ## typ(tx, index), name, name ## _len); \ + } +#ifdef BUILD_ELEMENTS +#define TX_SET_B_ELEMENTS(typ, name) TX_SET_B(typ, name) +#else +#define TX_SET_B_ELEMENTS(typ, name) \ + int wally_tx_set_ ## typ ## _ ## name(const struct wally_tx *tx, size_t index, \ + const unsigned char *name, size_t name ## _len) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ + + #define GET_TX_I(typ, name, outtyp) \ int wally_ ## typ ## _get_ ## name(const struct wally_ ## typ *input, outtyp * written) { \ if (written) *written = 0; \ @@ -3542,8 +3544,9 @@ GET_TX_B_FIXED(tx_input, entropy, SHA256_LEN, SHA256_LEN) return WALLY_OK; \ } - +GET_TX_B_FIXED(tx_input, txhash, WALLY_TXHASH_LEN, WALLY_TXHASH_LEN) GET_TX_B(tx_input, script, input->script_len) + static const struct wally_tx_witness_item *get_witness_preamble( const struct wally_tx_input *input, size_t index, size_t *written) { @@ -3582,7 +3585,10 @@ int wally_tx_input_get_witness_len(const struct wally_tx_input *input, *written = item->witness_len; return WALLY_OK; } -#ifdef BUILD_ELEMENTS + +#ifndef WALLY_ABI_NO_ELEMENTS +GET_TX_B_FIXED(tx_input, blinding_nonce, SHA256_LEN, SHA256_LEN) +GET_TX_B_FIXED(tx_input, entropy, SHA256_LEN, SHA256_LEN) GET_TX_B(tx_input, issuance_amount, input->issuance_amount_len) GET_TX_I(tx_input, issuance_amount_len, size_t) GET_TX_B(tx_input, inflation_keys, input->inflation_keys_len) @@ -3591,13 +3597,13 @@ GET_TX_B(tx_input, issuance_amount_rangeproof, input->issuance_amount_rangeproof GET_TX_I(tx_input, issuance_amount_rangeproof_len, size_t) GET_TX_B(tx_input, inflation_keys_rangeproof, input->inflation_keys_rangeproof_len) GET_TX_I(tx_input, inflation_keys_rangeproof_len, size_t) -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ GET_TX_B(tx_output, script, input->script_len) GET_TX_I(tx_output, satoshi, uint64_t) GET_TX_I(tx_output, script_len, size_t) -#ifdef BUILD_ELEMENTS +#ifndef WALLY_ABI_NO_ELEMENTS GET_TX_B_FIXED(tx_output, asset, input->asset_len, WALLY_TX_ASSET_CT_ASSET_LEN) GET_TX_I(tx_output, asset_len, size_t) GET_TX_B(tx_output, value, input->value_len) @@ -3608,7 +3614,7 @@ GET_TX_B(tx_output, surjectionproof, input->surjectionproof_len) GET_TX_I(tx_output, surjectionproof_len, size_t) GET_TX_B(tx_output, rangeproof, input->rangeproof_len) GET_TX_I(tx_output, rangeproof_len, size_t) -#endif /* BUILD_ELEMENTS */ +#endif /* WALLY_ABI_NO_ELEMENTS */ GET_TX_I(tx, version, size_t) GET_TX_I(tx, locktime, size_t) @@ -3629,14 +3635,20 @@ static int tx_setb_impl(const unsigned char *bytes, size_t bytes_len, *bytes_out_len = bytes_len; return WALLY_OK; } - -#define SET_TX_B(typ, name, siz) \ +#define SET_TX_B_ELEMENTS(typ, name, siz) \ int wally_ ## typ ## _set_ ## name(struct wally_ ## typ *output, \ const unsigned char *bytes, size_t siz) { \ if (!is_valid_elements_ ## typ(output) || BYTES_INVALID(bytes, siz)) \ return WALLY_EINVAL; \ return tx_setb_impl(bytes, siz, &output->name, &output->name ## _len); \ } +#else +#define SET_TX_B_ELEMENTS(typ, name, siz) \ + int wally_ ## typ ## _set_ ## name(struct wally_ ## typ *output, \ + const unsigned char *bytes, size_t siz) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ #define SET_TX_B_FIXED(typ, name, siz, n) \ int wally_ ## typ ## _set_ ## name(struct wally_ ## typ *output, \ @@ -3645,7 +3657,15 @@ static int tx_setb_impl(const unsigned char *bytes, size_t bytes_len, return WALLY_EINVAL; \ return tx_setb_impl(bytes, siz, &output->name, &output->name ## _len); \ } -#endif /* BUILD_ELEMENTS */ +#ifdef BUILD_ELEMENTS +#define SET_TX_B_FIXED_ELEMENTS(typ, name, siz, n) SET_TX_B_FIXED(typ, name, siz, n) +#else +#define SET_TX_B_FIXED_ELEMENTS(typ, name, siz, n) \ + int wally_ ## typ ## _set_ ## name(struct wally_ ## typ *output, \ + const unsigned char *bytes, size_t siz) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS*/ int wally_tx_input_set_index(struct wally_tx_input *input, uint32_t index) { @@ -3689,7 +3709,7 @@ int wally_tx_output_set_satoshi(struct wally_tx_output *output, uint64_t satoshi } #ifdef BUILD_ELEMENTS -#define SET_TX_ARRAY(typ, name, siz) \ +#define SET_TX_ARRAY_ELEMENTS(typ, name, siz) \ int wally_ ## typ ## _set_ ## name(struct wally_ ## typ *input, \ const unsigned char *name, size_t name ## _len) { \ if (!is_valid_elements_ ## typ(input) || !name || name ## _len != siz) \ @@ -3697,27 +3717,39 @@ int wally_tx_output_set_satoshi(struct wally_tx_output *output, uint64_t satoshi memcpy(input->name, name, siz); \ return WALLY_OK; \ } +#else +#define SET_TX_ARRAY_ELEMENTS(typ, name, siz) \ + int wally_ ## typ ## _set_ ## name(struct wally_ ## typ *input, \ + const unsigned char *name, size_t name ## _len) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ -SET_TX_ARRAY(tx_input, blinding_nonce, SHA256_LEN) -SET_TX_ARRAY(tx_input, entropy, SHA256_LEN) -SET_TX_B(tx_input, inflation_keys, siz) -SET_TX_B(tx_input, inflation_keys_rangeproof, siz) -SET_TX_B(tx_input, issuance_amount, siz) -SET_TX_B(tx_input, issuance_amount_rangeproof, siz) - -SET_TX_B_FIXED(tx_output, asset, siz, WALLY_TX_ASSET_CT_ASSET_LEN) +#ifndef WALLY_ABI_NO_ELEMENTS +SET_TX_ARRAY_ELEMENTS(tx_input, blinding_nonce, SHA256_LEN) +SET_TX_ARRAY_ELEMENTS(tx_input, entropy, SHA256_LEN) +SET_TX_B_ELEMENTS(tx_input, inflation_keys, siz) +SET_TX_B_ELEMENTS(tx_input, inflation_keys_rangeproof, siz) +SET_TX_B_ELEMENTS(tx_input, issuance_amount, siz) +SET_TX_B_ELEMENTS(tx_input, issuance_amount_rangeproof, siz) + +SET_TX_B_FIXED_ELEMENTS(tx_output, asset, siz, WALLY_TX_ASSET_CT_ASSET_LEN) int wally_tx_output_set_value(struct wally_tx_output *output, const unsigned char *value, size_t value_len) { +#ifdef BUILD_ELEMENTS if (!is_valid_elements_tx_output(output) || ((value != NULL) != (value_len == WALLY_TX_ASSET_CT_VALUE_LEN || value_len == WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN))) return WALLY_EINVAL; return tx_setb_impl(value, value_len, &output->value, &output->value_len); -} -SET_TX_B_FIXED(tx_output, nonce, siz, WALLY_TX_ASSET_CT_NONCE_LEN) -SET_TX_B(tx_output, surjectionproof, siz) -SET_TX_B(tx_output, rangeproof, siz) +#else + return WALLY_ERROR; #endif +} +SET_TX_B_FIXED_ELEMENTS(tx_output, nonce, siz, WALLY_TX_ASSET_CT_NONCE_LEN) +SET_TX_B_ELEMENTS(tx_output, surjectionproof, siz) +SET_TX_B_ELEMENTS(tx_output, rangeproof, siz) +#endif /* WALLY_ABI_NO_ELEMENTS */ static struct wally_tx_output *tx_get_output(const struct wally_tx *tx, size_t index) { @@ -3728,16 +3760,40 @@ static struct wally_tx_output *tx_get_output(const struct wally_tx *tx, size_t i int wally_tx_get_ ## typ ## _ ## name(const struct wally_tx *tx, size_t index, unsigned char *bytes_out, size_t len, size_t *written) { \ return wally_tx_ ## typ ## _get_ ## name(tx_get_ ## typ(tx, index), bytes_out, len, written); \ } +#ifdef BUILD_ELEMENTS +#define TX_GET_B_ELEMENTS(typ, name) TX_GET_B(typ, name) +#else +#define TX_GET_B_ELEMENTS(typ, name) \ + int wally_tx_get_ ## typ ## _ ## name(const struct wally_tx *tx, size_t index, unsigned char *bytes_out, size_t len, size_t *written) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ #define TX_GET_B_FIXED(typ, name) \ int wally_tx_get_ ## typ ## _ ## name(const struct wally_tx *tx, size_t index, unsigned char *bytes_out, size_t len) { \ return wally_tx_ ## typ ## _get_ ## name(tx_get_ ## typ(tx, index), bytes_out, len); \ } +#ifdef BUILD_ELEMENTS +#define TX_GET_B_FIXED_ELEMENTS(typ, name) TX_GET_B_FIXED(typ, name) +#else +#define TX_GET_B_FIXED_ELEMENTS(typ, name) \ + int wally_tx_get_ ## typ ## _ ## name(const struct wally_tx *tx, size_t index, unsigned char *bytes_out, size_t len) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ #define TX_GET_I(typ, name) \ int wally_tx_get_ ## typ ## _ ## name(const struct wally_tx *tx, size_t index, size_t *written) { \ return wally_tx_ ## typ ## _get_ ## name(tx_get_ ## typ(tx, index), written); \ } +#ifdef BUILD_ELEMENTS +#define TX_GET_I_ELEMENTS(typ, name) TX_GET_I(typ, name) +#else +#define TX_GET_I_ELEMENTS(typ, name) \ + int wally_tx_get_ ## typ ## _ ## name(const struct wally_tx *tx, size_t index, size_t *written) { \ + return WALLY_ERROR; \ + } +#endif /* BUILD_ELEMENTS */ TX_GET_B(input, script) TX_GET_I(input, script_len) @@ -3755,18 +3811,19 @@ int wally_tx_get_input_witness_len(const struct wally_tx *tx, size_t index, size return wally_tx_input_get_witness_len(tx_get_input(tx, index), wit_index, written); } -#ifdef BUILD_ELEMENTS -TX_GET_B_FIXED(input, blinding_nonce) -TX_GET_B_FIXED(input, entropy) -TX_GET_B(input, inflation_keys) -TX_GET_B(input, inflation_keys_rangeproof) -TX_GET_B(input, issuance_amount) -TX_GET_B(input, issuance_amount_rangeproof) -TX_GET_I(input, inflation_keys_len) -TX_GET_I(input, inflation_keys_rangeproof_len) -TX_GET_I(input, issuance_amount_len) -TX_GET_I(input, issuance_amount_rangeproof_len) -#endif /* BUILD_ELEMENTS */ +#ifndef WALLY_ABI_NO_ELEMENTS +TX_GET_B_FIXED_ELEMENTS(input, blinding_nonce) +TX_GET_B_FIXED_ELEMENTS(input, entropy) +TX_GET_B_ELEMENTS(input, inflation_keys) +TX_GET_B_ELEMENTS(input, inflation_keys_rangeproof) +TX_GET_B_ELEMENTS(input, issuance_amount) +TX_GET_B_ELEMENTS(input, issuance_amount_rangeproof) +TX_GET_I_ELEMENTS(input, inflation_keys_len) +TX_GET_I_ELEMENTS(input, inflation_keys_rangeproof_len) +TX_GET_I_ELEMENTS(input, issuance_amount_len) +TX_GET_I_ELEMENTS(input, issuance_amount_rangeproof_len) +#endif /* WALLY_ABI_NO_ELEMENTS */ + TX_GET_B(output, script) TX_GET_I(output, script_len) @@ -3775,18 +3832,18 @@ int wally_tx_get_output_satoshi(const struct wally_tx *tx, size_t index, uint64_ return wally_tx_output_get_satoshi(tx_get_output(tx, index), value_out); } -#ifdef BUILD_ELEMENTS -TX_GET_B_FIXED(output, asset) -TX_GET_B(output, value) -TX_GET_B_FIXED(output, nonce) -TX_GET_B(output, surjectionproof) -TX_GET_B(output, rangeproof) -TX_GET_I(output, asset_len) -TX_GET_I(output, value_len) -TX_GET_I(output, nonce_len) -TX_GET_I(output, surjectionproof_len) -TX_GET_I(output, rangeproof_len) -#endif /* BUILD_ELEMENTS */ +#ifndef WALLY_ABI_NO_ELEMENTS +TX_GET_B_FIXED_ELEMENTS(output, asset) +TX_GET_B_ELEMENTS(output, value) +TX_GET_B_FIXED_ELEMENTS(output, nonce) +TX_GET_B_ELEMENTS(output, surjectionproof) +TX_GET_B_ELEMENTS(output, rangeproof) +TX_GET_I_ELEMENTS(output, asset_len) +TX_GET_I_ELEMENTS(output, value_len) +TX_GET_I_ELEMENTS(output, nonce_len) +TX_GET_I_ELEMENTS(output, surjectionproof_len) +TX_GET_I_ELEMENTS(output, rangeproof_len) +#endif /* WALLY_ABI_NO_ELEMENTS */ TX_SET_B(input, txhash) @@ -3815,20 +3872,20 @@ int wally_tx_set_output_satoshi(const struct wally_tx *tx, size_t index, uint64_ return wally_tx_output_set_satoshi(tx_get_output(tx, index), satoshi); } -#ifdef BUILD_ELEMENTS -TX_SET_B(input, blinding_nonce) -TX_SET_B(input, entropy) -TX_SET_B(input, inflation_keys) -TX_SET_B(input, inflation_keys_rangeproof) -TX_SET_B(input, issuance_amount) -TX_SET_B(input, issuance_amount_rangeproof) - -TX_SET_B(output, asset) -TX_SET_B(output, value) -TX_SET_B(output, nonce) -TX_SET_B(output, surjectionproof) -TX_SET_B(output, rangeproof) -#endif +#ifndef WALLY_ABI_NO_ELEMENTS +TX_SET_B_ELEMENTS(input, blinding_nonce) +TX_SET_B_ELEMENTS(input, entropy) +TX_SET_B_ELEMENTS(input, inflation_keys) +TX_SET_B_ELEMENTS(input, inflation_keys_rangeproof) +TX_SET_B_ELEMENTS(input, issuance_amount) +TX_SET_B_ELEMENTS(input, issuance_amount_rangeproof) + +TX_SET_B_ELEMENTS(output, asset) +TX_SET_B_ELEMENTS(output, value) +TX_SET_B_ELEMENTS(output, nonce) +TX_SET_B_ELEMENTS(output, surjectionproof) +TX_SET_B_ELEMENTS(output, rangeproof) +#endif /* WALLY_ABI_NO_ELEMENTS */ int wally_tx_input_set_witness(struct wally_tx_input *input, const struct wally_tx_witness_stack *stack) From 4fb39f12f80ba70931860f34c73d076076927b4b Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 16:44:38 +1200 Subject: [PATCH 13/26] abi: move psbt_blind into the elements abi, update elements generation --- include/wally.hpp | 24 ++++++++++++------------ src/swig_python/python_extra.py_in | 2 +- tools/build_wrappers.py | 4 ++-- tools/wasm_exports.sh | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/wally.hpp b/include/wally.hpp index acd3627c8..94fd16c83 100644 --- a/include/wally.hpp +++ b/include/wally.hpp @@ -1078,18 +1078,6 @@ inline int psbt_add_tx_output_at(const PSBT& psbt, uint32_t index, uint32_t flag return detail::check_ret(__FUNCTION__, ret); } -template -inline int psbt_blind(const PSBT& psbt, const VALUES& values, const VBFS& vbfs, const ASSETS& assets, const ABFS& abfs, const ENTROPY& entropy, uint32_t output_index, uint32_t flags, struct wally_map* output) { - int ret = ::wally_psbt_blind(detail::get_p(psbt), detail::get_p(values), detail::get_p(vbfs), detail::get_p(assets), detail::get_p(abfs), entropy.data(), entropy.size(), output_index, flags, output); - return detail::check_ret(__FUNCTION__, ret); -} - -template -inline int psbt_blind_alloc(const PSBT& psbt, const VALUES& values, const VBFS& vbfs, const ASSETS& assets, const ABFS& abfs, const ENTROPY& entropy, uint32_t output_index, uint32_t flags, struct wally_map** output) { - int ret = ::wally_psbt_blind_alloc(detail::get_p(psbt), detail::get_p(values), detail::get_p(vbfs), detail::get_p(assets), detail::get_p(abfs), entropy.data(), entropy.size(), output_index, flags, output); - return detail::check_ret(__FUNCTION__, ret); -} - inline int psbt_clear_fallback_locktime(struct wally_psbt* psbt) { int ret = ::wally_psbt_clear_fallback_locktime(psbt); return detail::check_ret(__FUNCTION__, ret); @@ -2277,6 +2265,18 @@ inline int psbt_add_global_scalar(const PSBT& psbt, const SCALAR& scalar) { return detail::check_ret(__FUNCTION__, ret); } +template +inline int psbt_blind(const PSBT& psbt, const VALUES& values, const VBFS& vbfs, const ASSETS& assets, const ABFS& abfs, const ENTROPY& entropy, uint32_t output_index, uint32_t flags, struct wally_map* output) { + int ret = ::wally_psbt_blind(detail::get_p(psbt), detail::get_p(values), detail::get_p(vbfs), detail::get_p(assets), detail::get_p(abfs), entropy.data(), entropy.size(), output_index, flags, output); + return detail::check_ret(__FUNCTION__, ret); +} + +template +inline int psbt_blind_alloc(const PSBT& psbt, const VALUES& values, const VBFS& vbfs, const ASSETS& assets, const ABFS& abfs, const ENTROPY& entropy, uint32_t output_index, uint32_t flags, struct wally_map** output) { + int ret = ::wally_psbt_blind_alloc(detail::get_p(psbt), detail::get_p(values), detail::get_p(vbfs), detail::get_p(assets), detail::get_p(abfs), entropy.data(), entropy.size(), output_index, flags, output); + return detail::check_ret(__FUNCTION__, ret); +} + template inline int psbt_find_global_scalar(const PSBT& psbt, const SCALAR& scalar, size_t* written) { int ret = ::wally_psbt_find_global_scalar(detail::get_p(psbt), scalar.data(), scalar.size(), written); diff --git a/src/swig_python/python_extra.py_in b/src/swig_python/python_extra.py_in index 26d2894b6..131bba887 100644 --- a/src/swig_python/python_extra.py_in +++ b/src/swig_python/python_extra.py_in @@ -186,7 +186,6 @@ map_keypath_public_key_init = map_keypath_public_key_init_alloc map_preimage_init = map_preimage_init_alloc pbkdf2_hmac_sha256 = _wrap_bin(pbkdf2_hmac_sha256, PBKDF2_HMAC_SHA256_LEN) pbkdf2_hmac_sha512 = _wrap_bin(pbkdf2_hmac_sha512, PBKDF2_HMAC_SHA512_LEN) -psbt_blind = psbt_blind_alloc psbt_clone = psbt_clone_alloc psbt_get_global_tx = psbt_get_global_tx_alloc psbt_get_id = _wrap_bin(psbt_get_id, WALLY_TXHASH_LEN) @@ -282,6 +281,7 @@ if is_elements_build(): elements_pegout_script_from_bytes = _wrap_bin(elements_pegout_script_from_bytes, elements_pegout_script_from_bytes_len, resize=True) explicit_rangeproof = _wrap_bin(explicit_rangeproof, ASSET_EXPLICIT_RANGEPROOF_MAX_LEN, resize=True) explicit_surjectionproof = _wrap_bin(explicit_surjectionproof, ASSET_EXPLICIT_SURJECTIONPROOF_LEN) + psbt_blind = psbt_blind_alloc psbt_get_global_scalar = _wrap_bin(psbt_get_global_scalar, WALLY_SCALAR_OFFSET_LEN) psbt_get_input_amount_rangeproof = _wrap_bin(psbt_get_input_amount_rangeproof, psbt_get_input_amount_rangeproof_len) psbt_get_input_asset = _wrap_bin(psbt_get_input_asset, psbt_get_input_asset_len) diff --git a/tools/build_wrappers.py b/tools/build_wrappers.py index b5fd60d83..db097e45c 100755 --- a/tools/build_wrappers.py +++ b/tools/build_wrappers.py @@ -52,7 +52,7 @@ def replace_text(filename, text, delims): def get_non_elements_functions(): # SWIG_PYTHON_BUILD=1 used to include internal functions too - cmd = "-E -DSWIG_PYTHON_BUILD=1 include/*.h src/bip32_int.h |" \ + cmd = "-E -DWALLY_ABI_NO_ELEMENTS=1 -DSWIG_PYTHON_BUILD=1 include/*.h src/bip32_int.h |" \ "sort | uniq | sed 's/^ *WALLY_CORE_API//' | grep '^ *int ' | grep '(' | sed -e 's/^ *int //g' -e 's/(.*//g' | egrep '^wally_|^bip'" try: funcs = subprocess.check_output(u'gcc ' + cmd, shell=True) @@ -364,7 +364,7 @@ def gen_wasm_exports(funcs, all_funcs): text = [ f"EXPORTED_FUNCTIONS=\"['_malloc','_free',{exports}\"", - 'if [ -n "$ENABLE_ELEMENTS" ]; then', + 'if [ -z "$DISABLE_ELEMENTS" ]; then', f' EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS"",{elements_exports}"', 'fi', 'EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS""]"' diff --git a/tools/wasm_exports.sh b/tools/wasm_exports.sh index 3191be732..da4ccc587 100644 --- a/tools/wasm_exports.sh +++ b/tools/wasm_exports.sh @@ -178,8 +178,6 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \ ,'_wally_psbt_add_output_taproot_keypath' \ ,'_wally_psbt_add_tx_input_at' \ ,'_wally_psbt_add_tx_output_at' \ -,'_wally_psbt_blind' \ -,'_wally_psbt_blind_alloc' \ ,'_wally_psbt_clear_fallback_locktime' \ ,'_wally_psbt_clear_input_required_lockheight' \ ,'_wally_psbt_clear_input_required_locktime' \ @@ -463,7 +461,7 @@ EXPORTED_FUNCTIONS="['_malloc','_free','_bip32_key_free' \ ,'_wally_witness_program_from_bytes' \ ,'_wally_witness_program_from_bytes_and_version' \ " -if [ -n "$ENABLE_ELEMENTS" ]; then +if [ -z "$DISABLE_ELEMENTS" ]; then EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS"",'_bip32_key_get_pub_key_tweak_sum' \ ,'_bip32_key_with_tweak_from_parent_path' \ ,'_bip32_key_with_tweak_from_parent_path_alloc' \ @@ -503,6 +501,8 @@ if [ -n "$ENABLE_ELEMENTS" ]; then ,'_wally_explicit_surjectionproof' \ ,'_wally_explicit_surjectionproof_verify' \ ,'_wally_psbt_add_global_scalar' \ +,'_wally_psbt_blind' \ +,'_wally_psbt_blind_alloc' \ ,'_wally_psbt_clear_input_amount' \ ,'_wally_psbt_clear_input_amount_rangeproof' \ ,'_wally_psbt_clear_input_asset' \ From 96b1a58a2c20c07a60c0e328269228e23701437e Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Fri, 1 Sep 2023 19:28:45 +1200 Subject: [PATCH 14/26] map: add missing ext_key forward decl --- include/wally_map.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/wally_map.h b/include/wally_map.h index a55d1c69f..61886a4f1 100644 --- a/include/wally_map.h +++ b/include/wally_map.h @@ -5,6 +5,8 @@ extern "C" { #endif +struct ext_key; + #ifdef SWIG struct wally_map; typedef void *wally_map_verify_fn_t; From d78e0ca8ba1f69b64eb3ba8be0d7f691388fb843 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Wed, 30 Aug 2023 18:54:12 -0400 Subject: [PATCH 15/26] configure.ac: fix Bashisms The POSIX Shell 'test' built-in does not define a '==' operator. It works if /bin/sh happens to be Bash, but that is non-standard. --- configure.ac | 72 ++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/configure.ac b/configure.ac index 338cd6d30..2fc86bd2e 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ case $host_os in LDPATH_VAR=DYLD_LIBRARY_PATH ;; esac -AM_CONDITIONAL([IS_OSX], [test "x$is_osx" == "xyes"]) +AM_CONDITIONAL([IS_OSX], [test "x$is_osx" = "xyes"]) AC_SUBST([LDPATH_VAR]) case $host in @@ -25,7 +25,7 @@ case $host in is_mingw="yes" ;; esac -AM_CONDITIONAL([IS_MINGW], [test "x$is_mingw" == "xyes"]) +AM_CONDITIONAL([IS_MINGW], [test "x$is_mingw" = "xyes"]) # Require Automake 1.11.2 for AM_PROG_AR AM_INIT_AUTOMAKE([1.11.2 foreign subdir-objects]) @@ -43,10 +43,10 @@ AC_SUBST([RANLIB]) GNU_SED=sed AC_CHECK_PROG(HAVE_GSED,gsed,yes,no) -if test "x$HAVE_GSED" == "xyes"; then +if test "x$HAVE_GSED" = "xyes"; then GNU_SED=gsed else - if test "x$is_osx" == "xyes"; then + if test "x$is_osx" = "xyes"; then AC_MSG_ERROR([gsed must be available to build this library]) fi fi @@ -88,11 +88,11 @@ AC_ARG_ENABLE(secp256k1-tests, AC_ARG_ENABLE(asm, AS_HELP_STRING([--enable-asm],[enable assembly language implementations (default: yes)]), [asm=$enableval], [asm=yes]) -AM_CONDITIONAL([RUN_TESTS], [test "x$tests" == "xyes"]) -AM_CONDITIONAL([BUILD_ELEMENTS], [test "x$elements" == "xyes"]) -AM_CONDITIONAL([WALLY_ABI_NO_ELEMENTS], [test "x$elements_abi" == "xno"]) -AM_CONDITIONAL([BUILD_STANDARD_SECP], [test "x$standard_secp" == "xyes"]) -AM_CONDITIONAL([BUILD_MINIMAL], [test "x$minimal" == "xyes"]) +AM_CONDITIONAL([RUN_TESTS], [test "x$tests" = "xyes"]) +AM_CONDITIONAL([BUILD_ELEMENTS], [test "x$elements" = "xyes"]) +AM_CONDITIONAL([WALLY_ABI_NO_ELEMENTS], [test "x$elements_abi" = "xno"]) +AM_CONDITIONAL([BUILD_STANDARD_SECP], [test "x$standard_secp" = "xyes"]) +AM_CONDITIONAL([BUILD_MINIMAL], [test "x$minimal" = "xyes"]) AC_C_BIGENDIAN() AC_C_INLINE @@ -105,13 +105,13 @@ AC_TYPE_UINT8_T AM_CFLAGS= AX_CHECK_COMPILE_FLAG([-O0], [NOOPT_CFLAGS="-O0"]) -if test "x$debug" == "xyes"; then +if test "x$debug" = "xyes"; then # Make debugging easier, leave assertions in AM_CFLAGS="$AM_CFLAGS $NOOPT_CFLAGS" AX_CHECK_COMPILE_FLAG([-ggdb], [AM_CFLAGS="$AM_CFLAGS -ggdb"]) AX_CHECK_LINK_FLAG([-O0], [LDFLAGS="$LDFLAGS -O0"]) AX_CHECK_LINK_FLAG([-ggdb], [LDFLAGS="$LDFLAGS -ggdb"]) - if test "x$coverage" == "xyes"; then + if test "x$coverage" = "xyes"; then AX_CHECK_COMPILE_FLAG([-fprofile-arcs -ftest-coverage], [AM_CFLAGS="$AM_CFLAGS -fprofile-arcs -ftest-coverage"]) AX_CHECK_LINK_FLAG([-lgcov], [LDFLAGS="$LDFLAGS -lgcov"]) AX_CHECK_LINK_FLAG([--coverage], [LDFLAGS="$LDFLAGS --coverage"]) @@ -129,27 +129,27 @@ else AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"]) fi -if test "x$elements" == "xyes"; then +if test "x$elements" = "xyes"; then AX_CHECK_COMPILE_FLAG([-DBUILD_ELEMENTS=1], [AM_CFLAGS="$AM_CFLAGS -DBUILD_ELEMENTS=1"]) fi -if test "x$elements_abi" == "xno"; then - if test "x$elements" == "xyes"; then +if test "x$elements_abi" = "xno"; then + if test "x$elements" = "xyes"; then AC_MSG_FAILURE([ERROR: Elements ABI cannot be disabled when elements is enabled]) fi AX_CHECK_COMPILE_FLAG([-DWALLY_ABI_NO_ELEMENTS=1], [AM_CFLAGS="$AM_CFLAGS -DWALLY_ABI_NO_ELEMENTS=1"]) fi -if test "x$standard_secp" == "xyes"; then - if test "x$elements" == "xyes"; then +if test "x$standard_secp" = "xyes"; then + if test "x$elements" = "xyes"; then AC_MSG_FAILURE([ERROR: Elements cannot be enabled with standard libsecp256k1]) fi AX_CHECK_COMPILE_FLAG([-DBUILD_STANDARD_SECP=1], [AM_CFLAGS="$AM_CFLAGS -DBUILD_STANDARD_SECP=1"]) fi -if test "x$minimal" == "xyes"; then +if test "x$minimal" = "xyes"; then AX_CHECK_COMPILE_FLAG([-DBUILD_MINIMAL=1], [AM_CFLAGS="$AM_CFLAGS -DBUILD_MINIMAL=1"]) fi -if test "x$builtin_memset" == "xno"; then +if test "x$builtin_memset" = "xno"; then AX_CHECK_COMPILE_FLAG([-fno-builtin-memset], [AM_CFLAGS="$AM_CFLAGS -fno-builtin"]) fi @@ -200,7 +200,7 @@ AC_SUBST([SWIG_WARN_CFLAGS]) AC_ARG_ENABLE(export-all, AS_HELP_STRING([--enable-export-all],[export all functions (for testing, default: no)]), [export_all=$enableval], [export_all=no]) -AM_CONDITIONAL([EXPORT_ALL], [test "x$export_all" == "xyes"]) +AM_CONDITIONAL([EXPORT_ALL], [test "x$export_all" = "xyes"]) if test "x$export_all" != "xyes"; then AX_CHECK_COMPILE_FLAG([-fvisibility=hidden], [AM_CFLAGS="$AM_CFLAGS -fvisibility=hidden"]) @@ -225,7 +225,7 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]],[[return posix_memalign( AC_CHECK_FUNCS([memset_s explicit_bzero explicit_memset]) -if test "x$asm" == "xyes"; then +if test "x$asm" = "xyes"; then AC_MSG_CHECKING(whether we can use inline asm code) AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[ @@ -240,7 +240,7 @@ if test "x$asm" == "xyes"; then fi AC_CHECK_HEADERS([byteswap.h sys/mman.h]) -if test "x$mbedtls" == "xyes"; then +if test "x$mbedtls" = "xyes"; then AC_CHECK_HEADERS([mbedtls/sha256.h mbedtls/sha512.h]) fi @@ -249,8 +249,8 @@ AC_ARG_ENABLE(clear-tests, [clear_tests=$enableval], [clear_tests=yes]) AX_PTHREAD([ac_have_pthread=yes], [ac_have_pthread=no]) -AM_CONDITIONAL([USE_PTHREAD], [test "x$ac_have_pthread" == "xyes" -a "x$clear_tests" == "xyes"]) -if test "x$ac_have_pthread" == "xyes"; then +AM_CONDITIONAL([USE_PTHREAD], [test "x$ac_have_pthread" = "xyes" -a "x$clear_tests" = "xyes"]) +if test "x$ac_have_pthread" = "xyes"; then AC_DEFINE([HAVE_PTHREAD], 1, [Define if we have pthread support]) AC_CHECK_HEADERS([asm/page.h]) fi @@ -285,7 +285,7 @@ AC_SUBST([LIBADD_SECP256K1]) AC_ARG_ENABLE(python-manylinux, AS_HELP_STRING([--enable-python-manylinux],[enable manylinux Python compatibility (default: no)]), [python_manylinux=$enableval], [python_manylinux=no]) -AM_CONDITIONAL([PYTHON_MANYLINUX], [test "x$python_manylinux" == "xyes"]) +AM_CONDITIONAL([PYTHON_MANYLINUX], [test "x$python_manylinux" = "xyes"]) AX_PYTHON_DEVEL([>= '2.7.0']) AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != ""]) @@ -295,7 +295,7 @@ AC_ARG_ENABLE(wasm-interface, AS_HELP_STRING([--enable-wasm-interface],[enable the WASM interface (default: no)]), [wasm_interface=$enableval], [wasm_interface=no]) -if test "x$wasm_interface" == "xyes"; then +if test "x$wasm_interface" = "xyes"; then AX_CHECK_COMPILE_FLAG([-DWASM_BUILD=1], [AM_CFLAGS="$AM_CFLAGS -DWASM_BUILD=1"]) fi @@ -307,11 +307,11 @@ AC_PROG_SWIG AC_ARG_ENABLE(swig-python, AS_HELP_STRING([--enable-swig-python],[enable the SWIG Python interface (default: no)]), [swig_python=$enableval], [swig_python=no]) -AM_CONDITIONAL([USE_SWIG_PYTHON], [test "x$swig_python" == "xyes"]) +AM_CONDITIONAL([USE_SWIG_PYTHON], [test "x$swig_python" = "xyes"]) -AM_CONDITIONAL([RUN_PYTHON_TESTS], [test "$PYTHON" != "" -a "x$pythonexists" == "xyes"]) +AM_CONDITIONAL([RUN_PYTHON_TESTS], [test "$PYTHON" != "" -a "x$pythonexists" = "xyes"]) -if test "x$swig_python" == "xyes"; then +if test "x$swig_python" = "xyes"; then if test "x$pythonexists" != "xyes"; then AC_MSG_FAILURE([ERROR: No usable Python was found for swig-python]) fi @@ -322,9 +322,9 @@ fi AC_ARG_ENABLE(swig-java, AS_HELP_STRING([--enable-swig-java],[enable the SWIG java (JNI) interface (default: no)]), [swig_java=$enableval], [swig_java=no]) -AM_CONDITIONAL([USE_SWIG_JAVA], [test "x$swig_java" == "xyes"]) +AM_CONDITIONAL([USE_SWIG_JAVA], [test "x$swig_java" = "xyes"]) -if test "x$swig_java" == "xyes"; then +if test "x$swig_java" = "xyes"; then saved_JAVA_HOME=$JAVA_HOME if test x"$cross_compiling" = "xyes"; then # For cross compiling we assume the users host O/S Java install is not @@ -357,7 +357,7 @@ else fi AM_CONDITIONAL([HAVE_JAVA], [test "x$JAVA" != "x"]) AM_CONDITIONAL([HAVE_JAVAC], [test "x$JAVAC" != "x"]) -if test "x$swig_java" == "xyes"; then +if test "x$swig_java" = "xyes"; then if test "x$JAVAC" != "x"; then if test "x$JAVA" != "x"; then # Only run tests if we have java-swig, compiler and interpreter @@ -371,12 +371,12 @@ AC_SUBST([JAVAC_TARGET]) AC_SUBST([AM_CFLAGS]) -if test "x$enable_static" == "xyes"; then +if test "x$enable_static" = "xyes"; then CTEST_EXTRA_STATIC='$(libwallycore_la_LIBADD)' fi AC_SUBST([CTEST_EXTRA_STATIC]) -AM_CONDITIONAL([SHARED_BUILD_ENABLED], [test "x$enable_shared" == "xyes"]) +AM_CONDITIONAL([SHARED_BUILD_ENABLED], [test "x$enable_shared" = "xyes"]) AC_CONFIG_FILES([ Makefile @@ -385,15 +385,15 @@ AC_CONFIG_FILES([ ]) secp_asm="--with-asm=auto" -if test "x$asm" == "xno"; then +if test "x$asm" = "xno"; then secp_asm="--with-asm=no" fi -if test "x$debug" == "xyes"; then +if test "x$debug" = "xyes"; then secp_asm="--with-asm=no" fi secp256k1_test_opt="--disable-tests" -if test "x$secp256k1_tests" == "xyes"; then +if test "x$secp256k1_tests" = "xyes"; then secp256k1_test_opt="--enable-tests" fi From 1edcf315964afd9ca43177bbff5b2853a51ab984 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Tue, 6 Jun 2023 00:05:09 -0400 Subject: [PATCH 16/26] swig_python: add -Wno-unused-parameter to SWIG_WARN_CFLAGS SWIG generates code with unused parameters that trigger hundreds of warnings. --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 2fc86bd2e..34c77ae9e 100644 --- a/configure.ac +++ b/configure.ac @@ -190,6 +190,7 @@ AC_SUBST([NOBUILTIN_CFLAGS]) # SWIG versions vary in generated code quality; skip warnings SWIG_WARN_CFLAGS="-fno-strict-aliasing" +AX_CHECK_COMPILE_FLAG([-Wno-unused-parameter], [SWIG_WARN_CFLAGS="$SWIG_WARN_CFLAGS -Wno-unused-parameter"]) AX_CHECK_COMPILE_FLAG([-Wno-shadow], [SWIG_WARN_CFLAGS="$SWIG_WARN_CFLAGS -Wno-shadow"]) AX_CHECK_COMPILE_FLAG([-Wno-missing-field-initializers], [SWIG_WARN_CFLAGS="$SWIG_WARN_CFLAGS -Wno-missing-field-initializers"]) if echo | "$CC" -dM -E - | grep __clang__ >/dev/null; then From 72b7fe222b5f777bae4c56b10c925d94d7ee37d0 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Thu, 31 Aug 2023 05:20:30 -0400 Subject: [PATCH 17/26] src/Makefile.am: add -version-info to LDFLAGS in shared library builds version-info is what determines the dotted triplet of numbers trailing the shared library filename. Meticulous maintenance of version-info allows multiple ABI versions of the library to be installed on a system concurrently and also makes obvious when library clients need to be recompiled for a newer ABI (and when no recompilation is necessary). See: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html --- src/Makefile.am | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index d9ff95759..b8f62ed75 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -191,10 +191,17 @@ libwallycore_la_INCLUDES = \ include/wally_transaction.h if SHARED_BUILD_ENABLED +LT_VER_CURRENT = 1 # increment at every ABI change (whether breaking or non-breaking) +LT_VER_REVISION = 0 # increment at every release, but reset to 0 at every ABI change +LT_VER_AGE = 0 # increment at every ABI change, but reset to 0 if breaking +# The library filename will be "libwallycore.so.$((current-age)).$((age)).$((revision))", +# and the soname will be "libwallycore.so.$((current-age))". +# Do NOT try to make the library version-info follow the project release version number! +# Only follow the rules above, explained more fully at: +# https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html +libwallycore_la_LDFLAGS = -version-info $(LT_VER_CURRENT):$(LT_VER_REVISION):$(LT_VER_AGE) if IS_MINGW -libwallycore_la_LDFLAGS = -no-undefined -else -libwallycore_la_LDFLAGS = +libwallycore_la_LDFLAGS += -no-undefined endif endif # SHARED_BUILD_ENABLED From 06a4912f3571b289e4141743105ae63600821e6d Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Thu, 31 Aug 2023 21:10:47 -0400 Subject: [PATCH 18/26] configure.ac: drop --enable-openssl-tests from libsecp256k1 config Quoting jgriffiths: > --enable-openssl-tests is no longer supported in secp and should be removed Suggested-by: Jon Griffiths (@jgriffiths) See: https://github.com/ElementsProject/libwally-core/pull/414#discussion_r1312347724 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 34c77ae9e..993dd8d36 100644 --- a/configure.ac +++ b/configure.ac @@ -410,7 +410,7 @@ export ARFLAGS export AR_FLAGS export LD export LDFLAGS -ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-experimental --enable-module-ecdh --enable-module-recovery --enable-module-ecdsa-s2c --enable-module-rangeproof --enable-module-surjectionproof --enable-module-whitelist --enable-module-generator --enable-module-extrakeys --enable-module-schnorrsig ${secp256k1_test_opt} --enable-openssl-tests=no --enable-exhaustive-tests=no --enable-benchmark=no --disable-dependency-tracking ${secp_asm}" +ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-experimental --enable-module-ecdh --enable-module-recovery --enable-module-ecdsa-s2c --enable-module-rangeproof --enable-module-surjectionproof --enable-module-whitelist --enable-module-generator --enable-module-extrakeys --enable-module-schnorrsig ${secp256k1_test_opt} --enable-exhaustive-tests=no --enable-benchmark=no --disable-dependency-tracking ${secp_asm}" AC_CONFIG_SUBDIRS([src/secp256k1]) From 5e6f45da80849a2ce8564d332a02361b2cc6c217 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Fri, 1 Sep 2023 17:38:51 -0400 Subject: [PATCH 19/26] configure.ac: drop --with-bignum=no from libsecp256k1 config libsecp256k1 dropped support for bignum in October 2020. See: https://github.com/bitcoin-core/secp256k1/commit/1f233b3fa05eb29a744487e0682d925055fb0d4c --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 993dd8d36..4a57ce8e1 100644 --- a/configure.ac +++ b/configure.ac @@ -410,7 +410,7 @@ export ARFLAGS export AR_FLAGS export LD export LDFLAGS -ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-experimental --enable-module-ecdh --enable-module-recovery --enable-module-ecdsa-s2c --enable-module-rangeproof --enable-module-surjectionproof --enable-module-whitelist --enable-module-generator --enable-module-extrakeys --enable-module-schnorrsig ${secp256k1_test_opt} --enable-exhaustive-tests=no --enable-benchmark=no --disable-dependency-tracking ${secp_asm}" +ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-experimental --enable-module-ecdh --enable-module-recovery --enable-module-ecdsa-s2c --enable-module-rangeproof --enable-module-surjectionproof --enable-module-whitelist --enable-module-generator --enable-module-extrakeys --enable-module-schnorrsig ${secp256k1_test_opt} --enable-exhaustive-tests=no --enable-benchmark=no --disable-dependency-tracking ${secp_asm}" AC_CONFIG_SUBDIRS([src/secp256k1]) From e994e0ac62db1f3e7a3366b462e47540cdf52a88 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 2 Sep 2023 04:11:04 -0400 Subject: [PATCH 20/26] build: compile all Java classes in one javac invocation Starting up a JVM is not a lightweight affair. For this reason, typically all Java source files are compiled by a single invocation of javac. Use GNU Make's "grouped targets" feature to specify that all Java class files are produced by a single execution of the recipe. Further, avoid compiling the test classes if tests are disabled. --- configure.ac | 12 +++--------- src/Makefile.am | 12 +++++++----- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 4a57ce8e1..8d46dd3a7 100644 --- a/configure.ac +++ b/configure.ac @@ -358,15 +358,9 @@ else fi AM_CONDITIONAL([HAVE_JAVA], [test "x$JAVA" != "x"]) AM_CONDITIONAL([HAVE_JAVAC], [test "x$JAVAC" != "x"]) -if test "x$swig_java" = "xyes"; then - if test "x$JAVAC" != "x"; then - if test "x$JAVA" != "x"; then - # Only run tests if we have java-swig, compiler and interpreter - run_java_tests="yes" - fi - fi -fi -AM_CONDITIONAL([RUN_JAVA_TESTS], [test "x$run_java_tests" != "x"]) +AM_CONDITIONAL([RUN_JAVA_TESTS], + dnl Only run tests if we have java-swig, compiler and interpreter + [test "x$tests" = xyes -a "x$swig_java" = xyes -a -n "$JAVAC" -a -n "$JAVA"]) JAVAC_TARGET=1.7 AC_SUBST([JAVAC_TARGET]) diff --git a/src/Makefile.am b/src/Makefile.am index b8f62ed75..ed5c23b8f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -98,18 +98,15 @@ sjs=swig_java/src $(sjs)/$(cblw)/Wally.java: swig_java/swig_java_wrap.c $(AM_V_at)$(top_srcdir)/tools/swigjavapost.sh @GNU_SED@ $(TOOLS_EXTRA_ARGS) -$(sjs)/$(cblw)/Wally.class: $(sjs)/$(cblw)/Wally.java - $(AM_V_at)$(JAVAC) -implicit:none -source $(JAVAC_TARGET) -target $(JAVAC_TARGET) -sourcepath $(sjs)/$(cblw)/ $(sjs)/$(cblw)/Wally.java +JAVA_CLASSES = $(sjs)/$(cblw)/Wally.class swig_java/wallycore.jar: $(sjs)/$(cblw)/Wally.class $(AM_V_at)$(JAR) cf swig_java/wallycore.jar -C $(sjs) '$(cblw)/Wally$$Obj.class' -C $(sjs) '$(cblw)/Wally.class' -$(sjs)/$(cbt)/%.class: $(sjs)/$(cbt)/%.java swig_java/wallycore.jar - $(AM_V_at)$(JAVAC) -implicit:none -source $(JAVAC_TARGET) -target $(JAVAC_TARGET) -sourcepath $(sjs) $(filter %.java,$^) - if HAVE_JAVAC all: swig_java/wallycore.jar +if RUN_JAVA_TESTS SWIG_JAVA_TEST_DEPS = \ $(sjs)/$(cbt)/test_bip32.class \ $(sjs)/$(cbt)/test_descriptor.class \ @@ -122,7 +119,12 @@ SWIG_JAVA_TEST_DEPS += $(sjs)/$(cbt)/test_assets.class \ $(sjs)/$(cbt)/test_pegs.class endif +JAVA_CLASSES += $(SWIG_JAVA_TEST_DEPS) all: $(SWIG_JAVA_TEST_DEPS) +endif # RUN_JAVA_TESTS + +$(JAVA_CLASSES) &: $(JAVA_CLASSES:.class=.java) + $(AM_V_at)$(JAVAC) -implicit:none -source $(JAVAC_TARGET) -target $(JAVAC_TARGET) -sourcepath $(sjs) $^ JAVA_TEST = @LDPATH_VAR@=.libs $(JAVA) -Djava.library.path=.libs -classpath $(sjs) com.blockstream.test. From be416d41e5a9d3ace6ba4b2629cf1d13a6eee5ab Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Mon, 4 Sep 2023 19:28:02 +1200 Subject: [PATCH 21/26] build: use all-local rule to ensure extra java files are built Fixes a warning about overriding 'all'. --- src/Makefile.am | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index ed5c23b8f..5e32b0968 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -104,8 +104,6 @@ swig_java/wallycore.jar: $(sjs)/$(cblw)/Wally.class $(AM_V_at)$(JAR) cf swig_java/wallycore.jar -C $(sjs) '$(cblw)/Wally$$Obj.class' -C $(sjs) '$(cblw)/Wally.class' if HAVE_JAVAC -all: swig_java/wallycore.jar - if RUN_JAVA_TESTS SWIG_JAVA_TEST_DEPS = \ $(sjs)/$(cbt)/test_bip32.class \ @@ -120,7 +118,9 @@ SWIG_JAVA_TEST_DEPS += $(sjs)/$(cbt)/test_assets.class \ endif JAVA_CLASSES += $(SWIG_JAVA_TEST_DEPS) -all: $(SWIG_JAVA_TEST_DEPS) +all-local: swig_java/wallycore.jar $(SWIG_JAVA_TEST_DEPS) +else # RUN_JAVA_TESTS +all-local: swig_java/wallycore.jar endif # RUN_JAVA_TESTS $(JAVA_CLASSES) &: $(JAVA_CLASSES:.class=.java) From 3cbeb34d92b7bf4cb83e5745e4bcdf94d670e4ef Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Mon, 4 Sep 2023 17:29:46 +1200 Subject: [PATCH 22/26] configure.ac: use AX_SUBDIRS_CONFIGURE; don't alter ac_configure_args Altering ac_configure_args to configure libsecp256k1 with options differing from those of libwally-core causes issues if the wally Makefile is out of date and needs to call autoreconf etc to regenerate itself. The secp arguments are passed back to the top level configure which changes and possibly breaks the original configuration. Instead, import and use AX_SUBDIRS_CONFIGURE from the autoconf-archive which supports sub-confiration with bespoke arguments. Because autoreconf does not recurse into subdirectories named by AX_SUBDIRS_CONFIGURE, we lose the automagic Autotools (re)generation in src/secp256k1, so add an explicit call to src/secp256k1/autogen.sh in tools/autogen.sh. --- configure.ac | 3 +- setup.py | 24 +- tools/autogen.sh | 4 + tools/build-aux/m4/ax_subdirs_configure.m4 | 334 +++++++++++++++++++++ 4 files changed, 351 insertions(+), 14 deletions(-) create mode 100644 tools/build-aux/m4/ax_subdirs_configure.m4 diff --git a/configure.ac b/configure.ac index 8d46dd3a7..dc175143e 100644 --- a/configure.ac +++ b/configure.ac @@ -404,8 +404,7 @@ export ARFLAGS export AR_FLAGS export LD export LDFLAGS -ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-experimental --enable-module-ecdh --enable-module-recovery --enable-module-ecdsa-s2c --enable-module-rangeproof --enable-module-surjectionproof --enable-module-whitelist --enable-module-generator --enable-module-extrakeys --enable-module-schnorrsig ${secp256k1_test_opt} --enable-exhaustive-tests=no --enable-benchmark=no --disable-dependency-tracking ${secp_asm}" -AC_CONFIG_SUBDIRS([src/secp256k1]) +AX_SUBDIRS_CONFIGURE([src/secp256k1], [[--disable-shared], [--enable-static], [--with-pic], [--enable-experimental], [--enable-module-ecdh], [--enable-module-recovery], [--enable-module-ecdsa-s2c], [--enable-module-rangeproof], [--enable-module-surjectionproof], [--enable-module-whitelist], [--enable-module-generator], [--enable-module-extrakeys], [--enable-module-schnorrsig], [$secp256k1_test_opt], [--enable-exhaustive-tests=no], [--enable-benchmark=no], [--disable-dependency-tracking], [$secp_asm]]) AC_OUTPUT diff --git a/setup.py b/setup.py index e403ed81a..c43952df9 100644 --- a/setup.py +++ b/setup.py @@ -3,8 +3,9 @@ import copy, os, platform, shutil import distutils.sysconfig -CONFIGURE_ARGS = '--enable-swig-python --enable-python-manylinux' -CONFIGURE_ARGS += ' --disable-swig-java --disable-tests --disable-dependency-tracking' +CONFIGURE_ARGS = ['--disable-shared', '--enable-static', '--with-pic', + '--enable-swig-python', '--enable-python-manylinux', + '--disable-swig-java', '--disable-tests', '--disable-dependency-tracking'] distutils_env = distutils.sysconfig.get_config_vars() configure_env = copy.deepcopy(os.environ) @@ -26,11 +27,11 @@ if is_x86 and not is_native: # We are cross-compiling or compiling a univeral2 binary. # Configure our source code as a cross compile to make the build work - CONFIGURE_ARGS += ' --host x86_64-apple-darwin' + CONFIGURE_ARGS += ['--host', 'x86_64-apple-darwin'] arch = 'universal2' if len(archs) > 1 else archs[0] - CONFIGURE_ARGS += ' --target {}-apple-macos'.format(arch) + CONFIGURE_ARGS += ['--target', '{}-apple-macos'.format(arch)] if len(archs) > 1: - CONFIGURE_ARGS += ' --with-asm=no' + CONFIGURE_ARGS += ['--with-asm=no'] if 'PY_CFLAGS' in distutils_env: configure_env['CFLAGS'] = distutils_env['PY_CFLAGS'] configure_env['LDFLAGS'] = distutils_env['PY_LDFLAGS'] @@ -40,18 +41,17 @@ # then build using the standard Python ext module machinery. # (Windows requires source generation to be done separately). import multiprocessing - import os import subprocess abs_path = os.path.dirname(os.path.abspath(__file__)) + '/' - def call(cmd): - subprocess.check_call(cmd.split(' '), cwd=abs_path, env=configure_env) + def call(args): + subprocess.check_call(args, cwd=abs_path, env=configure_env) - call('./tools/cleanup.sh') - call('./tools/autogen.sh') - call('./configure {}'.format(CONFIGURE_ARGS)) - call('make -j{}'.format(multiprocessing.cpu_count())) + call(['./tools/cleanup.sh']) + call(['./tools/autogen.sh']) + call(['./configure'] + CONFIGURE_ARGS) + call(['make', '-j{}'.format(multiprocessing.cpu_count())]) define_macros=[ ('SWIG_PYTHON_BUILD', None), diff --git a/tools/autogen.sh b/tools/autogen.sh index f572fe1e5..3942bcc64 100755 --- a/tools/autogen.sh +++ b/tools/autogen.sh @@ -8,3 +8,7 @@ if uname | grep "Darwin" >/dev/null 2>&1; then done done fi + +if [ -x src/secp256k1/autogen.sh ] ; then + cd src/secp256k1 && ./autogen.sh +fi diff --git a/tools/build-aux/m4/ax_subdirs_configure.m4 b/tools/build-aux/m4/ax_subdirs_configure.m4 new file mode 100644 index 000000000..01cb074b3 --- /dev/null +++ b/tools/build-aux/m4/ax_subdirs_configure.m4 @@ -0,0 +1,334 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_subdirs_configure.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_SUBDIRS_CONFIGURE( [subdirs], [mandatory arguments], [possibly merged arguments], [replacement arguments], [forbidden arguments]) +# +# DESCRIPTION +# +# AX_SUBDIRS_CONFIGURE attempts to be the equivalent of AC_CONFIG_SUBDIRS +# with customizable options for configure scripts. +# +# Run the configure script for each directory from the comma-separated m4 +# list 'subdirs'. This macro can be used multiple times. All arguments of +# this macro must be comma-separated lists. +# +# All command line arguments from the parent configure script will be +# given to the subdirectory configure script after the following +# modifications (in that order): +# +# 1. The arguments from the 'mandatory arguments' list shall always be +# appended to the argument list. +# +# 2. The arguments from the 'possibly merged arguments' list shall be +# added if not present in the arguments of the parent configure script or +# merged with the existing argument otherwise. +# +# 3. The arguments from the 'replacement arguments' list shall be added if +# not present in the arguments of the parent configure script or replace +# the existing argument otherwise. +# +# 4. The arguments from the 'forbidden arguments' list shall always be +# removed from the argument list. +# +# The lists 'mandatory arguments' and 'forbidden arguments' can hold any +# kind of argument. The 'possibly merged arguments' and 'replacement +# arguments' expect their arguments to be of the form --option-name=value. +# +# This macro aims to remain as close as possible to the AC_CONFIG_SUBDIRS +# macro. It corrects the paths for '--srcdir' and adds +# '--disable-option-checking' and '--silent' if necessary. However, it +# does not change the '--cache-file' argument: typically, configure +# scripts run with different arguments will not be able to share the same +# cache. If you wish to share a single cache, you should give an absolute +# path to '--cache-file'. +# +# This macro also sets the output variable subdirs_extra to the list of +# directories recorded with AX_SUBDIRS_CONFIGURE. This variable can be +# used in Makefile rules or substituted in configured files. +# +# This macro shall do nothing more than managing the arguments of the +# configure script. Just like when using AC_CONFIG_SUBDIRS, it is up to +# the user to check any requirements or define and substitute any required +# variable for the remainder of the project. +# +# Configure scripts recorded with AX_SUBDIRS_CONFIGURE may be executed +# before configure scripts recorded with AC_CONFIG_SUBDIRS. +# +# Without additional arguments, the behaviour of AX_SUBDIRS_CONFIGURE +# should be identical to the behaviour of AC_CONFIG_SUBDIRS, apart from +# the contents of the variables subdirs and subdirs_extra (except that +# AX_SUBDIRS_CONFIGURE expects a comma-separated m4 list): +# +# AC_CONFIG_SUBDIRS([something]) +# AX_SUBDIRS_CONFIGURE([something]) +# +# This macro may be called multiple times. +# +# Usage example: +# +# Let us assume our project has 4 dependencies, namely A, B, C and D. Here +# are some characteristics of our project and its dependencies: +# +# - A does not require any special option. +# +# - we want to build B with an optional feature which can be enabled with +# its configure script's option '--enable-special-feature'. +# +# - B's configure script is strange and has an option '--with-B=build'. +# After close inspection of its documentation, we don't want B to receive +# this option. +# +# - C and D both need B. +# +# - Just like our project, C and D can build B themselves with the option +# '--with-B=build'. +# +# - We want C and D to use the B we build instead of building it +# themselves. +# +# Our top-level configure script will be called as follows: +# +# $ --with-A=build --with-B=build --with-C=build \ +# --with-D=build --some-option +# +# Thus we have to make sure that: +# +# - neither B, C or D receive the option '--with-B=build' +# +# - C and D know where to find the headers and libraries of B. +# +# Under those conditions, we can use the AC_CONFIG_SUBDIRS macro for A, +# but need to use AX_SUBDIRS_CONFIGURE for B, C and D: +# +# - B must receive '--enable-special-feature' but cannot receive +# '--with-B=build' +# +# - C and D cannot receive '--with-B=build' (or else it would be built +# thrice) and need to be told where to find B (since we are building it, +# it would probably not be available in standard paths). +# +# Here is a configure.ac snippet that solves our problem: +# +# AC_CONFIG_SUBDIRS([dependencies/A]) +# AX_SUBDIRS_CONFIGURE( +# [dependencies/B], [--enable-special-feature], [], [], +# [--with-B=build]) +# AX_SUBDIRS_CONFIGURE( +# [[dependencies/C],[dependencies/D]], +# [], +# [[CPPFLAGS=-I${ac_top_srcdir}/dependencies/B -I${ac_top_builddir}/dependencies/B], +# [LDFLAGS=-L${ac_abs_top_builddir}/dependencies/B/.libs]], +# [--with-B=system], +# []) +# +# If using automake, the following can be added to the Makefile.am (we use +# both $(subdirs) and $(subdirs_extra) since our example above used both +# AC_CONFIG_SUBDIRS and AX_SUBDIRS_CONFIGURE): +# +# SUBDIRS = $(subdirs) $(subdirs_extra) +# +# LICENSE +# +# Copyright (c) 2017 Harenome Ranaivoarivony-Razanajato +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# Under Section 7 of GPL version 3, you are granted additional permissions +# described in the Autoconf Configure Script Exception, version 3.0, as +# published by the Free Software Foundation. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +#serial 6 + +AC_DEFUN([AX_SUBDIRS_CONFIGURE], +[ + dnl Calls to AC_CONFIG_SUBDIRS perform preliminary steps and build a list + dnl '$subdirs' which is used later by _AC_OUTPUT_SUBDIRS (used by AC_OUTPUT) + dnl to actually run the configure scripts. + dnl This macro performs similar preliminary steps but uses + dnl AC_CONFIG_COMMANDS_PRE to delay the final tasks instead of building an + dnl intermediary list and relying on another macro. + dnl + dnl Since each configure script can get different options, a special variable + dnl named 'ax_sub_configure_args_' is constructed for each + dnl subdirectory. + + # Various preliminary checks. + AC_REQUIRE([AC_DISABLE_OPTION_CHECKING]) + AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT]) + AS_LITERAL_IF([$1], [], + [AC_DIAGNOSE([syntax], [$0: you should use literals])]) + + m4_foreach(subdir_path, [$1], + [ + ax_dir="subdir_path" + + dnl Build the argument list in a similar fashion to AC_CONFIG_SUBDIRS. + dnl A few arguments found in the final call to the configure script are not + dnl added here because they rely on variables that may not yet be available + dnl (see below the part that is similar to _AC_OUTPUT_SUBDIRS). + # Do not complain, so a configure script can configure whichever parts of a + # large source tree are present. + if test -d "$srcdir/$ax_dir"; then + _AC_SRCDIRS(["$ax_dir"]) + # Remove --cache-file, --srcdir, and --disable-option-checking arguments + # so they do not pile up. + ax_args= + ax_prev= + eval "set x $ac_configure_args" + shift + for ax_arg; do + if test -n "$ax_prev"; then + ax_prev= + continue + fi + case $ax_arg in + -cache-file | --cache-file | --cache-fil | --cache-fi | --cache-f \ + | --cache- | --cache | --cach | --cac | --ca | --c) + ax_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* \ + | --c=*) + ;; + --config-cache | -C) + ;; + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ax_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + ;; + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ax_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* \ + | --p=*) + ;; + --disable-option-checking) + ;; + *) case $ax_arg in + *\'*) ax_arg=$(AS_ECHO(["$ax_arg"]) | sed "s/'/'\\\\\\\\''/g");; + esac + AS_VAR_APPEND([ax_args], [" '$ax_arg'"]) ;; + esac + done + # Always prepend --disable-option-checking to silence warnings, since + # different subdirs can have different --enable and --with options. + ax_args="--disable-option-checking $ax_args" + # Options that must be added as they are provided. + m4_ifnblank([$2], [m4_foreach(opt, [$2], [AS_VAR_APPEND(ax_args, " 'opt'") + ])]) + # New options that may need to be merged with existing options. + m4_ifnblank([$3], [m4_foreach(opt, [$3], + [ax_candidate="opt" + ax_candidate_flag="${ax_candidate%%=*}" + ax_candidate_content="${ax_candidate#*=}" + if test "x$ax_candidate" != "x" -a "x$ax_candidate_flag" != "x"; then + if echo "$ax_args" | grep -- "${ax_candidate_flag}=" >/dev/null 2>&1; then + [ax_args=$(echo $ax_args | sed "s,\(${ax_candidate_flag}=[^']*\),\1 ${ax_candidate_content},")] + else + AS_VAR_APPEND(ax_args, " 'opt'") + fi + fi + ])]) + # New options that must replace existing options. + m4_ifnblank([$4], [m4_foreach(opt, [$4], + [ax_candidate="opt" + ax_candidate_flag="${ax_candidate%%=*}" + ax_candidate_content="${ax_candidate#*=}" + if test "x$ax_candidate" != "x" -a "x$ax_candidate_flag" != "x"; then + if echo "$ax_args" | grep -- "${ax_candidate_flag}=" >/dev/null 2>&1; then + [ax_args=$(echo $ax_args | sed "s,${ax_candidate_flag}=[^']*,${ax_candidate},")] + else + AS_VAR_APPEND(ax_args, " 'opt'") + fi + fi + ])]) + # Options that must be removed. + m4_ifnblank([$5], [m4_foreach(opt, [$5], [ax_args=$(echo $ax_args | sed "s,'opt',,") + ])]) + AS_VAR_APPEND([ax_args], [" '--srcdir=$ac_srcdir'"]) + + # Add the subdirectory to the list of target subdirectories. + ax_subconfigures="$ax_subconfigures $ax_dir" + # Save the argument list for this subdirectory. + dnl $1 is a path to some subdirectory: m4_bpatsubsts() is used to convert + dnl $1 into a valid shell variable name. + dnl For instance, "ax_sub_configure_args_path/to/subdir" becomes + dnl "ax_sub_configure_args_path_to_subdir". + ax_var=$(printf "$ax_dir" | tr -c "0-9a-zA-Z_" "_") + eval "ax_sub_configure_args_$ax_var=\"$ax_args\"" + eval "ax_sub_configure_$ax_var=\"yes\"" + else + AC_MSG_WARN([could not find source tree for $ax_dir]) + fi + + dnl Add some more arguments to the argument list and then actually run the + dnl configure script. This is mostly what happens in _AC_OUTPUT_SUBDIRS + dnl except it does not iterate over an intermediary list. + AC_CONFIG_COMMANDS_PRE( + dnl This very line cannot be quoted! m4_foreach has some work here. + ax_dir="subdir_path" + [ + # Convert the path to the subdirectory into a shell variable name. + ax_var=$(printf "$ax_dir" | tr -c "0-9a-zA-Z_" "_") + ax_configure_ax_var=$(eval "echo \"\$ax_sub_configure_$ax_var\"") + if test "$no_recursion" != "yes" -a "x$ax_configure_ax_var" = "xyes"; then + AC_SUBST([subdirs_extra], ["$subdirs_extra $ax_dir"]) + ax_msg="=== configuring in $ax_dir ($(pwd)/$ax_dir)" + _AS_ECHO_LOG([$ax_msg]) + _AS_ECHO([$ax_msg]) + AS_MKDIR_P(["$ax_dir"]) + _AC_SRCDIRS(["$ax_dir"]) + + ax_popdir=$(pwd) + cd "$ax_dir" + + # Check for guested configure; otherwise get Cygnus style configure. + if test -f "$ac_srcdir/configure.gnu"; then + ax_sub_configure=$ac_srcdir/configure.gnu + elif test -f "$ac_srcdir/configure"; then + ax_sub_configure=$ac_srcdir/configure + elif test -f "$ac_srcdir/configure.in"; then + # This should be Cygnus configure. + ax_sub_configure=$ac_aux_dir/configure + else + AC_MSG_WARN([no configuration information is in $ax_dir]) + ax_sub_configure= + fi + + if test -n "$ax_sub_configure"; then + # Get the configure arguments for the current configure. + eval "ax_sub_configure_args=\"\$ax_sub_configure_args_${ax_var}\"" + + # Always prepend --prefix to ensure using the same prefix + # in subdir configurations. + ax_arg="--prefix=$prefix" + case $ax_arg in + *\'*) ax_arg=$(AS_ECHO(["$ax_arg"]) | sed "s/'/'\\\\\\\\''/g");; + esac + ax_sub_configure_args="'$ax_arg' $ax_sub_configure_args" + if test "$silent" = yes; then + ax_sub_configure_args="--silent $ax_sub_configure_args" + fi + + AC_MSG_NOTICE([running $SHELL $ax_sub_configure $ax_sub_configure_args --cache-file=$cache_file]) + eval "\$SHELL \"$ax_sub_configure\" $ax_sub_configure_args --cache-file=\"$cache_file\"" \ + || AC_MSG_ERROR([$ax_sub_configure failed for $ax_dir]) + fi + + cd "$ax_popdir" + fi + ]) + ]) +]) From 3c639f6cbdfaa3f26e8e12b7656a6cabef4fab7d Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Mon, 4 Sep 2023 14:05:44 +1200 Subject: [PATCH 23/26] secp: use the configured include path for secp headers Extracted from a patch by Matt Whitlock . Also reduce the include directories given for python wheel building. --- configure.ac | 3 +++ setup.py | 4 +--- src/Makefile.am | 6 +++--- src/ecdh.c | 4 ++-- src/elements.c | 8 ++++---- src/internal.h | 8 ++++---- src/sign.c | 2 +- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index dc175143e..165f1eb49 100644 --- a/configure.ac +++ b/configure.ac @@ -259,6 +259,9 @@ fi # # libsecp256k1 # +libsecp256k1_CFLAGS='-I$(top_srcdir)/src/secp256k1/include' +AC_SUBST([libsecp256k1_CFLAGS]) + # FIXME: This is needed to force libtool to use all object files from secp. # We can only build secp properly by recursively invoking # configure/make, and can't include it as a noinst_ library. Libtool diff --git a/setup.py b/setup.py index c43952df9..3f30e1ca2 100644 --- a/setup.py +++ b/setup.py @@ -67,10 +67,8 @@ def call(args): include_dirs=[ './', './src', - './include', './src/ccan', - './src/secp256k1', - './src/secp256k1/src/' + './src/secp256k1/include', ] if is_windows: shutil.copyfile('./src/amalgamation/windows_config/libsecp256k1-config.h', 'src/secp256k1/src/libsecp256k1-config.h') diff --git a/src/Makefile.am b/src/Makefile.am index 5e32b0968..d604a3b26 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,7 +40,7 @@ if USE_SWIG_PYTHON noinst_LTLIBRARIES += libswig_python.la libswig_python_la_SOURCES = swig_python/swig_python_wrap.c -libswig_python_la_CFLAGS = -I$(top_srcdir) $(AM_CFLAGS) $(SWIG_PYTHON_CPPFLAGS) $(SWIG_WARN_CFLAGS) $(NOALIAS_CFLAGS) +libswig_python_la_CFLAGS = -I$(top_srcdir) $(libsecp256k1_CFLAGS) $(AM_CFLAGS) $(SWIG_PYTHON_CPPFLAGS) $(SWIG_WARN_CFLAGS) $(NOALIAS_CFLAGS) if PYTHON_MANYLINUX else libswig_python_la_LIBADD = $(PYTHON_LIBS) @@ -83,7 +83,7 @@ noinst_LTLIBRARIES += libswig_java.la libswig_java_la_SOURCES = \ swig_java/swig_java_wrap.c -libswig_java_la_CFLAGS = -I$(top_srcdir) $(AM_CFLAGS) $(SWIG_JAVA_CPPFLAGS) $(SWIG_WARN_CFLAGS) +libswig_java_la_CFLAGS = -I$(top_srcdir) $(libsecp256k1_CFLAGS) $(AM_CFLAGS) $(SWIG_JAVA_CPPFLAGS) $(SWIG_WARN_CFLAGS) SWIG_JOPT = $(SWIG_JAVA_OPT) -outdir swig_java -noproxy -package com.blockstream.libwally @@ -207,7 +207,7 @@ libwallycore_la_LDFLAGS += -no-undefined endif endif # SHARED_BUILD_ENABLED -libwallycore_la_CFLAGS = -I$(top_srcdir) -I$(srcdir)/ccan -DWALLY_CORE_BUILD=1 $(AM_CFLAGS) +libwallycore_la_CFLAGS = -I$(top_srcdir) -I$(srcdir)/ccan $(libsecp256k1_CFLAGS) -DWALLY_CORE_BUILD=1 $(AM_CFLAGS) libwallycore_la_LIBADD = $(LIBADD_SECP256K1) $(noinst_LTLIBRARIES) SUBDIRS = secp256k1 diff --git a/src/ecdh.c b/src/ecdh.c index f81e76c74..0130de427 100644 --- a/src/ecdh.c +++ b/src/ecdh.c @@ -1,7 +1,7 @@ #include "internal.h" #include -#include "secp256k1/include/secp256k1.h" -#include "secp256k1/include/secp256k1_ecdh.h" +#include +#include int wally_ecdh(const unsigned char *pub_key, size_t pub_key_len, const unsigned char *priv_key, size_t priv_key_len, diff --git a/src/elements.c b/src/elements.c index 9edb58ca8..cbe39ba1b 100644 --- a/src/elements.c +++ b/src/elements.c @@ -7,10 +7,10 @@ #include #include #include -#include "secp256k1/include/secp256k1_generator.h" -#include "secp256k1/include/secp256k1_rangeproof.h" -#include "src/secp256k1/include/secp256k1_surjectionproof.h" -#include "src/secp256k1/include/secp256k1_whitelist.h" +#include +#include +#include +#include static const unsigned char LABEL_STR[] = { diff --git a/src/internal.h b/src/internal.h index f99087b31..a60307afc 100644 --- a/src/internal.h +++ b/src/internal.h @@ -13,11 +13,11 @@ #pragma GCC diagnostic ignored "-Wunused-parameter" #endif /* BUILD_ELEMENTS */ #endif /* WALLY_ABI_NO_ELEMENTS */ -#include "secp256k1/include/secp256k1.h" -#include "secp256k1/include/secp256k1_recovery.h" -#include "secp256k1/include/secp256k1_extrakeys.h" +#include +#include +#include #ifndef BUILD_STANDARD_SECP -#include "secp256k1/include/secp256k1_ecdsa_s2c.h" +#include #endif #include #if defined(HAVE_MEMSET_S) diff --git a/src/sign.c b/src/sign.c index c76ab4474..f5b929fee 100644 --- a/src/sign.c +++ b/src/sign.c @@ -1,7 +1,7 @@ #include "internal.h" #include #include "script_int.h" -#include "secp256k1/include/secp256k1_schnorrsig.h" +#include #include "ccan/ccan/build_assert/build_assert.h" #define EC_FLAGS_TYPES (EC_FLAG_ECDSA | EC_FLAG_SCHNORR) From 8abbdd6d6a1533e91a85eb65683964c73d44641a Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Thu, 31 Aug 2023 00:32:26 -0400 Subject: [PATCH 24/26] configure.ac: support --with-system-secp256k1 (Modified from the original submission). Libwally-core, in its stock configuration, compiles and statically links against a private copy of libsecp256k1_zkp. However, Gentoo unbundles libsecp256k1_zkp and instead links libwally-core against a system-wide shared libsecp256k1_zkp with headers in /usr/include/secp256k1_zkp and a libsecp256k1_zkp.pc that specifies the relevant CFLAGS and LIBS. Implement a --with-system-secp256k1 configure option to allow compiling and linking against a system-installed libsecp256k1. Pass the user- specified package name (or 'libsecp256k1' or 'libsecp256k1_zkp' by default, depending on --enable-standard-secp) to PKG_CHECK_MODULES to find the CFLAGS and LIBS of a system-installed libsecp256k1. Call AC_CHECK_FUNCS to assert that the required modules are present in the system-installed libsecp256k1. If the user does not specify --with-system-secp256k1 (or specifies --without-system-secp256k1), the build will use the bundled copy of libsecp256k1_zkp as before. Remove the existing libtool hack: When building as a static library, the user will need to link libsecp256k1.a in addition to libwallycore.a. --- configure.ac | 66 ++++++++++++++++++++++++++++++++----------------- src/Makefile.am | 4 ++- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/configure.ac b/configure.ac index 165f1eb49..0dc0b0f71 100644 --- a/configure.ac +++ b/configure.ac @@ -259,29 +259,47 @@ fi # # libsecp256k1 # -libsecp256k1_CFLAGS='-I$(top_srcdir)/src/secp256k1/include' +AC_ARG_WITH([system-secp256k1], + [AS_HELP_STRING([[--with-system-secp256k1[=PKG]]], + [build using system-installed libsecp256k1 instead of bundled, passing PKG (default: libsecp256k1 or libsecp256k1_zkp, depending on --enable-standard-secp) to pkg-config (default: no)])], + [AS_IF([test "x$withval" = xyes], + [AM_COND_IF([BUILD_STANDARD_SECP], [with_system_secp256k1=libsecp256k1], [with_system_secp256k1=libsecp256k1_zkp])])], + [with_system_secp256k1=no]) + +AM_CONDITIONAL([LINK_SYSTEM_SECP256K1], [test "x$with_system_secp256k1" != xno]) +AM_COND_IF([LINK_SYSTEM_SECP256K1], [ + dnl Use the secp installed system-wide (after checking it for suitability) + saved_LIBS=$LIBS + PKG_CHECK_MODULES([libsecp256k1], [$with_system_secp256k1]) + LIBS="$libsecp256k1_LIBS $LIBS" + missing_modules= + AC_DEFUN([CHECK_MODULE], [ + AC_CHECK_FUNCS([$2], [], [missing_modules="${missing_modules} $1"]) + ]) + CHECK_MODULE([ecdh], [secp256k1_ecdh]) + CHECK_MODULE([extrakeys], [secp256k1_xonly_pubkey_parse]) + CHECK_MODULE([recovery], [secp256k1_ecdsa_recover]) + CHECK_MODULE([schnorrsig], [secp256k1_schnorrsig_verify]) + AM_COND_IF([BUILD_STANDARD_SECP], [], [ + CHECK_MODULE([ecdsa-s2c], [secp256k1_ecdsa_s2c_sign]) + ]) + AM_COND_IF([BUILD_ELEMENTS], [ + CHECK_MODULE([generator], [secp256k1_generator_parse]) + CHECK_MODULE([rangeproof], [secp256k1_rangeproof_verify]) + CHECK_MODULE([surjectionproof], [secp256k1_surjectionproof_initialize]) + CHECK_MODULE([whitelist], [secp256k1_whitelist_sign]) + ]) + AS_IF([test -n "${missing_modules}"], [ + AC_MSG_ERROR([system-installed $with_system_secp256k1 does not support these required modules:${missing_modules}]) + ]) + LIBS=$saved_LIBS +], [ + dnl Use the secp in-tree submodule + libsecp256k1_CFLAGS='-I$(top_srcdir)/src/secp256k1/include' + libsecp256k1_LIBS='$(top_srcdir)/src/secp256k1/libsecp256k1.la' +]) AC_SUBST([libsecp256k1_CFLAGS]) - -# FIXME: This is needed to force libtool to use all object files from secp. -# We can only build secp properly by recursively invoking -# configure/make, and can't include it as a noinst_ library. Libtool -# assumes that such libraries will be installed along with our library -# target and so won't force all object files in the library to be -# included in ours - despite the fact that we are making a shared -# library and linking to a static one. This is broken and we work -# around it by hacking the secp objects directly into the library -# via the _LDADD variable for wallycore. -# We previously achieved this by adding the libsecp256k1.a archive, -# but changes to libtool and apples linkers mean that -# archives-within-archives no longer work. -# Because automake tries to police its users very strictly and fails -# hard when flags are passed in this way, we have to substitute the -# flags here. -# Because libtool both intercepts -Wl and arbitrarily re-orders its -# command line inputs, we have to concoct a single expression to -# enforce linking that cannot be split, hence the below expression. -LIBADD_SECP256K1="-Wl,secp256k1/src/libsecp256k1_la-secp256k1.${OBJEXT},secp256k1/src/libsecp256k1_precomputed_la-precomputed_ecmult_gen.${OBJEXT},secp256k1/src/libsecp256k1_precomputed_la-precomputed_ecmult.${OBJEXT}" -AC_SUBST([LIBADD_SECP256K1]) +AC_SUBST([libsecp256k1_LIBS]) # # Python facilities @@ -408,6 +426,8 @@ export AR_FLAGS export LD export LDFLAGS -AX_SUBDIRS_CONFIGURE([src/secp256k1], [[--disable-shared], [--enable-static], [--with-pic], [--enable-experimental], [--enable-module-ecdh], [--enable-module-recovery], [--enable-module-ecdsa-s2c], [--enable-module-rangeproof], [--enable-module-surjectionproof], [--enable-module-whitelist], [--enable-module-generator], [--enable-module-extrakeys], [--enable-module-schnorrsig], [$secp256k1_test_opt], [--enable-exhaustive-tests=no], [--enable-benchmark=no], [--disable-dependency-tracking], [$secp_asm]]) +AM_COND_IF([LINK_SYSTEM_SECP256K1], [], [ + AX_SUBDIRS_CONFIGURE([src/secp256k1], [[--disable-shared], [--enable-static], [--with-pic], [--enable-experimental], [--enable-module-ecdh], [--enable-module-recovery], [--enable-module-ecdsa-s2c], [--enable-module-rangeproof], [--enable-module-surjectionproof], [--enable-module-whitelist], [--enable-module-generator], [--enable-module-extrakeys], [--enable-module-schnorrsig], [$secp256k1_test_opt], [--enable-exhaustive-tests=no], [--enable-benchmark=no], [--disable-dependency-tracking], [$secp_asm]]) +]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index d604a3b26..4dcdc6afe 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -208,9 +208,11 @@ endif endif # SHARED_BUILD_ENABLED libwallycore_la_CFLAGS = -I$(top_srcdir) -I$(srcdir)/ccan $(libsecp256k1_CFLAGS) -DWALLY_CORE_BUILD=1 $(AM_CFLAGS) -libwallycore_la_LIBADD = $(LIBADD_SECP256K1) $(noinst_LTLIBRARIES) +libwallycore_la_LIBADD = $(libsecp256k1_LIBS) $(noinst_LTLIBRARIES) +if !LINK_SYSTEM_SECP256K1 SUBDIRS = secp256k1 +endif TESTS = noinst_PROGRAMS = From 50ffb2963840d2c86a1193f93816646d82b60ce5 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 16:45:05 +1200 Subject: [PATCH 25/26] docs: update for v1.0.0 --- CHANGES.md | 14 ++++++++++++++ README.md | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 738c98d72..c79a2e0ba 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,19 @@ # Changes +## Version 1.0.0 +- The library now follows semantic versioning as per https://semver.org/. +- Elements support is now enabled by default, reflecting the common library + usage. Please see the `configure --help` entries for `--disable-elements` + and `--disable-elements-abi` for details. +- The ABI of the library is now consistent by default regardless of whether + it is built with or without Elements support. +- When configured to build as a static library, linking to libwallycore.a + requires additionally linking to libsecp256k1.a. +- Wally can now be configured to build against a system-wide libsecp256k1. +- Some functions in the c++ header wally.hpp have changed interface slightly. + Note that this header is deprecated and will be replaced in an upcoming + release with higher level wrappers in the same manner as Python and JS. + ## Version 0.9.1 - PSET: When adding an Elements transaction output to a PSET, the nonce commitment was incorrectly mapped to the PSET output blinding key field. diff --git a/README.md b/README.md index c1aa4a3e9..24fdbedbe 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ for cryptocurrency wallets. Read the API documentation at https://wally.readthedocs.io. -Note that library interfaces may change slightly while the library design matures. Please see the [CHANGES](./CHANGES.md) file to determine if the API has changed when upgrading. +Please see the [CHANGES](./CHANGES.md) for details of ABI changes when upgrading. Please report bugs and submit patches to [Our github repository](https://github.com/ElementsProject/libwally-core). If you wish to report a security issue, please read [Our security reporting guidelines](./SECURITY.md). @@ -88,6 +88,8 @@ $ brew install swig header files. This option *must not be given if wally is being installed as a system/shared library*. (default: no). - `--enabled-standard-secp`. Excludes support for features that are unavailable in the standard [libsecp256k1 library](https://github.com/bitcoin-core/secp256k1). +- `--with-system-secp256k1=`. Compile and link against a system-wide + install of libsecp256k1 instead of the in-tree submodule. (default: not enabled). - `--enable-mbed-tls`. Use mbed-tls hashing functions if available. This typically results in faster hashing on embedded platforms such as STM32. Note that the user must define `MBEDTLS_SHA256_ALT` and/or `SOC_SHA_SUPPORT_PARALLEL_ENG` matching the From 0df2d508f2ee87014dfa3909d80d197bae962810 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 30 Aug 2023 16:46:17 +1200 Subject: [PATCH 26/26] Bump version to 1.0.0 --- README.md | 2 +- _CMakeLists.txt | 2 +- configure.ac | 2 +- docs/source/conf.py | 2 +- include/wally_core.h | 8 ++++---- setup.py | 2 +- src/wasm_package/package-lock.json | 4 ++-- src/wasm_package/package.json | 2 +- src/wasm_package/src/const.js | 8 ++++---- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 24fdbedbe..cbd991418 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ installed. For non-development use, you can install wally with `pip` as follows: ``` -pip install wallycore==0.9.2 +pip install wallycore==1.0.0 ``` For python development, you can build and install wally using: diff --git a/_CMakeLists.txt b/_CMakeLists.txt index 23a4b7f63..e575b10c2 100644 --- a/_CMakeLists.txt +++ b/_CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20) project( libwallycore - VERSION 0.9.2 + VERSION 1.0.0 DESCRIPTION "A collection of useful primitives for cryptocurrency wallets" LANGUAGES C ) diff --git a/configure.ac b/configure.ac index 0dc0b0f71..3397f03a2 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.60]) -AC_INIT([libwallycore],[0.9.2]) +AC_INIT([libwallycore],[1.0.0]) AC_CONFIG_AUX_DIR([tools/build-aux]) AC_CONFIG_MACRO_DIR([tools/build-aux/m4]) AC_CONFIG_SRCDIR([src/mnemonic.h]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 61da01509..e5ca68a98 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -167,7 +167,7 @@ def extract_docs(infile, outfile): # built documents. # # The short X.Y version. -version = u'0.9.2' +version = u'1.0.0' # The full version, including alpha/beta/rc tags. release = version diff --git a/include/wally_core.h b/include/wally_core.h index e5d6a958e..328b2417b 100644 --- a/include/wally_core.h +++ b/include/wally_core.h @@ -29,10 +29,10 @@ extern "C" { #define WALLY_ENOMEM -3 /** malloc() failed */ /** Library version */ -#define WALLY_MAJOR_VER 0 -#define WALLY_MINOR_VER 9 -#define WALLY_PATCH_VER 2 -#define WALLY_BUILD_VER 0x902 +#define WALLY_MAJOR_VER 1 +#define WALLY_MINOR_VER 0 +#define WALLY_PATCH_VER 0 +#define WALLY_BUILD_VER 0x10000 /** * Initialize wally. diff --git a/setup.py b/setup.py index 3f30e1ca2..fd073ef8e 100644 --- a/setup.py +++ b/setup.py @@ -91,7 +91,7 @@ def call(args): kwargs = { 'name': 'wallycore', - 'version': '0.9.2', + 'version': '1.0.0', 'description': 'libwally Bitcoin library', 'long_description': 'Python bindings for the libwally Bitcoin library', 'url': 'https://github.com/ElementsProject/libwally-core', diff --git a/src/wasm_package/package-lock.json b/src/wasm_package/package-lock.json index b2352c941..3e0bad7fd 100644 --- a/src/wasm_package/package-lock.json +++ b/src/wasm_package/package-lock.json @@ -1,12 +1,12 @@ { "name": "wallycore", - "version": "0.9.2", + "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "wallycore", - "version": "0.9.2", + "version": "1.0.0", "license": "(MIT or BSD)", "devDependencies": { "buffer": "^6.0.3", diff --git a/src/wasm_package/package.json b/src/wasm_package/package.json index afc68984a..604d4a23b 100644 --- a/src/wasm_package/package.json +++ b/src/wasm_package/package.json @@ -1,6 +1,6 @@ { "name": "wallycore", - "version": "0.9.2", + "version": "1.0.0", "description": "JavaScript bindings for libwally", "main": "src/index.js", "type": "module", diff --git a/src/wasm_package/src/const.js b/src/wasm_package/src/const.js index 1d65a81fa..0388fa3f4 100755 --- a/src/wasm_package/src/const.js +++ b/src/wasm_package/src/const.js @@ -109,7 +109,7 @@ export const WALLY_ADDRESS_VERSION_WIF_TESTNET = 0xEF; /** Wallet Import Format export const WALLY_BIP32_CHAIN_CODE_LEN = 32; export const WALLY_BIP32_TWEAK_SUM_LEN = 32; export const WALLY_BTC_MAX = 21000000; -export const WALLY_BUILD_VER = 0x902; +export const WALLY_BUILD_VER = 0x10000; export const WALLY_CA_PREFIX_LIQUID = 0x0c; /** Liquid v1 confidential address prefix */ export const WALLY_CA_PREFIX_LIQUID_REGTEST = 0x04; /** Liquid v1 confidential address prefix for regtest */ export const WALLY_CA_PREFIX_LIQUID_TESTNET = 0x17; /** Liquid v1 confidential address prefix for testnet */ @@ -118,14 +118,14 @@ export const WALLY_EINVAL = -2; /** Invalid argument */ export const WALLY_ENOMEM = -3; /** malloc() failed */ export const WALLY_ERROR = -1; /** General error */ export const WALLY_HOST_COMMITMENT_LEN = 32; -export const WALLY_MAJOR_VER = 0; +export const WALLY_MAJOR_VER = 1; export const WALLY_MAX_OP_RETURN_LEN = 80; /* Maximum length of OP_RETURN data push */ export const WALLY_MINISCRIPT_DEPTH_MASK = 0xffff0000; /** Mask for limiting maximum depth */ export const WALLY_MINISCRIPT_DEPTH_SHIFT = 16; /** Shift to convert maximum depth to flags */ export const WALLY_MINISCRIPT_ONLY = 0x02; /** Only allow miniscript (not descriptor) expressions */ export const WALLY_MINISCRIPT_REQUIRE_CHECKSUM = 0x04; /** Require a checksum to be present */ export const WALLY_MINISCRIPT_TAPSCRIPT = 0x01; /** Tapscript, use x-only pubkeys */ -export const WALLY_MINOR_VER = 9; +export const WALLY_MINOR_VER = 0; export const WALLY_MS_CANONICAL_NO_CHECKSUM = 0x01; /** Do not include a checksum */ export const WALLY_MS_IS_DESCRIPTOR = 0x20; /** Contains only descriptor expressions (no miniscript) */ export const WALLY_MS_IS_MULTIPATH = 0x02; /** Allows multiple paths via ```` */ @@ -142,7 +142,7 @@ export const WALLY_NETWORK_LIQUID_TESTNET = 0x05; /** Liquid v1 testnet */ export const WALLY_NETWORK_NONE = 0x00; /** Used for miniscript parsing only */ export const WALLY_NO_CODESEPARATOR = 0xffffffff; /* No BIP342 code separator position */ export const WALLY_OK = 0; /** Success */ -export const WALLY_PATCH_VER = 2; +export const WALLY_PATCH_VER = 0; export const WALLY_PSBT_EXTRACT_NON_FINAL = 0x1; /* Extract without final scriptsig and witness */ export const WALLY_PSBT_FINALIZE_NO_CLEAR = 0x1; /* Finalize without clearing redeem/witness scripts etc */ export const WALLY_PSBT_FLAG_NON_FINAL = 0x1;