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 authored and Alex Coats committed Jul 24, 2023
1 parent 2474b9f commit 8f5fb2c
Show file tree
Hide file tree
Showing 29 changed files with 71 additions and 412 deletions.
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 @@ -105,7 +105,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 = 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 @@ -6,7 +6,8 @@ use alloc::{string::String, vec::Vec};
use crate::types::block::{
output::{dto::OutputDto, OutputMetadata, OutputWithMetadata},
protocol::ProtocolParameters,
BlockId,
slot::SlotIndex,
BlockId, IssuerId,
};

/// Response of GET /api/core/v3/info.
Expand All @@ -20,12 +21,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: ProtocolParameters,
pub pending_protocol_parameters: Vec<PendingProtocolParameter>,
pub base_token: BaseTokenResponse,
pub metrics: MetricsResponse,
pub features: Vec<String>,
}

Expand All @@ -46,57 +47,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 @@ -113,24 +90,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 @@ -302,18 +265,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 @@ -46,6 +47,7 @@ pub use self::{
convert::ConvertTo,
core::{dto::BlockDto, Block, BlockBuilder},
error::Error,
issuer_id::IssuerId,
};

pub(crate) const PROTOCOL_VERSION: u8 = 2;
25 changes: 24 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(with = "crate::utils::serde::string"))]
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 @@ -135,6 +156,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()
}
2 changes: 2 additions & 0 deletions sdk/src/wallet/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,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
4 changes: 3 additions & 1 deletion sdk/tests/client/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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 @@ -22,6 +22,3 @@ mod native_tokens;
mod output_preparation;
mod syncing;
mod transactions;
#[cfg(not(target_os = "windows"))]
#[cfg(feature = "rocksdb")]
mod wallet_storage;
Loading

0 comments on commit 8f5fb2c

Please sign in to comment.