Skip to content

Commit

Permalink
Update InfoResponse (#648)
Browse files Browse the repository at this point in the history
* Remove WhiteFlagResponse

* Update InfoResponse

* Add IssuerId

* Update ProtocolParameters

* Remove check_existing_db tests

* Fix test

* fix

* Revert triple slash
  • Loading branch information
thibault-martinez committed Jun 28, 2023
1 parent 7936c46 commit 1107a70
Show file tree
Hide file tree
Showing 32 changed files with 84 additions and 312 deletions.
2 changes: 2 additions & 0 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
params.rent_structure().byte_factor_data(),
),
token_supply: params.token_supply().to_string(),
genesis_unix_timestamp: params.genesis_unix_timestamp(),
slot_duration_in_seconds: params.slot_duration_in_seconds(),
};
Response::ProtocolParameters(protocol_response)
}
Expand Down
2 changes: 2 additions & 0 deletions sdk/examples/wallet/offline_signing/2_sign_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ async fn main() -> Result<()> {
.with_byte_factor_key(1)
.with_byte_factor_data(10),
1813620509061365,
1582328545,
10,
)
.unwrap();

Expand Down
2 changes: 2 additions & 0 deletions sdk/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ impl From<NetworkInfo> for NetworkInfoDto {
info.protocol_parameters.rent_structure().byte_factor_data(),
),
token_supply: info.protocol_parameters.token_supply().to_string(),
genesis_unix_timestamp: info.protocol_parameters.genesis_unix_timestamp(),
slot_duration_in_seconds: info.protocol_parameters.slot_duration_in_seconds(),
},
local_pow: info.local_pow,
fallback_to_local_pow: info.fallback_to_local_pow,
Expand Down
3 changes: 2 additions & 1 deletion sdk/src/client/node_manager/syncing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ impl ClientInner {
if let Some((info, _node_url)) = nodes.first() {
let mut network_info = self.network_info.write().await;

network_info.latest_milestone_timestamp = info.status.latest_milestone.timestamp;
// TODO change to one of the new timestamps, which ones ?
// network_info.latest_milestone_timestamp = info.status.latest_milestone.timestamp;
network_info.protocol_parameters = ProtocolParameters::try_from(info.protocol.clone())?;
}

Expand Down
97 changes: 24 additions & 73 deletions sdk/src/types/api/core/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::types::block::{
OutputWithMetadata,
},
protocol::dto::ProtocolParametersDto,
BlockId,
slot::SlotIndex,
BlockId, IssuerId,
};

/// Response of GET /api/core/v3/info.
Expand All @@ -23,12 +24,12 @@ use crate::types::block::{
pub struct InfoResponse {
pub name: String,
pub version: String,
pub issuer_id: IssuerId,
pub status: StatusResponse,
pub metrics: MetricsResponse,
pub supported_protocol_versions: Vec<u8>,
pub protocol: ProtocolParametersDto,
pub pending_protocol_parameters: Vec<PendingProtocolParameter>,
pub base_token: BaseTokenResponse,
pub metrics: MetricsResponse,
pub features: Vec<String>,
}

Expand All @@ -49,57 +50,33 @@ impl core::fmt::Display for InfoResponse {
)]
pub struct StatusResponse {
pub is_healthy: bool,
pub latest_milestone: LatestMilestoneResponse,
pub confirmed_milestone: ConfirmedMilestoneResponse,
pub pruning_index: u32,
}

/// Returned in [`StatusResponse`].
/// Information about the latest milestone.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "camelCase")
)]
pub struct LatestMilestoneResponse {
pub index: u32,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub timestamp: Option<u32>,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub milestone_id: Option<String>,
}

/// Returned in [`StatusResponse`].
/// Information about the confirmed milestone.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "camelCase")
)]
pub struct ConfirmedMilestoneResponse {
pub index: u32,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub timestamp: Option<u32>,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub milestone_id: Option<String>,
pub last_accepted_block_id: BlockId,
pub last_confirmed_block_id: BlockId,
pub finalized_slot: SlotIndex,
#[cfg_attr(feature = "serde", serde(rename = "ATT"))]
pub att: u64,
#[cfg_attr(feature = "serde", serde(rename = "RATT"))]
pub ratt: u64,
#[cfg_attr(feature = "serde", serde(rename = "CTT"))]
pub ctt: u64,
#[cfg_attr(feature = "serde", serde(rename = "RCTT"))]
pub rctt: u64,
pub latest_committed_slot: SlotIndex,
pub pruning_slot: SlotIndex,
}

/// Returned in [`InfoResponse`].
/// Pending protocol parameters.
#[derive(Clone, Debug, Eq, PartialEq)]
/// Metric information about the node.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "camelCase")
)]
pub struct PendingProtocolParameter {
#[cfg_attr(feature = "serde", serde(rename = "type"))]
pub kind: u8,
pub target_milestone_index: u32,
pub protocol_version: u8,
pub params: String,
pub struct MetricsResponse {
pub blocks_per_second: f64,
pub confirmed_blocks_per_second: f64,
pub confirmed_rate: f64,
}

/// Returned in [`InfoResponse`].
Expand All @@ -116,24 +93,10 @@ pub struct BaseTokenResponse {
pub unit: String,
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub subunit: Option<String>,
pub decimals: u8,
pub decimals: u32,
pub use_metric_prefix: bool,
}

/// Returned in [`InfoResponse`].
/// Metric information about the node.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "camelCase")
)]
pub struct MetricsResponse {
pub blocks_per_second: f64,
pub referenced_blocks_per_second: f64,
pub referenced_rate: f64,
}

/// Response of GET /api/core/v3/tips.
/// Returns non-lazy tips.
#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -305,18 +268,6 @@ pub struct PeerResponse {
pub gossip: Option<Gossip>,
}

/// Response of GET /api/plugins/debug/whiteflag.
/// Returns the computed merkle tree hash for the given white flag traversal.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "camelCase")
)]
pub struct WhiteFlagResponse {
pub merkle_tree_hash: String,
}

/// Response of GET /api/routes.
/// Returns the available API route groups of the node.
#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down
11 changes: 11 additions & 0 deletions sdk/src/types/block/issuer_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2020-2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

impl_id!(
pub IssuerId,
32,
"Identifier of a block issuer."
);

#[cfg(feature = "serde")]
string_serde_impl!(IssuerId);
2 changes: 2 additions & 0 deletions sdk/src/types/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod r#macro;
mod block_id;
mod convert;
mod error;
mod issuer_id;

/// A module that provides types and syntactic validations of addresses.
pub mod address;
Expand Down Expand Up @@ -47,6 +48,7 @@ pub use self::{
block_id::BlockId,
convert::ConvertTo,
error::Error,
issuer_id::IssuerId,
};

pub(crate) const PROTOCOL_VERSION: u8 = 2;
29 changes: 28 additions & 1 deletion sdk/src/types/block/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ pub struct ProtocolParameters {
// TokenSupply defines the current token supply on the network.
#[cfg_attr(feature = "serde", serde(alias = "tokenSupply"))]
token_supply: u64,
// Genesis timestamp at which the slots start to count.
#[cfg_attr(feature = "serde", serde(alias = "genesisUnixTimestamp"))]
genesis_unix_timestamp: u32,
// Duration of each slot in seconds.
#[cfg_attr(feature = "serde", serde(alias = "slotDurationInSeconds"))]
slot_duration_in_seconds: u8,
}

// This implementation is required to make [`ProtocolParameters`] a [`Packable`] visitor.
Expand All @@ -50,19 +56,22 @@ impl Default for ProtocolParameters {
// PANIC: These values are known to be correct.
Self::new(
PROTOCOL_VERSION,
String::from("shimmer"),
String::from("iota-core-testnet"),
"smr",
1500,
15,
RentStructure::default(),
1_813_620_509_061_365,
1582328545,
10,
)
.unwrap()
}
}

impl ProtocolParameters {
/// Creates a new [`ProtocolParameters`].
#[allow(clippy::too_many_arguments)]
pub fn new(
protocol_version: u8,
network_name: String,
Expand All @@ -71,6 +80,8 @@ impl ProtocolParameters {
below_max_depth: u8,
rent_structure: RentStructure,
token_supply: u64,
genesis_unix_timestamp: u32,
slot_duration_in_seconds: u8,
) -> Result<Self, Error> {
Ok(Self {
protocol_version,
Expand All @@ -80,6 +91,8 @@ impl ProtocolParameters {
below_max_depth,
rent_structure,
token_supply,
genesis_unix_timestamp,
slot_duration_in_seconds,
})
}

Expand Down Expand Up @@ -122,6 +135,14 @@ impl ProtocolParameters {
pub fn token_supply(&self) -> u64 {
self.token_supply
}

pub fn genesis_unix_timestamp(&self) -> u32 {
self.genesis_unix_timestamp
}

pub fn slot_duration_in_seconds(&self) -> u8 {
self.slot_duration_in_seconds
}
}

/// Returns a [`ProtocolParameters`] for testing purposes.
Expand All @@ -136,6 +157,8 @@ pub fn protocol_parameters() -> ProtocolParameters {
15,
crate::types::block::output::RentStructure::new(500, 10, 1),
1_813_620_509_061_365,
1582328545,
10,
)
.unwrap()
}
Expand All @@ -161,6 +184,8 @@ pub mod dto {
pub below_max_depth: u8,
pub rent_structure: RentStructure,
pub token_supply: String,
pub genesis_unix_timestamp: u32,
pub slot_duration_in_seconds: u8,
}

impl TryFrom<ProtocolParametersDto> for ProtocolParameters {
Expand All @@ -178,6 +203,8 @@ pub mod dto {
.token_supply
.parse()
.map_err(|_| Error::InvalidField("token_supply"))?,
value.genesis_unix_timestamp,
value.slot_duration_in_seconds,
)
}
}
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/wallet/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ fn serialize() {
15,
crate::types::block::output::RentStructure::new(500, 10, 1),
1_813_620_509_061_365,
1582328545,
10,
)
.unwrap();

Expand Down
4 changes: 3 additions & 1 deletion sdk/src/wallet/account/operations/participation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ where
participations: &mut Participations,
) -> crate::wallet::Result<()> {
log::debug!("[remove_ended_participation_events]");
let latest_milestone_index = self.client().get_info().await?.node_info.status.latest_milestone.index;
// TODO change to one of the new timestamps, which ones ?
let latest_milestone_index = 0;
// let latest_milestone_index = self.client().get_info().await?.node_info.status.latest_milestone.index;

let account_index = self.details().await.index;
let events = self
Expand Down
8 changes: 6 additions & 2 deletions sdk/tests/client/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ async fn client_builder() {
"vByteFactorKey":10,
"vByteFactorData":1
},
"tokenSupply":1813620509061365
"tokenSupply":1813620509061365,
"genesisUnixTimestamp":1582328545,
"slotDurationInSeconds":10
},
"localPow":true,
"fallbackToLocalPow":true,
Expand Down Expand Up @@ -105,7 +107,9 @@ async fn client_builder() {
"vByteFactorKey":10,
"vByteFactorData":1
},
"tokenSupply":1813620509061365
"tokenSupply":1813620509061365,
"genesisUnixTimestamp":1582328545,
"slotDurationInSeconds":10
},
"localPow":true,
"fallbackToLocalPow":true,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion sdk/tests/wallet/fixtures/check_existing_1_db_test/CURRENT

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion sdk/tests/wallet/fixtures/check_existing_2_db_test/CURRENT

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion sdk/tests/wallet/fixtures/check_existing_db_test/CURRENT

This file was deleted.

1 change: 0 additions & 1 deletion sdk/tests/wallet/fixtures/check_existing_db_test/IDENTITY

This file was deleted.

Binary file not shown.
Binary file not shown.
3 changes: 0 additions & 3 deletions sdk/tests/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ mod syncing;
mod transactions;
#[allow(clippy::module_inception)]
mod wallet;
#[cfg(not(target_os = "windows"))]
#[cfg(feature = "rocksdb")]
mod wallet_storage;
Loading

0 comments on commit 1107a70

Please sign in to comment.