From 5a96eb451cb0fd30cc8855acfbcfc7274e4dab56 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Thu, 12 Feb 2026 12:38:34 -0300 Subject: [PATCH] minor refactor --- wallet-ffi/src/transfer.rs | 56 +++++++++++--------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/wallet-ffi/src/transfer.rs b/wallet-ffi/src/transfer.rs index 003488d0..94feaddc 100644 --- a/wallet-ffi/src/transfer.rs +++ b/wallet-ffi/src/transfer.rs @@ -90,13 +90,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_public( (*out_result).tx_hash = ptr::null_mut(); (*out_result).success = false; } - match e { - ExecutionFailureKind::InsufficientFundsError => WalletFfiError::InsufficientFunds, - ExecutionFailureKind::KeyNotFoundError => WalletFfiError::KeyNotFound, - ExecutionFailureKind::SequencerError => WalletFfiError::NetworkError, - ExecutionFailureKind::SequencerClientError(_) => WalletFfiError::NetworkError, - _ => WalletFfiError::InternalError, - } + map_execution_error(e) } Err(e) => e, } @@ -187,13 +181,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_shielded( (*out_result).tx_hash = ptr::null_mut(); (*out_result).success = false; } - match e { - ExecutionFailureKind::InsufficientFundsError => WalletFfiError::InsufficientFunds, - ExecutionFailureKind::KeyNotFoundError => WalletFfiError::KeyNotFound, - ExecutionFailureKind::SequencerError => WalletFfiError::NetworkError, - ExecutionFailureKind::SequencerClientError(_) => WalletFfiError::NetworkError, - _ => WalletFfiError::InternalError, - } + map_execution_error(e) } Err(e) => e, } @@ -275,13 +263,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_deshielded( (*out_result).tx_hash = ptr::null_mut(); (*out_result).success = false; } - match e { - ExecutionFailureKind::InsufficientFundsError => WalletFfiError::InsufficientFunds, - ExecutionFailureKind::KeyNotFoundError => WalletFfiError::KeyNotFound, - ExecutionFailureKind::SequencerError => WalletFfiError::NetworkError, - ExecutionFailureKind::SequencerClientError(_) => WalletFfiError::NetworkError, - _ => WalletFfiError::InternalError, - } + map_execution_error(e) } Err(e) => e, } @@ -371,13 +353,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_private( (*out_result).tx_hash = ptr::null_mut(); (*out_result).success = false; } - match e { - ExecutionFailureKind::InsufficientFundsError => WalletFfiError::InsufficientFunds, - ExecutionFailureKind::KeyNotFoundError => WalletFfiError::KeyNotFound, - ExecutionFailureKind::SequencerError => WalletFfiError::NetworkError, - ExecutionFailureKind::SequencerClientError(_) => WalletFfiError::NetworkError, - _ => WalletFfiError::InternalError, - } + map_execution_error(e) } Err(e) => e, } @@ -450,12 +426,7 @@ pub unsafe extern "C" fn wallet_ffi_register_public_account( (*out_result).tx_hash = ptr::null_mut(); (*out_result).success = false; } - match e { - ExecutionFailureKind::KeyNotFoundError => WalletFfiError::KeyNotFound, - ExecutionFailureKind::SequencerError => WalletFfiError::NetworkError, - ExecutionFailureKind::SequencerClientError(_) => WalletFfiError::NetworkError, - _ => WalletFfiError::InternalError, - } + map_execution_error(e) } Err(e) => e, } @@ -528,12 +499,7 @@ pub unsafe extern "C" fn wallet_ffi_register_private_account( (*out_result).tx_hash = ptr::null_mut(); (*out_result).success = false; } - match e { - ExecutionFailureKind::KeyNotFoundError => WalletFfiError::KeyNotFound, - ExecutionFailureKind::SequencerError => WalletFfiError::NetworkError, - ExecutionFailureKind::SequencerClientError(_) => WalletFfiError::NetworkError, - _ => WalletFfiError::InternalError, - } + map_execution_error(e) } Err(e) => e, } @@ -557,3 +523,13 @@ pub unsafe extern "C" fn wallet_ffi_free_transfer_result(result: *mut FfiTransfe } } } + +fn map_execution_error(e: ExecutionFailureKind) -> WalletFfiError { + match e { + ExecutionFailureKind::InsufficientFundsError => WalletFfiError::InsufficientFunds, + ExecutionFailureKind::KeyNotFoundError => WalletFfiError::KeyNotFound, + ExecutionFailureKind::SequencerError => WalletFfiError::NetworkError, + ExecutionFailureKind::SequencerClientError(_) => WalletFfiError::NetworkError, + _ => WalletFfiError::InternalError, + } +}