Skip to content

Commit

Permalink
feat(wallet-ffi)!: add features, metadata_signature and sender_offset…
Browse files Browse the repository at this point in the history
…_public_key to import_utxo
  • Loading branch information
sdbondi committed Jan 28, 2022
1 parent caa2837 commit bea1748
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
36 changes: 28 additions & 8 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,9 +181,11 @@ 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 struct TariContacts(Vec<TariContact>);
Expand Down Expand Up @@ -4811,10 +4813,12 @@ 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,
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. */
// TODO: Update this interface to add the script private key
) -> c_ulonglong {
let mut error = 0;
ptr::swap(error_out, &mut error as *mut c_int);
Expand All @@ -4836,6 +4840,22 @@ 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 features.is_null() {
*features = OutputFeatures::with_maturity(0);
}

let message_string;
if !message.is_null() {
match CStr::from_ptr(message).to_str() {
Expand Down Expand Up @@ -4870,11 +4890,11 @@ 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(),
)) {
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
9 changes: 9 additions & 0 deletions integration_tests/helpers/ffi/ffiInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ class InterfaceFFI {
this.ulonglong,
this.ptr,
this.ptr,
this.ptr,
this.ptr,
this.ptr,
this.string,
this.intPtr,
],
Expand Down Expand Up @@ -1440,6 +1443,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 +1454,9 @@ class InterfaceFFI {
amount,
spending_key_ptr,
source_public_key_ptr,
features_ptr,
metadata_signature_ptr,
sender_offset_public_key_ptr,
message,
error
);
Expand Down

0 comments on commit bea1748

Please sign in to comment.