From 4bf183e4e8162b52f33045b98bf4c9279ee576e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=B6ller?= Date: Tue, 30 Jan 2024 14:41:55 +0100 Subject: [PATCH 1/5] Update SDK Version, point version to develop, fix listen_wallet --- Cargo.toml | 4 ++-- src/wallet.rs | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c1a490d..ce80e41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iota-sdk-native-bindings" -version = "0.1.0" +version = "0.1.1" authors = [ "IOTA Stiftung" ] edition = "2021" description = "Native wrapper for the IOTA SDK library" @@ -22,7 +22,7 @@ default = ["std"] std = ["zeroize/std"] [dependencies] -iota-sdk-bindings-core = { git = "https://github.com/iotaledger/iota-sdk.git", rev = "8f57f0c50f555b5e62f78ebf0177fc71b78f0396", default-features = false, features = [ +iota-sdk-bindings-core = { git = "https://github.com/iotaledger/iota-sdk.git", branch = "develop", default-features = false, features = [ "events", "rocksdb", "ledger_nano", diff --git a/src/wallet.rs b/src/wallet.rs index 53942ac..f3b6a53 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -118,22 +118,26 @@ unsafe fn internal_listen_wallet( }; let events_string = CStr::from_ptr(events_ptr).to_str().unwrap(); - let rust_events = serde_json::from_str::>(events_string); + let rust_events = serde_json::from_str::>(events_string); if rust_events.is_err() { return Ok(false); } - let mut wallet_events: Vec = Vec::new(); - for event in rust_events.unwrap() { - let event = match serde_json::from_str::(&event) { - Ok(event) => event, + let rust_events_unwrapped = rust_events.unwrap(); + + let mut event_types: Vec = Vec::with_capacity(rust_events_unwrapped.len()); + for event_id in rust_events_unwrapped { + let wallet_event_type = + WalletEventType::try_from(event_id); + + match wallet_event_type { + Ok(event) => event_types.push(event), Err(e) => { - debug!("Wrong event to listen! {e:?}"); - return Ok(false); + set_last_error(Error { error: e }); + false; } - }; - wallet_events.push(event); + } } crate::block_on(async { @@ -143,7 +147,7 @@ unsafe fn internal_listen_wallet( .await .as_ref() .expect("wallet got destroyed") - .listen(wallet_events, move |event_data| { + .listen(event_types, move |event_data| { if let Ok(event_str) = serde_json::to_string(event_data) { let s = CString::new(event_str).unwrap(); handler(s.into_raw()) From 9be72e78990594d6274557783df156b1f9f36388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=B6ller?= Date: Wed, 31 Jan 2024 16:44:23 +0100 Subject: [PATCH 2/5] Fix error handling --- src/wallet.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/wallet.rs b/src/wallet.rs index f3b6a53..d8bb4eb 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -112,6 +112,8 @@ unsafe fn internal_listen_wallet( events_ptr: *const c_char, handler: extern "C" fn(*const c_char), ) -> Result { + log::debug!("ON LISTEN WALLET BEGIN"); + let wallet = { assert!(!wallet_ptr.is_null()); &mut *wallet_ptr @@ -121,10 +123,11 @@ unsafe fn internal_listen_wallet( let rust_events = serde_json::from_str::>(events_string); if rust_events.is_err() { - return Ok(false); + return Err(Error {error: rust_events.unwrap_err().to_string() }); } let rust_events_unwrapped = rust_events.unwrap(); + log::debug!("ON LISTEN WALLET"); let mut event_types: Vec = Vec::with_capacity(rust_events_unwrapped.len()); for event_id in rust_events_unwrapped { @@ -134,8 +137,7 @@ unsafe fn internal_listen_wallet( match wallet_event_type { Ok(event) => event_types.push(event), Err(e) => { - set_last_error(Error { error: e }); - false; + return Err(Error { error: e }); } } } @@ -150,10 +152,13 @@ unsafe fn internal_listen_wallet( .listen(event_types, move |event_data| { if let Ok(event_str) = serde_json::to_string(event_data) { let s = CString::new(event_str).unwrap(); + + log::debug!("Calling handler"); + handler(s.into_raw()) } }) - .await + .await; }); Ok(true) From 78296f0557676b04e07ad44cd796324b7b2b1707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=B6ller?= Date: Tue, 20 Feb 2024 13:28:38 +0100 Subject: [PATCH 3/5] Add arm mac variant --- .github/workflows/bindings-native-publish.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bindings-native-publish.yml b/.github/workflows/bindings-native-publish.yml index 0001c74..52416a6 100644 --- a/.github/workflows/bindings-native-publish.yml +++ b/.github/workflows/bindings-native-publish.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-13, ubuntu-20.04, windows-2022] + os: [macos-13, macos-13-arm, ubuntu-20.04, windows-2022] steps: - uses: actions/checkout@v3 @@ -24,7 +24,7 @@ jobs: - name: Select Xcode uses: maxim-lobanov/setup-xcode@v1 - if: matrix.os == 'macos-13' + if: matrix.os == 'macos-13' || matrix.os == 'macos-13-arm' with: xcode-version: '14.3' @@ -47,11 +47,11 @@ jobs: - name: Set deployment target (macOS) run: echo "MACOSX_DEPLOYMENT_TARGET=10.14" >> $GITHUB_ENV - if: matrix.os == 'macos-13' + if: matrix.os == 'macos-13' || matrix.os == 'macos-13-arm' - name: Get current date run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV - if: matrix.os == 'macos-13' || ${{ startsWith(matrix.os, 'ubuntu') }} + if: matrix.os == 'macos-13' || matrix.os == 'macos-13-arm' || ${{ startsWith(matrix.os, 'ubuntu') }} - name: Get current date if: matrix.os == 'windows-2022' From a4f3079575c1dbaba0cf6aad2cc17d8b13feaf1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=B6ller?= Date: Tue, 20 Feb 2024 13:56:34 +0100 Subject: [PATCH 4/5] Set image to macos-13-xlarge --- .github/workflows/bindings-native-publish.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bindings-native-publish.yml b/.github/workflows/bindings-native-publish.yml index 52416a6..0140fdf 100644 --- a/.github/workflows/bindings-native-publish.yml +++ b/.github/workflows/bindings-native-publish.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-13, macos-13-arm, ubuntu-20.04, windows-2022] + os: [macos-13, macos-13-xlarge, ubuntu-20.04, windows-2022] steps: - uses: actions/checkout@v3 @@ -24,7 +24,7 @@ jobs: - name: Select Xcode uses: maxim-lobanov/setup-xcode@v1 - if: matrix.os == 'macos-13' || matrix.os == 'macos-13-arm' + if: matrix.os == 'macos-13' || matrix.os == 'macos-13-xlarge' with: xcode-version: '14.3' @@ -47,11 +47,11 @@ jobs: - name: Set deployment target (macOS) run: echo "MACOSX_DEPLOYMENT_TARGET=10.14" >> $GITHUB_ENV - if: matrix.os == 'macos-13' || matrix.os == 'macos-13-arm' + if: matrix.os == 'macos-13' || matrix.os == 'macos-13-xlarge' - name: Get current date run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV - if: matrix.os == 'macos-13' || matrix.os == 'macos-13-arm' || ${{ startsWith(matrix.os, 'ubuntu') }} + if: matrix.os == 'macos-13' || matrix.os == 'macos-13-xlarge' || ${{ startsWith(matrix.os, 'ubuntu') }} - name: Get current date if: matrix.os == 'windows-2022' From adcd7d3a772ffdfebdac8b86271afb669024a129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=B6ller?= Date: Tue, 20 Feb 2024 17:17:11 +0100 Subject: [PATCH 5/5] Add arch naming --- .github/workflows/bindings-native-publish.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bindings-native-publish.yml b/.github/workflows/bindings-native-publish.yml index 0140fdf..7a4bebf 100644 --- a/.github/workflows/bindings-native-publish.yml +++ b/.github/workflows/bindings-native-publish.yml @@ -94,6 +94,14 @@ jobs: - name: Cargo build run: cargo build --release + + - name: Rename file (MacOS/arm64) + run: mv target/release/libiota_sdk.dylib target/release/libiota_sdk_arm64.dylib + if: matrix.os == 'macos-13-xlarge' + + - name: Rename file (MacOS/amd64) + run: mv target/release/libiota_sdk.dylib target/release/libiota_sdk_amd64.dylib + if: matrix.os == 'macos-13' - name: Upload package to Github release uses: softprops/action-gh-release@v1 @@ -102,6 +110,8 @@ jobs: files: | target/release/libiota_sdk.so target/release/iota_sdk.dll - target/release/libiota_sdk.dylib + target/release/libiota_sdk_arm64.dylib + target/release/libiota_sdk_amd64.dylib + fail_on_unmatched_files: false tag_name: ${{ steps.prepare_release.outputs.tag_name }} \ No newline at end of file