Skip to content

Commit

Permalink
feat: wallet FFI cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
Cifko committed Jan 16, 2023
1 parent 2bfb182 commit 795e717
Show file tree
Hide file tree
Showing 38 changed files with 4,591 additions and 343 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4717,6 +4717,65 @@ pub unsafe extern "C" fn comms_list_connected_public_keys(
}
}

/// Gets the length of the public keys vector
///
/// ## Arguments
/// `public_keys` - Pointer to TariPublicKeys
///
/// ## Returns
/// `c_uint` - Length of the TariPublicKeys vector, 0 if is null
///
/// # Safety
/// None
#[no_mangle]
pub unsafe extern "C" fn public_keys_get_length(public_keys: *const TariPublicKeys, error_out: *mut c_int) -> c_uint {
let mut error = 0;
ptr::swap(error_out, &mut error as *mut c_int);
if public_keys.is_null() {
error = LibWalletError::from(InterfaceError::NullError("public_keys".to_string())).code;
ptr::swap(error_out, &mut error as *mut c_int);
return 0;
}
(*public_keys).0.len() as c_uint
}

/// Gets a ByteVector at position in a EmojiSet
///
/// ## Arguments
/// `public_keys` - The pointer to a TariPublicKeys
/// `position` - The integer position
/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
/// as an out parameter.
///
/// ## Returns
/// `ByteVector` - Returns a ByteVector. Note that the ByteVector will be null if ptr
/// is null or if the position is invalid
///
/// # Safety
/// The ```byte_vector_destroy``` function must be called when finished with the ByteVector to prevent a memory leak.
#[no_mangle]
pub unsafe extern "C" fn public_keys_get_at(
public_keys: *const TariPublicKeys,
position: c_uint,
error_out: *mut c_int,
) -> *mut TariPublicKey {
let mut error = 0;
ptr::swap(error_out, &mut error as *mut c_int);
if public_keys.is_null() {
error = LibWalletError::from(InterfaceError::NullError("public_keys".to_string())).code;
ptr::swap(error_out, &mut error as *mut c_int);
return ptr::null_mut();
}
let last_index = public_keys_get_length(public_keys, error_out) - 1;
if position > last_index {
error = LibWalletError::from(InterfaceError::PositionInvalidError).code;
ptr::swap(error_out, &mut error as *mut c_int);
return ptr::null_mut();
}
let result = (*public_keys).0[position as usize].clone();
Box::into_raw(Box::new(result))
}

/// ---------------------------------------------------------------------------------------------- ///

/// ------------------------------------- Wallet -------------------------------------------------///
Expand Down
34 changes: 34 additions & 0 deletions base_layer/wallet_ffi/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2473,6 +2473,40 @@ void comms_config_destroy(TariCommsConfig *wc);
struct TariPublicKeys *comms_list_connected_public_keys(struct TariWallet *wallet,
int *error_out);

/**
* Gets the length of the public keys vector
*
* ## Arguments
* `public_keys` - Pointer to TariPublicKeys
*
* ## Returns
* `c_uint` - Length of the TariPublicKeys vector, 0 if is null
*
* # Safety
* None
*/
unsigned int public_keys_get_length(const struct TariPublicKeys *public_keys, int *error_out);

/**
* Gets a ByteVector at position in a EmojiSet
*
* ## Arguments
* `public_keys` - The pointer to a TariPublicKeys
* `position` - The integer position
* `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
* as an out parameter.
*
* ## Returns
* `ByteVector` - Returns a ByteVector. Note that the ByteVector will be null if ptr
* is null or if the position is invalid
*
* # Safety
* The ```byte_vector_destroy``` function must be called when finished with the ByteVector to prevent a memory leak.
*/
TariPublicKey *public_keys_get_at(const struct TariPublicKeys *public_keys,
unsigned int position,
int *error_out);

/**
* Creates a TariWallet
*
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tari_test_utils = { path = "../infrastructure/test_utils" }
tari_base_node = { path = "../applications/tari_base_node" }
tari_console_wallet = { path = "../applications/tari_console_wallet" }
tari_wallet = { path = "../base_layer/wallet" }
tari_wallet_ffi = { path = "../base_layer/wallet_ffi" }
tari_common_types = { path = "../base_layer/common_types" }
tari_script = { path = "../infrastructure/tari_script" }
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.10"}
Expand All @@ -42,6 +43,7 @@ diesel = { version = "1.4.8", default-features = false, features = ["sqlite"] }
futures = { version = "^0.3.1" }
json5 = "0.2.2"
include_dir = "0.7.2"
libc = "0.2.65"
log = { version = "0.4.8", features = ["std"] }
log4rs = { version = "1.1.1", features = ["rolling_file_appender", "compound_policy", "size_trigger", "fixed_window_roller"] }
lmdb-zero = "0.4.4"
Expand Down
Loading

0 comments on commit 795e717

Please sign in to comment.