Skip to content

Commit

Permalink
feat(wallet_ffi)!: add get_balance callback to wallet ffi (#3475)
Browse files Browse the repository at this point in the history
Description
---
- Added get_balance callback to the wallet ffi callback handler that fires only if the balance has actually changed.
- Expanded the wallet ffi callback handler test framework to include a mock output manager request-response server.
- _**Update:** Added required methods and interfaces to the cucumber test framework._
- _**Update:** Fixed flaky wallet FFI cucumber tests._
- _**Update:** Fixed a bug in the wallet FFI cucumber test framework where the return type of `ref.types.ulonglong` did not correspond to the Rust return type and had a memory alignment problem._
- _**Update:** Fixed an issue whereby on a fast 8-core multi-tasking computer (e.g. AMD Ryzen 7 2700X) some of the wallet FFI cucumber tests did not complete properly after the test and went into an endless wait. The root cause of this issue has been traced down to incorrect use of synchronous calls to wallet FFI destroy methods where in actual fact those methods have async behaviour._
- _**Update:** Re-applied #3271._

~~The following anomaly exists when compiling the proposed `wallet_ffi/tests` module:~~
```
24 | use tari_wallet_ffi::callback_handler::CallbackHandler;
   |     ^^^^^^^^^^^^^^^ use of undeclared crate or module `tari_wallet_ffi`
```

_**Update**_ ~~Various code organizations have been tried, all with the same result. As an alternative, a working test and output manager service mock has been added into the test module in `callback_handler.rs`. Hopefully, the anomaly can be fixed. Duplicate code will be removed before the final commit.~~

Motivation and Context
---
- Mobile wallet efficiency.
- Resilient wallet FFI cucumber tests.

How Has This Been Tested?
---
- Expanded the current FFI `test_callback_handler` unit test.
- _**Update:** Ran all the wallet FFI cucumber tests to verify the new callback is working properly when using the wallet FFI library:_ 

```
2021-10-21T06:29:32.160Z callbackTransactionValidationComplete(9123501482775375388,0)
2021-10-21T06:29:32.161Z callbackBalanceUpdated: available = 0,  time locked = 0  pending incoming = 2000000 pending outgoing = 0
2021-10-21T06:29:32.263Z received Transaction with txID 14659183447022727953

...

2021-10-21T06:31:38.358Z Transaction with txID 14659183447022727953 was mined.
2021-10-21T06:31:38.358Z callbackBalanceUpdated: available = 2000000,  time locked = 2000000  pending incoming = 0 pending outgoing = 0
2021-10-21T06:31:38.359Z callbackTransactionValidationComplete(17755253868227079780,0)
```
  • Loading branch information
hansieodendaal authored Oct 28, 2021
1 parent c04fca5 commit 930860d
Show file tree
Hide file tree
Showing 20 changed files with 1,811 additions and 2,977 deletions.
1 change: 1 addition & 0 deletions 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
1 change: 1 addition & 0 deletions base_layer/wallet_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,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" }
468 changes: 60 additions & 408 deletions base_layer/wallet_ffi/src/callback_handler.rs

Large diffs are not rendered by default.

Loading

0 comments on commit 930860d

Please sign in to comment.