Skip to content

Commit

Permalink
update all ffi interfaces, re-organize tests, cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Oct 24, 2021
1 parent 2d58760 commit 416145b
Show file tree
Hide file tree
Showing 22 changed files with 1,870 additions and 7,330 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

22 changes: 10 additions & 12 deletions applications/ffi_client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ try {
let err = ref.alloc(i32);
// console.log(err);

let recoveryInProgress = ref.alloc(bool);

console.log("Create Tor transport...");
let tor = lib.transport_tor_create(
"/ip4/127.0.0.1/tcp/9051",
Expand Down Expand Up @@ -79,17 +81,13 @@ try {
const txCancelled = ffi.Callback("void", ["pointer"], function (ptr) {
console.log("txCancelled: ", ptr);
});
// callback_utxo_validation_complete: unsafe extern "C" fn(u64, u8),
const utxoValidation = ffi.Callback("void", [u64, u8], function (i, j) {
// callback_txo_validation_complete: unsafe extern "C" fn(u64, u8),
const txoValidation = ffi.Callback("void", [u64, u8], function (i, j) {
console.log("utxoValidation: ", i, j);
});
// callback_stxo_validation_complete: unsafe extern "C" fn(u64, u8),
const stxoValidation = ffi.Callback("void", [u64, u8], function (i, j) {
console.log("stxoValidation: ", i, j);
});
// callback_invalid_txo_validation_complete: unsafe extern "C" fn(u64, u8),
const itxoValidation = ffi.Callback("void", [u64, u8], function (i, j) {
console.log("itxoValidation: ", i, j);
// callback_balance_updated: unsafe extern "C" fn(*mut Balance),
const balanceUpdated = ffi.Callback("void", ["pointer"], function (ptr) {
console.log("balanceUpdated: ", ptr);
});
// callback_transaction_validation_complete: unsafe extern "C" fn(u64, u8),
const txValidation = ffi.Callback("void", [u64, u8], function (i, j) {
Expand Down Expand Up @@ -117,11 +115,11 @@ try {
directSendResult,
safResult,
txCancelled,
utxoValidation,
stxoValidation,
itxoValidation,
txoValidation,
balanceUpdated,
txValidation,
safsReceived,
recoveryInProgress,
err
);

Expand Down
6 changes: 3 additions & 3 deletions base_layer/wallet_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "tari_wallet_ffi"
authors = ["The Tari Development Community"]
description = "Tari cryptocurrency wallet C FFI bindings"
license = "BSD-3-Clause"
version = "0.19.0"
version = "0.20.0"
edition = "2018"

[dependencies]
Expand All @@ -16,7 +16,6 @@ tari_p2p = { version = "^0.11", path = "../p2p" }
tari_wallet = { version = "^0.11", path = "../wallet", features = ["c_integration"]}
tari_shutdown = { version = "^0.11", path = "../../infrastructure/shutdown" }
tari_utilities = "^0.3"
tari_service_framework = { path = "../../base_layer/service_framework" }

chrono = { version = "0.4.6", features = ["serde"]}
futures = { version = "^0.3.1", features =["compat", "std"]}
Expand Down Expand Up @@ -44,7 +43,7 @@ default-features = false
features = ["transactions"]

[lib]
crate-type = ["staticlib","cdylib", "lib"]
crate-type = ["staticlib","cdylib"]

[dev-dependencies]
tempfile = "3.1.0"
Expand All @@ -53,3 +52,4 @@ env_logger = "0.7.1"
tari_key_manager = { version = "^0.11", path = "../key_manager" }
tari_common_types = { version = "^0.11", path = "../../base_layer/common_types"}
tari_test_utils = { version = "^0.11", path = "../../infrastructure/test_utils"}
tari_service_framework = { path = "../../base_layer/service_framework" }
27 changes: 4 additions & 23 deletions base_layer/wallet_ffi/src/callback_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
//! and false that the process timed out and new one will be started
use log::*;
use std::sync::{Arc, Mutex};
use tari_common_types::transaction::TxId;
use tari_comms::types::CommsPublicKey;
use tari_comms_dht::event::{DhtEvent, DhtEventReceiver};
Expand All @@ -70,23 +69,6 @@ use tari_wallet::{

const LOG_TARGET: &str = "wallet::transaction_service::callback_handler";

/// This macro unlocks a Mutex or RwLock. If the lock is poisoned (i.e. panic while unlocked) the last value
/// before the panic is used.
macro_rules! acquire_lock {
($e:expr, $m:ident) => {
match $e.$m() {
Ok(lock) => lock,
Err(poisoned) => {
log::warn!(target: "wallet", "Lock has been POISONED and will be silently recovered");
poisoned.into_inner()
},
}
};
($e:expr) => {
acquire_lock!($e, lock)
};
}

#[derive(Clone, Copy)]
enum CallbackValidationResults {
Success, // 0
Expand Down Expand Up @@ -118,7 +100,7 @@ where TBackend: TransactionBackend + 'static
dht_event_stream: DhtEventReceiver,
shutdown_signal: Option<ShutdownSignal>,
comms_public_key: CommsPublicKey,
balance_cache: Arc<Mutex<Balance>>,
balance_cache: Balance,
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -221,7 +203,7 @@ where TBackend: TransactionBackend + 'static
dht_event_stream,
shutdown_signal: Some(shutdown_signal),
comms_public_key,
balance_cache: Arc::new(Mutex::new(Balance::zero())),
balance_cache: Balance::zero(),
}
}

Expand Down Expand Up @@ -400,9 +382,8 @@ where TBackend: TransactionBackend + 'static
async fn trigger_balance_refresh(&mut self) {
match self.output_manager_service.get_balance().await {
Ok(balance) => {
let mut cached_balance = acquire_lock!(self.balance_cache);
if balance != (*cached_balance).clone() {
*cached_balance = balance.clone();
if balance != self.balance_cache {
self.balance_cache = balance.clone();
debug!(
target: LOG_TARGET,
"Calling Update Balance callback function: available {}, time locked {:?}, incoming {}, \
Expand Down
Loading

0 comments on commit 416145b

Please sign in to comment.