Skip to content

Commit

Permalink
feat: loosen ffi import utxo requirements (#4126)
Browse files Browse the repository at this point in the history
Description
---
- Made import UTXO less strict for the FFI - _source public key_, _features_ and _covenant_ are now optional inputs.
- Added missing `TariTransactionSendStatus` decode and destroy methods to the FFI interface file `wallet.h`.

Motivation and Context
---
- The facet is missing some non-critical parameters
- Methods to de-structure `callback_transaction_send_result` were missing in the FFI interface file `wallet.h`.

How Has This Been Tested?
---
Existing unit tests
  • Loading branch information
hansieodendaal authored May 23, 2022
1 parent 384928e commit 83a6fd9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
36 changes: 18 additions & 18 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3037,7 +3037,7 @@ pub unsafe extern "C" fn pending_inbound_transaction_destroy(transaction: *mut T
/// ----------------------------------- Transport Send Status -----------------------------------///
/// Encode the transaction send status of a TariTransactionSendStatus
/// Decode the transaction send status of a TariTransactionSendStatus
///
/// ## Arguments
/// `status` - The pointer to a TariTransactionSendStatus
Expand Down Expand Up @@ -5480,11 +5480,11 @@ pub unsafe extern "C" fn wallet_import_external_utxo_as_non_rewindable(
return 0;
}

if source_public_key.is_null() {
error = LibWalletError::from(InterfaceError::NullError("source_public_key".to_string())).code;
ptr::swap(error_out, &mut error as *mut c_int);
return 0;
}
let source_public_key = if source_public_key.is_null() {
TariPublicKey::default()
} else {
(*source_public_key).clone()
};

if metadata_signature.is_null() {
error = LibWalletError::from(InterfaceError::NullError("metadata_signature".to_string())).code;
Expand All @@ -5504,16 +5504,16 @@ pub unsafe extern "C" fn wallet_import_external_utxo_as_non_rewindable(
return 0;
}

if features.is_null() {
error = LibWalletError::from(InterfaceError::NullError("features".to_string())).code;
ptr::swap(error_out, &mut error as *mut c_int);
return 0;
}
let features = if features.is_null() {
TariOutputFeatures::default()
} else {
(*features).clone()
};

if covenant.is_null() {
error = LibWalletError::from(InterfaceError::NullError("covenant".to_string())).code;
ptr::swap(error_out, &mut error as *mut c_int);
return 0;
let covenant = if covenant.is_null() {
TariCovenant::default()
} else {
(*covenant).clone()
};

let message_string;
Expand Down Expand Up @@ -5552,14 +5552,14 @@ pub unsafe extern "C" fn wallet_import_external_utxo_as_non_rewindable(
&(*spending_key).clone(),
script!(Nop),
inputs!(public_script_key),
&(*source_public_key).clone(),
(*features).clone(),
&source_public_key,
features,
message_string,
(*metadata_signature).clone(),
&(*script_private_key).clone(),
&(*sender_offset_public_key).clone(),
0,
(*covenant).clone(),
covenant,
)) {
Ok(tx_id) => {
if let Err(e) = (*wallet)
Expand Down
13 changes: 13 additions & 0 deletions base_layer/wallet_ffi/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,19 @@ int pending_inbound_transaction_get_status(struct TariPendingInboundTransaction
// Frees memory for a TariPendingInboundTransaction
void pending_inbound_transaction_destroy(struct TariPendingInboundTransaction *transaction);

/// -------------------------------- Transport Send Status ------------------------------------------------------ ///

// Decode the transaction send status of a TariTransactionSendStatus
// !direct_send & !saf_send & queued = 0
// direct_send & saf_send & !queued = 1
// direct_send & !saf_send & !queued = 2
// !direct_send & saf_send & !queued = 3
// any other combination (is not valid) = 4
unsigned int fn transaction_send_status_decode(struct TariTransactionSendStatus *status, int *error_out);

// Frees memory for a TariTransactionSendStatus
void transaction_send_status_destroy(struct TariTransactionSendStatus *status);

/// -------------------------------- InboundTransactions ------------------------------------------------------ ///

// Gets the number of elements in a TariPendingInboundTransactions
Expand Down

0 comments on commit 83a6fd9

Please sign in to comment.