adapt wallet ffi

This commit is contained in:
Sergio Chouhy 2026-04-15 19:35:48 -03:00
parent 0fd2682d2e
commit 3a3358e389
3 changed files with 22 additions and 6 deletions

View File

@ -26,7 +26,7 @@ use nssa_core::program::DEFAULT_PROGRAM_ID;
use tempfile::tempdir;
use wallet_ffi::{
FfiAccount, FfiAccountList, FfiBytes32, FfiPrivateAccountKeys, FfiPublicAccountKey,
FfiTransferResult, WalletHandle, error,
FfiTransferResult, FfiU128, WalletHandle, error,
};
unsafe extern "C" {
@ -116,6 +116,7 @@ unsafe extern "C" {
handle: *mut WalletHandle,
from: *const FfiBytes32,
to_keys: *const FfiPrivateAccountKeys,
to_identifier: *const FfiU128,
amount: *const [u8; 16],
out_result: *mut FfiTransferResult,
) -> error::WalletFfiError;
@ -132,6 +133,7 @@ unsafe extern "C" {
handle: *mut WalletHandle,
from: *const FfiBytes32,
to_keys: *const FfiPrivateAccountKeys,
to_identifier: *const FfiU128,
amount: *const [u8; 16],
out_result: *mut FfiTransferResult,
) -> error::WalletFfiError;
@ -846,10 +848,12 @@ fn test_wallet_ffi_transfer_shielded() -> Result<()> {
let mut transfer_result = FfiTransferResult::default();
unsafe {
let to_identifier = FfiU128 { data: 0_u128.to_le_bytes() };
wallet_ffi_transfer_shielded(
wallet_ffi_handle,
&raw const from,
&raw const to_keys,
&raw const to_identifier,
&raw const amount,
&raw mut transfer_result,
);
@ -981,10 +985,12 @@ fn test_wallet_ffi_transfer_private() -> Result<()> {
let mut transfer_result = FfiTransferResult::default();
unsafe {
let to_identifier = FfiU128 { data: 0_u128.to_le_bytes() };
wallet_ffi_transfer_private(
wallet_ffi_handle,
&raw const from,
&raw const to_keys,
&raw const to_identifier,
&raw const amount,
&raw mut transfer_result,
);

View File

@ -9,7 +9,7 @@ use crate::{
block_on,
error::{print_error, WalletFfiError},
map_execution_error,
types::{FfiBytes32, FfiTransferResult, WalletHandle},
types::{FfiBytes32, FfiTransferResult, FfiU128, WalletHandle},
wallet::get_wallet,
FfiPrivateAccountKeys,
};
@ -102,6 +102,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_public(
/// - `handle`: Valid wallet handle
/// - `from`: Source account ID (must be owned by this wallet)
/// - `to_keys`: Destination account keys
/// - `to_identifier`: Identifier for the recipient's private account
/// - `amount`: Amount to transfer as little-endian [u8; 16]
/// - `out_result`: Output pointer for transfer result
///
@ -125,6 +126,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_shielded(
handle: *mut WalletHandle,
from: *const FfiBytes32,
to_keys: *const FfiPrivateAccountKeys,
to_identifier: *const FfiU128,
amount: *const [u8; 16],
out_result: *mut FfiTransferResult,
) -> WalletFfiError {
@ -133,7 +135,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_shielded(
Err(e) => return e,
};
if from.is_null() || to_keys.is_null() || amount.is_null() || out_result.is_null() {
if from.is_null() || to_keys.is_null() || to_identifier.is_null() || amount.is_null() || out_result.is_null() {
print_error("Null pointer argument");
return WalletFfiError::NullPointer;
}
@ -155,12 +157,13 @@ pub unsafe extern "C" fn wallet_ffi_transfer_shielded(
return e;
}
};
let to_identifier = u128::from_le_bytes(unsafe { (*to_identifier).data });
let amount = u128::from_le_bytes(unsafe { *amount });
let transfer = NativeTokenTransfer(&wallet);
match block_on(
transfer.send_shielded_transfer_to_outer_account(from_id, to_npk, to_vpk, 0, amount),
transfer.send_shielded_transfer_to_outer_account(from_id, to_npk, to_vpk, to_identifier, amount),
) {
Ok((tx_hash, _shared_key)) => {
let tx_hash = CString::new(tx_hash.to_string())
@ -271,6 +274,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_deshielded(
/// - `handle`: Valid wallet handle
/// - `from`: Source account ID (must be owned by this wallet)
/// - `to_keys`: Destination account keys
/// - `to_identifier`: Identifier for the recipient's private account
/// - `amount`: Amount to transfer as little-endian [u8; 16]
/// - `out_result`: Output pointer for transfer result
///
@ -294,6 +298,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_private(
handle: *mut WalletHandle,
from: *const FfiBytes32,
to_keys: *const FfiPrivateAccountKeys,
to_identifier: *const FfiU128,
amount: *const [u8; 16],
out_result: *mut FfiTransferResult,
) -> WalletFfiError {
@ -302,7 +307,7 @@ pub unsafe extern "C" fn wallet_ffi_transfer_private(
Err(e) => return e,
};
if from.is_null() || to_keys.is_null() || amount.is_null() || out_result.is_null() {
if from.is_null() || to_keys.is_null() || to_identifier.is_null() || amount.is_null() || out_result.is_null() {
print_error("Null pointer argument");
return WalletFfiError::NullPointer;
}
@ -324,11 +329,12 @@ pub unsafe extern "C" fn wallet_ffi_transfer_private(
return e;
}
};
let to_identifier = u128::from_le_bytes(unsafe { (*to_identifier).data });
let amount = u128::from_le_bytes(unsafe { *amount });
let transfer = NativeTokenTransfer(&wallet);
match block_on(transfer.send_private_transfer_to_outer_account(from_id, to_npk, to_vpk, 0, amount))
match block_on(transfer.send_private_transfer_to_outer_account(from_id, to_npk, to_vpk, to_identifier, amount))
{
Ok((tx_hash, _shared_key)) => {
let tx_hash = CString::new(tx_hash.to_string())

View File

@ -685,6 +685,7 @@ enum WalletFfiError wallet_ffi_transfer_public(struct WalletHandle *handle,
* - `handle`: Valid wallet handle
* - `from`: Source account ID (must be owned by this wallet)
* - `to_keys`: Destination account keys
* - `to_identifier`: Identifier for the recipient's private account
* - `amount`: Amount to transfer as little-endian [u8; 16]
* - `out_result`: Output pointer for transfer result
*
@ -707,6 +708,7 @@ enum WalletFfiError wallet_ffi_transfer_public(struct WalletHandle *handle,
enum WalletFfiError wallet_ffi_transfer_shielded(struct WalletHandle *handle,
const struct FfiBytes32 *from,
const struct FfiPrivateAccountKeys *to_keys,
const struct FfiU128 *to_identifier,
const uint8_t (*amount)[16],
struct FfiTransferResult *out_result);
@ -753,6 +755,7 @@ enum WalletFfiError wallet_ffi_transfer_deshielded(struct WalletHandle *handle,
* - `handle`: Valid wallet handle
* - `from`: Source account ID (must be owned by this wallet)
* - `to_keys`: Destination account keys
* - `to_identifier`: Identifier for the recipient's private account
* - `amount`: Amount to transfer as little-endian [u8; 16]
* - `out_result`: Output pointer for transfer result
*
@ -775,6 +778,7 @@ enum WalletFfiError wallet_ffi_transfer_deshielded(struct WalletHandle *handle,
enum WalletFfiError wallet_ffi_transfer_private(struct WalletHandle *handle,
const struct FfiBytes32 *from,
const struct FfiPrivateAccountKeys *to_keys,
const struct FfiU128 *to_identifier,
const uint8_t (*amount)[16],
struct FfiTransferResult *out_result);