Skip to content

Commit c679199

Browse files
feat(bindings): Remove uniffi impls from core crates and use object wrappers (#47)
* wrap address * Add more impls * even more * more!!! * fix name value impl * MOREEEE * revert error changes * cleanup * Remove uniffi features * update python bindings * nit * add object IDs to schema * add gas implt * record impl
1 parent f3fef42 commit c679199

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+12427
-24051
lines changed

bindings/python/lib/iota_graphql_client.py

Lines changed: 0 additions & 5911 deletions
This file was deleted.

bindings/python/lib/iota_sdk_ffi.py

Lines changed: 10932 additions & 3846 deletions
Large diffs are not rendered by default.

bindings/python/lib/iota_sdk_types.py

Lines changed: 0 additions & 13539 deletions
This file was deleted.

bindings/python/test.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
from lib.iota_graphql_client import Direction
2-
from lib.iota_sdk_ffi import GraphQlClient, PaginationFilter
3-
from lib.iota_sdk_types import address_from_hex, ObjectReference
1+
from lib.iota_sdk_ffi import GraphQlClient, PaginationFilter, Address, Direction, TransactionsFilter, ObjectId, EventFilter
42
import asyncio
53

64
async def main():
75
client = GraphQlClient.new_devnet()
86
chain_id = await client.chain_id()
97
print(chain_id)
10-
11-
my_address=address_from_hex("0xda06e01d11c8d3ef8f8e238c2f144076fdc6832378fb48b153d57027ae868b39")
8+
9+
my_address=Address.from_hex("0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f")
1210

1311
coins = await client.coins(
1412
my_address,
15-
PaginationFilter(direction=Direction.FORWARD, cursor=None, limit=None)
13+
PaginationFilter(direction=Direction.forward(), cursor=None, limit=None)
1614
)
17-
my_coins = []
1815
for coin in coins.data():
19-
print(f'ID = 0x{coin.id.hex()} Balance = {coin.balance}')
16+
print(f'ID = 0x{coin.id().to_hex()} Balance = {coin.balance()}')
2017

2118
balance = await client.balance(my_address)
2219

2320
print(f'Total Balance = {balance}')
2421

22+
filter=TransactionsFilter().at_checkpoint(3).input_object(ObjectId.from_hex("0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f"))
23+
24+
filter=EventFilter(sender=my_address)
25+
2526

2627
if __name__ == '__main__':
2728
asyncio.run(main())

crates/iota-graphql-client-build/schema.graphql

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ input CheckpointId {
500500
Some 0x2::coin::Coin Move object.
501501
"""
502502
type Coin implements IMoveObject & IObject & IOwner {
503-
address: IotaAddress!
503+
objectId: ObjectId!
504504
"""
505505
Objects owned by this object, optionally `filter`-ed.
506506
"""
@@ -678,7 +678,7 @@ type CoinEdge {
678678
The metadata for a coin type.
679679
"""
680680
type CoinMetadata implements IMoveObject & IObject & IOwner {
681-
address: IotaAddress!
681+
objectId: ObjectId!
682682
"""
683683
Objects owned by this object, optionally `filter`-ed.
684684
"""
@@ -1646,11 +1646,11 @@ type Linkage {
16461646
"""
16471647
The ID on-chain of the first version of the dependency.
16481648
"""
1649-
originalId: IotaAddress!
1649+
originalId: ObjectId!
16501650
"""
16511651
The ID on-chain of the version of the dependency that this package depends on.
16521652
"""
1653-
upgradedId: IotaAddress!
1653+
upgradedId: ObjectId!
16541654
"""
16551655
The version of the dependency that this package depends on.
16561656
"""
@@ -1742,8 +1742,8 @@ The contents of a Move Value, corresponding to the following recursive type:
17421742
17431743
type MoveData =
17441744
{ Address: IotaAddress }
1745-
| { UID: IotaAddress }
1746-
| { ID: IotaAddress }
1745+
| { UID: ObjectId }
1746+
| { ID: ObjectId }
17471747
| { Bool: bool }
17481748
| { Number: BigInt }
17491749
| { String: string }
@@ -2048,7 +2048,7 @@ The representation of an object as a Move Object, which exposes additional infor
20482048
(content, module that governs it, version, is transferrable, etc.) about this object.
20492049
"""
20502050
type MoveObject implements IMoveObject & IObject & IOwner {
2051-
address: IotaAddress!
2051+
objectId: ObjectId!
20522052
"""
20532053
Objects owned by this object, optionally `filter`-ed.
20542054
"""
@@ -2658,7 +2658,7 @@ with fields) with additional metadata detailing its id, version, transaction dig
26582658
field indicating how this object can be accessed.
26592659
"""
26602660
type Object implements IObject & IOwner {
2661-
address: IotaAddress!
2661+
objectId: ObjectId!
26622662
"""
26632663
Objects owned by this object, optionally `filter`-ed.
26642664
"""
@@ -2796,7 +2796,7 @@ type ObjectChange {
27962796
"""
27972797
The address of the object that has changed.
27982798
"""
2799-
address: IotaAddress!
2799+
objectId: ObjectId!
28002800
"""
28012801
The contents of the object immediately before the transaction.
28022802
"""
@@ -2897,11 +2897,11 @@ input ObjectFilter {
28972897
"""
28982898
Filter for live objects by their IDs.
28992899
"""
2900-
objectIds: [IotaAddress!]
2900+
objectIds: [ObjectId!]
29012901
}
29022902

29032903
input ObjectKey {
2904-
objectId: IotaAddress!
2904+
objectId: ObjectId!
29052905
version: UInt53!
29062906
}
29072907

@@ -2926,7 +2926,7 @@ input ObjectRef {
29262926
"""
29272927
ID of the object.
29282928
"""
2929-
address: IotaAddress!
2929+
objectId: ObjectId!
29302930
"""
29312931
Version or sequence number of the object.
29322932
"""
@@ -2984,7 +2984,7 @@ type OwnedOrImmutable {
29842984
"""
29852985
ID of the object being read.
29862986
"""
2987-
address: IotaAddress!
2987+
objectId: ObjectId!
29882988
"""
29892989
Version of the object being read.
29902990
"""
@@ -3277,7 +3277,7 @@ type Query {
32773277
The object corresponding to the given address at the (optionally) given version.
32783278
When no version is given, the latest version is returned.
32793279
"""
3280-
object(address: IotaAddress!, version: UInt53): Object
3280+
object(objectId: ObjectId!, version: UInt53): Object
32813281
"""
32823282
The package corresponding to the given address (at the optionally given version).
32833283
@@ -3457,7 +3457,7 @@ type Receiving {
34573457
"""
34583458
ID of the object being read.
34593459
"""
3460-
address: IotaAddress!
3460+
objectId: ObjectId!
34613461
"""
34623462
Version of the object being read.
34633463
"""
@@ -3620,7 +3620,7 @@ type Shared {
36203620
A Move object that's shared.
36213621
"""
36223622
type SharedInput {
3623-
address: IotaAddress!
3623+
objectId: ObjectId!
36243624
"""
36253625
The version that this this object was shared at.
36263626
"""
@@ -3642,7 +3642,7 @@ type SharedObjectCancelled {
36423642
"""
36433643
ID of the shared object.
36443644
"""
3645-
address: IotaAddress!
3645+
objectId: ObjectId!
36463646
"""
36473647
The assigned shared object version. It is a special version indicating transaction cancellation reason.
36483648
"""
@@ -3657,7 +3657,7 @@ type SharedObjectDelete {
36573657
"""
36583658
ID of the shared object.
36593659
"""
3660-
address: IotaAddress!
3660+
objectId: ObjectId!
36613661
"""
36623662
The version of the shared object that was assigned to this transaction during by consensus,
36633663
during sequencing.
@@ -3677,7 +3677,7 @@ type SharedObjectRead {
36773677
"""
36783678
ID of the object being read.
36793679
"""
3680-
address: IotaAddress!
3680+
objectId: ObjectId!
36813681
"""
36823682
Version of the object being read.
36833683
"""
@@ -3760,7 +3760,7 @@ type StakeSubsidy {
37603760
Represents a `0x3::staking_pool::StakedIota` Move object on-chain.
37613761
"""
37623762
type StakedIota implements IMoveObject & IObject & IOwner {
3763-
address: IotaAddress!
3763+
objectId: ObjectId!
37643764
"""
37653765
Objects owned by this object, optionally `filter`-ed.
37663766
"""
@@ -3907,7 +3907,7 @@ type StakedIota implements IMoveObject & IObject & IOwner {
39073907
"""
39083908
The object id of the validator staking pool this stake belongs to.
39093909
"""
3910-
poolId: IotaAddress
3910+
poolId: ObjectId
39113911
"""
39123912
The IOTA that was initially staked.
39133913
"""
@@ -3987,8 +3987,13 @@ String containing 32B hex-encoded address, with a leading "0x". Leading zeroes c
39873987
"""
39883988
scalar IotaAddress
39893989

3990+
"""
3991+
String containing 32B hex-encoded address, with a leading "0x". Leading zeroes can be omitted on input but will always appear in outputs.
3992+
"""
3993+
scalar ObjectId
3994+
39903995
type IotaNSRegistration implements IMoveObject & IObject & IOwner {
3991-
address: IotaAddress!
3996+
objectId: ObjectId!
39923997
"""
39933998
Objects owned by this object, optionally `filter`-ed.
39943999
"""
@@ -4379,15 +4384,15 @@ input TransactionBlockFilter {
43794384
This filter will be removed with 1.36.0 (2024-10-14), or at least one release after
43804385
`affectedObject` is introduced, whichever is later.
43814386
"""
4382-
inputObject: IotaAddress
4387+
inputObject: ObjectId
43834388
"""
43844389
Limit to transactions that output a versioon of this object. NOTE: this input filter has
43854390
been deprecated in favor of `affectedObject` which offers an easier to understand behavor.
43864391
43874392
This filter will be removed with 1.36.0 (2024-10-14), or at least one release after
43884393
`affectedObject` is introduced, whichever is later.
43894394
"""
4390-
changedObject: IotaAddress
4395+
changedObject: ObjectId
43914396
"""
43924397
Select transactions by their digest.
43934398
"""
@@ -4601,7 +4606,7 @@ type Validator {
46014606
"""
46024607
The ID of this validator's `0x3::staking_pool::StakingPool`.
46034608
"""
4604-
stakingPoolId: IotaAddress!
4609+
stakingPoolId: ObjectId!
46054610
"""
46064611
The validator's current exchange object. The exchange rate is used to determine
46074612
the amount of IOTA tokens that each past IOTA staker can withdraw in the future.
@@ -4745,7 +4750,7 @@ type ValidatorSet {
47454750
"""
47464751
Object ID of the wrapped object `TableVec` storing the pending active validators.
47474752
"""
4748-
pendingActiveValidatorsId: IotaAddress
4753+
pendingActiveValidatorsId: ObjectId
47494754
"""
47504755
Size of the pending active validators table.
47514756
"""
@@ -4755,23 +4760,23 @@ type ValidatorSet {
47554760
of the corresponding validators. This is needed because a validator's address
47564761
can potentially change but the object ID of its pool will not.
47574762
"""
4758-
stakingPoolMappingsId: IotaAddress
4763+
stakingPoolMappingsId: ObjectId
47594764
"""
47604765
Size of the stake pool mappings `Table`.
47614766
"""
47624767
stakingPoolMappingsSize: Int
47634768
"""
47644769
Object ID of the `Table` storing the inactive staking pools.
47654770
"""
4766-
inactivePoolsId: IotaAddress
4771+
inactivePoolsId: ObjectId
47674772
"""
47684773
Size of the inactive pools `Table`.
47694774
"""
47704775
inactivePoolsSize: Int
47714776
"""
47724777
Object ID of the `Table` storing the validator candidates.
47734778
"""
4774-
validatorCandidatesId: IotaAddress
4779+
validatorCandidatesId: ObjectId
47754780
"""
47764781
Size of the validator candidates `Table`.
47774782
"""

crates/iota-graphql-client/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ serde = { version = "1.0.144" }
2424
serde_json = { version = "1.0.95" }
2525
tokio = { version = "1.36.0", features = ["time"] }
2626
tracing = "0.1.37"
27-
uniffi = { version = "0.29", features = ["cli", "tokio"], optional = true }
2827
url = "2.5.3"
2928

3029
[dev-dependencies]
@@ -34,7 +33,3 @@ tokio = { version = "1.40.0", features = ["full"] }
3433

3534
[build-dependencies]
3635
iota-graphql-client-build = { version = "0.0.1", path = "../iota-graphql-client-build" }
37-
38-
[features]
39-
default = []
40-
uniffi = ["dep:uniffi", "iota-types/uniffi"]

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
1414
/// General error type for the client. It is used to wrap all the possible
1515
/// errors that can occur.
1616
#[derive(Debug)]
17-
#[cfg_attr(feature = "uniffi", derive(uniffi::Object), uniffi::export(Display))]
1817
pub struct Error {
1918
inner: Box<InnerError>,
2019
}
@@ -33,7 +32,6 @@ struct InnerError {
3332
}
3433

3534
#[derive(Debug, Copy, Clone)]
36-
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
3735
#[non_exhaustive]
3836
pub enum Kind {
3937
Deserialization,
@@ -48,14 +46,6 @@ impl std::error::Error for Error {
4846
}
4947
}
5048

51-
#[cfg_attr(feature = "uniffi", uniffi::export)]
52-
impl Error {
53-
/// Returns the kind of error.
54-
pub fn kind(&self) -> Kind {
55-
self.inner.kind
56-
}
57-
}
58-
5949
impl Error {
6050
/// Original GraphQL query errors.
6151
pub fn graphql_errors(&self) -> Option<&[GraphQlError]> {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ struct BatchStatusFaucetResponse {
3737
}
3838

3939
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
40-
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
4140
#[serde(rename_all = "UPPERCASE")]
4241
pub enum BatchSendStatusType {
4342
Inprogress,
@@ -46,21 +45,17 @@ pub enum BatchSendStatusType {
4645
}
4746

4847
#[derive(Serialize, Deserialize, Debug, Clone)]
49-
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
5048
pub struct BatchSendStatus {
5149
pub status: BatchSendStatusType,
52-
#[cfg_attr(feature = "uniffi", uniffi(default = None))]
5350
pub transferred_gas_objects: Option<FaucetReceipt>,
5451
}
5552

5653
#[derive(Serialize, Deserialize, Debug, Clone)]
57-
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
5854
pub struct FaucetReceipt {
5955
pub sent: Vec<CoinInfo>,
6056
}
6157

6258
#[derive(Serialize, Deserialize, Debug, Clone)]
63-
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
6459
#[serde(rename_all = "camelCase")]
6560
pub struct CoinInfo {
6661
pub amount: u64,

0 commit comments

Comments
 (0)