rpc: refactor app code to use getters with default values
What changed, and why it matters
This commit is a straightforward code cleanup that replaces verbose 'read this optional value, or leave the default' patterns with shorter helper functions that do the same thing. There is no change in behavior and no security issue visible in the diff.
No action required; this is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors calls to rpc_get_boolean(), rpc_get_sizet(), and rpc_get_string() to new ‘…_or()’ getter variants that accept a default value. In every case the default value passed to the new helper is identical to the previous explicit default, and the surrounding logic is unchanged. No bounds checks, validation, or control flow were altered.
Changed components
main/assets.cmain/process/auth_user.cmain/process/debug_set_mnemonic.cmain/process/get_receive_address.cmain/process/ota_util.cmain/process/register_multisig.cmain/process/sign_tx.cmain/process/update_pinserver.cInspect captured patch +22 / −34
diff --git a/main/assets.c b/main/assets.c
index 4f49408..f16fe2c 100644
--- a/main/assets.c
+++ b/main/assets.c
@@ -169,9 +169,7 @@ bool assets_get_allocate(const char* field, const CborValue* value, asset_info_t
}
// "precision" field is optional in the asset contract and defaults to 0
- size_t precision = 0;
- IGNORE_RESULT(rpc_get_sizet("precision", &contract, &precision));
- asset->precision = precision;
+ asset->precision = rpc_get_sizet_or("precision", &contract, 0);
}
CborError err = cbor_value_advance(&arrayItem);
diff --git a/main/process/auth_user.c b/main/process/auth_user.c
index 2cdc7d5..6f517fe 100644
--- a/main/process/auth_user.c
+++ b/main/process/auth_user.c
@@ -359,8 +359,8 @@ void auth_user_process(void* process_ptr)
}
// Optional flag to suppress user confirmation of any pin change
- bool suppress_pin_change_confirmation = false;
- rpc_get_boolean("suppress_pin_change_confirmation", ¶ms, &suppress_pin_change_confirmation);
+ const bool suppress_pin_change_confirmation
+ = rpc_get_boolean_or("suppress_pin_change_confirmation", ¶ms, false);
// We have five cases:
// 1. Temporary - has a temporary keys in memory
diff --git a/main/process/debug_set_mnemonic.c b/main/process/debug_set_mnemonic.c
index e272a8c..bea2a4f 100644
--- a/main/process/debug_set_mnemonic.c
+++ b/main/process/debug_set_mnemonic.c
@@ -36,7 +36,6 @@ void debug_set_mnemonic_process(void* process_ptr)
char passphrase[PASSPHRASE_MAX_LEN + 1];
SENSITIVE_PUSH(passphrase, sizeof(passphrase));
const char* p_passphrase = NULL;
- bool temporary_wallet = false;
const uint8_t* seed = NULL;
size_t written = 0;
@@ -44,7 +43,7 @@ void debug_set_mnemonic_process(void* process_ptr)
SENSITIVE_PUSH(&keydata, sizeof(keydata));
// Get field which can be set to test 'temporary restore' wallet
- rpc_get_boolean("temporary_wallet", ¶ms, &temporary_wallet);
+ bool temporary_wallet = rpc_get_boolean_or("temporary_wallet", ¶ms, false);
// Slightly hacky, can accept a seed or a mnemonic
if (rpc_has_field_data("seed", ¶ms)) {
diff --git a/main/process/get_receive_address.c b/main/process/get_receive_address.c
index b56d3f4..9d4c57b 100644
--- a/main/process/get_receive_address.c
+++ b/main/process/get_receive_address.c
@@ -47,8 +47,8 @@ void get_receive_address_process(void* process_ptr)
const uint8_t* p_master_blinding_key = NULL;
size_t master_blinding_key_len = 0;
- bool confidential = isLiquid; // default to confidential addresses for liquid
- rpc_get_boolean("confidential", ¶ms, &confidential);
+ // Defaults to confidential addresses for liquid
+ const bool confidential = rpc_get_boolean_or("confidential", ¶ms, isLiquid);
if (confidential && !isLiquid) {
jade_process_reject_message(
process, CBOR_RPC_BAD_PARAMETERS, "Confidential addresses only apply to liquid networks");
@@ -110,8 +110,8 @@ void get_receive_address_process(void* process_ptr)
}
// The path is given in two parts - optional (change) branch and mandatory index pointer
- size_t branch = 0, pointer = 0;
- rpc_get_sizet("branch", ¶ms, &branch); // optional
+ const size_t branch = rpc_get_sizet_or("branch", ¶ms, 0); // optional
+ size_t pointer = 0;
if (!rpc_get_sizet("pointer", ¶ms, &pointer)) {
jade_process_reject_message(
process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract path elements from parameters");
@@ -163,8 +163,7 @@ void get_receive_address_process(void* process_ptr)
rpc_get_string("recovery_xpub", sizeof(xpubrecovery), ¶ms, xpubrecovery, &written);
// Optional 'blocks' for csv outputs
- size_t csv_blocks = 0;
- rpc_get_sizet("csv_blocks", ¶ms, &csv_blocks);
+ const size_t csv_blocks = rpc_get_sizet_or("csv_blocks", ¶ms, 0);
if (csv_blocks && !network_is_known_csv_blocks(network_id, csv_blocks)) {
const int ret
diff --git a/main/process/ota_util.c b/main/process/ota_util.c
index 7dc91f4..eaca1b2 100644
--- a/main/process/ota_util.c
+++ b/main/process/ota_util.c
@@ -216,8 +216,7 @@ jade_ota_ctx_t* ota_init(jade_process_t* process, const bool is_delta)
}
// Optional field indicating preference for rich reply data
- bool extended_replies = false;
- rpc_get_boolean("extended_replies", ¶ms, &extended_replies);
+ const bool extended_replies = rpc_get_boolean_or("extended_replies", ¶ms, false);
// Can accept either uploaded file data hash (legacy) or hash of the full/final firmware image (preferred)
uint8_t expected_hash[SHA256_LEN];
diff --git a/main/process/register_multisig.c b/main/process/register_multisig.c
index eff0d77..3f8efd2 100644
--- a/main/process/register_multisig.c
+++ b/main/process/register_multisig.c
@@ -711,8 +711,7 @@ void register_multisig_process(void* process_ptr)
}
// Threshold
- written = 0;
- rpc_get_sizet("threshold", &descriptor, &written);
+ written = rpc_get_sizet_or("threshold", &descriptor, 0);
if (written == 0 || written > MAX_ALLOWED_SIGNERS) {
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, "Invalid multisig threshold value");
goto cleanup;
diff --git a/main/process/sign_tx.c b/main/process/sign_tx.c
index 2e1e561..38761f8 100644
--- a/main/process/sign_tx.c
+++ b/main/process/sign_tx.c
@@ -133,10 +133,8 @@ static bool params_signing_outputs(jade_process_t* process, const CborValue* par
// For backward-compatibility reasons we assume all populated items
// are change unless told otherwise (ie. explicit is_change: false)
- bool is_change = true;
- rpc_get_boolean("is_change", &arrayItem, &is_change);
+ bool is_change = rpc_get_boolean_or("is_change", &arrayItem, true);
- size_t csv_blocks = 0;
size_t script_len = 0;
uint8_t script[WALLY_SCRIPTPUBKEY_P2WSH_LEN]; // Sufficient
size_t written = 0;
@@ -190,8 +188,8 @@ static bool params_signing_outputs(jade_process_t* process, const CborValue* par
}
// The path is given in two parts - optional (change) branch and mandatory index pointer
- size_t branch = 0, pointer = 0;
- rpc_get_sizet("branch", &arrayItem, &branch); // optional
+ const size_t branch = rpc_get_sizet_or("branch", &arrayItem, 0); // optional
+ size_t pointer = 0;
if (!rpc_get_sizet("pointer", &arrayItem, &pointer)) {
errmsg = "Failed to extract path elements from parameters";
goto cleanup;
@@ -240,8 +238,8 @@ static bool params_signing_outputs(jade_process_t* process, const CborValue* par
is_change = false;
}
- // Optional 'blocks' for csv outputs
- rpc_get_sizet("csv_blocks", &arrayItem, &csv_blocks);
+ // Optional 'blocks' for csv outputs, defaults to 0
+ const size_t csv_blocks = rpc_get_sizet_or("csv_blocks", &arrayItem, 0);
// If number of csv blocks unexpected show a warning message and ask the user to confirm
if (csv_blocks && !network_is_known_csv_blocks(network_id, csv_blocks)) {
@@ -452,8 +450,7 @@ static void sign_tx_impl(jade_process_t* process, const bool for_liquid)
// Whether to use Anti-Exfil signatures and message flow
// Optional flag, defaults to false
- bool use_ae_signatures = false;
- rpc_get_boolean("use_ae_signatures", ¶ms, &use_ae_signatures);
+ const bool use_ae_signatures = rpc_get_boolean_or("use_ae_signatures", ¶ms, false);
commitment_t* commitments = NULL;
// Liquid: Copy trusted commitment data so we can free the message
@@ -648,8 +645,7 @@ static void sign_tx_impl(jade_process_t* process, const bool for_liquid)
}
} else if (!for_liquid) {
// Bitcoin: May still need witness flag
- bool is_witness = false;
- rpc_get_boolean("is_witness", ¶ms, &is_witness);
+ const bool is_witness = rpc_get_boolean_or("is_witness", ¶ms, false);
input_data->sig_type = is_witness ? WALLY_SIGTYPE_SW_V0 : WALLY_SIGTYPE_PRE_SW;
input_data->sighash = WALLY_SIGHASH_ALL;
}
diff --git a/main/process/update_pinserver.c b/main/process/update_pinserver.c
index afb334b..e588c17 100644
--- a/main/process/update_pinserver.c
+++ b/main/process/update_pinserver.c
@@ -87,9 +87,8 @@ int update_pinserver(const CborValue* const params, const char** errmsg)
int retval = CBOR_RPC_BAD_PARAMETERS;
- // 1. update or erase the pinserver details
- bool reset_details = false;
- rpc_get_boolean("reset_details", params, &reset_details);
+ // 1. update or erase the pinserver details (defaults to false)
+ const bool reset_details = rpc_get_boolean_or("reset_details", params, false);
size_t urlA_len = 0, urlB_len = 0;
rpc_get_string("urlA", sizeof(urlA), params, urlA, &urlA_len);
@@ -176,9 +175,8 @@ int update_pinserver(const CborValue* const params, const char** errmsg)
}
}
- // 2. update or erase the certificate
- bool reset_certificate = false;
- rpc_get_boolean("reset_certificate", params, &reset_certificate);
+ // 2. update or erase the certificate (defaults to false)
+ const bool reset_certificate = rpc_get_boolean_or("reset_certificate", params, false);
const bool set_certificate = rpc_has_field_data("certificate", params);
if (set_certificate && reset_certificate) {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.