Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ffi)!: add features, metadata_signature and sender_offset_public_key to import_utxo #3767

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ use rand::rngs::OsRng;
use tari_common_types::{
emoji::{emoji_set, EmojiId, EmojiIdError},
transaction::{TransactionDirection, TransactionStatus, TxId},
types::{ComSignature, PublicKey},
types::PublicKey,
};
use tari_comms::{
multiaddr::Multiaddr,
Expand Down Expand Up @@ -181,10 +181,13 @@ mod tasks;
const LOG_TARGET: &str = "wallet_ffi";

pub type TariTransportType = tari_p2p::transport::TransportType;
pub type TariPublicKey = tari_comms::types::CommsPublicKey;
pub type TariPrivateKey = tari_comms::types::CommsSecretKey;
pub type TariPublicKey = tari_common_types::types::PublicKey;
pub type TariPrivateKey = tari_common_types::types::PrivateKey;
pub type TariOutputFeatures = tari_core::transactions::transaction::OutputFeatures;
pub type TariCommsConfig = tari_p2p::initialization::P2pConfig;
pub type TariCommitmentSignature = tari_common_types::types::ComSignature;
pub type TariTransactionKernel = tari_core::transactions::transaction::TransactionKernel;
pub type TariCovenant = tari_core::covenants::Covenant;

pub struct TariContacts(Vec<TariContact>);

Expand Down Expand Up @@ -4811,10 +4814,13 @@ pub unsafe extern "C" fn wallet_import_utxo(
amount: c_ulonglong,
spending_key: *mut TariPrivateKey,
source_public_key: *mut TariPublicKey,
features: *mut TariOutputFeatures,
metadata_signature: *mut TariCommitmentSignature,
sender_offset_public_key: *mut TariPublicKey,
script_private_key: *mut TariPrivateKey,
covenant: *mut TariCovenant,
message: *const c_char,
error_out: *mut c_int,
/* TODO: Update this interface to add the metadata signature, script private key and script offset public keys
* here. */
) -> c_ulonglong {
let mut error = 0;
ptr::swap(error_out, &mut error as *mut c_int);
Expand All @@ -4836,6 +4842,31 @@ pub unsafe extern "C" fn wallet_import_utxo(
return 0;
}

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

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

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

if features.is_null() {
*features = OutputFeatures::with_maturity(0);
}
sdbondi marked this conversation as resolved.
Show resolved Hide resolved
if covenant.is_null() {
*covenant = Covenant::default();
}

let message_string;
if !message.is_null() {
match CStr::from_ptr(message).to_str() {
Expand Down Expand Up @@ -4870,13 +4901,13 @@ pub unsafe extern "C" fn wallet_import_utxo(
script!(Nop),
inputs!(public_script_key),
&(*source_public_key).clone(),
OutputFeatures::default(),
(*features).clone(),
message_string,
ComSignature::default(),
(*metadata_signature).clone(),
&(*spending_key).clone(),
&Default::default(),
&(*sender_offset_public_key).clone(),
0,
Covenant::default(),
(*covenant).clone(),
)) {
Ok(tx_id) => {
if let Err(e) = (*wallet)
Expand Down
16 changes: 15 additions & 1 deletion base_layer/wallet_ffi/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ struct TariPublicKey;

struct TariPublicKeys;

struct TariCommitmentSignature;

struct TariOutputFeatures;

struct TariContacts;

struct TariContact;
Expand Down Expand Up @@ -573,7 +577,17 @@ struct TariCompletedTransaction *wallet_get_cancelled_transaction_by_id(struct T

// Import a UTXO into the wallet. This will add a spendable UTXO and create a faux completed transaction to record the
// event.
unsigned long long wallet_import_utxo(struct TariWallet *wallet, unsigned long long amount, struct TariPrivateKey *spending_key, struct TariPublicKey *source_public_key, const char *message, int *error_out);
unsigned long long wallet_import_utxo(
struct TariWallet *wallet,
unsigned long long amount,
struct TariPrivateKey *spending_key,
struct TariPublicKey *source_public_key,
struct TariOutputFeatures *features,
struct TariCommitmentSignature *metadata_signature,
struct TariPublicKey *sender_offset_public_key,
const char *message,
int *error_out
);

// This function will tell the wallet to query the set base node to confirm the status of unspent transaction outputs (UTXOs).
unsigned long long wallet_start_txo_validation(struct TariWallet *wallet, int *error_out);
Expand Down
15 changes: 15 additions & 0 deletions integration_tests/helpers/ffi/ffiInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ class InterfaceFFI {
this.ulonglong,
this.ptr,
this.ptr,
this.ptr,
this.ptr,
this.ptr,
this.ptr,
this.ptr,
this.string,
this.intPtr,
],
Expand Down Expand Up @@ -1440,6 +1445,9 @@ class InterfaceFFI {
amount,
spending_key_ptr,
source_public_key_ptr,
features_ptr,
metadata_signature_ptr,
sender_offset_public_key_ptr,
message
) {
let error = this.initError();
Expand All @@ -1448,6 +1456,13 @@ class InterfaceFFI {
amount,
spending_key_ptr,
source_public_key_ptr,
features_ptr,
metadata_signature_ptr,
sender_offset_public_key_ptr,
// script_private_key
spending_key_ptr,
// default Covenant
null,
message,
error
);
Expand Down