Skip to content

Commit 6f6d863

Browse files
feat(iota-sdk-ffi): convert Epoch to Record (#166)
* feat(iota-sdk-ffi): convert Epoch to Record * rename one ValidatorSet to to ValidatorSetQuery * remove ValidatorSetQuery from bindings --------- Co-authored-by: Thibault Martinez <thibault@iota.org>
1 parent b2ce029 commit 6f6d863

File tree

9 files changed

+1540
-620
lines changed

9 files changed

+1540
-620
lines changed

bindings/go/iota_sdk_ffi/iota_sdk_ffi.go

Lines changed: 383 additions & 149 deletions
Large diffs are not rendered by default.

bindings/go/iota_sdk_ffi/iota_sdk_ffi.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,16 +1358,6 @@ void* uniffi_iota_sdk_ffi_fn_constructor_endofepochtransactionkind_new_change_ep
13581358
void* uniffi_iota_sdk_ffi_fn_constructor_endofepochtransactionkind_new_change_epoch_v2(void* tx, RustCallStatus *out_status
13591359
);
13601360
#endif
1361-
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CLONE_EPOCH
1362-
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CLONE_EPOCH
1363-
void* uniffi_iota_sdk_ffi_fn_clone_epoch(void* ptr, RustCallStatus *out_status
1364-
);
1365-
#endif
1366-
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_FREE_EPOCH
1367-
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_FREE_EPOCH
1368-
void uniffi_iota_sdk_ffi_fn_free_epoch(void* ptr, RustCallStatus *out_status
1369-
);
1370-
#endif
13711361
#ifndef UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CLONE_EXECUTIONTIMEOBSERVATION
13721362
#define UNIFFI_FFIDEF_UNIFFI_IOTA_SDK_FFI_FN_CLONE_EXECUTIONTIMEOBSERVATION
13731363
void* uniffi_iota_sdk_ffi_fn_clone_executiontimeobservation(void* ptr, RustCallStatus *out_status

bindings/kotlin/lib/iota_sdk/iota_sdk_ffi.kt

Lines changed: 412 additions & 294 deletions
Large diffs are not rendered by default.

bindings/python/lib/iota_sdk_ffi.py

Lines changed: 534 additions & 130 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct ActiveValidatorsArgs<'a> {
3131
variables = "ActiveValidatorsArgs"
3232
)]
3333
pub struct EpochValidator {
34-
pub validator_set: Option<ValidatorSet>,
34+
pub validator_set: Option<ValidatorSetQuery>,
3535
}
3636

3737
#[derive(cynic::QueryFragment, Debug)]
@@ -40,7 +40,7 @@ pub struct EpochValidator {
4040
graphql_type = "ValidatorSet",
4141
variables = "ActiveValidatorsArgs"
4242
)]
43-
pub struct ValidatorSet {
43+
pub struct ValidatorSetQuery {
4444
#[arguments(after: $after, before: $before, first: $first, last: $last)]
4545
pub active_validators: ValidatorConnection,
4646
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod transaction;
2121

2222
pub use active_validators::{
2323
ActiveValidatorsArgs, ActiveValidatorsQuery, EpochValidator, Validator, ValidatorConnection,
24-
ValidatorCredentials, ValidatorSet,
24+
ValidatorCredentials, ValidatorSetQuery,
2525
};
2626
pub use balance::{Balance, BalanceArgs, BalanceQuery, Owner};
2727
pub use chain::ChainIdentifierQuery;
@@ -36,7 +36,7 @@ pub use dynamic_fields::{
3636
DynamicFieldArgs, DynamicFieldConnectionArgs, DynamicFieldName, DynamicFieldQuery,
3737
DynamicFieldsOwnerQuery, DynamicObjectFieldQuery,
3838
};
39-
pub use epoch::{Epoch, EpochArgs, EpochQuery, EpochSummaryQuery};
39+
pub use epoch::{Epoch, EpochArgs, EpochQuery, EpochSummaryQuery, ValidatorSet};
4040
pub use events::{Event, EventConnection, EventFilter, EventsQuery, EventsQueryArgs};
4141
pub use execute_tx::{ExecuteTransactionArgs, ExecuteTransactionQuery, ExecutionResult};
4242
use iota_types::{Address, ObjectId};

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,8 @@ impl GraphQLClient {
255255
/// Return the epoch information for the provided epoch. If no epoch is
256256
/// provided, it will return the last known epoch.
257257
#[uniffi::method(default(epoch = None))]
258-
pub async fn epoch(&self, epoch: Option<u64>) -> Result<Option<Arc<Epoch>>> {
259-
Ok(self
260-
.0
261-
.read()
262-
.await
263-
.epoch(epoch)
264-
.await?
265-
.map(Into::into)
266-
.map(Arc::new))
258+
pub async fn epoch(&self, epoch: Option<u64>) -> Result<Option<Epoch>> {
259+
Ok(self.0.read().await.epoch(epoch).await?.map(Into::into))
267260
}
268261

269262
/// Return the number of checkpoints in this epoch. This will return

crates/iota-sdk-ffi/src/types/graphql.rs

Lines changed: 204 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,210 @@ impl From<ObjectRef> for iota_graphql_client::query_types::ObjectRef {
207207
}
208208
}
209209

210-
#[derive(derive_more::From, uniffi::Object)]
211-
pub struct Epoch(pub iota_graphql_client::query_types::Epoch);
210+
#[derive(uniffi::Record)]
211+
pub struct Epoch {
212+
/// The epoch's id as a sequence number that starts at 0 and is incremented
213+
/// by one at every epoch change.
214+
pub epoch_id: u64,
215+
/// The storage fees paid for transactions executed during the epoch.
216+
#[uniffi(default = None)]
217+
pub fund_inflow: Option<String>,
218+
/// The storage fee rebates paid to users who deleted the data associated
219+
/// with past transactions.
220+
#[uniffi(default = None)]
221+
pub fund_outflow: Option<String>,
222+
/// The storage fund available in this epoch.
223+
/// This fund is used to redistribute storage fees from past transactions
224+
/// to future validators.
225+
#[uniffi(default = None)]
226+
pub fund_size: Option<String>,
227+
/// A commitment by the committee at the end of epoch on the contents of the
228+
/// live object set at that time. This can be used to verify state
229+
/// snapshots.
230+
#[uniffi(default = None)]
231+
pub live_object_set_digest: Option<String>,
232+
/// The difference between the fund inflow and outflow, representing
233+
/// the net amount of storage fees accumulated in this epoch.
234+
#[uniffi(default = None)]
235+
pub net_inflow: Option<String>,
236+
/// The epoch's corresponding protocol configuration, including the feature
237+
/// flags and the configuration options.
238+
#[uniffi(default = None)]
239+
pub protocol_configs: Option<ProtocolConfigs>,
240+
/// The minimum gas price that a quorum of validators are guaranteed to sign
241+
/// a transaction for.
242+
#[uniffi(default = None)]
243+
pub reference_gas_price: Option<String>,
244+
/// The epoch's starting timestamp.
245+
pub start_timestamp: u64,
246+
/// The epoch's ending timestamp. Note that this is available only on epochs
247+
/// that have ended.
248+
#[uniffi(default = None)]
249+
pub end_timestamp: Option<u64>,
250+
/// The value of the `version` field of `0x5`, the
251+
/// `0x3::iota::IotaSystemState` object. This version changes whenever
252+
/// the fields contained in the system state object (held in a dynamic
253+
/// field attached to `0x5`) change.
254+
#[uniffi(default = None)]
255+
pub system_state_version: Option<u64>,
256+
/// The total number of checkpoints in this epoch.
257+
#[uniffi(default = None)]
258+
pub total_checkpoints: Option<u64>,
259+
/// The total amount of gas fees (in IOTA) that were paid in this epoch.
260+
#[uniffi(default = None)]
261+
pub total_gas_fees: Option<String>,
262+
/// The total IOTA rewarded as stake.
263+
#[uniffi(default = None)]
264+
pub total_stake_rewards: Option<String>,
265+
/// The total number of transaction in this epoch.
266+
#[uniffi(default = None)]
267+
pub total_transactions: Option<u64>,
268+
/// Validator related properties. For active validators, see
269+
/// `active_validators` API.
270+
#[uniffi(default = None)]
271+
pub validator_set: Option<ValidatorSet>,
272+
}
273+
274+
impl From<iota_graphql_client::query_types::Epoch> for Epoch {
275+
fn from(value: iota_graphql_client::query_types::Epoch) -> Self {
276+
Self {
277+
epoch_id: value.epoch_id,
278+
fund_inflow: value.fund_inflow.map(|v| v.0),
279+
fund_outflow: value.fund_outflow.map(|v| v.0),
280+
fund_size: value.fund_size.map(|v| v.0),
281+
live_object_set_digest: value.live_object_set_digest,
282+
net_inflow: value.net_inflow.map(|v| v.0),
283+
protocol_configs: value.protocol_configs,
284+
reference_gas_price: value.reference_gas_price.map(|v| v.0),
285+
start_timestamp: value.start_timestamp.0.parse().unwrap_or(0),
286+
end_timestamp: value.end_timestamp.map(|dt| dt.0.parse().unwrap_or(0)),
287+
system_state_version: value.system_state_version,
288+
total_checkpoints: value.total_checkpoints,
289+
total_gas_fees: value.total_gas_fees.map(|v| v.0),
290+
total_stake_rewards: value.total_stake_rewards.map(|v| v.0),
291+
total_transactions: value.total_transactions,
292+
validator_set: value.validator_set.map(|vs| ValidatorSet {
293+
inactive_pools_id: vs.inactive_pools_id.map(Into::into).map(Arc::new),
294+
inactive_pools_size: vs.inactive_pools_size,
295+
pending_active_validators_id: vs
296+
.pending_active_validators_id
297+
.map(Into::into)
298+
.map(Arc::new),
299+
pending_active_validators_size: vs.pending_active_validators_size,
300+
pending_removals: vs.pending_removals,
301+
staking_pool_mappings_id: vs.staking_pool_mappings_id.map(Into::into).map(Arc::new),
302+
staking_pool_mappings_size: vs.staking_pool_mappings_size,
303+
total_stake: vs.total_stake.map(|v| v.0),
304+
validator_candidates_size: vs.validator_candidates_size,
305+
validator_candidates_id: vs.validator_candidates_id.map(Into::into).map(Arc::new),
306+
}),
307+
}
308+
}
309+
}
310+
311+
impl From<Epoch> for iota_graphql_client::query_types::Epoch {
312+
fn from(value: Epoch) -> Self {
313+
Self {
314+
epoch_id: value.epoch_id,
315+
fund_inflow: value.fund_inflow.map(|v| v.into()),
316+
fund_outflow: value.fund_outflow.map(|v| v.into()),
317+
fund_size: value.fund_size.map(|v| v.into()),
318+
live_object_set_digest: value.live_object_set_digest,
319+
net_inflow: value.net_inflow.map(|v| v.into()),
320+
protocol_configs: value.protocol_configs,
321+
reference_gas_price: value.reference_gas_price.map(|v| v.into()),
322+
start_timestamp: iota_graphql_client::query_types::DateTime(
323+
value.start_timestamp.to_string(),
324+
),
325+
end_timestamp: value
326+
.end_timestamp
327+
.map(|ts| iota_graphql_client::query_types::DateTime(ts.to_string())),
328+
system_state_version: value.system_state_version,
329+
total_checkpoints: value.total_checkpoints,
330+
total_gas_fees: value.total_gas_fees.map(|v| v.into()),
331+
total_stake_rewards: value.total_stake_rewards.map(|v| v.into()),
332+
total_transactions: value.total_transactions,
333+
validator_set: value.validator_set.map(Into::into),
334+
}
335+
}
336+
}
337+
338+
#[derive(uniffi::Record)]
339+
pub struct ValidatorSet {
340+
/// Object ID of the `Table` storing the inactive staking pools.
341+
#[uniffi(default = None)]
342+
pub inactive_pools_id: Option<Arc<ObjectId>>,
343+
/// Size of the inactive pools `Table`.
344+
#[uniffi(default = None)]
345+
pub inactive_pools_size: Option<i32>,
346+
/// Object ID of the wrapped object `TableVec` storing the pending active
347+
/// validators.
348+
#[uniffi(default = None)]
349+
pub pending_active_validators_id: Option<Arc<ObjectId>>,
350+
/// Size of the pending active validators table.
351+
#[uniffi(default = None)]
352+
pub pending_active_validators_size: Option<i32>,
353+
/// Validators that are pending removal from the active validator set,
354+
/// expressed as indices in to `activeValidators`.
355+
#[uniffi(default = None)]
356+
pub pending_removals: Option<Vec<i32>>,
357+
/// Object ID of the `Table` storing the mapping from staking pool ids to
358+
/// the addresses of the corresponding validators. This is needed
359+
/// because a validator's address can potentially change but the object
360+
/// ID of its pool will not.
361+
#[uniffi(default = None)]
362+
pub staking_pool_mappings_id: Option<Arc<ObjectId>>,
363+
/// Size of the stake pool mappings `Table`.
364+
#[uniffi(default = None)]
365+
pub staking_pool_mappings_size: Option<i32>,
366+
/// Total amount of stake for all active validators at the beginning of the
367+
/// epoch.
368+
#[uniffi(default = None)]
369+
pub total_stake: Option<String>,
370+
/// Size of the validator candidates `Table`.
371+
#[uniffi(default = None)]
372+
pub validator_candidates_size: Option<i32>,
373+
/// Object ID of the `Table` storing the validator candidates.
374+
#[uniffi(default = None)]
375+
pub validator_candidates_id: Option<Arc<ObjectId>>,
376+
}
377+
378+
impl From<iota_graphql_client::query_types::ValidatorSet> for ValidatorSet {
379+
fn from(value: iota_graphql_client::query_types::ValidatorSet) -> Self {
380+
Self {
381+
inactive_pools_id: value.inactive_pools_id.map(Into::into).map(Arc::new),
382+
inactive_pools_size: value.inactive_pools_size,
383+
pending_active_validators_id: value
384+
.pending_active_validators_id
385+
.map(Into::into)
386+
.map(Arc::new),
387+
pending_active_validators_size: value.pending_active_validators_size,
388+
pending_removals: value.pending_removals,
389+
staking_pool_mappings_id: value.staking_pool_mappings_id.map(Into::into).map(Arc::new),
390+
staking_pool_mappings_size: value.staking_pool_mappings_size,
391+
total_stake: value.total_stake.map(|v| v.0),
392+
validator_candidates_size: value.validator_candidates_size,
393+
validator_candidates_id: value.validator_candidates_id.map(Into::into).map(Arc::new),
394+
}
395+
}
396+
}
397+
398+
impl From<ValidatorSet> for iota_graphql_client::query_types::ValidatorSet {
399+
fn from(value: ValidatorSet) -> Self {
400+
Self {
401+
inactive_pools_id: value.inactive_pools_id.map(|v| **v),
402+
inactive_pools_size: value.inactive_pools_size,
403+
pending_active_validators_id: value.pending_active_validators_id.map(|v| **v),
404+
pending_active_validators_size: value.pending_active_validators_size,
405+
pending_removals: value.pending_removals,
406+
staking_pool_mappings_id: value.staking_pool_mappings_id.map(|v| **v),
407+
staking_pool_mappings_size: value.staking_pool_mappings_size,
408+
total_stake: value.total_stake.map(|v| v.into()),
409+
validator_candidates_size: value.validator_candidates_size,
410+
validator_candidates_id: value.validator_candidates_id.map(|v| **v),
411+
}
412+
}
413+
}
212414

213415
#[derive(uniffi::Record)]
214416
pub struct EventFilter {
@@ -567,27 +769,6 @@ pub enum Direction {
567769
Backward,
568770
}
569771

570-
#[derive(uniffi::Record)]
571-
pub struct ValidatorSet {
572-
pub active_validators: ValidatorConnection,
573-
}
574-
575-
impl From<iota_graphql_client::query_types::ValidatorSet> for ValidatorSet {
576-
fn from(value: iota_graphql_client::query_types::ValidatorSet) -> Self {
577-
ValidatorSet {
578-
active_validators: value.active_validators.into(),
579-
}
580-
}
581-
}
582-
583-
impl From<ValidatorSet> for iota_graphql_client::query_types::ValidatorSet {
584-
fn from(value: ValidatorSet) -> Self {
585-
iota_graphql_client::query_types::ValidatorSet {
586-
active_validators: value.active_validators.into(),
587-
}
588-
}
589-
}
590-
591772
#[derive(uniffi::Record)]
592773
pub struct ValidatorConnection {
593774
pub page_info: PageInfo,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ define_paged_record!(SignedTransactionPage, SignedTransaction);
4040
define_paged_record!(TransactionDataEffectsPage, TransactionDataEffects);
4141
define_paged_record!(DynamicFieldOutputPage, DynamicFieldOutput);
4242
define_paged_record!(EventPage, Event);
43+
define_paged_record!(EpochPage, Epoch);
4344
define_paged_record!(ValidatorPage, Validator);
4445

4546
macro_rules! define_paged_object {
@@ -74,7 +75,6 @@ define_paged_object!(CoinPage, Coin);
7475
define_paged_object!(ObjectPage, Object);
7576
define_paged_object!(TransactionEffectsPage, TransactionEffects);
7677
define_paged_object!(MovePackagePage, MovePackage);
77-
define_paged_object!(EpochPage, Epoch);
7878
define_paged_object!(CheckpointSummaryPage, CheckpointSummary);
7979

8080
uniffi::custom_type!(Value, String, {

0 commit comments

Comments
 (0)