Skip to content

Commit c8b4c06

Browse files
Merge branch 'feat/more-bindings' into feat/more-uniffi-impls
2 parents 12497ec + 9000944 commit c8b4c06

File tree

12 files changed

+77
-58
lines changed

12 files changed

+77
-58
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ name: CI
22

33
on:
44
push:
5-
branches: [main]
5+
branches: [develop]
66
pull_request:
77
types: [opened, synchronize, reopened, ready_for_review]
88
workflow_dispatch:
99
schedule: [cron: "40 1 * * *"]
1010

11+
concurrency:
12+
group: ci-${{ github.event.pull_request.number || github.ref }}
13+
cancel-in-progress: ${{ github.ref != 'refs/heads/develop' }}
14+
1115
permissions:
1216
contents: read
1317

crates/iota-graphql-client/src/pagination.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use crate::query_types::PageInfo;
55

6-
#[derive(Clone, Debug)]
76
/// A page of items returned by the GraphQL server.
7+
#[derive(Clone, Debug)]
88
pub struct Page<T> {
99
/// Information about the page, such as the cursor and whether there are
1010
/// more pages.

crates/iota-graphql-client/src/query_types/object.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// Modifications Copyright (c) 2025 IOTA Stiftung
33
// SPDX-License-Identifier: Apache-2.0
44

5-
use iota_types::ObjectId;
6-
7-
use crate::query_types::{Address, Base64, MoveObjectContents, PageInfo, schema};
5+
use crate::query_types::{Address, Base64, MoveObjectContents, ObjectId, PageInfo, schema};
86

97
// ===========================================================================
108
// Object(s) Queries

crates/iota-sdk-ffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ crate-type = ["lib", "cdylib"]
1515
base64ct = { version = "1.6.0", features = ["alloc", "std"] }
1616
derive_more = { version = "2.0", features = ["from", "deref"] }
1717
rand = "0.8"
18-
serde_json = { version = "1.0.95" }
18+
serde_json = "1.0.95"
1919
tokio = { version = "1.36.0", features = ["time"] }
2020
uniffi = { version = "0.29", features = ["cli", "tokio"] }
2121

crates/iota-sdk-ffi/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# IOTA SDK Bindings
1+
# IOTA SDK FFI
22

33
This crate can generate bindings for various languages (Go, Kotlin, Python, etc.) using [UniFFI](https://github.com/mozilla/uniffi-rs).
44

crates/iota-sdk-ffi/src/error.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use std::fmt;
55

66
use uniffi::Error;
77

8-
pub type Result<T, E = BindingsSdkError> = std::result::Result<T, E>;
8+
pub type Result<T, E = SdkFfiError> = std::result::Result<T, E>;
99

1010
#[derive(Debug, Error)]
1111
#[uniffi(flat_error)]
12-
pub enum BindingsSdkError {
12+
pub enum SdkFfiError {
1313
Generic(String),
1414
}
1515

16-
impl BindingsSdkError {
16+
impl SdkFfiError {
1717
pub fn new<E: std::error::Error>(err: E) -> Self {
1818
Self::Generic(err.to_string())
1919
}
@@ -23,16 +23,16 @@ impl BindingsSdkError {
2323
}
2424
}
2525

26-
impl fmt::Display for BindingsSdkError {
26+
impl fmt::Display for SdkFfiError {
2727
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2828
match self {
2929
Self::Generic(e) => write!(f, "{e}"),
3030
}
3131
}
3232
}
3333

34-
impl<E: std::error::Error> From<E> for BindingsSdkError {
35-
fn from(e: E) -> BindingsSdkError {
34+
impl<E: std::error::Error> From<E> for SdkFfiError {
35+
fn from(e: E) -> SdkFfiError {
3636
Self::new(e)
3737
}
3838
}

crates/iota-sdk-ffi/src/faucet.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::sync::Arc;
55

66
use crate::{
7-
error::{BindingsSdkError, Result},
7+
error::{Result, SdkFfiError},
88
types::address::Address,
99
};
1010

@@ -47,10 +47,7 @@ impl FaucetClient {
4747
/// request and not wait until the token is received. Use
4848
/// `request_and_wait` to wait for the token.
4949
pub async fn request(&self, address: &Address) -> Result<Option<String>> {
50-
self.0
51-
.request(**address)
52-
.await
53-
.map_err(BindingsSdkError::custom)
50+
self.0.request(**address).await.map_err(SdkFfiError::custom)
5451
}
5552

5653
/// Request gas from the faucet and wait until the request is completed and
@@ -65,7 +62,7 @@ impl FaucetClient {
6562
.0
6663
.request_and_wait(**address)
6764
.await
68-
.map_err(BindingsSdkError::custom)?
65+
.map_err(SdkFfiError::custom)?
6966
.map(Into::into)
7067
.map(Arc::new))
7168
}
@@ -78,7 +75,7 @@ impl FaucetClient {
7875
.0
7976
.request_status(id)
8077
.await
81-
.map_err(BindingsSdkError::custom)?
78+
.map_err(SdkFfiError::custom)?
8279
.map(Into::into)
8380
.map(Arc::new))
8481
}

crates/iota-sdk-types/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test:
1818
# --all-features
1919
.PHONY: wasm
2020
wasm:
21-
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' CC=clang wasm-pack test --node --all-features
21+
CC=clang wasm-pack test -r --node --all-features
2222

2323
%:
2424
$(MAKE) -C ../.. $@

crates/iota-sdk-types/src/lib.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ macro_rules! def_is {
196196
}
197197

198198
#[macro_export]
199-
macro_rules! def_is_as_opt {
199+
macro_rules! def_is_as_into_opt {
200200
($($variant:ident => $inner:ty),* $(,)?) => {
201201
paste::paste! {$(
202202
#[inline]
@@ -206,10 +206,7 @@ macro_rules! def_is_as_opt {
206206

207207
#[inline]
208208
pub fn [< as_ $variant:snake >](&self) -> &$inner {
209-
let Self::$variant(inner) = self else {
210-
panic!("not a {}", stringify!($variant));
211-
};
212-
inner
209+
self.[< as_ $variant:snake _opt >]().expect(&format!("not a {}", stringify!($variant)))
213210
}
214211

215212
#[inline]
@@ -221,17 +218,23 @@ macro_rules! def_is_as_opt {
221218
}
222219
}
223220

221+
#[inline]
222+
pub fn [< into_ $variant:snake _opt >](self) -> Option<$inner> {
223+
if let Self::$variant(inner) = self {
224+
Some(inner)
225+
} else {
226+
None
227+
}
228+
}
229+
224230
#[inline]
225231
pub fn [< into_ $variant:snake >](self) -> $inner {
226-
let Self::$variant(inner) = self else {
227-
panic!("not a {}", stringify!($variant));
228-
};
229-
inner
232+
self.[< into_ $variant:snake _opt >]().expect(&format!("not a {}", stringify!($variant)))
230233
}
231234
)*}
232235
};
233236
($($variant:ident),* $(,)?) => {
234-
$crate::def_is_as_opt!{$($variant => $variant,)*}
237+
$crate::def_is_as_into_opt!{$($variant => $variant,)*}
235238
};
236239
}
237240

crates/iota-sdk-types/src/object.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub enum ObjectData {
145145
}
146146

147147
impl ObjectData {
148-
crate::def_is_as_opt!(Struct => MoveStruct, Package => MovePackage);
148+
crate::def_is_as_into_opt!(Struct => MoveStruct, Package => MovePackage);
149149
}
150150

151151
/// A move package
@@ -292,7 +292,6 @@ pub struct MoveStruct {
292292
serde(with = "::serde_with::As::<serialization::BinaryMoveStructType>")
293293
)]
294294
pub type_: StructTag,
295-
296295
/// Number that increases each time a tx takes this object as a mutable
297296
/// input This is a lamport timestamp, not a sequentially increasing
298297
/// version
@@ -319,7 +318,7 @@ pub enum ObjectType {
319318
impl ObjectType {
320319
crate::def_is!(Package);
321320

322-
crate::def_is_as_opt!(Struct => StructTag);
321+
crate::def_is_as_into_opt!(Struct => StructTag);
323322
}
324323

325324
/// An object on the IOTA blockchain

0 commit comments

Comments
 (0)