Skip to content

Commit

Permalink
Merge pull request #5 from iotaledger/add_mac_arm
Browse files Browse the repository at this point in the history
fix: release workflow, error handling, mac arm, listen_wallet
  • Loading branch information
lmoe authored Mar 11, 2024
2 parents c4133b6 + adcd7d3 commit dd3f997
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/bindings-native-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-13, ubuntu-20.04, windows-2022]
os: [macos-13, macos-13-xlarge, ubuntu-20.04, windows-2022]

steps:
- uses: actions/checkout@v3
Expand All @@ -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-xlarge'
with:
xcode-version: '14.3'

Expand All @@ -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-xlarge'

- 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-xlarge' || ${{ startsWith(matrix.os, 'ubuntu') }}

- name: Get current date
if: matrix.os == 'windows-2022'
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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",
Expand Down
33 changes: 21 additions & 12 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,34 @@ unsafe fn internal_listen_wallet(
events_ptr: *const c_char,
handler: extern "C" fn(*const c_char),
) -> Result<bool> {
log::debug!("ON LISTEN WALLET BEGIN");

let wallet = {
assert!(!wallet_ptr.is_null());
&mut *wallet_ptr
};

let events_string = CStr::from_ptr(events_ptr).to_str().unwrap();
let rust_events = serde_json::from_str::<Vec<String>>(events_string);
let rust_events = serde_json::from_str::<Vec<u8>>(events_string);

if rust_events.is_err() {
return Ok(false);
return Err(Error {error: rust_events.unwrap_err().to_string() });
}

let mut wallet_events: Vec<WalletEventType> = Vec::new();
for event in rust_events.unwrap() {
let event = match serde_json::from_str::<WalletEventType>(&event) {
Ok(event) => event,
let rust_events_unwrapped = rust_events.unwrap();
log::debug!("ON LISTEN WALLET");

let mut event_types: Vec<WalletEventType> = 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);
return Err(Error { error: e });
}
};
wallet_events.push(event);
}
}

crate::block_on(async {
Expand All @@ -143,13 +149,16 @@ 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();

log::debug!("Calling handler");

handler(s.into_raw())
}
})
.await
.await;
});

Ok(true)
Expand Down

0 comments on commit dd3f997

Please sign in to comment.