From e3a414919fedf5a051c4d58ef7033075551a3d3f Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Tue, 27 Sep 2022 12:35:41 +0200 Subject: [PATCH 01/25] Make macro name more descriptive --- bee-inx/src/block.rs | 10 +++++----- bee-inx/src/ledger.rs | 16 ++++++++-------- bee-inx/src/lib.rs | 2 +- bee-inx/src/metadata.rs | 4 ++-- bee-inx/src/milestone/mod.rs | 10 +++++----- bee-inx/src/node/config.rs | 4 ++-- bee-inx/src/node/status.rs | 8 ++++---- bee-inx/src/treasury.rs | 8 ++++---- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/bee-inx/src/block.rs b/bee-inx/src/block.rs index 53c92828c0..e65f792c39 100644 --- a/bee-inx/src/block.rs +++ b/bee-inx/src/block.rs @@ -4,7 +4,7 @@ use bee_block as bee; use inx::proto; -use crate::{maybe_missing, Raw}; +use crate::{return_err_if_none, Raw}; /// The [`Block`] type. #[derive(Clone, Debug, PartialEq, Eq)] @@ -29,8 +29,8 @@ impl TryFrom for BlockWithMetadata { fn try_from(value: proto::BlockWithMetadata) -> Result { Ok(BlockWithMetadata { - metadata: maybe_missing!(value.metadata).try_into()?, - block: maybe_missing!(value.block).data.into(), + metadata: return_err_if_none!(value.metadata).try_into()?, + block: return_err_if_none!(value.block).data.into(), }) } } @@ -49,8 +49,8 @@ impl TryFrom for Block { fn try_from(value: proto::Block) -> Result { Ok(Block { - block_id: maybe_missing!(value.block_id).try_into()?, - block: maybe_missing!(value.block).data.into(), + block_id: return_err_if_none!(value.block_id).try_into()?, + block: return_err_if_none!(value.block).data.into(), }) } } diff --git a/bee-inx/src/ledger.rs b/bee-inx/src/ledger.rs index 8f1e26cd65..5064cba229 100644 --- a/bee-inx/src/ledger.rs +++ b/bee-inx/src/ledger.rs @@ -4,7 +4,7 @@ use bee_block as bee; use inx::proto; -use crate::{maybe_missing, Raw}; +use crate::{return_err_if_none, Raw}; /// Represents a new output in the ledger. #[allow(missing_docs)] @@ -135,7 +135,7 @@ impl TryFrom for LedgerUpdate { fn try_from(value: proto::LedgerUpdate) -> Result { use proto::ledger_update::Op as proto; - Ok(match maybe_missing!(value.op) { + Ok(match return_err_if_none!(value.op) { proto::BatchMarker(marker) => marker.into(), proto::Consumed(consumed) => LedgerUpdate::Consumed(consumed.try_into()?), proto::Created(created) => LedgerUpdate::Created(created.try_into()?), @@ -162,11 +162,11 @@ impl TryFrom for LedgerOutput { fn try_from(value: proto::LedgerOutput) -> Result { Ok(Self { - output_id: maybe_missing!(value.output_id).try_into()?, - block_id: maybe_missing!(value.block_id).try_into()?, + output_id: return_err_if_none!(value.output_id).try_into()?, + block_id: return_err_if_none!(value.block_id).try_into()?, milestone_index_booked: value.milestone_index_booked.into(), milestone_timestamp_booked: value.milestone_timestamp_booked, - output: maybe_missing!(value.output).into(), + output: return_err_if_none!(value.output).into(), }) } } @@ -188,8 +188,8 @@ impl TryFrom for LedgerSpent { fn try_from(value: proto::LedgerSpent) -> Result { Ok(Self { - output: maybe_missing!(value.output).try_into()?, - transaction_id_spent: maybe_missing!(value.transaction_id_spent).try_into()?, + output: return_err_if_none!(value.output).try_into()?, + transaction_id_spent: return_err_if_none!(value.transaction_id_spent).try_into()?, milestone_index_spent: value.milestone_index_spent.into(), milestone_timestamp_spent: value.milestone_timestamp_spent, }) @@ -213,7 +213,7 @@ impl TryFrom for UnspentOutput { fn try_from(value: proto::UnspentOutput) -> Result { Ok(Self { ledger_index: value.ledger_index.into(), - output: maybe_missing!(value.output).try_into()?, + output: return_err_if_none!(value.output).try_into()?, }) } } diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index 416ed7ce77..d2b34c710a 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -23,7 +23,7 @@ pub mod proto { } #[macro_export] -macro_rules! maybe_missing { +macro_rules! return_err_if_none { ($object:ident.$field:ident) => { $object.$field.ok_or(Self::Error::MissingField(stringify!($field)))? }; diff --git a/bee-inx/src/metadata.rs b/bee-inx/src/metadata.rs index 923dc2a078..a685d2f87b 100644 --- a/bee-inx/src/metadata.rs +++ b/bee-inx/src/metadata.rs @@ -4,7 +4,7 @@ use bee_block as bee; use inx::proto; -use crate::maybe_missing; +use crate::return_err_if_none; #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] @@ -53,7 +53,7 @@ impl TryFrom for BlockMetadata { .collect::, _>>()?; Ok(BlockMetadata { - block_id: maybe_missing!(value.block_id).try_into()?, + block_id: return_err_if_none!(value.block_id).try_into()?, parents: parents.into_boxed_slice(), is_solid: value.solid, should_promote: value.should_promote, diff --git a/bee-inx/src/milestone/mod.rs b/bee-inx/src/milestone/mod.rs index b878bcb46f..5b08e7f396 100644 --- a/bee-inx/src/milestone/mod.rs +++ b/bee-inx/src/milestone/mod.rs @@ -8,7 +8,7 @@ mod info; use inx::proto; pub use self::info::MilestoneInfo; -use crate::{maybe_missing, ProtocolParameters, Raw}; +use crate::{return_err_if_none, ProtocolParameters, Raw}; /// The [`Milestone`] type. #[derive(Clone, Debug, PartialEq, Eq)] @@ -25,8 +25,8 @@ impl TryFrom for Milestone { fn try_from(value: proto::Milestone) -> Result { Ok(Self { - milestone_info: maybe_missing!(value.milestone_info).try_into()?, - milestone: maybe_missing!(value.milestone).data.into(), + milestone_info: return_err_if_none!(value.milestone_info).try_into()?, + milestone: return_err_if_none!(value.milestone).data.into(), }) } } @@ -52,8 +52,8 @@ impl TryFrom for MilestoneAndProtocolPara fn try_from(value: proto::MilestoneAndProtocolParameters) -> Result { Ok(Self { - milestone: maybe_missing!(value.milestone).try_into()?, - current_protocol_parameters: maybe_missing!(value.current_protocol_parameters).into(), + milestone: return_err_if_none!(value.milestone).try_into()?, + current_protocol_parameters: return_err_if_none!(value.current_protocol_parameters).into(), }) } } diff --git a/bee-inx/src/node/config.rs b/bee-inx/src/node/config.rs index d57eca1644..4cab291c68 100644 --- a/bee-inx/src/node/config.rs +++ b/bee-inx/src/node/config.rs @@ -4,7 +4,7 @@ use bee_block as bee; use inx::proto; -use crate::maybe_missing; +use crate::return_err_if_none; /// The [`BaseToken`] type. #[derive(Clone, Debug, PartialEq, Eq)] @@ -86,7 +86,7 @@ impl TryFrom for NodeConfiguration { Ok(NodeConfiguration { milestone_public_key_count: value.milestone_public_key_count, milestone_key_ranges: value.milestone_key_ranges.into_iter().map(Into::into).collect(), - base_token: maybe_missing!(value.base_token).into(), + base_token: return_err_if_none!(value.base_token).into(), supported_protocol_versions: value.supported_protocol_versions.into_iter().map(|v| v as u8).collect(), }) } diff --git a/bee-inx/src/node/status.rs b/bee-inx/src/node/status.rs index b92c2dedb0..0c26473018 100644 --- a/bee-inx/src/node/status.rs +++ b/bee-inx/src/node/status.rs @@ -4,7 +4,7 @@ use bee_block as bee; use inx::proto; -use crate::{maybe_missing, Milestone, ProtocolParameters}; +use crate::{return_err_if_none, Milestone, ProtocolParameters}; /// The [`NodeStatus`] type. #[derive(Clone, Debug, PartialEq, Eq)] @@ -39,9 +39,9 @@ impl TryFrom for NodeStatus { is_healthy: value.is_healthy, is_synced: value.is_synced, is_almost_synced: value.is_almost_synced, - latest_milestone: maybe_missing!(value.latest_milestone).try_into()?, - confirmed_milestone: maybe_missing!(value.confirmed_milestone).try_into()?, - current_protocol_parameters: maybe_missing!(value.current_protocol_parameters).into(), + latest_milestone: return_err_if_none!(value.latest_milestone).try_into()?, + confirmed_milestone: return_err_if_none!(value.confirmed_milestone).try_into()?, + current_protocol_parameters: return_err_if_none!(value.current_protocol_parameters).into(), tangle_pruning_index: value.tangle_pruning_index.into(), milestones_pruning_index: value.milestones_pruning_index.into(), ledger_pruning_index: value.ledger_pruning_index.into(), diff --git a/bee-inx/src/treasury.rs b/bee-inx/src/treasury.rs index d6cbbff88e..352fb54102 100644 --- a/bee-inx/src/treasury.rs +++ b/bee-inx/src/treasury.rs @@ -4,7 +4,7 @@ use bee_block as bee; use inx::proto; -use crate::maybe_missing; +use crate::return_err_if_none; /// Represents a treasury output. #[allow(missing_docs)] @@ -19,7 +19,7 @@ impl TryFrom for TreasuryOutput { fn try_from(value: proto::TreasuryOutput) -> Result { Ok(TreasuryOutput { - milestone_id: maybe_missing!(value.milestone_id).try_into()?, + milestone_id: return_err_if_none!(value.milestone_id).try_into()?, amount: value.amount, }) } @@ -49,8 +49,8 @@ impl TryFrom for TreasuryUpdate { fn try_from(value: proto::TreasuryUpdate) -> Result { Ok(Self { milestone_index: value.milestone_index, - created: maybe_missing!(value.created).try_into()?, - consumed: maybe_missing!(value.consumed).try_into()?, + created: return_err_if_none!(value.created).try_into()?, + consumed: return_err_if_none!(value.consumed).try_into()?, }) } } From 4dc28e47e62d6fe596109713d162be196f1cfad2 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Tue, 27 Sep 2022 12:44:55 +0200 Subject: [PATCH 02/25] Make 'protocol_parameters' a sub-module of 'node' --- bee-inx/src/lib.rs | 3 +-- bee-inx/src/node/mod.rs | 3 ++- bee-inx/src/{ => node}/protocol_parameters.rs | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename bee-inx/src/{ => node}/protocol_parameters.rs (100%) diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index d2b34c710a..bc1cbf04f3 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -8,13 +8,12 @@ mod ledger; mod metadata; mod milestone; mod node; -mod protocol_parameters; mod raw; mod request; mod treasury; pub use self::{ - block::*, error::Error, ledger::*, metadata::*, milestone::*, node::*, protocol_parameters::*, raw::*, request::*, + block::*, error::Error, ledger::*, metadata::*, milestone::*, node::*, raw::*, request::*, treasury::*, }; diff --git a/bee-inx/src/node/mod.rs b/bee-inx/src/node/mod.rs index 2dbe947ce5..df49c774ab 100644 --- a/bee-inx/src/node/mod.rs +++ b/bee-inx/src/node/mod.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 mod config; +mod protocol_parameters; mod status; -pub use self::{config::NodeConfiguration, status::NodeStatus}; +pub use self::{config::NodeConfiguration, status::NodeStatus, protocol_parameters::ProtocolParameters}; diff --git a/bee-inx/src/protocol_parameters.rs b/bee-inx/src/node/protocol_parameters.rs similarity index 100% rename from bee-inx/src/protocol_parameters.rs rename to bee-inx/src/node/protocol_parameters.rs From a1d029d2165c77027844f1d62072f26ee174bee5 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Tue, 27 Sep 2022 12:52:01 +0200 Subject: [PATCH 03/25] Make 'metadata' a sub-module of 'block' --- bee-inx/src/{ => block}/metadata.rs | 0 bee-inx/src/{block.rs => block/mod.rs} | 3 +++ bee-inx/src/lib.rs | 6 +----- bee-inx/src/milestone/mod.rs | 3 +-- bee-inx/src/node/mod.rs | 2 +- 5 files changed, 6 insertions(+), 8 deletions(-) rename bee-inx/src/{ => block}/metadata.rs (100%) rename bee-inx/src/{block.rs => block/mod.rs} (97%) diff --git a/bee-inx/src/metadata.rs b/bee-inx/src/block/metadata.rs similarity index 100% rename from bee-inx/src/metadata.rs rename to bee-inx/src/block/metadata.rs diff --git a/bee-inx/src/block.rs b/bee-inx/src/block/mod.rs similarity index 97% rename from bee-inx/src/block.rs rename to bee-inx/src/block/mod.rs index e65f792c39..a5a9c37a0d 100644 --- a/bee-inx/src/block.rs +++ b/bee-inx/src/block/mod.rs @@ -1,9 +1,12 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +pub mod metadata; + use bee_block as bee; use inx::proto; +pub use self::metadata::*; use crate::{return_err_if_none, Raw}; /// The [`Block`] type. diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index bc1cbf04f3..61c51d23b2 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -5,17 +5,13 @@ mod block; pub mod client; mod error; mod ledger; -mod metadata; mod milestone; mod node; mod raw; mod request; mod treasury; -pub use self::{ - block::*, error::Error, ledger::*, metadata::*, milestone::*, node::*, raw::*, request::*, - treasury::*, -}; +pub use self::{block::*, error::Error, ledger::*, milestone::*, node::*, raw::*, request::*, treasury::*}; pub mod proto { pub use inx::proto::*; diff --git a/bee-inx/src/milestone/mod.rs b/bee-inx/src/milestone/mod.rs index 5b08e7f396..de28e1b13d 100644 --- a/bee-inx/src/milestone/mod.rs +++ b/bee-inx/src/milestone/mod.rs @@ -1,10 +1,9 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use bee_block as bee; - mod info; +use bee_block as bee; use inx::proto; pub use self::info::MilestoneInfo; diff --git a/bee-inx/src/node/mod.rs b/bee-inx/src/node/mod.rs index df49c774ab..2170ae0ad5 100644 --- a/bee-inx/src/node/mod.rs +++ b/bee-inx/src/node/mod.rs @@ -5,4 +5,4 @@ mod config; mod protocol_parameters; mod status; -pub use self::{config::NodeConfiguration, status::NodeStatus, protocol_parameters::ProtocolParameters}; +pub use self::{config::NodeConfiguration, protocol_parameters::ProtocolParameters, status::NodeStatus}; From 4fad702333f2f8cfb33abf829e8ea411280f6a50 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 28 Sep 2022 08:35:57 +0200 Subject: [PATCH 04/25] Make fully exported modules pub --- bee-inx/src/block/metadata.rs | 16 ++++++++-------- bee-inx/src/lib.rs | 17 +++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/bee-inx/src/block/metadata.rs b/bee-inx/src/block/metadata.rs index a685d2f87b..a240462060 100644 --- a/bee-inx/src/block/metadata.rs +++ b/bee-inx/src/block/metadata.rs @@ -6,14 +6,6 @@ use inx::proto; use crate::return_err_if_none; -#[allow(missing_docs)] -#[derive(Clone, Debug, PartialEq, Eq)] -pub enum LedgerInclusionState { - NoTransaction, - Included, - Conflicting, -} - /// The metadata for a block with a given [`BlockId`](bee::BlockId). #[derive(Clone, Debug, PartialEq, Eq)] pub struct BlockMetadata { @@ -105,3 +97,11 @@ impl From for proto::BlockMetadata { } } } + +#[allow(missing_docs)] +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum LedgerInclusionState { + NoTransaction, + Included, + Conflicting, +} diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index 61c51d23b2..12909062a5 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -1,15 +1,16 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -mod block; -pub mod client; mod error; -mod ledger; -mod milestone; -mod node; -mod raw; -mod request; -mod treasury; + +pub mod block; +pub mod client; +pub mod ledger; +pub mod milestone; +pub mod node; +pub mod raw; +pub mod request; +pub mod treasury; pub use self::{block::*, error::Error, ledger::*, milestone::*, node::*, raw::*, request::*, treasury::*}; From fbfbd0d8ac88fe35a840f54e5363a1874eb21072 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 28 Sep 2022 10:05:17 +0200 Subject: [PATCH 05/25] Refactor client --- bee-inx/examples/milestone.rs | 2 +- bee-inx/src/client.rs | 105 ++---------------- bee-inx/src/lib.rs | 11 +- bee-inx/src/milestone/mod.rs | 62 +++++++++-- .../src/node/{config.rs => configuration.rs} | 86 +++++++------- bee-inx/src/node/mod.rs | 36 +++++- bee-inx/src/{ => utxo}/ledger.rs | 0 bee-inx/src/utxo/mod.rs | 40 +++++++ bee-inx/src/{ => utxo}/treasury.rs | 0 9 files changed, 189 insertions(+), 153 deletions(-) rename bee-inx/src/node/{config.rs => configuration.rs} (100%) rename bee-inx/src/{ => utxo}/ledger.rs (100%) create mode 100644 bee-inx/src/utxo/mod.rs rename bee-inx/src/{ => utxo}/treasury.rs (100%) diff --git a/bee-inx/examples/milestone.rs b/bee-inx/examples/milestone.rs index 7bdbe17fa7..9ffba47146 100644 --- a/bee-inx/examples/milestone.rs +++ b/bee-inx/examples/milestone.rs @@ -8,7 +8,7 @@ const INX_ADDRESS: &str = "http://localhost:9029"; #[tokio::main] async fn main() -> Result<(), Error> { - let mut inx = client::Inx::connect(INX_ADDRESS.into()).await?; + let mut inx = client::Inx::connect(INX_ADDRESS).await?; let mut milestone_stream = inx.listen_to_confirmed_milestones((..).into()).await?; // Listen to the milestones from the node. diff --git a/bee-inx/src/client.rs b/bee-inx/src/client.rs index 97595be2fa..195da1b364 100644 --- a/bee-inx/src/client.rs +++ b/bee-inx/src/client.rs @@ -1,110 +1,29 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use futures::stream::{Stream, StreamExt}; -use inx::{proto, proto::inx_client::InxClient, tonic}; +use ::inx::{proto::inx_client::InxClient, tonic}; -use crate::{Error, Milestone, MilestoneRangeRequest, MilestoneRequest, NodeConfiguration, NodeStatus}; +use crate::error::Error; /// An INX client connection. #[derive(Clone, Debug)] pub struct Inx { - inx: InxClient, -} - -fn unpack_proto_msg(msg: Result) -> Result -where - Bee: TryFrom, -{ - let inner = msg.map_err(Error::StatusCode)?; - Bee::try_from(inner).map_err(Error::InxError) + pub(crate) client: InxClient, } impl Inx { /// Connect to the INX interface of a node. - pub async fn connect(address: String) -> Result { + pub async fn connect(address: impl ToString) -> Result { Ok(Self { - inx: InxClient::connect(address).await?, + client: InxClient::connect(address.to_string()).await?, }) } +} - /// Listens to confirmed milestones in the range of - pub async fn listen_to_confirmed_milestones( - &mut self, - request: MilestoneRangeRequest, - ) -> Result>, Error> { - Ok(self - .inx - .listen_to_confirmed_milestones(proto::MilestoneRangeRequest::from(request)) - .await? - .into_inner() - .map(unpack_proto_msg)) - } - - pub async fn listen_to_ledger_updates( - &mut self, - request: MilestoneRangeRequest, - ) -> Result>, Error> { - Ok(self - .inx - .listen_to_ledger_updates(proto::MilestoneRangeRequest::from(request)) - .await? - .into_inner() - .map(unpack_proto_msg)) - } - - pub async fn read_node_status(&mut self) -> Result { - NodeStatus::try_from(self.inx.read_node_status(proto::NoParams {}).await?.into_inner()).map_err(Error::InxError) - } - - pub async fn read_node_configuration(&mut self) -> Result { - NodeConfiguration::try_from(self.inx.read_node_configuration(proto::NoParams {}).await?.into_inner()) - .map_err(Error::InxError) - } - - pub async fn read_unspent_outputs( - &mut self, - ) -> Result>, Error> { - Ok(self - .inx - .read_unspent_outputs(proto::NoParams {}) - .await? - .into_inner() - .map(unpack_proto_msg)) - } - - pub async fn read_protocol_parameters( - &mut self, - request: MilestoneRequest, - ) -> Result { - Ok(self - .inx - .read_protocol_parameters(proto::MilestoneRequest::from(request)) - .await? - .into_inner() - .into()) - } - - /// Reads the past cone of a milestone specified by a [`MilestoneRequest`]. - pub async fn read_milestone_cone( - &mut self, - request: MilestoneRequest, - ) -> Result>, Error> { - Ok(self - .inx - .read_milestone_cone(proto::MilestoneRequest::from(request)) - .await? - .into_inner() - .map(unpack_proto_msg)) - } - - pub async fn read_milestone(&mut self, request: MilestoneRequest) -> Result { - Milestone::try_from( - self.inx - .read_milestone(proto::MilestoneRequest::from(request)) - .await? - .into_inner(), - ) - .map_err(Error::InxError) - } +pub(crate) fn try_convert_proto_msg(msg: Result) -> Result +where + B: TryFrom, +{ + let inner = msg.map_err(Error::StatusCode)?; + B::try_from(inner).map_err(Error::InxError) } diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index 12909062a5..3b48c799da 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -5,17 +5,16 @@ mod error; pub mod block; pub mod client; -pub mod ledger; pub mod milestone; pub mod node; pub mod raw; pub mod request; -pub mod treasury; +pub mod utxo; -pub use self::{block::*, error::Error, ledger::*, milestone::*, node::*, raw::*, request::*, treasury::*}; +pub use self::{block::*, error::Error, milestone::*, node::*, raw::*, request::*, utxo::*}; -pub mod proto { - pub use inx::proto::*; +pub mod inx { + pub use ::inx::proto::*; } #[macro_export] @@ -31,7 +30,7 @@ mod test { #[test] fn macro_missing_field() { - let proto = proto::TreasuryOutput { + let proto = inx::TreasuryOutput { milestone_id: None, amount: 42, }; diff --git a/bee-inx/src/milestone/mod.rs b/bee-inx/src/milestone/mod.rs index de28e1b13d..1daa3e61f8 100644 --- a/bee-inx/src/milestone/mod.rs +++ b/bee-inx/src/milestone/mod.rs @@ -4,10 +4,17 @@ mod info; use bee_block as bee; -use inx::proto; +use futures::stream::{Stream, StreamExt}; pub use self::info::MilestoneInfo; -use crate::{return_err_if_none, ProtocolParameters, Raw}; +use crate::{ + block::BlockWithMetadata, + client::{try_convert_proto_msg, Inx}, + error::Error, + inx, + request::{MilestoneRangeRequest, MilestoneRequest}, + return_err_if_none, ProtocolParameters, Raw, +}; /// The [`Milestone`] type. #[derive(Clone, Debug, PartialEq, Eq)] @@ -19,10 +26,10 @@ pub struct Milestone { pub milestone: Raw, } -impl TryFrom for Milestone { +impl TryFrom for Milestone { type Error = bee::InxError; - fn try_from(value: proto::Milestone) -> Result { + fn try_from(value: inx::Milestone) -> Result { Ok(Self { milestone_info: return_err_if_none!(value.milestone_info).try_into()?, milestone: return_err_if_none!(value.milestone).data.into(), @@ -30,7 +37,7 @@ impl TryFrom for Milestone { } } -impl From for proto::Milestone { +impl From for inx::Milestone { fn from(value: Milestone) -> Self { Self { milestone_info: Some(value.milestone_info.into()), @@ -46,10 +53,10 @@ pub struct MilestoneAndProtocolParameters { pub current_protocol_parameters: ProtocolParameters, } -impl TryFrom for MilestoneAndProtocolParameters { +impl TryFrom for MilestoneAndProtocolParameters { type Error = bee::InxError; - fn try_from(value: proto::MilestoneAndProtocolParameters) -> Result { + fn try_from(value: inx::MilestoneAndProtocolParameters) -> Result { Ok(Self { milestone: return_err_if_none!(value.milestone).try_into()?, current_protocol_parameters: return_err_if_none!(value.current_protocol_parameters).into(), @@ -57,7 +64,7 @@ impl TryFrom for MilestoneAndProtocolPara } } -impl From for proto::MilestoneAndProtocolParameters { +impl From for inx::MilestoneAndProtocolParameters { fn from(value: MilestoneAndProtocolParameters) -> Self { Self { milestone: Some(value.milestone.into()), @@ -65,3 +72,42 @@ impl From for proto::MilestoneAndProtocolParamet } } } + +impl Inx { + /// TODO + pub async fn read_milestone(&mut self, request: MilestoneRequest) -> Result { + Milestone::try_from( + self.client + .read_milestone(inx::MilestoneRequest::from(request)) + .await? + .into_inner(), + ) + .map_err(Error::InxError) + } + + /// Listens to confirmed milestones in a certain range. + pub async fn listen_to_confirmed_milestones( + &mut self, + request: MilestoneRangeRequest, + ) -> Result>, Error> { + Ok(self + .client + .listen_to_confirmed_milestones(inx::MilestoneRangeRequest::from(request)) + .await? + .into_inner() + .map(try_convert_proto_msg)) + } + + /// Reads the past cone of a milestone specified by a [`MilestoneRequest`]. + pub async fn read_milestone_cone( + &mut self, + request: MilestoneRequest, + ) -> Result>, Error> { + Ok(self + .client + .read_milestone_cone(inx::MilestoneRequest::from(request)) + .await? + .into_inner() + .map(try_convert_proto_msg)) + } +} diff --git a/bee-inx/src/node/config.rs b/bee-inx/src/node/configuration.rs similarity index 100% rename from bee-inx/src/node/config.rs rename to bee-inx/src/node/configuration.rs index 4cab291c68..1ece30bf64 100644 --- a/bee-inx/src/node/config.rs +++ b/bee-inx/src/node/configuration.rs @@ -6,6 +6,49 @@ use inx::proto; use crate::return_err_if_none; +/// The [`NodeConfiguration`] type. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct NodeConfiguration { + pub milestone_public_key_count: u32, + pub milestone_key_ranges: Box<[MilestoneKeyRange]>, + pub base_token: BaseToken, + pub supported_protocol_versions: Box<[u8]>, +} + +impl TryFrom for NodeConfiguration { + type Error = bee::InxError; + + fn try_from(value: proto::NodeConfiguration) -> Result { + Ok(NodeConfiguration { + milestone_public_key_count: value.milestone_public_key_count, + milestone_key_ranges: value.milestone_key_ranges.into_iter().map(Into::into).collect(), + base_token: return_err_if_none!(value.base_token).into(), + supported_protocol_versions: value.supported_protocol_versions.into_iter().map(|v| v as u8).collect(), + }) + } +} + +impl From for proto::NodeConfiguration { + fn from(value: NodeConfiguration) -> Self { + Self { + milestone_public_key_count: value.milestone_public_key_count, + milestone_key_ranges: value + .milestone_key_ranges + .into_vec() + .into_iter() + .map(Into::into) + .collect(), + base_token: Some(value.base_token.into()), + supported_protocol_versions: value + .supported_protocol_versions + .into_vec() + .into_iter() + .map(|v| v as _) + .collect(), + } + } +} + /// The [`BaseToken`] type. #[derive(Clone, Debug, PartialEq, Eq)] pub struct BaseToken { @@ -69,46 +112,3 @@ impl From for proto::MilestoneKeyRange { } } } - -/// The [`NodeConfiguration`] type. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct NodeConfiguration { - pub milestone_public_key_count: u32, - pub milestone_key_ranges: Box<[MilestoneKeyRange]>, - pub base_token: BaseToken, - pub supported_protocol_versions: Box<[u8]>, -} - -impl TryFrom for NodeConfiguration { - type Error = bee::InxError; - - fn try_from(value: proto::NodeConfiguration) -> Result { - Ok(NodeConfiguration { - milestone_public_key_count: value.milestone_public_key_count, - milestone_key_ranges: value.milestone_key_ranges.into_iter().map(Into::into).collect(), - base_token: return_err_if_none!(value.base_token).into(), - supported_protocol_versions: value.supported_protocol_versions.into_iter().map(|v| v as u8).collect(), - }) - } -} - -impl From for proto::NodeConfiguration { - fn from(value: NodeConfiguration) -> Self { - Self { - milestone_public_key_count: value.milestone_public_key_count, - milestone_key_ranges: value - .milestone_key_ranges - .into_vec() - .into_iter() - .map(Into::into) - .collect(), - base_token: Some(value.base_token.into()), - supported_protocol_versions: value - .supported_protocol_versions - .into_vec() - .into_iter() - .map(|v| v as _) - .collect(), - } - } -} diff --git a/bee-inx/src/node/mod.rs b/bee-inx/src/node/mod.rs index 2170ae0ad5..2bdc075418 100644 --- a/bee-inx/src/node/mod.rs +++ b/bee-inx/src/node/mod.rs @@ -1,8 +1,40 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -mod config; +mod configuration; mod protocol_parameters; mod status; -pub use self::{config::NodeConfiguration, protocol_parameters::ProtocolParameters, status::NodeStatus}; +pub use self::{configuration::NodeConfiguration, protocol_parameters::ProtocolParameters, status::NodeStatus}; +use crate::{client::Inx, error::Error, inx, request::MilestoneRequest}; + +// TODO: listen_to_node_status + +impl Inx { + /// TODO + pub async fn read_node_status(&mut self) -> Result { + NodeStatus::try_from(self.client.read_node_status(inx::NoParams {}).await?.into_inner()) + .map_err(Error::InxError) + } + + /// TODO + pub async fn read_node_configuration(&mut self) -> Result { + NodeConfiguration::try_from( + self.client + .read_node_configuration(inx::NoParams {}) + .await? + .into_inner(), + ) + .map_err(Error::InxError) + } + + /// TODO + pub async fn read_protocol_parameters(&mut self, request: MilestoneRequest) -> Result { + Ok(self + .client + .read_protocol_parameters(inx::MilestoneRequest::from(request)) + .await? + .into_inner() + .into()) + } +} diff --git a/bee-inx/src/ledger.rs b/bee-inx/src/utxo/ledger.rs similarity index 100% rename from bee-inx/src/ledger.rs rename to bee-inx/src/utxo/ledger.rs diff --git a/bee-inx/src/utxo/mod.rs b/bee-inx/src/utxo/mod.rs new file mode 100644 index 0000000000..bf21f64132 --- /dev/null +++ b/bee-inx/src/utxo/mod.rs @@ -0,0 +1,40 @@ +// Copyright 2022 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +pub mod ledger; +pub mod treasury; + +use futures::{Stream, StreamExt}; + +pub use self::{ledger::*, treasury::*}; +use crate::{ + client::{try_convert_proto_msg, Inx}, + error::Error, + inx, + request::MilestoneRangeRequest, +}; + +impl Inx { + pub async fn listen_to_ledger_updates( + &mut self, + request: MilestoneRangeRequest, + ) -> Result>, Error> { + Ok(self + .client + .listen_to_ledger_updates(inx::MilestoneRangeRequest::from(request)) + .await? + .into_inner() + .map(try_convert_proto_msg)) + } + + pub async fn read_unspent_outputs( + &mut self, + ) -> Result>, Error> { + Ok(self + .client + .read_unspent_outputs(inx::NoParams {}) // TODO: ().into() + .await? + .into_inner() + .map(try_convert_proto_msg)) + } +} diff --git a/bee-inx/src/treasury.rs b/bee-inx/src/utxo/treasury.rs similarity index 100% rename from bee-inx/src/treasury.rs rename to bee-inx/src/utxo/treasury.rs From 5a31ca740d9cf9b9b232427dc5f461fee57885a6 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 28 Sep 2022 10:19:06 +0200 Subject: [PATCH 06/25] Move block types into 'types' module --- bee-inx/src/block/mod.rs | 66 ++--------------- bee-inx/src/block/{metadata.rs => types.rs} | 79 ++++++++++++++++++--- bee-inx/src/lib.rs | 1 + 3 files changed, 74 insertions(+), 72 deletions(-) rename bee-inx/src/block/{metadata.rs => types.rs} (58%) diff --git a/bee-inx/src/block/mod.rs b/bee-inx/src/block/mod.rs index a5a9c37a0d..a6a2664074 100644 --- a/bee-inx/src/block/mod.rs +++ b/bee-inx/src/block/mod.rs @@ -1,68 +1,12 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -pub mod metadata; +pub mod types; -use bee_block as bee; -use inx::proto; +pub use self::types::*; -pub use self::metadata::*; -use crate::{return_err_if_none, Raw}; +use crate::client::Inx; -/// The [`Block`] type. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct Block { - /// The [`BlockId`](bee::BlockId) of the block. - pub block_id: bee::BlockId, - /// The complete [`Block`](bee::Block) as raw bytes. - pub block: Raw, -} - -/// The [`BlockWithMetadata`] type. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct BlockWithMetadata { - /// The [`Metadata`](crate::BlockMetadata) of the block. - pub metadata: crate::BlockMetadata, - /// The complete [`Block`](bee::Block) as raw bytes. - pub block: Raw, -} - -impl TryFrom for BlockWithMetadata { - type Error = bee::InxError; - - fn try_from(value: proto::BlockWithMetadata) -> Result { - Ok(BlockWithMetadata { - metadata: return_err_if_none!(value.metadata).try_into()?, - block: return_err_if_none!(value.block).data.into(), - }) - } -} - -impl From for proto::BlockWithMetadata { - fn from(value: BlockWithMetadata) -> Self { - Self { - metadata: Some(value.metadata.into()), - block: Some(value.block.into()), - } - } -} - -impl TryFrom for Block { - type Error = bee::InxError; - - fn try_from(value: proto::Block) -> Result { - Ok(Block { - block_id: return_err_if_none!(value.block_id).try_into()?, - block: return_err_if_none!(value.block).data.into(), - }) - } -} - -impl From for proto::Block { - fn from(value: Block) -> Self { - Self { - block_id: Some(value.block_id.into()), - block: Some(value.block.into()), - } - } +impl Inx { + // TODO } diff --git a/bee-inx/src/block/metadata.rs b/bee-inx/src/block/types.rs similarity index 58% rename from bee-inx/src/block/metadata.rs rename to bee-inx/src/block/types.rs index a240462060..b49074874b 100644 --- a/bee-inx/src/block/metadata.rs +++ b/bee-inx/src/block/types.rs @@ -2,9 +2,66 @@ // SPDX-License-Identifier: Apache-2.0 use bee_block as bee; -use inx::proto; -use crate::return_err_if_none; +use crate::{inx, raw::Raw, return_err_if_none}; + +/// The [`Block`] type. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Block { + /// The [`BlockId`](bee::BlockId) of the block. + pub block_id: bee::BlockId, + /// The complete [`Block`](bee::Block) as raw bytes. + pub block: Raw, +} + +impl TryFrom for Block { + type Error = bee::InxError; + + fn try_from(value: inx::Block) -> Result { + Ok(Block { + block_id: return_err_if_none!(value.block_id).try_into()?, + block: return_err_if_none!(value.block).data.into(), + }) + } +} + +impl From for inx::Block { + fn from(value: Block) -> Self { + Self { + block_id: Some(value.block_id.into()), + block: Some(value.block.into()), + } + } +} + +/// The [`BlockWithMetadata`] type. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct BlockWithMetadata { + /// The [`Metadata`](crate::BlockMetadata) of the block. + pub metadata: crate::BlockMetadata, + /// The complete [`Block`](bee::Block) as raw bytes. + pub block: Raw, +} + +impl TryFrom for BlockWithMetadata { + type Error = bee::InxError; + + fn try_from(value: inx::BlockWithMetadata) -> Result { + Ok(BlockWithMetadata { + metadata: return_err_if_none!(value.metadata).try_into()?, + block: return_err_if_none!(value.block).data.into(), + }) + } +} + +impl From for inx::BlockWithMetadata { + fn from(value: BlockWithMetadata) -> Self { + Self { + metadata: Some(value.metadata.into()), + block: Some(value.block.into()), + } + } +} /// The metadata for a block with a given [`BlockId`](bee::BlockId). #[derive(Clone, Debug, PartialEq, Eq)] @@ -31,10 +88,10 @@ pub struct BlockMetadata { pub white_flag_index: u32, } -impl TryFrom for BlockMetadata { +impl TryFrom for BlockMetadata { type Error = bee::InxError; - fn try_from(value: proto::BlockMetadata) -> Result { + fn try_from(value: inx::BlockMetadata) -> Result { let ledger_inclusion_state = value.ledger_inclusion_state().into(); let conflict_reason = value.conflict_reason().into(); @@ -59,9 +116,9 @@ impl TryFrom for BlockMetadata { } } -impl From for LedgerInclusionState { - fn from(value: proto::block_metadata::LedgerInclusionState) -> Self { - use proto::block_metadata::LedgerInclusionState::*; +impl From for LedgerInclusionState { + fn from(value: inx::LedgerInclusionState) -> Self { + use crate::inx::LedgerInclusionState::*; match value { NoTransaction => LedgerInclusionState::NoTransaction, Included => LedgerInclusionState::Included, @@ -70,7 +127,7 @@ impl From for LedgerInclusionState } } -impl From for proto::block_metadata::LedgerInclusionState { +impl From for inx::LedgerInclusionState { fn from(value: LedgerInclusionState) -> Self { match value { LedgerInclusionState::NoTransaction => Self::NoTransaction, @@ -80,7 +137,7 @@ impl From for proto::block_metadata::LedgerInclusionState } } -impl From for proto::BlockMetadata { +impl From for inx::BlockMetadata { fn from(value: BlockMetadata) -> Self { Self { block_id: Some(value.block_id.into()), @@ -90,9 +147,9 @@ impl From for proto::BlockMetadata { should_reattach: value.should_reattach, referenced_by_milestone_index: value.referenced_by_milestone_index, milestone_index: value.milestone_index, - ledger_inclusion_state: proto::block_metadata::LedgerInclusionState::from(value.ledger_inclusion_state) + ledger_inclusion_state: inx::block_metadata::LedgerInclusionState::from(value.ledger_inclusion_state) .into(), - conflict_reason: proto::block_metadata::ConflictReason::from(value.conflict_reason).into(), + conflict_reason: inx::block_metadata::ConflictReason::from(value.conflict_reason).into(), white_flag_index: value.white_flag_index, } } diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index 3b48c799da..d60c87fffd 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -15,6 +15,7 @@ pub use self::{block::*, error::Error, milestone::*, node::*, raw::*, request::* pub mod inx { pub use ::inx::proto::*; + pub use ::inx::proto::block_metadata::*; } #[macro_export] From f4b84c9b095f4148a66caa66fa450a9867a076b5 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 28 Sep 2022 10:25:56 +0200 Subject: [PATCH 07/25] Move milestone types into 'types' module --- bee-inx/src/block/mod.rs | 1 - bee-inx/src/lib.rs | 3 +- bee-inx/src/milestone/info.rs | 38 -------------- bee-inx/src/milestone/mod.rs | 65 ++--------------------- bee-inx/src/milestone/types.rs | 96 ++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+), 103 deletions(-) delete mode 100644 bee-inx/src/milestone/info.rs create mode 100644 bee-inx/src/milestone/types.rs diff --git a/bee-inx/src/block/mod.rs b/bee-inx/src/block/mod.rs index a6a2664074..ae848b4bed 100644 --- a/bee-inx/src/block/mod.rs +++ b/bee-inx/src/block/mod.rs @@ -4,7 +4,6 @@ pub mod types; pub use self::types::*; - use crate::client::Inx; impl Inx { diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index d60c87fffd..22a1d3965e 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -14,8 +14,7 @@ pub mod utxo; pub use self::{block::*, error::Error, milestone::*, node::*, raw::*, request::*, utxo::*}; pub mod inx { - pub use ::inx::proto::*; - pub use ::inx::proto::block_metadata::*; + pub use ::inx::proto::{block_metadata::*, *}; } #[macro_export] diff --git a/bee-inx/src/milestone/info.rs b/bee-inx/src/milestone/info.rs deleted file mode 100644 index 46edc527dc..0000000000 --- a/bee-inx/src/milestone/info.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use bee_block as bee; -use inx::proto; - -/// The [`MilestoneInfo`] type. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct MilestoneInfo { - /// The [`MilestoneId`](bee::payload::milestone::MilestoneId) of the milestone. - pub milestone_id: Option, - /// The milestone index. - pub milestone_index: bee::payload::milestone::MilestoneIndex, - /// The timestamp of the milestone. - pub milestone_timestamp: u32, -} - -impl TryFrom for MilestoneInfo { - type Error = bee::InxError; - - fn try_from(value: proto::MilestoneInfo) -> Result { - Ok(MilestoneInfo { - milestone_id: value.milestone_id.map(TryInto::try_into).transpose()?, - milestone_index: value.milestone_index.into(), - milestone_timestamp: value.milestone_timestamp, - }) - } -} - -impl From for proto::MilestoneInfo { - fn from(value: MilestoneInfo) -> Self { - Self { - milestone_id: value.milestone_id.map(Into::into), - milestone_index: value.milestone_index.0, - milestone_timestamp: value.milestone_timestamp, - } - } -} diff --git a/bee-inx/src/milestone/mod.rs b/bee-inx/src/milestone/mod.rs index 1daa3e61f8..a4e8438359 100644 --- a/bee-inx/src/milestone/mod.rs +++ b/bee-inx/src/milestone/mod.rs @@ -1,78 +1,19 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -mod info; +pub mod types; -use bee_block as bee; use futures::stream::{Stream, StreamExt}; -pub use self::info::MilestoneInfo; +pub use self::types::*; use crate::{ - block::BlockWithMetadata, + block::types::BlockWithMetadata, client::{try_convert_proto_msg, Inx}, error::Error, inx, request::{MilestoneRangeRequest, MilestoneRequest}, - return_err_if_none, ProtocolParameters, Raw, }; -/// The [`Milestone`] type. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct Milestone { - /// Information about the milestone. - pub milestone_info: MilestoneInfo, - /// The raw bytes of the milestone. Note that this is not a [`bee::payload::milestone::MilestonePayload`], but - /// rather a [`bee::payload::Payload`] and still needs to be unpacked. - pub milestone: Raw, -} - -impl TryFrom for Milestone { - type Error = bee::InxError; - - fn try_from(value: inx::Milestone) -> Result { - Ok(Self { - milestone_info: return_err_if_none!(value.milestone_info).try_into()?, - milestone: return_err_if_none!(value.milestone).data.into(), - }) - } -} - -impl From for inx::Milestone { - fn from(value: Milestone) -> Self { - Self { - milestone_info: Some(value.milestone_info.into()), - milestone: Some(value.milestone.into()), - } - } -} - -/// The [`Milestone`] type. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct MilestoneAndProtocolParameters { - pub milestone: Milestone, - pub current_protocol_parameters: ProtocolParameters, -} - -impl TryFrom for MilestoneAndProtocolParameters { - type Error = bee::InxError; - - fn try_from(value: inx::MilestoneAndProtocolParameters) -> Result { - Ok(Self { - milestone: return_err_if_none!(value.milestone).try_into()?, - current_protocol_parameters: return_err_if_none!(value.current_protocol_parameters).into(), - }) - } -} - -impl From for inx::MilestoneAndProtocolParameters { - fn from(value: MilestoneAndProtocolParameters) -> Self { - Self { - milestone: Some(value.milestone.into()), - current_protocol_parameters: Some(value.current_protocol_parameters.into()), - } - } -} - impl Inx { /// TODO pub async fn read_milestone(&mut self, request: MilestoneRequest) -> Result { diff --git a/bee-inx/src/milestone/types.rs b/bee-inx/src/milestone/types.rs new file mode 100644 index 0000000000..e25c98439b --- /dev/null +++ b/bee-inx/src/milestone/types.rs @@ -0,0 +1,96 @@ +// Copyright 2022 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use bee_block as bee; + +use crate::{inx, return_err_if_none, ProtocolParameters, Raw}; + +/// The [`Milestone`] type. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Milestone { + /// Information about the milestone. + pub milestone_info: MilestoneInfo, + /// The raw bytes of the milestone. Note that this is not a [`bee::payload::milestone::MilestonePayload`], but + /// rather a [`bee::payload::Payload`] and still needs to be unpacked. + pub milestone: Raw, +} + +impl TryFrom for Milestone { + type Error = bee::InxError; + + fn try_from(value: inx::Milestone) -> Result { + Ok(Self { + milestone_info: return_err_if_none!(value.milestone_info).try_into()?, + milestone: return_err_if_none!(value.milestone).data.into(), + }) + } +} + +impl From for inx::Milestone { + fn from(value: Milestone) -> Self { + Self { + milestone_info: Some(value.milestone_info.into()), + milestone: Some(value.milestone.into()), + } + } +} + +/// The [`Milestone`] type. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct MilestoneAndProtocolParameters { + pub milestone: Milestone, + pub current_protocol_parameters: ProtocolParameters, +} + +impl TryFrom for MilestoneAndProtocolParameters { + type Error = bee::InxError; + + fn try_from(value: inx::MilestoneAndProtocolParameters) -> Result { + Ok(Self { + milestone: return_err_if_none!(value.milestone).try_into()?, + current_protocol_parameters: return_err_if_none!(value.current_protocol_parameters).into(), + }) + } +} + +impl From for inx::MilestoneAndProtocolParameters { + fn from(value: MilestoneAndProtocolParameters) -> Self { + Self { + milestone: Some(value.milestone.into()), + current_protocol_parameters: Some(value.current_protocol_parameters.into()), + } + } +} + +/// The [`MilestoneInfo`] type. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct MilestoneInfo { + /// The [`MilestoneId`](bee::payload::milestone::MilestoneId) of the milestone. + pub milestone_id: Option, + /// The milestone index. + pub milestone_index: bee::payload::milestone::MilestoneIndex, + /// The timestamp of the milestone. + pub milestone_timestamp: u32, +} + +impl TryFrom for MilestoneInfo { + type Error = bee::InxError; + + fn try_from(value: inx::MilestoneInfo) -> Result { + Ok(MilestoneInfo { + milestone_id: value.milestone_id.map(TryInto::try_into).transpose()?, + milestone_index: value.milestone_index.into(), + milestone_timestamp: value.milestone_timestamp, + }) + } +} + +impl From for inx::MilestoneInfo { + fn from(value: MilestoneInfo) -> Self { + Self { + milestone_id: value.milestone_id.map(Into::into), + milestone_index: value.milestone_index.0, + milestone_timestamp: value.milestone_timestamp, + } + } +} From 89419a208a718f6991bdc59f1e9796912069226d Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 28 Sep 2022 10:32:58 +0200 Subject: [PATCH 08/25] Rename fn that converts from INX type --- bee-inx/src/client.rs | 2 +- bee-inx/src/milestone/mod.rs | 6 +++--- bee-inx/src/utxo/mod.rs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bee-inx/src/client.rs b/bee-inx/src/client.rs index 195da1b364..9f901c12bb 100644 --- a/bee-inx/src/client.rs +++ b/bee-inx/src/client.rs @@ -20,7 +20,7 @@ impl Inx { } } -pub(crate) fn try_convert_proto_msg(msg: Result) -> Result +pub(crate) fn try_from_inx_type(msg: Result) -> Result where B: TryFrom, { diff --git a/bee-inx/src/milestone/mod.rs b/bee-inx/src/milestone/mod.rs index a4e8438359..f7cb22cdef 100644 --- a/bee-inx/src/milestone/mod.rs +++ b/bee-inx/src/milestone/mod.rs @@ -8,7 +8,7 @@ use futures::stream::{Stream, StreamExt}; pub use self::types::*; use crate::{ block::types::BlockWithMetadata, - client::{try_convert_proto_msg, Inx}, + client::{try_from_inx_type, Inx}, error::Error, inx, request::{MilestoneRangeRequest, MilestoneRequest}, @@ -36,7 +36,7 @@ impl Inx { .listen_to_confirmed_milestones(inx::MilestoneRangeRequest::from(request)) .await? .into_inner() - .map(try_convert_proto_msg)) + .map(try_from_inx_type)) } /// Reads the past cone of a milestone specified by a [`MilestoneRequest`]. @@ -49,6 +49,6 @@ impl Inx { .read_milestone_cone(inx::MilestoneRequest::from(request)) .await? .into_inner() - .map(try_convert_proto_msg)) + .map(try_from_inx_type)) } } diff --git a/bee-inx/src/utxo/mod.rs b/bee-inx/src/utxo/mod.rs index bf21f64132..9e9e93f71c 100644 --- a/bee-inx/src/utxo/mod.rs +++ b/bee-inx/src/utxo/mod.rs @@ -8,7 +8,7 @@ use futures::{Stream, StreamExt}; pub use self::{ledger::*, treasury::*}; use crate::{ - client::{try_convert_proto_msg, Inx}, + client::{try_from_inx_type, Inx}, error::Error, inx, request::MilestoneRangeRequest, @@ -24,7 +24,7 @@ impl Inx { .listen_to_ledger_updates(inx::MilestoneRangeRequest::from(request)) .await? .into_inner() - .map(try_convert_proto_msg)) + .map(try_from_inx_type)) } pub async fn read_unspent_outputs( @@ -35,6 +35,6 @@ impl Inx { .read_unspent_outputs(inx::NoParams {}) // TODO: ().into() .await? .into_inner() - .map(try_convert_proto_msg)) + .map(try_from_inx_type)) } } From 4123d4c3ddb0edd1df781f888e8787ec35ba3960 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 28 Sep 2022 10:37:27 +0200 Subject: [PATCH 09/25] Move node types into 'types' module --- bee-inx/src/node/mod.rs | 10 +-- bee-inx/src/node/protocol_parameters.rs | 32 ------- bee-inx/src/node/status.rs | 68 -------------- .../src/node/{configuration.rs => types.rs} | 88 ++++++++++++++++++- 4 files changed, 91 insertions(+), 107 deletions(-) delete mode 100644 bee-inx/src/node/protocol_parameters.rs delete mode 100644 bee-inx/src/node/status.rs rename bee-inx/src/node/{configuration.rs => types.rs} (50%) diff --git a/bee-inx/src/node/mod.rs b/bee-inx/src/node/mod.rs index 2bdc075418..cadd85f694 100644 --- a/bee-inx/src/node/mod.rs +++ b/bee-inx/src/node/mod.rs @@ -1,15 +1,11 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -mod configuration; -mod protocol_parameters; -mod status; +mod types; -pub use self::{configuration::NodeConfiguration, protocol_parameters::ProtocolParameters, status::NodeStatus}; +pub use self::types::*; use crate::{client::Inx, error::Error, inx, request::MilestoneRequest}; -// TODO: listen_to_node_status - impl Inx { /// TODO pub async fn read_node_status(&mut self) -> Result { @@ -17,6 +13,8 @@ impl Inx { .map_err(Error::InxError) } + // TODO: listen_to_node_status + /// TODO pub async fn read_node_configuration(&mut self) -> Result { NodeConfiguration::try_from( diff --git a/bee-inx/src/node/protocol_parameters.rs b/bee-inx/src/node/protocol_parameters.rs deleted file mode 100644 index c5d5ebf30e..0000000000 --- a/bee-inx/src/node/protocol_parameters.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2022 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use bee_block as bee; -use inx::proto; - -use crate::Raw; - -#[allow(missing_docs)] -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct ProtocolParameters { - pub protocol_version: u8, - pub params: Raw, -} - -impl From for ProtocolParameters { - fn from(value: proto::RawProtocolParameters) -> Self { - Self { - protocol_version: value.protocol_version as u8, - params: value.params.into(), - } - } -} - -impl From for proto::RawProtocolParameters { - fn from(value: ProtocolParameters) -> Self { - Self { - protocol_version: value.protocol_version as u32, - params: value.params.data(), - } - } -} diff --git a/bee-inx/src/node/status.rs b/bee-inx/src/node/status.rs deleted file mode 100644 index 0c26473018..0000000000 --- a/bee-inx/src/node/status.rs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2022 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use bee_block as bee; -use inx::proto; - -use crate::{return_err_if_none, Milestone, ProtocolParameters}; - -/// The [`NodeStatus`] type. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct NodeStatus { - /// Signals if the node is healthy. - pub is_healthy: bool, - /// Signals if the node is synced. - pub is_synced: bool, - /// Signals if the node is almost synced (within a configured range). - pub is_almost_synced: bool, - /// The latest milestone seen by the node. - pub latest_milestone: Milestone, - /// The last confirmed milestone. - pub confirmed_milestone: Milestone, - /// The current protocol parameters. - pub current_protocol_parameters: ProtocolParameters, - /// The tangle pruning index of the node. - pub tangle_pruning_index: bee::payload::milestone::MilestoneIndex, - /// The milestones pruning index of the node. - pub milestones_pruning_index: bee::payload::milestone::MilestoneIndex, - /// The ledger pruning index of the node. - pub ledger_pruning_index: bee::payload::milestone::MilestoneIndex, - /// The ledger index of the node. - pub ledger_index: bee::payload::milestone::MilestoneIndex, -} - -impl TryFrom for NodeStatus { - type Error = bee::InxError; - - fn try_from(value: proto::NodeStatus) -> Result { - Ok(NodeStatus { - is_healthy: value.is_healthy, - is_synced: value.is_synced, - is_almost_synced: value.is_almost_synced, - latest_milestone: return_err_if_none!(value.latest_milestone).try_into()?, - confirmed_milestone: return_err_if_none!(value.confirmed_milestone).try_into()?, - current_protocol_parameters: return_err_if_none!(value.current_protocol_parameters).into(), - tangle_pruning_index: value.tangle_pruning_index.into(), - milestones_pruning_index: value.milestones_pruning_index.into(), - ledger_pruning_index: value.ledger_pruning_index.into(), - ledger_index: value.ledger_index.into(), - }) - } -} - -impl From for proto::NodeStatus { - fn from(value: NodeStatus) -> Self { - Self { - is_healthy: value.is_healthy, - is_synced: value.is_synced, - is_almost_synced: value.is_almost_synced, - latest_milestone: Some(value.latest_milestone.into()), - confirmed_milestone: Some(value.confirmed_milestone.into()), - current_protocol_parameters: Some(value.current_protocol_parameters.into()), - tangle_pruning_index: value.tangle_pruning_index.0, - milestones_pruning_index: value.milestones_pruning_index.0, - ledger_pruning_index: value.ledger_pruning_index.0, - ledger_index: value.ledger_index.0, - } - } -} diff --git a/bee-inx/src/node/configuration.rs b/bee-inx/src/node/types.rs similarity index 50% rename from bee-inx/src/node/configuration.rs rename to bee-inx/src/node/types.rs index 1ece30bf64..b75e9145cd 100644 --- a/bee-inx/src/node/configuration.rs +++ b/bee-inx/src/node/types.rs @@ -4,7 +4,68 @@ use bee_block as bee; use inx::proto; -use crate::return_err_if_none; +use crate::{milestone::types::Milestone, raw::Raw, return_err_if_none}; + +/// The [`NodeStatus`] type. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct NodeStatus { + /// Signals if the node is healthy. + pub is_healthy: bool, + /// Signals if the node is synced. + pub is_synced: bool, + /// Signals if the node is almost synced (within a configured range). + pub is_almost_synced: bool, + /// The latest milestone seen by the node. + pub latest_milestone: Milestone, + /// The last confirmed milestone. + pub confirmed_milestone: Milestone, + /// The current protocol parameters. + pub current_protocol_parameters: ProtocolParameters, + /// The tangle pruning index of the node. + pub tangle_pruning_index: bee::payload::milestone::MilestoneIndex, + /// The milestones pruning index of the node. + pub milestones_pruning_index: bee::payload::milestone::MilestoneIndex, + /// The ledger pruning index of the node. + pub ledger_pruning_index: bee::payload::milestone::MilestoneIndex, + /// The ledger index of the node. + pub ledger_index: bee::payload::milestone::MilestoneIndex, +} + +impl TryFrom for NodeStatus { + type Error = bee::InxError; + + fn try_from(value: proto::NodeStatus) -> Result { + Ok(NodeStatus { + is_healthy: value.is_healthy, + is_synced: value.is_synced, + is_almost_synced: value.is_almost_synced, + latest_milestone: return_err_if_none!(value.latest_milestone).try_into()?, + confirmed_milestone: return_err_if_none!(value.confirmed_milestone).try_into()?, + current_protocol_parameters: return_err_if_none!(value.current_protocol_parameters).into(), + tangle_pruning_index: value.tangle_pruning_index.into(), + milestones_pruning_index: value.milestones_pruning_index.into(), + ledger_pruning_index: value.ledger_pruning_index.into(), + ledger_index: value.ledger_index.into(), + }) + } +} + +impl From for proto::NodeStatus { + fn from(value: NodeStatus) -> Self { + Self { + is_healthy: value.is_healthy, + is_synced: value.is_synced, + is_almost_synced: value.is_almost_synced, + latest_milestone: Some(value.latest_milestone.into()), + confirmed_milestone: Some(value.confirmed_milestone.into()), + current_protocol_parameters: Some(value.current_protocol_parameters.into()), + tangle_pruning_index: value.tangle_pruning_index.0, + milestones_pruning_index: value.milestones_pruning_index.0, + ledger_pruning_index: value.ledger_pruning_index.0, + ledger_index: value.ledger_index.0, + } + } +} /// The [`NodeConfiguration`] type. #[derive(Clone, Debug, PartialEq, Eq)] @@ -112,3 +173,28 @@ impl From for proto::MilestoneKeyRange { } } } + +#[allow(missing_docs)] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct ProtocolParameters { + pub protocol_version: u8, + pub params: Raw, +} + +impl From for ProtocolParameters { + fn from(value: proto::RawProtocolParameters) -> Self { + Self { + protocol_version: value.protocol_version as u8, + params: value.params.into(), + } + } +} + +impl From for proto::RawProtocolParameters { + fn from(value: ProtocolParameters) -> Self { + Self { + protocol_version: value.protocol_version as u32, + params: value.params.data(), + } + } +} From 35aaf3a4476547bb2cc5447b72e9f13107887b79 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 28 Sep 2022 10:41:58 +0200 Subject: [PATCH 10/25] Rename to 'requests' module --- bee-inx/src/lib.rs | 4 ++-- bee-inx/src/milestone/mod.rs | 2 +- bee-inx/src/node/mod.rs | 2 +- bee-inx/src/{request.rs => requests.rs} | 17 +++++++++-------- bee-inx/src/utxo/mod.rs | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) rename bee-inx/src/{request.rs => requests.rs} (83%) diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index 22a1d3965e..7838974fba 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -8,10 +8,10 @@ pub mod client; pub mod milestone; pub mod node; pub mod raw; -pub mod request; +pub mod requests; pub mod utxo; -pub use self::{block::*, error::Error, milestone::*, node::*, raw::*, request::*, utxo::*}; +pub use self::{block::*, error::Error, milestone::*, node::*, raw::*, requests::*, utxo::*}; pub mod inx { pub use ::inx::proto::{block_metadata::*, *}; diff --git a/bee-inx/src/milestone/mod.rs b/bee-inx/src/milestone/mod.rs index f7cb22cdef..2d3c8432e3 100644 --- a/bee-inx/src/milestone/mod.rs +++ b/bee-inx/src/milestone/mod.rs @@ -11,7 +11,7 @@ use crate::{ client::{try_from_inx_type, Inx}, error::Error, inx, - request::{MilestoneRangeRequest, MilestoneRequest}, + requests::{MilestoneRangeRequest, MilestoneRequest}, }; impl Inx { diff --git a/bee-inx/src/node/mod.rs b/bee-inx/src/node/mod.rs index cadd85f694..af19d6330b 100644 --- a/bee-inx/src/node/mod.rs +++ b/bee-inx/src/node/mod.rs @@ -4,7 +4,7 @@ mod types; pub use self::types::*; -use crate::{client::Inx, error::Error, inx, request::MilestoneRequest}; +use crate::{client::Inx, error::Error, inx, requests::MilestoneRequest}; impl Inx { /// TODO diff --git a/bee-inx/src/request.rs b/bee-inx/src/requests.rs similarity index 83% rename from bee-inx/src/request.rs rename to bee-inx/src/requests.rs index 71a7f0899e..6f35e31bcb 100644 --- a/bee-inx/src/request.rs +++ b/bee-inx/src/requests.rs @@ -4,14 +4,15 @@ use std::ops::{Bound, RangeBounds}; use bee_block::payload::milestone::{MilestoneId, MilestoneIndex}; -use inx::proto; + +use crate::inx; pub enum MilestoneRequest { MilestoneIndex(MilestoneIndex), MilestoneId(MilestoneId), } -impl From for proto::MilestoneRequest { +impl From for inx::MilestoneRequest { fn from(value: MilestoneRequest) -> Self { match value { MilestoneRequest::MilestoneIndex(MilestoneIndex(milestone_index)) => Self { @@ -32,7 +33,7 @@ impl> From for MilestoneRequest { } } -fn to_milestone_range_request(range: T) -> proto::MilestoneRangeRequest +fn to_milestone_range_request(range: T) -> inx::MilestoneRangeRequest where T: RangeBounds, I: Into + Copy, @@ -47,7 +48,7 @@ where Bound::Excluded(&idx) => idx.into() - 1, Bound::Unbounded => 0, }; - proto::MilestoneRangeRequest { + inx::MilestoneRangeRequest { start_milestone_index, end_milestone_index, } @@ -55,7 +56,7 @@ where /// A request for a range of milestones by [`MilestoneIndex`]. #[derive(Clone, Debug, PartialEq)] -pub struct MilestoneRangeRequest(proto::MilestoneRangeRequest); +pub struct MilestoneRangeRequest(inx::MilestoneRangeRequest); impl From for MilestoneRangeRequest where @@ -66,7 +67,7 @@ where } } -impl From for proto::MilestoneRangeRequest { +impl From for inx::MilestoneRangeRequest { fn from(value: MilestoneRangeRequest) -> Self { value.0 } @@ -81,7 +82,7 @@ mod test { let range = MilestoneRangeRequest::from(17..43); assert_eq!( range, - MilestoneRangeRequest(proto::MilestoneRangeRequest { + MilestoneRangeRequest(inx::MilestoneRangeRequest { start_milestone_index: 17, end_milestone_index: 42 }) @@ -93,7 +94,7 @@ mod test { let range = MilestoneRangeRequest::from(17..=42); assert_eq!( range, - MilestoneRangeRequest(proto::MilestoneRangeRequest { + MilestoneRangeRequest(inx::MilestoneRangeRequest { start_milestone_index: 17, end_milestone_index: 42 }) diff --git a/bee-inx/src/utxo/mod.rs b/bee-inx/src/utxo/mod.rs index 9e9e93f71c..732d1f2b89 100644 --- a/bee-inx/src/utxo/mod.rs +++ b/bee-inx/src/utxo/mod.rs @@ -11,7 +11,7 @@ use crate::{ client::{try_from_inx_type, Inx}, error::Error, inx, - request::MilestoneRangeRequest, + requests::MilestoneRangeRequest, }; impl Inx { From 727ccd633746e0798fc3a73b559a2a44cce1832f Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 28 Sep 2022 11:07:35 +0200 Subject: [PATCH 11/25] Move utxo types into 'types' module --- bee-inx/src/lib.rs | 6 +- bee-inx/src/utxo/mod.rs | 7 +- bee-inx/src/utxo/treasury.rs | 66 ---------- bee-inx/src/utxo/{ledger.rs => types.rs} | 158 ++++++++++++++++------- 4 files changed, 116 insertions(+), 121 deletions(-) delete mode 100644 bee-inx/src/utxo/treasury.rs rename bee-inx/src/utxo/{ledger.rs => types.rs} (65%) diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index 7838974fba..9ad9e87a1f 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -14,7 +14,11 @@ pub mod utxo; pub use self::{block::*, error::Error, milestone::*, node::*, raw::*, requests::*, utxo::*}; pub mod inx { - pub use ::inx::proto::{block_metadata::*, *}; + pub use ::inx::proto::{ + block_metadata::*, + ledger_update::{marker::*, *}, + *, + }; } #[macro_export] diff --git a/bee-inx/src/utxo/mod.rs b/bee-inx/src/utxo/mod.rs index 732d1f2b89..55b8c6e791 100644 --- a/bee-inx/src/utxo/mod.rs +++ b/bee-inx/src/utxo/mod.rs @@ -1,12 +1,11 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -pub mod ledger; -pub mod treasury; +pub mod types; use futures::{Stream, StreamExt}; -pub use self::{ledger::*, treasury::*}; +pub use self::types::*; use crate::{ client::{try_from_inx_type, Inx}, error::Error, @@ -32,7 +31,7 @@ impl Inx { ) -> Result>, Error> { Ok(self .client - .read_unspent_outputs(inx::NoParams {}) // TODO: ().into() + .read_unspent_outputs(inx::NoParams {}) .await? .into_inner() .map(try_from_inx_type)) diff --git a/bee-inx/src/utxo/treasury.rs b/bee-inx/src/utxo/treasury.rs deleted file mode 100644 index 352fb54102..0000000000 --- a/bee-inx/src/utxo/treasury.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2022 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -use bee_block as bee; -use inx::proto; - -use crate::return_err_if_none; - -/// Represents a treasury output. -#[allow(missing_docs)] -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct TreasuryOutput { - pub milestone_id: bee::payload::milestone::MilestoneId, - pub amount: u64, -} - -impl TryFrom for TreasuryOutput { - type Error = bee::InxError; - - fn try_from(value: proto::TreasuryOutput) -> Result { - Ok(TreasuryOutput { - milestone_id: return_err_if_none!(value.milestone_id).try_into()?, - amount: value.amount, - }) - } -} - -impl From for proto::TreasuryOutput { - fn from(value: TreasuryOutput) -> Self { - Self { - milestone_id: Some(value.milestone_id.into()), - amount: value.amount, - } - } -} - -/// Represents an update to the treasury. -#[allow(missing_docs)] -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct TreasuryUpdate { - pub milestone_index: u32, - pub created: TreasuryOutput, - pub consumed: TreasuryOutput, -} - -impl TryFrom for TreasuryUpdate { - type Error = bee::InxError; - - fn try_from(value: proto::TreasuryUpdate) -> Result { - Ok(Self { - milestone_index: value.milestone_index, - created: return_err_if_none!(value.created).try_into()?, - consumed: return_err_if_none!(value.consumed).try_into()?, - }) - } -} - -impl From for proto::TreasuryUpdate { - fn from(value: TreasuryUpdate) -> Self { - Self { - milestone_index: value.milestone_index, - created: Some(value.created.into()), - consumed: Some(value.consumed.into()), - } - } -} diff --git a/bee-inx/src/utxo/ledger.rs b/bee-inx/src/utxo/types.rs similarity index 65% rename from bee-inx/src/utxo/ledger.rs rename to bee-inx/src/utxo/types.rs index 5064cba229..f8d9e21215 100644 --- a/bee-inx/src/utxo/ledger.rs +++ b/bee-inx/src/utxo/types.rs @@ -2,9 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 use bee_block as bee; -use inx::proto; -use crate::{return_err_if_none, Raw}; +use crate::{inx, return_err_if_none, Raw}; /// Represents a new output in the ledger. #[allow(missing_docs)] @@ -17,6 +16,32 @@ pub struct LedgerOutput { pub output: Raw, } +impl TryFrom for LedgerOutput { + type Error = bee::InxError; + + fn try_from(value: inx::LedgerOutput) -> Result { + Ok(Self { + output_id: return_err_if_none!(value.output_id).try_into()?, + block_id: return_err_if_none!(value.block_id).try_into()?, + milestone_index_booked: value.milestone_index_booked.into(), + milestone_timestamp_booked: value.milestone_timestamp_booked, + output: return_err_if_none!(value.output).into(), + }) + } +} + +impl From for inx::LedgerOutput { + fn from(value: LedgerOutput) -> Self { + Self { + output_id: Some(value.output_id.into()), + block_id: Some(value.block_id.into()), + milestone_index_booked: value.milestone_index_booked.0, + milestone_timestamp_booked: value.milestone_timestamp_booked, + output: Some(value.output.into()), + } + } +} + /// Represents a spent output in the ledger. #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] @@ -85,8 +110,8 @@ impl LedgerUpdate { } } -impl From for Marker { - fn from(value: proto::ledger_update::Marker) -> Self { +impl From for Marker { + fn from(value: inx::ledger_update::Marker) -> Self { Self { milestone_index: value.milestone_index.into(), consumed_count: value.consumed_count as usize, @@ -95,21 +120,21 @@ impl From for Marker { } } -impl From for LedgerUpdate { - fn from(value: proto::ledger_update::Marker) -> Self { - use proto::ledger_update::marker::MarkerType as proto; +impl From for LedgerUpdate { + fn from(value: inx::Marker) -> Self { + use crate::inx::MarkerType; match value.marker_type() { - proto::Begin => Self::Begin(value.into()), - proto::End => Self::End(value.into()), + MarkerType::Begin => Self::Begin(value.into()), + MarkerType::End => Self::End(value.into()), } } } -impl TryFrom for proto::ledger_update::Marker { +impl TryFrom for inx::ledger_update::Marker { type Error = bee::InxError; fn try_from(value: LedgerUpdate) -> Result { - use proto::ledger_update::marker::MarkerType; + use crate::inx::MarkerType; let marker_type = match &value { LedgerUpdate::Begin(_) => MarkerType::Begin, LedgerUpdate::End(_) => MarkerType::End, @@ -130,22 +155,22 @@ impl TryFrom for proto::ledger_update::Marker { } } -impl TryFrom for LedgerUpdate { +impl TryFrom for LedgerUpdate { type Error = bee::InxError; - fn try_from(value: proto::LedgerUpdate) -> Result { - use proto::ledger_update::Op as proto; + fn try_from(value: inx::LedgerUpdate) -> Result { + use crate::inx::Op; Ok(match return_err_if_none!(value.op) { - proto::BatchMarker(marker) => marker.into(), - proto::Consumed(consumed) => LedgerUpdate::Consumed(consumed.try_into()?), - proto::Created(created) => LedgerUpdate::Created(created.try_into()?), + Op::BatchMarker(marker) => marker.into(), + Op::Consumed(consumed) => LedgerUpdate::Consumed(consumed.try_into()?), + Op::Created(created) => LedgerUpdate::Created(created.try_into()?), }) } } -impl From for proto::LedgerUpdate { +impl From for inx::LedgerUpdate { fn from(value: LedgerUpdate) -> Self { - use proto::ledger_update::Op; + use crate::inx::Op; Self { op: match value { LedgerUpdate::Consumed(consumed) => Op::Consumed(consumed.into()), @@ -157,72 +182,105 @@ impl From for proto::LedgerUpdate { } } -impl TryFrom for LedgerOutput { +impl TryFrom for LedgerSpent { type Error = bee::InxError; - fn try_from(value: proto::LedgerOutput) -> Result { + fn try_from(value: inx::LedgerSpent) -> Result { Ok(Self { - output_id: return_err_if_none!(value.output_id).try_into()?, - block_id: return_err_if_none!(value.block_id).try_into()?, - milestone_index_booked: value.milestone_index_booked.into(), - milestone_timestamp_booked: value.milestone_timestamp_booked, - output: return_err_if_none!(value.output).into(), + output: return_err_if_none!(value.output).try_into()?, + transaction_id_spent: return_err_if_none!(value.transaction_id_spent).try_into()?, + milestone_index_spent: value.milestone_index_spent.into(), + milestone_timestamp_spent: value.milestone_timestamp_spent, }) } } -impl From for proto::LedgerOutput { - fn from(value: LedgerOutput) -> Self { +impl From for inx::LedgerSpent { + fn from(value: LedgerSpent) -> Self { Self { - output_id: Some(value.output_id.into()), - block_id: Some(value.block_id.into()), - milestone_index_booked: value.milestone_index_booked.0, - milestone_timestamp_booked: value.milestone_timestamp_booked, output: Some(value.output.into()), + transaction_id_spent: Some(value.transaction_id_spent.into()), + milestone_index_spent: value.milestone_index_spent.0, + milestone_timestamp_spent: value.milestone_timestamp_spent, } } } -impl TryFrom for LedgerSpent { +impl TryFrom for UnspentOutput { type Error = bee::InxError; - fn try_from(value: proto::LedgerSpent) -> Result { + fn try_from(value: inx::UnspentOutput) -> Result { Ok(Self { + ledger_index: value.ledger_index.into(), output: return_err_if_none!(value.output).try_into()?, - transaction_id_spent: return_err_if_none!(value.transaction_id_spent).try_into()?, - milestone_index_spent: value.milestone_index_spent.into(), - milestone_timestamp_spent: value.milestone_timestamp_spent, }) } } -impl From for proto::LedgerSpent { - fn from(value: LedgerSpent) -> Self { +impl From for inx::UnspentOutput { + fn from(value: UnspentOutput) -> Self { Self { + ledger_index: value.ledger_index.0, output: Some(value.output.into()), - transaction_id_spent: Some(value.transaction_id_spent.into()), - milestone_index_spent: value.milestone_index_spent.0, - milestone_timestamp_spent: value.milestone_timestamp_spent, } } } -impl TryFrom for UnspentOutput { +/// Represents a treasury output. +#[allow(missing_docs)] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct TreasuryOutput { + pub milestone_id: bee::payload::milestone::MilestoneId, + pub amount: u64, +} + +impl TryFrom for TreasuryOutput { type Error = bee::InxError; - fn try_from(value: proto::UnspentOutput) -> Result { + fn try_from(value: inx::TreasuryOutput) -> Result { + Ok(TreasuryOutput { + milestone_id: return_err_if_none!(value.milestone_id).try_into()?, + amount: value.amount, + }) + } +} + +impl From for inx::TreasuryOutput { + fn from(value: TreasuryOutput) -> Self { + Self { + milestone_id: Some(value.milestone_id.into()), + amount: value.amount, + } + } +} + +/// Represents an update to the treasury. +#[allow(missing_docs)] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct TreasuryUpdate { + pub milestone_index: u32, + pub created: TreasuryOutput, + pub consumed: TreasuryOutput, +} + +impl TryFrom for TreasuryUpdate { + type Error = bee::InxError; + + fn try_from(value: inx::TreasuryUpdate) -> Result { Ok(Self { - ledger_index: value.ledger_index.into(), - output: return_err_if_none!(value.output).try_into()?, + milestone_index: value.milestone_index, + created: return_err_if_none!(value.created).try_into()?, + consumed: return_err_if_none!(value.consumed).try_into()?, }) } } -impl From for proto::UnspentOutput { - fn from(value: UnspentOutput) -> Self { +impl From for inx::TreasuryUpdate { + fn from(value: TreasuryUpdate) -> Self { Self { - ledger_index: value.ledger_index.0, - output: Some(value.output.into()), + milestone_index: value.milestone_index, + created: Some(value.created.into()), + consumed: Some(value.consumed.into()), } } } From 73f193e2e04ed154dc8e65f3cc4480ab71d8e9e1 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 28 Sep 2022 21:49:06 +0200 Subject: [PATCH 12/25] Add 'listen_to_node_status' API --- bee-inx/src/block/mod.rs | 7 ++++ bee-inx/src/block/types.rs | 6 +-- bee-inx/src/lib.rs | 9 ++++- bee-inx/src/milestone/mod.rs | 11 +++++- bee-inx/src/{ => milestone}/requests.rs | 38 +++++++++---------- bee-inx/src/node/mod.rs | 27 ++++++++++++-- bee-inx/src/node/requests.rs | 26 +++++++++++++ bee-inx/src/node/types.rs | 49 ++++++++++++------------- bee-inx/src/utxo/mod.rs | 29 +++++++++++++-- 9 files changed, 141 insertions(+), 61 deletions(-) rename bee-inx/src/{ => milestone}/requests.rs (100%) create mode 100644 bee-inx/src/node/requests.rs diff --git a/bee-inx/src/block/mod.rs b/bee-inx/src/block/mod.rs index ae848b4bed..13ac4aceb2 100644 --- a/bee-inx/src/block/mod.rs +++ b/bee-inx/src/block/mod.rs @@ -6,6 +6,13 @@ pub mod types; pub use self::types::*; use crate::client::Inx; +// rpc ListenToBlocks(NoParams) returns (stream Block); +// rpc ListenToSolidBlocks(NoParams) returns (stream BlockMetadata); +// rpc ListenToReferencedBlocks(NoParams) returns (stream BlockMetadata); +// rpc SubmitBlock(RawBlock) returns (BlockId); +// rpc ReadBlock(BlockId) returns (RawBlock); +// rpc ReadBlockMetadata(BlockId) returns (BlockMetadata); + impl Inx { // TODO } diff --git a/bee-inx/src/block/types.rs b/bee-inx/src/block/types.rs index b49074874b..604861e517 100644 --- a/bee-inx/src/block/types.rs +++ b/bee-inx/src/block/types.rs @@ -1,9 +1,7 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use bee_block as bee; - -use crate::{inx, raw::Raw, return_err_if_none}; +use crate::{bee, inx, raw::Raw, return_err_if_none}; /// The [`Block`] type. #[derive(Clone, Debug, PartialEq, Eq)] @@ -83,7 +81,7 @@ pub struct BlockMetadata { /// Indicates if a block is part of the ledger state or not. pub ledger_inclusion_state: LedgerInclusionState, /// Indicates if a conflict occurred, and if so holds information about the reason for the conflict. - pub conflict_reason: bee::semantic::ConflictReason, + pub conflict_reason: bee::ConflictReason, /// The whiteflag index of this block inside the milestone. pub white_flag_index: u32, } diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index 9ad9e87a1f..716da9846c 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -8,10 +8,9 @@ pub mod client; pub mod milestone; pub mod node; pub mod raw; -pub mod requests; pub mod utxo; -pub use self::{block::*, error::Error, milestone::*, node::*, raw::*, requests::*, utxo::*}; +pub use self::{block::*, error::Error, milestone::*, node::*, raw::*, utxo::*}; pub mod inx { pub use ::inx::proto::{ @@ -21,6 +20,12 @@ pub mod inx { }; } +pub(crate) mod bee { + pub use bee_block::{payload::milestone::MilestoneIndex, protocol::ProtocolParameters, InxError}; + pub use bee_block::{Block, BlockId}; + pub use bee_block::semantic::ConflictReason; +} + #[macro_export] macro_rules! return_err_if_none { ($object:ident.$field:ident) => { diff --git a/bee-inx/src/milestone/mod.rs b/bee-inx/src/milestone/mod.rs index 2d3c8432e3..624836d126 100644 --- a/bee-inx/src/milestone/mod.rs +++ b/bee-inx/src/milestone/mod.rs @@ -1,19 +1,26 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +pub mod requests; pub mod types; use futures::stream::{Stream, StreamExt}; -pub use self::types::*; +pub use self::{requests::*, types::*}; use crate::{ block::types::BlockWithMetadata, client::{try_from_inx_type, Inx}, error::Error, inx, - requests::{MilestoneRangeRequest, MilestoneRequest}, }; +// rpc ReadMilestone(MilestoneRequest) returns (Milestone); +// rpc ListenToLatestMilestones(NoParams) returns (stream Milestone); +// rpc ListenToConfirmedMilestones(MilestoneRangeRequest) returns (stream MilestoneAndProtocolParameters); +// rpc ComputeWhiteFlag(WhiteFlagRequest) returns (WhiteFlagResponse); +// rpc ReadMilestoneCone(MilestoneRequest) returns (stream BlockWithMetadata); +// rpc ReadMilestoneConeMetadata(MilestoneRequest) returns (stream BlockMetadata); + impl Inx { /// TODO pub async fn read_milestone(&mut self, request: MilestoneRequest) -> Result { diff --git a/bee-inx/src/requests.rs b/bee-inx/src/milestone/requests.rs similarity index 100% rename from bee-inx/src/requests.rs rename to bee-inx/src/milestone/requests.rs index 6f35e31bcb..4bf35ec571 100644 --- a/bee-inx/src/requests.rs +++ b/bee-inx/src/milestone/requests.rs @@ -33,6 +33,25 @@ impl> From for MilestoneRequest { } } +/// A request for a range of milestones by [`MilestoneIndex`]. +#[derive(Clone, Debug, PartialEq)] +pub struct MilestoneRangeRequest(inx::MilestoneRangeRequest); + +impl From for MilestoneRangeRequest +where + T: RangeBounds, +{ + fn from(value: T) -> MilestoneRangeRequest { + MilestoneRangeRequest(to_milestone_range_request(value)) + } +} + +impl From for inx::MilestoneRangeRequest { + fn from(value: MilestoneRangeRequest) -> Self { + value.0 + } +} + fn to_milestone_range_request(range: T) -> inx::MilestoneRangeRequest where T: RangeBounds, @@ -54,25 +73,6 @@ where } } -/// A request for a range of milestones by [`MilestoneIndex`]. -#[derive(Clone, Debug, PartialEq)] -pub struct MilestoneRangeRequest(inx::MilestoneRangeRequest); - -impl From for MilestoneRangeRequest -where - T: RangeBounds, -{ - fn from(value: T) -> MilestoneRangeRequest { - MilestoneRangeRequest(to_milestone_range_request(value)) - } -} - -impl From for inx::MilestoneRangeRequest { - fn from(value: MilestoneRangeRequest) -> Self { - value.0 - } -} - #[cfg(test)] mod test { use super::*; diff --git a/bee-inx/src/node/mod.rs b/bee-inx/src/node/mod.rs index af19d6330b..936b5d6e14 100644 --- a/bee-inx/src/node/mod.rs +++ b/bee-inx/src/node/mod.rs @@ -1,10 +1,18 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -mod types; +pub mod requests; +pub mod types; -pub use self::types::*; -use crate::{client::Inx, error::Error, inx, requests::MilestoneRequest}; +use futures::stream::{Stream, StreamExt}; + +pub use self::{requests::*, types::*}; +use crate::{ + client::{try_from_inx_type, Inx}, + error::Error, + inx, + milestone::requests::MilestoneRequest, +}; impl Inx { /// TODO @@ -13,7 +21,18 @@ impl Inx { .map_err(Error::InxError) } - // TODO: listen_to_node_status + // TODO + pub async fn listen_to_node_status( + &mut self, + request: NodeStatusRequest, + ) -> Result>, Error> { + Ok(self + .client + .listen_to_node_status(inx::NodeStatusRequest::from(request)) + .await? + .into_inner() + .map(try_from_inx_type)) + } /// TODO pub async fn read_node_configuration(&mut self) -> Result { diff --git a/bee-inx/src/node/requests.rs b/bee-inx/src/node/requests.rs new file mode 100644 index 0000000000..c3fc466d30 --- /dev/null +++ b/bee-inx/src/node/requests.rs @@ -0,0 +1,26 @@ +// Copyright 2022 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use crate::inx; + +/// TODO +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct NodeStatusRequest { + cooldown_in_milliseconds: u32, +} + +impl From for NodeStatusRequest { + fn from(value: inx::NodeStatusRequest) -> Self { + Self { + cooldown_in_milliseconds: value.cooldown_in_milliseconds, + } + } +} + +impl From for inx::NodeStatusRequest { + fn from(value: NodeStatusRequest) -> Self { + Self { + cooldown_in_milliseconds: value.cooldown_in_milliseconds, + } + } +} diff --git a/bee-inx/src/node/types.rs b/bee-inx/src/node/types.rs index b75e9145cd..e11e220969 100644 --- a/bee-inx/src/node/types.rs +++ b/bee-inx/src/node/types.rs @@ -1,10 +1,7 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use bee_block as bee; -use inx::proto; - -use crate::{milestone::types::Milestone, raw::Raw, return_err_if_none}; +use crate::{bee, inx, milestone::types::Milestone, raw::Raw, return_err_if_none}; /// The [`NodeStatus`] type. #[derive(Clone, Debug, PartialEq, Eq)] @@ -22,19 +19,19 @@ pub struct NodeStatus { /// The current protocol parameters. pub current_protocol_parameters: ProtocolParameters, /// The tangle pruning index of the node. - pub tangle_pruning_index: bee::payload::milestone::MilestoneIndex, + pub tangle_pruning_index: bee::MilestoneIndex, /// The milestones pruning index of the node. - pub milestones_pruning_index: bee::payload::milestone::MilestoneIndex, + pub milestones_pruning_index: bee::MilestoneIndex, /// The ledger pruning index of the node. - pub ledger_pruning_index: bee::payload::milestone::MilestoneIndex, + pub ledger_pruning_index: bee::MilestoneIndex, /// The ledger index of the node. - pub ledger_index: bee::payload::milestone::MilestoneIndex, + pub ledger_index: bee::MilestoneIndex, } -impl TryFrom for NodeStatus { +impl TryFrom for NodeStatus { type Error = bee::InxError; - fn try_from(value: proto::NodeStatus) -> Result { + fn try_from(value: inx::NodeStatus) -> Result { Ok(NodeStatus { is_healthy: value.is_healthy, is_synced: value.is_synced, @@ -50,7 +47,7 @@ impl TryFrom for NodeStatus { } } -impl From for proto::NodeStatus { +impl From for inx::NodeStatus { fn from(value: NodeStatus) -> Self { Self { is_healthy: value.is_healthy, @@ -76,10 +73,10 @@ pub struct NodeConfiguration { pub supported_protocol_versions: Box<[u8]>, } -impl TryFrom for NodeConfiguration { +impl TryFrom for NodeConfiguration { type Error = bee::InxError; - fn try_from(value: proto::NodeConfiguration) -> Result { + fn try_from(value: inx::NodeConfiguration) -> Result { Ok(NodeConfiguration { milestone_public_key_count: value.milestone_public_key_count, milestone_key_ranges: value.milestone_key_ranges.into_iter().map(Into::into).collect(), @@ -89,7 +86,7 @@ impl TryFrom for NodeConfiguration { } } -impl From for proto::NodeConfiguration { +impl From for inx::NodeConfiguration { fn from(value: NodeConfiguration) -> Self { Self { milestone_public_key_count: value.milestone_public_key_count, @@ -121,8 +118,8 @@ pub struct BaseToken { pub use_metric_prefix: bool, } -impl From for BaseToken { - fn from(value: proto::BaseToken) -> Self { +impl From for BaseToken { + fn from(value: inx::BaseToken) -> Self { Self { name: value.name, ticker_symbol: value.ticker_symbol, @@ -134,7 +131,7 @@ impl From for BaseToken { } } -impl From for proto::BaseToken { +impl From for inx::BaseToken { fn from(value: BaseToken) -> Self { Self { name: value.name, @@ -150,12 +147,12 @@ impl From for proto::BaseToken { #[derive(Clone, Debug, PartialEq, Eq)] pub struct MilestoneKeyRange { pub public_key: Box<[u8]>, - pub start_index: bee::payload::milestone::MilestoneIndex, - pub end_index: bee::payload::milestone::MilestoneIndex, + pub start_index: bee::MilestoneIndex, + pub end_index: bee::MilestoneIndex, } -impl From for MilestoneKeyRange { - fn from(value: proto::MilestoneKeyRange) -> Self { +impl From for MilestoneKeyRange { + fn from(value: inx::MilestoneKeyRange) -> Self { Self { public_key: value.public_key.into_boxed_slice(), start_index: value.start_index.into(), @@ -164,7 +161,7 @@ impl From for MilestoneKeyRange { } } -impl From for proto::MilestoneKeyRange { +impl From for inx::MilestoneKeyRange { fn from(value: MilestoneKeyRange) -> Self { Self { public_key: value.public_key.into_vec(), @@ -178,11 +175,11 @@ impl From for proto::MilestoneKeyRange { #[derive(Clone, Debug, PartialEq, Eq)] pub struct ProtocolParameters { pub protocol_version: u8, - pub params: Raw, + pub params: Raw, } -impl From for ProtocolParameters { - fn from(value: proto::RawProtocolParameters) -> Self { +impl From for ProtocolParameters { + fn from(value: inx::RawProtocolParameters) -> Self { Self { protocol_version: value.protocol_version as u8, params: value.params.into(), @@ -190,7 +187,7 @@ impl From for ProtocolParameters { } } -impl From for proto::RawProtocolParameters { +impl From for inx::RawProtocolParameters { fn from(value: ProtocolParameters) -> Self { Self { protocol_version: value.protocol_version as u32, diff --git a/bee-inx/src/utxo/mod.rs b/bee-inx/src/utxo/mod.rs index 55b8c6e791..c3c1eadd25 100644 --- a/bee-inx/src/utxo/mod.rs +++ b/bee-inx/src/utxo/mod.rs @@ -10,10 +10,29 @@ use crate::{ client::{try_from_inx_type, Inx}, error::Error, inx, - requests::MilestoneRangeRequest, + milestone::requests::MilestoneRangeRequest, }; +// rpc ReadUnspentOutputs(NoParams) returns (stream UnspentOutput); +// rpc ListenToLedgerUpdates(MilestoneRangeRequest) returns (stream LedgerUpdate); +// rpc ListenToTreasuryUpdates(MilestoneRangeRequest) returns (stream TreasuryUpdate); +// rpc ReadOutput(OutputId) returns (OutputResponse); +// rpc ListenToMigrationReceipts(NoParams) returns (stream RawReceipt); + impl Inx { + /// TODO + pub async fn read_unspent_outputs( + &mut self, + ) -> Result>, Error> { + Ok(self + .client + .read_unspent_outputs(inx::NoParams {}) + .await? + .into_inner() + .map(try_from_inx_type)) + } + + /// TODO pub async fn listen_to_ledger_updates( &mut self, request: MilestoneRangeRequest, @@ -26,12 +45,14 @@ impl Inx { .map(try_from_inx_type)) } - pub async fn read_unspent_outputs( + /// TODO + pub async fn listen_to_treasury_updates( &mut self, - ) -> Result>, Error> { + request: MilestoneRangeRequest, + ) -> Result>, Error> { Ok(self .client - .read_unspent_outputs(inx::NoParams {}) + .listen_to_treasury_updates(inx::MilestoneRangeRequest::from(request)) .await? .into_inner() .map(try_from_inx_type)) From efd6a35b17169cd4de889c0e54f4621e7ea2daf0 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 28 Sep 2022 21:52:21 +0200 Subject: [PATCH 13/25] Rename 'types' modules to 'responses' --- bee-inx/src/block/mod.rs | 4 ++-- bee-inx/src/block/{types.rs => responses.rs} | 0 bee-inx/src/lib.rs | 7 ++++--- bee-inx/src/milestone/mod.rs | 6 +++--- bee-inx/src/milestone/{types.rs => responses.rs} | 0 bee-inx/src/node/mod.rs | 4 ++-- bee-inx/src/node/{types.rs => responses.rs} | 2 +- bee-inx/src/utxo/mod.rs | 4 ++-- bee-inx/src/utxo/{types.rs => responses.rs} | 0 9 files changed, 14 insertions(+), 13 deletions(-) rename bee-inx/src/block/{types.rs => responses.rs} (100%) rename bee-inx/src/milestone/{types.rs => responses.rs} (100%) rename bee-inx/src/node/{types.rs => responses.rs} (98%) rename bee-inx/src/utxo/{types.rs => responses.rs} (100%) diff --git a/bee-inx/src/block/mod.rs b/bee-inx/src/block/mod.rs index 13ac4aceb2..2949586a03 100644 --- a/bee-inx/src/block/mod.rs +++ b/bee-inx/src/block/mod.rs @@ -1,9 +1,9 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -pub mod types; +pub mod responses; -pub use self::types::*; +pub use self::responses::*; use crate::client::Inx; // rpc ListenToBlocks(NoParams) returns (stream Block); diff --git a/bee-inx/src/block/types.rs b/bee-inx/src/block/responses.rs similarity index 100% rename from bee-inx/src/block/types.rs rename to bee-inx/src/block/responses.rs diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index 716da9846c..ba926b46f6 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -21,9 +21,10 @@ pub mod inx { } pub(crate) mod bee { - pub use bee_block::{payload::milestone::MilestoneIndex, protocol::ProtocolParameters, InxError}; - pub use bee_block::{Block, BlockId}; - pub use bee_block::semantic::ConflictReason; + pub use bee_block::{ + payload::milestone::MilestoneIndex, protocol::ProtocolParameters, semantic::ConflictReason, Block, BlockId, + InxError, + }; } #[macro_export] diff --git a/bee-inx/src/milestone/mod.rs b/bee-inx/src/milestone/mod.rs index 624836d126..c8b00027ab 100644 --- a/bee-inx/src/milestone/mod.rs +++ b/bee-inx/src/milestone/mod.rs @@ -2,13 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 pub mod requests; -pub mod types; +pub mod responses; use futures::stream::{Stream, StreamExt}; -pub use self::{requests::*, types::*}; +pub use self::{requests::*, responses::*}; use crate::{ - block::types::BlockWithMetadata, + block::responses::BlockWithMetadata, client::{try_from_inx_type, Inx}, error::Error, inx, diff --git a/bee-inx/src/milestone/types.rs b/bee-inx/src/milestone/responses.rs similarity index 100% rename from bee-inx/src/milestone/types.rs rename to bee-inx/src/milestone/responses.rs diff --git a/bee-inx/src/node/mod.rs b/bee-inx/src/node/mod.rs index 936b5d6e14..23f1c38f9d 100644 --- a/bee-inx/src/node/mod.rs +++ b/bee-inx/src/node/mod.rs @@ -2,11 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 pub mod requests; -pub mod types; +pub mod responses; use futures::stream::{Stream, StreamExt}; -pub use self::{requests::*, types::*}; +pub use self::{requests::*, responses::*}; use crate::{ client::{try_from_inx_type, Inx}, error::Error, diff --git a/bee-inx/src/node/types.rs b/bee-inx/src/node/responses.rs similarity index 98% rename from bee-inx/src/node/types.rs rename to bee-inx/src/node/responses.rs index e11e220969..740fca87a3 100644 --- a/bee-inx/src/node/types.rs +++ b/bee-inx/src/node/responses.rs @@ -1,7 +1,7 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use crate::{bee, inx, milestone::types::Milestone, raw::Raw, return_err_if_none}; +use crate::{bee, inx, milestone::responses::Milestone, raw::Raw, return_err_if_none}; /// The [`NodeStatus`] type. #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/bee-inx/src/utxo/mod.rs b/bee-inx/src/utxo/mod.rs index c3c1eadd25..ef9a019705 100644 --- a/bee-inx/src/utxo/mod.rs +++ b/bee-inx/src/utxo/mod.rs @@ -1,11 +1,11 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -pub mod types; +pub mod responses; use futures::{Stream, StreamExt}; -pub use self::types::*; +pub use self::responses::*; use crate::{ client::{try_from_inx_type, Inx}, error::Error, diff --git a/bee-inx/src/utxo/types.rs b/bee-inx/src/utxo/responses.rs similarity index 100% rename from bee-inx/src/utxo/types.rs rename to bee-inx/src/utxo/responses.rs From 86b2c74e964724da9cbbfc61bd1d2fc79b5f6aa2 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 28 Sep 2022 22:46:56 +0200 Subject: [PATCH 14/25] Add 'node' example --- bee-inx/Cargo.toml | 1 + bee-inx/examples/milestone.rs | 17 ++++++++++----- bee-inx/examples/node.rs | 41 +++++++++++++++++++++++++++++++++++ bee-inx/src/node/requests.rs | 2 +- 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 bee-inx/examples/node.rs diff --git a/bee-inx/Cargo.toml b/bee-inx/Cargo.toml index 2eb527a03b..59171573ba 100644 --- a/bee-inx/Cargo.toml +++ b/bee-inx/Cargo.toml @@ -20,5 +20,6 @@ packable = { version = "0.6.2", default-features = false } [dev-dependencies] bee-block = { version = "1.0.0", path = "../bee-block", default-features = false, features = [ "inx", "rand" ] } +dotenvy = { version = "0.15.5", default-features = false } tokio = { version = "1.20.1", default-features = false, features = [ "macros", "rt-multi-thread" ] } diff --git a/bee-inx/examples/milestone.rs b/bee-inx/examples/milestone.rs index 9ffba47146..a4119593f1 100644 --- a/bee-inx/examples/milestone.rs +++ b/bee-inx/examples/milestone.rs @@ -4,17 +4,24 @@ use bee_inx::{client, Error}; use futures::StreamExt; -const INX_ADDRESS: &str = "http://localhost:9029"; - #[tokio::main] async fn main() -> Result<(), Error> { - let mut inx = client::Inx::connect(INX_ADDRESS).await?; + dotenvy::dotenv().ok(); + let inx_connect_url = std::env::var("INX_CONNECT_URL").expect("missing INX_CONNECT_URL environment variable"); + + let mut inx = client::Inx::connect(&inx_connect_url).await?; + println!("Connected via INX to node at {inx_connect_url}"); + let mut milestone_stream = inx.listen_to_confirmed_milestones((..).into()).await?; + println!("Streaming confirmed milestones and protocol parameters... "); // Listen to the milestones from the node. while let Some(milestone_and_params) = milestone_stream.next().await { - let milestone_index = milestone_and_params?.milestone.milestone_info.milestone_index; - println!("Fetch cone of milestone {milestone_index}"); + let milestone_and_params = milestone_and_params?; + println!("{:?}", milestone_and_params); + + let milestone_index = milestone_and_params.milestone.milestone_info.milestone_index; + println!("Fetching cone of milestone {milestone_index}"); // Listen to blocks in the past cone of a milestone. let mut cone_stream = inx.read_milestone_cone(milestone_index.0.into()).await?; diff --git a/bee-inx/examples/node.rs b/bee-inx/examples/node.rs new file mode 100644 index 0000000000..47f419075b --- /dev/null +++ b/bee-inx/examples/node.rs @@ -0,0 +1,41 @@ +// Copyright 2022 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use bee_inx::{client, milestone::requests::MilestoneRequest, node::requests::NodeStatusRequest, Error}; +use futures::StreamExt; + +#[tokio::main] +async fn main() -> Result<(), Error> { + dotenvy::dotenv().ok(); + let inx_connect_url = std::env::var("INX_CONNECT_URL").expect("missing INX_CONNECT_URL environment variable"); + + let mut inx = client::Inx::connect(&inx_connect_url).await?; + println!("Connected via INX to node at {inx_connect_url}"); + + let node_status = inx.read_node_status().await?; + println!("{:?}", node_status); + + let node_configuration = inx.read_node_configuration().await?; + println!("{:?}", node_configuration); + + let protocol_parameters = inx + .read_protocol_parameters(MilestoneRequest::MilestoneIndex(node_status.ledger_index)) + .await?; + println!("{:?}", protocol_parameters); + + const COOLDOWN_MS: u32 = 5000; + let mut node_status_stream = inx + .listen_to_node_status(NodeStatusRequest { + cooldown_in_milliseconds: COOLDOWN_MS, + }) + .await?; + println!("Streaming current node status ... "); + + while let Some(node_status) = node_status_stream.next().await { + let node_status = node_status?; + + println!("healthy: {} | synced: {} | ledger_index: {}", node_status.is_healthy, node_status.is_synced, node_status.ledger_index); + } + + Ok(()) +} diff --git a/bee-inx/src/node/requests.rs b/bee-inx/src/node/requests.rs index c3fc466d30..38dea8aef5 100644 --- a/bee-inx/src/node/requests.rs +++ b/bee-inx/src/node/requests.rs @@ -6,7 +6,7 @@ use crate::inx; /// TODO #[derive(Clone, Debug, PartialEq, Eq)] pub struct NodeStatusRequest { - cooldown_in_milliseconds: u32, + pub cooldown_in_milliseconds: u32, } impl From for NodeStatusRequest { From 8d9f01a22f4a77d21aef0d94f63f64a8c8655f3d Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 29 Sep 2022 00:27:13 +0200 Subject: [PATCH 15/25] Finish block related queries and example --- bee-inx/examples/block.rs | 84 +++++++++++++++++++++++++++++++++++ bee-inx/examples/milestone.rs | 2 +- bee-inx/examples/node.rs | 7 ++- bee-inx/src/block/mod.rs | 78 ++++++++++++++++++++++++++++---- bee-inx/src/lib.rs | 2 +- bee-inx/src/milestone/mod.rs | 13 +++--- 6 files changed, 167 insertions(+), 19 deletions(-) create mode 100644 bee-inx/examples/block.rs diff --git a/bee-inx/examples/block.rs b/bee-inx/examples/block.rs new file mode 100644 index 0000000000..725fd7e97a --- /dev/null +++ b/bee-inx/examples/block.rs @@ -0,0 +1,84 @@ +// Copyright 2022 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use bee_block::BlockId; +use bee_inx::{client::Inx, Error}; +use futures::StreamExt; + +#[tokio::main] +async fn main() -> Result<(), Error> { + dotenvy::dotenv().ok(); + let inx_connect_url = std::env::var("INX_CONNECT_URL").unwrap_or_else(|_| "http://localhost:9029".to_string()); + let block_stream = std::env::var("BLOCK_STREAM").unwrap_or_else(|_| "blocks".to_string()); + let read_block = std::env::var("READ_BLOCK") + .unwrap_or_else(|_| "false".to_string()) + .parse::() + .unwrap(); + let read_block_metadata = std::env::var("READ_BLOCK_METADATA") + .unwrap_or_else(|_| "false".to_string()) + .parse::() + .unwrap(); + + let mut inx = Inx::connect(&inx_connect_url).await?; + println!("Connected via INX to node at {inx_connect_url}"); + + match block_stream.as_str() { + "blocks" => { + let mut block_stream = inx.listen_to_blocks().await?; + println!("Streaming blocks ... "); + + while let Some(block) = block_stream.next().await { + let block = block?; + println!("{}", block.block_id); + + print_block_metadata(&mut inx, block.block_id, read_block, read_block_metadata).await?; + } + } + "solid_blocks" => { + let mut block_stream = inx.listen_to_solid_blocks().await?; + println!("Streaming solid blocks ... "); + + while let Some(block_metadata) = block_stream.next().await { + let block_metadata = block_metadata?; + println!("{}", block_metadata.block_id); + + print_block_metadata(&mut inx, block_metadata.block_id, read_block, read_block_metadata).await?; + } + } + "referenced_blocks" => { + let mut block_stream = inx.listen_to_referenced_blocks().await?; + println!("Streaming referenced blocks ... "); + + while let Some(block_metadata) = block_stream.next().await { + let block_metadata = block_metadata?; + println!("{}", block_metadata.block_id); + + print_block_metadata(&mut inx, block_metadata.block_id, read_block, read_block_metadata).await?; + } + } + _ => { + panic!("unknown block stream variant '{}'", block_stream); + } + } + + Ok(()) +} + +async fn print_block_metadata( + inx: &mut Inx, + block_id: BlockId, + read_block: bool, + read_block_metadata: bool, +) -> Result<(), Error> { + if read_block { + let raw_block = inx.read_block(block_id).await?; + println!("{:?}", raw_block.inner_unverified()); + } + + if read_block_metadata { + let block_metadata = inx.read_block_metadata(block_id).await?; + println!("{:?}", block_metadata); + } + + Ok(()) +} diff --git a/bee-inx/examples/milestone.rs b/bee-inx/examples/milestone.rs index a4119593f1..defe2f8a56 100644 --- a/bee-inx/examples/milestone.rs +++ b/bee-inx/examples/milestone.rs @@ -7,7 +7,7 @@ use futures::StreamExt; #[tokio::main] async fn main() -> Result<(), Error> { dotenvy::dotenv().ok(); - let inx_connect_url = std::env::var("INX_CONNECT_URL").expect("missing INX_CONNECT_URL environment variable"); + let inx_connect_url = std::env::var("INX_CONNECT_URL").unwrap_or_else(|_| "http://localhost:9029".to_string()); let mut inx = client::Inx::connect(&inx_connect_url).await?; println!("Connected via INX to node at {inx_connect_url}"); diff --git a/bee-inx/examples/node.rs b/bee-inx/examples/node.rs index 47f419075b..b6781c4836 100644 --- a/bee-inx/examples/node.rs +++ b/bee-inx/examples/node.rs @@ -7,7 +7,7 @@ use futures::StreamExt; #[tokio::main] async fn main() -> Result<(), Error> { dotenvy::dotenv().ok(); - let inx_connect_url = std::env::var("INX_CONNECT_URL").expect("missing INX_CONNECT_URL environment variable"); + let inx_connect_url = std::env::var("INX_CONNECT_URL").unwrap_or_else(|_| "http://localhost:9029".to_string()); let mut inx = client::Inx::connect(&inx_connect_url).await?; println!("Connected via INX to node at {inx_connect_url}"); @@ -34,7 +34,10 @@ async fn main() -> Result<(), Error> { while let Some(node_status) = node_status_stream.next().await { let node_status = node_status?; - println!("healthy: {} | synced: {} | ledger_index: {}", node_status.is_healthy, node_status.is_synced, node_status.ledger_index); + println!( + "healthy: {} | synced: {} | ledger_index: {}", + node_status.is_healthy, node_status.is_synced, node_status.ledger_index + ); } Ok(()) diff --git a/bee-inx/src/block/mod.rs b/bee-inx/src/block/mod.rs index 2949586a03..0b5afa26a8 100644 --- a/bee-inx/src/block/mod.rs +++ b/bee-inx/src/block/mod.rs @@ -3,16 +3,78 @@ pub mod responses; -pub use self::responses::*; -use crate::client::Inx; +use futures::stream::{Stream, StreamExt}; -// rpc ListenToBlocks(NoParams) returns (stream Block); -// rpc ListenToSolidBlocks(NoParams) returns (stream BlockMetadata); -// rpc ListenToReferencedBlocks(NoParams) returns (stream BlockMetadata); -// rpc SubmitBlock(RawBlock) returns (BlockId); -// rpc ReadBlock(BlockId) returns (RawBlock); -// rpc ReadBlockMetadata(BlockId) returns (BlockMetadata); +pub use self::responses::*; +use crate::{ + bee, + client::{try_from_inx_type, Inx}, + error::Error, + inx, + raw::Raw, +}; impl Inx { // TODO + pub async fn listen_to_blocks(&mut self) -> Result>, Error> { + Ok(self + .client + .listen_to_blocks(inx::NoParams {}) + .await? + .into_inner() + .map(try_from_inx_type)) + } + + // TODO + pub async fn listen_to_solid_blocks(&mut self) -> Result>, Error> { + Ok(self + .client + .listen_to_solid_blocks(inx::NoParams {}) + .await? + .into_inner() + .map(try_from_inx_type)) + } + + // TODO + pub async fn listen_to_referenced_blocks( + &mut self, + ) -> Result>, Error> { + Ok(self + .client + .listen_to_referenced_blocks(inx::NoParams {}) + .await? + .into_inner() + .map(try_from_inx_type)) + } + + // TODO + pub async fn read_block(&mut self, block_id: bee::BlockId) -> Result, Error> { + Ok(self + .client + .read_block(inx::BlockId::from(block_id)) + .await? + .into_inner() + .data + .into()) + } + + // TODO + pub async fn read_block_metadata(&mut self, block_id: bee::BlockId) -> Result { + Ok(self + .client + .read_block_metadata(inx::BlockId::from(block_id)) + .await? + .into_inner() + .try_into()?) + } + + // TODO + pub async fn submit_block(&mut self, raw_block: Raw) -> Result { + Ok(self + .client + .submit_block(inx::RawBlock { data: raw_block.data() }) + .await? + .into_inner() + .try_into()?) + } } diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index ba926b46f6..4d42985098 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -39,7 +39,7 @@ mod test { use super::*; #[test] - fn macro_missing_field() { + fn test_return_err_if_none() { let proto = inx::TreasuryOutput { milestone_id: None, amount: 42, diff --git a/bee-inx/src/milestone/mod.rs b/bee-inx/src/milestone/mod.rs index c8b00027ab..7add055375 100644 --- a/bee-inx/src/milestone/mod.rs +++ b/bee-inx/src/milestone/mod.rs @@ -24,13 +24,12 @@ use crate::{ impl Inx { /// TODO pub async fn read_milestone(&mut self, request: MilestoneRequest) -> Result { - Milestone::try_from( - self.client - .read_milestone(inx::MilestoneRequest::from(request)) - .await? - .into_inner(), - ) - .map_err(Error::InxError) + Ok(self + .client + .read_milestone(inx::MilestoneRequest::from(request)) + .await? + .into_inner() + .try_into()?) } /// Listens to confirmed milestones in a certain range. From c9bbe7c16216a777be5ddd9b44c74474521ef20b Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 29 Sep 2022 00:29:04 +0200 Subject: [PATCH 16/25] Ignore .env files --- .gitignore | 2 ++ Cargo.lock | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/.gitignore b/.gitignore index 38c08dd1cb..1cd885951e 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ book # vscode **/.vscode/ + +**/.env diff --git a/Cargo.lock b/Cargo.lock index eb3f84922f..42e01fbe73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -363,6 +363,7 @@ name = "bee-inx" version = "1.0.0-beta.6" dependencies = [ "bee-block", + "dotenvy", "futures", "inx", "packable", @@ -1322,6 +1323,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "dotenvy" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9155c8f4dc55c7470ae9da3f63c6785245093b3f6aeb0f5bf2e968efbba314" +dependencies = [ + "dirs", +] + [[package]] name = "dtoa" version = "1.0.3" From 7c12754b926ed818795c6d33169e332ad69eadc6 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 29 Sep 2022 02:03:39 +0200 Subject: [PATCH 17/25] Finish milestone related queries --- bee-inx/src/block/responses.rs | 36 ++++++++++----------- bee-inx/src/lib.rs | 6 ++-- bee-inx/src/milestone/mod.rs | 42 ++++++++++++++++++++----- bee-inx/src/milestone/requests.rs | 50 +++++++++++++++++++++++++----- bee-inx/src/milestone/responses.rs | 29 +++++++++++++++++ 5 files changed, 128 insertions(+), 35 deletions(-) diff --git a/bee-inx/src/block/responses.rs b/bee-inx/src/block/responses.rs index 604861e517..f98f388839 100644 --- a/bee-inx/src/block/responses.rs +++ b/bee-inx/src/block/responses.rs @@ -114,6 +114,24 @@ impl TryFrom for BlockMetadata { } } +impl From for inx::BlockMetadata { + fn from(value: BlockMetadata) -> Self { + Self { + block_id: Some(value.block_id.into()), + parents: value.parents.into_vec().into_iter().map(Into::into).collect(), + solid: value.is_solid, + should_promote: value.should_promote, + should_reattach: value.should_reattach, + referenced_by_milestone_index: value.referenced_by_milestone_index, + milestone_index: value.milestone_index, + ledger_inclusion_state: inx::block_metadata::LedgerInclusionState::from(value.ledger_inclusion_state) + .into(), + conflict_reason: inx::block_metadata::ConflictReason::from(value.conflict_reason).into(), + white_flag_index: value.white_flag_index, + } + } +} + impl From for LedgerInclusionState { fn from(value: inx::LedgerInclusionState) -> Self { use crate::inx::LedgerInclusionState::*; @@ -135,24 +153,6 @@ impl From for inx::LedgerInclusionState { } } -impl From for inx::BlockMetadata { - fn from(value: BlockMetadata) -> Self { - Self { - block_id: Some(value.block_id.into()), - parents: value.parents.into_vec().into_iter().map(Into::into).collect(), - solid: value.is_solid, - should_promote: value.should_promote, - should_reattach: value.should_reattach, - referenced_by_milestone_index: value.referenced_by_milestone_index, - milestone_index: value.milestone_index, - ledger_inclusion_state: inx::block_metadata::LedgerInclusionState::from(value.ledger_inclusion_state) - .into(), - conflict_reason: inx::block_metadata::ConflictReason::from(value.conflict_reason).into(), - white_flag_index: value.white_flag_index, - } - } -} - #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub enum LedgerInclusionState { diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index 4d42985098..7d0b495683 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -22,8 +22,10 @@ pub mod inx { pub(crate) mod bee { pub use bee_block::{ - payload::milestone::MilestoneIndex, protocol::ProtocolParameters, semantic::ConflictReason, Block, BlockId, - InxError, + payload::milestone::{MilestoneId, MilestoneIndex}, + protocol::ProtocolParameters, + semantic::ConflictReason, + Block, BlockId, InxError, }; } diff --git a/bee-inx/src/milestone/mod.rs b/bee-inx/src/milestone/mod.rs index 7add055375..314bd89f3d 100644 --- a/bee-inx/src/milestone/mod.rs +++ b/bee-inx/src/milestone/mod.rs @@ -8,19 +8,12 @@ use futures::stream::{Stream, StreamExt}; pub use self::{requests::*, responses::*}; use crate::{ - block::responses::BlockWithMetadata, + block::responses::{BlockMetadata, BlockWithMetadata}, client::{try_from_inx_type, Inx}, error::Error, inx, }; -// rpc ReadMilestone(MilestoneRequest) returns (Milestone); -// rpc ListenToLatestMilestones(NoParams) returns (stream Milestone); -// rpc ListenToConfirmedMilestones(MilestoneRangeRequest) returns (stream MilestoneAndProtocolParameters); -// rpc ComputeWhiteFlag(WhiteFlagRequest) returns (WhiteFlagResponse); -// rpc ReadMilestoneCone(MilestoneRequest) returns (stream BlockWithMetadata); -// rpc ReadMilestoneConeMetadata(MilestoneRequest) returns (stream BlockMetadata); - impl Inx { /// TODO pub async fn read_milestone(&mut self, request: MilestoneRequest) -> Result { @@ -32,6 +25,16 @@ impl Inx { .try_into()?) } + /// Listens to latest milestones. + pub async fn listen_to_latest_milestones(&mut self) -> Result>, Error> { + Ok(self + .client + .listen_to_latest_milestones(inx::NoParams {}) + .await? + .into_inner() + .map(try_from_inx_type)) + } + /// Listens to confirmed milestones in a certain range. pub async fn listen_to_confirmed_milestones( &mut self, @@ -45,6 +48,16 @@ impl Inx { .map(try_from_inx_type)) } + /// TODO + pub async fn compute_white_flag(&mut self, request: WhiteFlagRequest) -> Result { + Ok(self + .client + .compute_white_flag(inx::WhiteFlagRequest::from(request)) + .await? + .into_inner() + .into()) + } + /// Reads the past cone of a milestone specified by a [`MilestoneRequest`]. pub async fn read_milestone_cone( &mut self, @@ -57,4 +70,17 @@ impl Inx { .into_inner() .map(try_from_inx_type)) } + + /// TODO + pub async fn read_milestone_cone_metadata( + &mut self, + request: MilestoneRequest, + ) -> Result>, Error> { + Ok(self + .client + .read_milestone_cone_metadata(inx::MilestoneRequest::from(request)) + .await? + .into_inner() + .map(try_from_inx_type)) + } } diff --git a/bee-inx/src/milestone/requests.rs b/bee-inx/src/milestone/requests.rs index 4bf35ec571..957433167f 100644 --- a/bee-inx/src/milestone/requests.rs +++ b/bee-inx/src/milestone/requests.rs @@ -3,19 +3,17 @@ use std::ops::{Bound, RangeBounds}; -use bee_block::payload::milestone::{MilestoneId, MilestoneIndex}; - -use crate::inx; +use crate::{bee, error, inx}; pub enum MilestoneRequest { - MilestoneIndex(MilestoneIndex), - MilestoneId(MilestoneId), + MilestoneIndex(bee::MilestoneIndex), + MilestoneId(bee::MilestoneId), } impl From for inx::MilestoneRequest { fn from(value: MilestoneRequest) -> Self { match value { - MilestoneRequest::MilestoneIndex(MilestoneIndex(milestone_index)) => Self { + MilestoneRequest::MilestoneIndex(bee::MilestoneIndex(milestone_index)) => Self { milestone_index, milestone_id: None, }, @@ -29,7 +27,7 @@ impl From for inx::MilestoneRequest { impl> From for MilestoneRequest { fn from(value: T) -> Self { - Self::MilestoneIndex(MilestoneIndex(value.into())) + Self::MilestoneIndex(bee::MilestoneIndex(value.into())) } } @@ -73,6 +71,44 @@ where } } +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct WhiteFlagRequest { + milestone_index: bee::MilestoneIndex, + milestone_timestamp: u32, + parents: Box<[bee::BlockId]>, + previous_milestone_id: Option, +} + +impl TryFrom for WhiteFlagRequest { + type Error = error::Error; + + fn try_from(value: inx::WhiteFlagRequest) -> Result { + let parents = value + .parents + .into_iter() + .map(TryInto::try_into) + .collect::, _>>()?; + + Ok(Self { + milestone_index: value.milestone_index.into(), + milestone_timestamp: value.milestone_timestamp, + parents: parents.into_boxed_slice(), + previous_milestone_id: value.previous_milestone_id.map(TryInto::try_into).transpose()?, + }) + } +} + +impl From for inx::WhiteFlagRequest { + fn from(value: WhiteFlagRequest) -> Self { + Self { + milestone_index: value.milestone_index.0, + milestone_timestamp: value.milestone_timestamp, + parents: value.parents.into_vec().into_iter().map(Into::into).collect(), + previous_milestone_id: value.previous_milestone_id.map(Into::into), + } + } +} + #[cfg(test)] mod test { use super::*; diff --git a/bee-inx/src/milestone/responses.rs b/bee-inx/src/milestone/responses.rs index e25c98439b..d1812b2170 100644 --- a/bee-inx/src/milestone/responses.rs +++ b/bee-inx/src/milestone/responses.rs @@ -94,3 +94,32 @@ impl From for inx::MilestoneInfo { } } } + +// message WhiteFlagResponse { +// bytes milestone_inclusion_merkle_root = 1; +// bytes milestone_applied_merkle_root = 2; +// } + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct WhiteFlagResponse { + milestone_inclusion_merkle_root: Vec, + milestone_applied_merkle_root: Vec, +} + +impl From for WhiteFlagResponse { + fn from(value: inx::WhiteFlagResponse) -> Self { + Self { + milestone_inclusion_merkle_root: value.milestone_inclusion_merkle_root, + milestone_applied_merkle_root: value.milestone_applied_merkle_root, + } + } +} + +impl From for inx::WhiteFlagResponse { + fn from(value: WhiteFlagResponse) -> Self { + Self { + milestone_inclusion_merkle_root: value.milestone_inclusion_merkle_root, + milestone_applied_merkle_root: value.milestone_applied_merkle_root, + } + } +} From ea28d2a2dedecb3c59a57a3edab94b3ea8dbdf5a Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 29 Sep 2022 02:35:59 +0200 Subject: [PATCH 18/25] Improve milestone example --- bee-inx/examples/block.rs | 10 ++--- bee-inx/examples/milestone.rs | 82 +++++++++++++++++++++++++++++------ 2 files changed, 73 insertions(+), 19 deletions(-) diff --git a/bee-inx/examples/block.rs b/bee-inx/examples/block.rs index 725fd7e97a..416f9c9a8d 100644 --- a/bee-inx/examples/block.rs +++ b/bee-inx/examples/block.rs @@ -31,7 +31,7 @@ async fn main() -> Result<(), Error> { let block = block?; println!("{}", block.block_id); - print_block_metadata(&mut inx, block.block_id, read_block, read_block_metadata).await?; + fetch_block_and_metadata(&mut inx, block.block_id, read_block, read_block_metadata).await?; } } "solid_blocks" => { @@ -42,7 +42,7 @@ async fn main() -> Result<(), Error> { let block_metadata = block_metadata?; println!("{}", block_metadata.block_id); - print_block_metadata(&mut inx, block_metadata.block_id, read_block, read_block_metadata).await?; + fetch_block_and_metadata(&mut inx, block_metadata.block_id, read_block, read_block_metadata).await?; } } "referenced_blocks" => { @@ -53,18 +53,18 @@ async fn main() -> Result<(), Error> { let block_metadata = block_metadata?; println!("{}", block_metadata.block_id); - print_block_metadata(&mut inx, block_metadata.block_id, read_block, read_block_metadata).await?; + fetch_block_and_metadata(&mut inx, block_metadata.block_id, read_block, read_block_metadata).await?; } } _ => { - panic!("unknown block stream variant '{}'", block_stream); + panic!("unknown block stream variant: '{block_stream}'"); } } Ok(()) } -async fn print_block_metadata( +async fn fetch_block_and_metadata( inx: &mut Inx, block_id: BlockId, read_block: bool, diff --git a/bee-inx/examples/milestone.rs b/bee-inx/examples/milestone.rs index defe2f8a56..3032b01db6 100644 --- a/bee-inx/examples/milestone.rs +++ b/bee-inx/examples/milestone.rs @@ -1,40 +1,94 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use bee_inx::{client, Error}; +use bee_block::payload::milestone::MilestoneIndex; +use bee_inx::{client::Inx, Error}; use futures::StreamExt; #[tokio::main] async fn main() -> Result<(), Error> { dotenvy::dotenv().ok(); let inx_connect_url = std::env::var("INX_CONNECT_URL").unwrap_or_else(|_| "http://localhost:9029".to_string()); + let milestone_stream = std::env::var("MILESTONE_STREAM").unwrap_or_else(|_| "confirmed_milestones".to_string()); + let read_cone = std::env::var("READ_CONE") + .unwrap_or_else(|_| "false".to_string()) + .parse::() + .unwrap(); + let read_cone_metadata = std::env::var("READ_CONE_METADATA") + .unwrap_or_else(|_| "false".to_string()) + .parse::() + .unwrap(); - let mut inx = client::Inx::connect(&inx_connect_url).await?; + let mut inx = Inx::connect(&inx_connect_url).await?; println!("Connected via INX to node at {inx_connect_url}"); - let mut milestone_stream = inx.listen_to_confirmed_milestones((..).into()).await?; - println!("Streaming confirmed milestones and protocol parameters... "); + match milestone_stream.as_str() { + "confirmed_milestones" => { + let mut milestone_stream = inx.listen_to_confirmed_milestones((..).into()).await?; + println!("Streaming confirmed milestones and protocol parameters... "); - // Listen to the milestones from the node. - while let Some(milestone_and_params) = milestone_stream.next().await { - let milestone_and_params = milestone_and_params?; - println!("{:?}", milestone_and_params); + while let Some(milestone_and_params) = milestone_stream.next().await { + let milestone_and_params = milestone_and_params?; + println!( + "{:?}{:?}", + milestone_and_params.milestone.milestone_info, milestone_and_params.current_protocol_parameters + ); - let milestone_index = milestone_and_params.milestone.milestone_info.milestone_index; - println!("Fetching cone of milestone {milestone_index}"); + let milestone_index = milestone_and_params.milestone.milestone_info.milestone_index; + fetch_cone_and_metadata(&mut inx, milestone_index, read_cone, read_cone_metadata).await?; + } + } + "latest_milestones" => { + let mut milestone_stream = inx.listen_to_latest_milestones().await?; + + while let Some(milestone) = milestone_stream.next().await { + let milestone = milestone?; + println!("{:?}", milestone.milestone_info); + + let milestone_index = milestone.milestone_info.milestone_index; + fetch_cone_and_metadata(&mut inx, milestone_index, read_cone, read_cone_metadata).await?; + } + } + _ => { + panic!("unknown milestone stream variant: '{milestone_stream}'"); + } + } + + Ok(()) +} + +async fn fetch_cone_and_metadata( + inx: &mut Inx, + milestone_index: MilestoneIndex, + read_cone: bool, + read_cone_metadata: bool, +) -> Result<(), Error> { + if read_cone { + println!("Fetching cone for {milestone_index}..."); - // Listen to blocks in the past cone of a milestone. let mut cone_stream = inx.read_milestone_cone(milestone_index.0.into()).await?; + let mut count = 0usize; + + while let Some(Ok(block_metadata)) = cone_stream.next().await { + println!("\t{}", block_metadata.metadata.block_id); + count += 1; + } + + println!("Fetched {count} blocks in total."); + } + + if read_cone_metadata { + println!("Fetching cone metadata for {milestone_index}..."); - // Keep track of the number of blocks. + let mut cone_stream = inx.read_milestone_cone_metadata(milestone_index.0.into()).await?; let mut count = 0usize; while let Some(Ok(block_metadata)) = cone_stream.next().await { - println!("Received block with id `{}`", block_metadata.metadata.block_id); + println!("\t{}", block_metadata.block_id); count += 1; } - println!("Milestone `{:?}` contained {count} blocks", milestone_index); + println!("Fetched {count} blocks in total."); } Ok(()) From ef9ce4d91c5163cba02b3b9e4870854e96c5fc9a Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 29 Sep 2022 02:43:54 +0200 Subject: [PATCH 19/25] Cleanup --- bee-inx/examples/milestone.rs | 2 ++ bee-inx/src/milestone/responses.rs | 5 ----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/bee-inx/examples/milestone.rs b/bee-inx/examples/milestone.rs index 3032b01db6..f4365fc3c1 100644 --- a/bee-inx/examples/milestone.rs +++ b/bee-inx/examples/milestone.rs @@ -39,6 +39,8 @@ async fn main() -> Result<(), Error> { } } "latest_milestones" => { + println!("Streaming latest milestones... "); + let mut milestone_stream = inx.listen_to_latest_milestones().await?; while let Some(milestone) = milestone_stream.next().await { diff --git a/bee-inx/src/milestone/responses.rs b/bee-inx/src/milestone/responses.rs index d1812b2170..ddafd2ee16 100644 --- a/bee-inx/src/milestone/responses.rs +++ b/bee-inx/src/milestone/responses.rs @@ -95,11 +95,6 @@ impl From for inx::MilestoneInfo { } } -// message WhiteFlagResponse { -// bytes milestone_inclusion_merkle_root = 1; -// bytes milestone_applied_merkle_root = 2; -// } - #[derive(Clone, Debug, PartialEq, Eq)] pub struct WhiteFlagResponse { milestone_inclusion_merkle_root: Vec, From f3938d2cca7cbcefb5c35c24b6e4d3ad18051cc6 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 29 Sep 2022 10:03:25 +0200 Subject: [PATCH 20/25] Add 'read_output' query --- bee-inx/src/lib.rs | 6 +- bee-inx/src/utxo/mod.rs | 11 ++ bee-inx/src/utxo/responses.rs | 226 +++++++++++++++++++++------------- 3 files changed, 155 insertions(+), 88 deletions(-) diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index 7d0b495683..f8e1d51308 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -22,7 +22,11 @@ pub mod inx { pub(crate) mod bee { pub use bee_block::{ - payload::milestone::{MilestoneId, MilestoneIndex}, + output::{Output, OutputId}, + payload::{ + milestone::{MilestoneId, MilestoneIndex}, + transaction::TransactionId, + }, protocol::ProtocolParameters, semantic::ConflictReason, Block, BlockId, InxError, diff --git a/bee-inx/src/utxo/mod.rs b/bee-inx/src/utxo/mod.rs index ef9a019705..8da0772714 100644 --- a/bee-inx/src/utxo/mod.rs +++ b/bee-inx/src/utxo/mod.rs @@ -7,6 +7,7 @@ use futures::{Stream, StreamExt}; pub use self::responses::*; use crate::{ + bee, client::{try_from_inx_type, Inx}, error::Error, inx, @@ -57,4 +58,14 @@ impl Inx { .into_inner() .map(try_from_inx_type)) } + + /// TODO + pub async fn read_output(&mut self, output_id: bee::OutputId) -> Result { + Ok(self + .client + .read_output(inx::OutputId::from(output_id)) + .await? + .into_inner() + .try_into()?) + } } diff --git a/bee-inx/src/utxo/responses.rs b/bee-inx/src/utxo/responses.rs index f8d9e21215..fba34e97e2 100644 --- a/bee-inx/src/utxo/responses.rs +++ b/bee-inx/src/utxo/responses.rs @@ -1,19 +1,17 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use bee_block as bee; - -use crate::{inx, return_err_if_none, Raw}; +use crate::{bee, inx, return_err_if_none, Raw}; /// Represents a new output in the ledger. #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct LedgerOutput { - pub output_id: bee::output::OutputId, + pub output_id: bee::OutputId, pub block_id: bee::BlockId, - pub milestone_index_booked: bee::payload::milestone::MilestoneIndex, + pub milestone_index_booked: bee::MilestoneIndex, pub milestone_timestamp_booked: u32, - pub output: Raw, + pub output: Raw, } impl TryFrom for LedgerOutput { @@ -47,24 +45,60 @@ impl From for inx::LedgerOutput { #[derive(Clone, Debug, PartialEq, Eq)] pub struct LedgerSpent { pub output: LedgerOutput, - pub transaction_id_spent: bee::payload::transaction::TransactionId, - pub milestone_index_spent: bee::payload::milestone::MilestoneIndex, + pub transaction_id_spent: bee::TransactionId, + pub milestone_index_spent: bee::MilestoneIndex, pub milestone_timestamp_spent: u32, } +impl TryFrom for LedgerSpent { + type Error = bee::InxError; + + fn try_from(value: inx::LedgerSpent) -> Result { + Ok(Self { + output: return_err_if_none!(value.output).try_into()?, + transaction_id_spent: return_err_if_none!(value.transaction_id_spent).try_into()?, + milestone_index_spent: value.milestone_index_spent.into(), + milestone_timestamp_spent: value.milestone_timestamp_spent, + }) + } +} + +impl From for inx::LedgerSpent { + fn from(value: LedgerSpent) -> Self { + Self { + output: Some(value.output.into()), + transaction_id_spent: Some(value.transaction_id_spent.into()), + milestone_index_spent: value.milestone_index_spent.0, + milestone_timestamp_spent: value.milestone_timestamp_spent, + } + } +} + #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct UnspentOutput { - pub ledger_index: bee::payload::milestone::MilestoneIndex, + pub ledger_index: bee::MilestoneIndex, pub output: LedgerOutput, } -#[allow(missing_docs)] -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct Marker { - pub milestone_index: bee::payload::milestone::MilestoneIndex, - pub consumed_count: usize, - pub created_count: usize, +impl TryFrom for UnspentOutput { + type Error = bee::InxError; + + fn try_from(value: inx::UnspentOutput) -> Result { + Ok(Self { + ledger_index: value.ledger_index.into(), + output: return_err_if_none!(value.output).try_into()?, + }) + } +} + +impl From for inx::UnspentOutput { + fn from(value: UnspentOutput) -> Self { + Self { + ledger_index: value.ledger_index.0, + output: Some(value.output.into()), + } + } } #[allow(missing_docs)] @@ -110,6 +144,41 @@ impl LedgerUpdate { } } +impl TryFrom for LedgerUpdate { + type Error = bee::InxError; + + fn try_from(value: inx::LedgerUpdate) -> Result { + use crate::inx::Op; + Ok(match return_err_if_none!(value.op) { + Op::BatchMarker(marker) => marker.into(), + Op::Consumed(consumed) => LedgerUpdate::Consumed(consumed.try_into()?), + Op::Created(created) => LedgerUpdate::Created(created.try_into()?), + }) + } +} + +impl From for inx::LedgerUpdate { + fn from(value: LedgerUpdate) -> Self { + use crate::inx::Op; + Self { + op: match value { + LedgerUpdate::Consumed(consumed) => Op::Consumed(consumed.into()), + LedgerUpdate::Created(created) => Op::Created(created.into()), + marker => Op::BatchMarker(marker.try_into().unwrap()), + } + .into(), + } + } +} + +#[allow(missing_docs)] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Marker { + pub milestone_index: bee::MilestoneIndex, + pub consumed_count: usize, + pub created_count: usize, +} + impl From for Marker { fn from(value: inx::ledger_update::Marker) -> Self { Self { @@ -155,82 +224,11 @@ impl TryFrom for inx::ledger_update::Marker { } } -impl TryFrom for LedgerUpdate { - type Error = bee::InxError; - - fn try_from(value: inx::LedgerUpdate) -> Result { - use crate::inx::Op; - Ok(match return_err_if_none!(value.op) { - Op::BatchMarker(marker) => marker.into(), - Op::Consumed(consumed) => LedgerUpdate::Consumed(consumed.try_into()?), - Op::Created(created) => LedgerUpdate::Created(created.try_into()?), - }) - } -} - -impl From for inx::LedgerUpdate { - fn from(value: LedgerUpdate) -> Self { - use crate::inx::Op; - Self { - op: match value { - LedgerUpdate::Consumed(consumed) => Op::Consumed(consumed.into()), - LedgerUpdate::Created(created) => Op::Created(created.into()), - marker => Op::BatchMarker(marker.try_into().unwrap()), - } - .into(), - } - } -} - -impl TryFrom for LedgerSpent { - type Error = bee::InxError; - - fn try_from(value: inx::LedgerSpent) -> Result { - Ok(Self { - output: return_err_if_none!(value.output).try_into()?, - transaction_id_spent: return_err_if_none!(value.transaction_id_spent).try_into()?, - milestone_index_spent: value.milestone_index_spent.into(), - milestone_timestamp_spent: value.milestone_timestamp_spent, - }) - } -} - -impl From for inx::LedgerSpent { - fn from(value: LedgerSpent) -> Self { - Self { - output: Some(value.output.into()), - transaction_id_spent: Some(value.transaction_id_spent.into()), - milestone_index_spent: value.milestone_index_spent.0, - milestone_timestamp_spent: value.milestone_timestamp_spent, - } - } -} - -impl TryFrom for UnspentOutput { - type Error = bee::InxError; - - fn try_from(value: inx::UnspentOutput) -> Result { - Ok(Self { - ledger_index: value.ledger_index.into(), - output: return_err_if_none!(value.output).try_into()?, - }) - } -} - -impl From for inx::UnspentOutput { - fn from(value: UnspentOutput) -> Self { - Self { - ledger_index: value.ledger_index.0, - output: Some(value.output.into()), - } - } -} - /// Represents a treasury output. #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct TreasuryOutput { - pub milestone_id: bee::payload::milestone::MilestoneId, + pub milestone_id: bee::MilestoneId, pub amount: u64, } @@ -284,3 +282,57 @@ impl From for inx::TreasuryUpdate { } } } + +// message OutputResponse { +// uint32 ledger_index = 1; +// oneof payload { +// LedgerOutput output = 2; +// LedgerSpent spent = 3; +// } +// } + +/// Represents an output response. +#[allow(missing_docs)] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct OutputResponse { + pub ledger_index: bee::MilestoneIndex, + pub payload: Option, +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum OutputResponsePayload { + LedgerOutput(LedgerOutput), + LedgerSpent(LedgerSpent), +} + +impl TryFrom for OutputResponse { + type Error = bee::InxError; + + fn try_from(value: inx::OutputResponse) -> Result { + use crate::inx::output_response::Payload::*; + Ok(Self { + ledger_index: value.ledger_index.into(), + payload: if let Some(payload) = value.payload { + Some(match payload { + Output(ledger_output) => OutputResponsePayload::LedgerOutput(ledger_output.try_into()?), + Spent(ledger_spent) => OutputResponsePayload::LedgerSpent(ledger_spent.try_into()?), + }) + } else { + None + }, + }) + } +} + +impl From for inx::OutputResponse { + fn from(value: OutputResponse) -> Self { + use OutputResponsePayload::*; + Self { + ledger_index: value.ledger_index.0, + payload: value.payload.map(|payload| match payload { + LedgerOutput(ledger_output) => inx::output_response::Payload::Output(ledger_output.into()), + LedgerSpent(ledger_spent) => inx::output_response::Payload::Spent(ledger_spent.into()), + }), + } + } +} From ad7345c8e6663c12a5718f33e3124e68d3986285 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 29 Sep 2022 10:50:24 +0200 Subject: [PATCH 21/25] Add 'listen_to_migration_receipts' query --- bee-inx/src/client.rs | 14 +++++++++--- bee-inx/src/lib.rs | 5 ++++- bee-inx/src/raw.rs | 50 ++++++++++++++++++++++++----------------- bee-inx/src/utxo/mod.rs | 21 +++++++++++------ 4 files changed, 59 insertions(+), 31 deletions(-) diff --git a/bee-inx/src/client.rs b/bee-inx/src/client.rs index 9f901c12bb..2ab2782f6c 100644 --- a/bee-inx/src/client.rs +++ b/bee-inx/src/client.rs @@ -20,10 +20,18 @@ impl Inx { } } -pub(crate) fn try_from_inx_type(msg: Result) -> Result +pub(crate) fn try_from_inx_type(msg: Result) -> Result where - B: TryFrom, + BeeType: TryFrom, { let inner = msg.map_err(Error::StatusCode)?; - B::try_from(inner).map_err(Error::InxError) + BeeType::try_from(inner).map_err(Error::InxError) +} + +pub(crate) fn from_inx_type(msg: Result) -> Result +where + BeeType: From, +{ + let inner = msg.map_err(Error::StatusCode)?; + Ok(BeeType::from(inner)) } diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index f8e1d51308..6612111fda 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -24,13 +24,16 @@ pub(crate) mod bee { pub use bee_block::{ output::{Output, OutputId}, payload::{ - milestone::{MilestoneId, MilestoneIndex}, + milestone::{MilestoneId, MilestoneIndex, MilestoneOption}, transaction::TransactionId, + Payload, }, protocol::ProtocolParameters, semantic::ConflictReason, Block, BlockId, InxError, }; + #[cfg(test)] + pub use bee_block::{protocol::protocol_parameters, rand::output::rand_output}; } #[macro_export] diff --git a/bee-inx/src/raw.rs b/bee-inx/src/raw.rs index 94f79fbbf7..6f466cb26b 100644 --- a/bee-inx/src/raw.rs +++ b/bee-inx/src/raw.rs @@ -3,11 +3,9 @@ use std::marker::PhantomData; -use bee_block as bee; -use inx::proto; use packable::{Packable, PackableExt}; -use crate::Error; +use crate::{bee, inx, Error}; /// Represents a type as raw bytes. #[derive(Debug, Clone, PartialEq, Eq)] @@ -44,67 +42,79 @@ impl From> for Raw { } } -impl From for Raw { - fn from(value: proto::RawOutput) -> Self { +impl From for Raw { + fn from(value: inx::RawOutput) -> Self { value.data.into() } } -impl From> for proto::RawOutput { - fn from(value: Raw) -> Self { +impl From> for inx::RawOutput { + fn from(value: Raw) -> Self { Self { data: value.data } } } -impl From for Raw { - fn from(value: proto::RawBlock) -> Self { +impl From for Raw { + fn from(value: inx::RawBlock) -> Self { value.data.into() } } -impl From> for proto::RawBlock { +impl From> for inx::RawBlock { fn from(value: Raw) -> Self { Self { data: value.data } } } -impl From for Raw { - fn from(value: proto::RawMilestone) -> Self { +impl From for Raw { + fn from(value: inx::RawMilestone) -> Self { value.data.into() } } -impl From> for proto::RawMilestone { - fn from(value: Raw) -> Self { +impl From> for inx::RawMilestone { + fn from(value: Raw) -> Self { + Self { data: value.data } + } +} + +impl From for Raw { + fn from(value: inx::RawReceipt) -> Self { + value.data.into() + } +} + +impl From> for inx::RawReceipt { + fn from(value: Raw) -> Self { Self { data: value.data } } } #[cfg(test)] mod test { - use bee::{payload::Payload, rand::output::rand_output}; + use bee::{rand_output, Payload}; use super::*; use crate::ProtocolParameters; #[test] fn raw_output() { - let protocol_parameters = bee::protocol::protocol_parameters(); + let protocol_parameters = bee::protocol_parameters(); let output = rand_output(protocol_parameters.token_supply()); - let proto = proto::RawOutput { + let proto = inx::RawOutput { data: output.pack_to_vec(), }; - let raw: Raw = proto.into(); + let raw: Raw = proto.into(); assert_eq!(output, raw.clone().inner_unverified().unwrap()); assert_eq!(output, raw.inner(&protocol_parameters).unwrap()); } #[test] fn raw_protocol_parameters() { - let protocol_parameters = bee::protocol::protocol_parameters(); - let proto = proto::RawProtocolParameters::from(protocol_parameters.clone()); + let protocol_parameters = bee::protocol_parameters(); + let proto = inx::RawProtocolParameters::from(protocol_parameters.clone()); let pp: ProtocolParameters = proto.into(); assert_eq!(protocol_parameters, pp.params.inner(&()).unwrap()); diff --git a/bee-inx/src/utxo/mod.rs b/bee-inx/src/utxo/mod.rs index 8da0772714..5c1384852c 100644 --- a/bee-inx/src/utxo/mod.rs +++ b/bee-inx/src/utxo/mod.rs @@ -8,18 +8,13 @@ use futures::{Stream, StreamExt}; pub use self::responses::*; use crate::{ bee, - client::{try_from_inx_type, Inx}, + client::{from_inx_type, try_from_inx_type, Inx}, error::Error, inx, milestone::requests::MilestoneRangeRequest, + raw::Raw, }; -// rpc ReadUnspentOutputs(NoParams) returns (stream UnspentOutput); -// rpc ListenToLedgerUpdates(MilestoneRangeRequest) returns (stream LedgerUpdate); -// rpc ListenToTreasuryUpdates(MilestoneRangeRequest) returns (stream TreasuryUpdate); -// rpc ReadOutput(OutputId) returns (OutputResponse); -// rpc ListenToMigrationReceipts(NoParams) returns (stream RawReceipt); - impl Inx { /// TODO pub async fn read_unspent_outputs( @@ -68,4 +63,16 @@ impl Inx { .into_inner() .try_into()?) } + + /// TODO + pub async fn listen_to_migration_receipts( + &mut self, + ) -> Result, Error>>, Error> { + Ok(self + .client + .listen_to_migration_receipts(inx::NoParams {}) + .await? + .into_inner() + .map(from_inx_type)) + } } From 8da288af8edf6608a94fc13ccf5816570768a674 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 29 Sep 2022 11:48:08 +0200 Subject: [PATCH 22/25] Add utxo example --- bee-inx/examples/utxo.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 bee-inx/examples/utxo.rs diff --git a/bee-inx/examples/utxo.rs b/bee-inx/examples/utxo.rs new file mode 100644 index 0000000000..46947b4d83 --- /dev/null +++ b/bee-inx/examples/utxo.rs @@ -0,0 +1,31 @@ +// Copyright 2022 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use bee_inx::{client::Inx, Error, MilestoneRangeRequest}; +use futures::StreamExt; + +#[tokio::main] +async fn main() -> Result<(), Error> { + dotenvy::dotenv().ok(); + let inx_connect_url = std::env::var("INX_CONNECT_URL").unwrap_or_else(|_| "http://localhost:9029".to_string()); + + let mut inx = Inx::connect(&inx_connect_url).await?; + println!("Connected via INX to node at {inx_connect_url}"); + + let mut unspent_outputs = inx.read_unspent_outputs().await?; + + let mut count = 0; + while let Some(_) = unspent_outputs.next().await { + count += 1; + } + println!("Read {count} unspent outputs."); + + let mut ledger_update_feed = inx.listen_to_ledger_updates(MilestoneRangeRequest::from(..)).await?; + + while let Some(ledger_update) = ledger_update_feed.next().await { + let ledger_update = ledger_update?; + println!("{:?}", ledger_update); + } + + Ok(()) +} From 97233daed584c9fa824c3648f100a163d60dc68a Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 29 Sep 2022 13:43:42 +0200 Subject: [PATCH 23/25] Deny missing docs --- bee-inx/examples/utxo.rs | 2 +- bee-inx/src/block/mod.rs | 13 +++++++------ bee-inx/src/block/responses.rs | 1 + bee-inx/src/error.rs | 1 + bee-inx/src/lib.rs | 13 ++++++++++++- bee-inx/src/milestone/mod.rs | 8 +++++--- bee-inx/src/milestone/requests.rs | 3 +++ bee-inx/src/milestone/responses.rs | 3 +++ bee-inx/src/node/mod.rs | 10 ++++++---- bee-inx/src/node/requests.rs | 3 ++- bee-inx/src/node/responses.rs | 9 +++++++-- bee-inx/src/raw.rs | 3 +++ bee-inx/src/utxo/mod.rs | 11 ++++++----- bee-inx/src/utxo/responses.rs | 16 ++++++---------- 14 files changed, 63 insertions(+), 33 deletions(-) diff --git a/bee-inx/examples/utxo.rs b/bee-inx/examples/utxo.rs index 46947b4d83..3f2c4529ef 100644 --- a/bee-inx/examples/utxo.rs +++ b/bee-inx/examples/utxo.rs @@ -15,7 +15,7 @@ async fn main() -> Result<(), Error> { let mut unspent_outputs = inx.read_unspent_outputs().await?; let mut count = 0; - while let Some(_) = unspent_outputs.next().await { + while let Some(_unspent_output) = unspent_outputs.next().await { count += 1; } println!("Read {count} unspent outputs."); diff --git a/bee-inx/src/block/mod.rs b/bee-inx/src/block/mod.rs index 0b5afa26a8..06d1093be7 100644 --- a/bee-inx/src/block/mod.rs +++ b/bee-inx/src/block/mod.rs @@ -1,6 +1,7 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +/// A module that provides block related INX responses. pub mod responses; use futures::stream::{Stream, StreamExt}; @@ -15,7 +16,7 @@ use crate::{ }; impl Inx { - // TODO + /// Listens to all blocks. pub async fn listen_to_blocks(&mut self) -> Result>, Error> { Ok(self .client @@ -25,7 +26,7 @@ impl Inx { .map(try_from_inx_type)) } - // TODO + /// Listens to solid blocks. pub async fn listen_to_solid_blocks(&mut self) -> Result>, Error> { Ok(self .client @@ -35,7 +36,7 @@ impl Inx { .map(try_from_inx_type)) } - // TODO + /// Listens to referenced blocks. pub async fn listen_to_referenced_blocks( &mut self, ) -> Result>, Error> { @@ -47,7 +48,7 @@ impl Inx { .map(try_from_inx_type)) } - // TODO + /// Requests the block with the given block id. pub async fn read_block(&mut self, block_id: bee::BlockId) -> Result, Error> { Ok(self .client @@ -58,7 +59,7 @@ impl Inx { .into()) } - // TODO + /// Requests the metadata of the block with the given block id. pub async fn read_block_metadata(&mut self, block_id: bee::BlockId) -> Result { Ok(self .client @@ -68,7 +69,7 @@ impl Inx { .try_into()?) } - // TODO + /// Submits a block and returns its corresponding block id. pub async fn submit_block(&mut self, raw_block: Raw) -> Result { Ok(self .client diff --git a/bee-inx/src/block/responses.rs b/bee-inx/src/block/responses.rs index f98f388839..3f96bdf9e0 100644 --- a/bee-inx/src/block/responses.rs +++ b/bee-inx/src/block/responses.rs @@ -153,6 +153,7 @@ impl From for inx::LedgerInclusionState { } } +/// Whether a block contains a transaction that is either included or conflicting, or contains no transaction at all. #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub enum LedgerInclusionState { diff --git a/bee-inx/src/error.rs b/bee-inx/src/error.rs index 152ef62e5f..1094a9530e 100644 --- a/bee-inx/src/error.rs +++ b/bee-inx/src/error.rs @@ -4,6 +4,7 @@ use inx::tonic; use thiserror::Error; +#[allow(missing_docs)] #[derive(Debug, Error)] pub enum Error { #[error(transparent)] diff --git a/bee-inx/src/lib.rs b/bee-inx/src/lib.rs index 6612111fda..a3c9f40f38 100644 --- a/bee-inx/src/lib.rs +++ b/bee-inx/src/lib.rs @@ -1,18 +1,28 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +//! Bee compatible INX types and INX node request bindings. + +#![deny(missing_docs)] + mod error; +/// A module that provides block related requests.. pub mod block; +/// A module that provides the INX client. pub mod client; +/// A module that provides milestone related requests. pub mod milestone; +/// A module that provides node related requests. pub mod node; +/// A module that provides the [`Raw`] struct. pub mod raw; +/// A module that provides UTXO ledger related requests. pub mod utxo; pub use self::{block::*, error::Error, milestone::*, node::*, raw::*, utxo::*}; -pub mod inx { +pub(crate) mod inx { pub use ::inx::proto::{ block_metadata::*, ledger_update::{marker::*, *}, @@ -36,6 +46,7 @@ pub(crate) mod bee { pub use bee_block::{protocol::protocol_parameters, rand::output::rand_output}; } +#[allow(missing_docs)] #[macro_export] macro_rules! return_err_if_none { ($object:ident.$field:ident) => { diff --git a/bee-inx/src/milestone/mod.rs b/bee-inx/src/milestone/mod.rs index 314bd89f3d..59693fe24d 100644 --- a/bee-inx/src/milestone/mod.rs +++ b/bee-inx/src/milestone/mod.rs @@ -1,7 +1,9 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +/// A module that provides milestone related INX requests. pub mod requests; +/// A module that provides milestone related INX responses. pub mod responses; use futures::stream::{Stream, StreamExt}; @@ -15,7 +17,7 @@ use crate::{ }; impl Inx { - /// TODO + /// Requests a particular milestone. pub async fn read_milestone(&mut self, request: MilestoneRequest) -> Result { Ok(self .client @@ -48,7 +50,7 @@ impl Inx { .map(try_from_inx_type)) } - /// TODO + /// Requests "white flag" data for a milestone. pub async fn compute_white_flag(&mut self, request: WhiteFlagRequest) -> Result { Ok(self .client @@ -71,7 +73,7 @@ impl Inx { .map(try_from_inx_type)) } - /// TODO + /// Reads the past cone metadata of a milestone specified by a [`MilestoneRequest`]. pub async fn read_milestone_cone_metadata( &mut self, request: MilestoneRequest, diff --git a/bee-inx/src/milestone/requests.rs b/bee-inx/src/milestone/requests.rs index 957433167f..aae957233f 100644 --- a/bee-inx/src/milestone/requests.rs +++ b/bee-inx/src/milestone/requests.rs @@ -5,6 +5,8 @@ use std::ops::{Bound, RangeBounds}; use crate::{bee, error, inx}; +/// Allows to request a milestone by either its index or its id. +#[allow(missing_docs)] pub enum MilestoneRequest { MilestoneIndex(bee::MilestoneIndex), MilestoneId(bee::MilestoneId), @@ -71,6 +73,7 @@ where } } +/// Allows to request "white flag" data for a particular milestone. #[derive(Clone, Debug, PartialEq, Eq)] pub struct WhiteFlagRequest { milestone_index: bee::MilestoneIndex, diff --git a/bee-inx/src/milestone/responses.rs b/bee-inx/src/milestone/responses.rs index ddafd2ee16..ccda4f95c0 100644 --- a/bee-inx/src/milestone/responses.rs +++ b/bee-inx/src/milestone/responses.rs @@ -36,6 +36,7 @@ impl From for inx::Milestone { } /// The [`Milestone`] type. +#[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MilestoneAndProtocolParameters { pub milestone: Milestone, @@ -95,6 +96,8 @@ impl From for inx::MilestoneInfo { } } +/// The response of a corresponding "white flag" request. +#[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct WhiteFlagResponse { milestone_inclusion_merkle_root: Vec, diff --git a/bee-inx/src/node/mod.rs b/bee-inx/src/node/mod.rs index 23f1c38f9d..00255b9c84 100644 --- a/bee-inx/src/node/mod.rs +++ b/bee-inx/src/node/mod.rs @@ -1,7 +1,9 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +/// A module that provides node related INX requests. pub mod requests; +/// A module that provides node related INX responses. pub mod responses; use futures::stream::{Stream, StreamExt}; @@ -15,13 +17,13 @@ use crate::{ }; impl Inx { - /// TODO + /// Requests the status of the connected node. pub async fn read_node_status(&mut self) -> Result { NodeStatus::try_from(self.client.read_node_status(inx::NoParams {}).await?.into_inner()) .map_err(Error::InxError) } - // TODO + /// Listens to node status updates. pub async fn listen_to_node_status( &mut self, request: NodeStatusRequest, @@ -34,7 +36,7 @@ impl Inx { .map(try_from_inx_type)) } - /// TODO + /// Requests the configuration of the connected node. pub async fn read_node_configuration(&mut self) -> Result { NodeConfiguration::try_from( self.client @@ -45,7 +47,7 @@ impl Inx { .map_err(Error::InxError) } - /// TODO + /// Requests the protocol parameters of the connected node. pub async fn read_protocol_parameters(&mut self, request: MilestoneRequest) -> Result { Ok(self .client diff --git a/bee-inx/src/node/requests.rs b/bee-inx/src/node/requests.rs index 38dea8aef5..6731e4bbf5 100644 --- a/bee-inx/src/node/requests.rs +++ b/bee-inx/src/node/requests.rs @@ -3,7 +3,8 @@ use crate::inx; -/// TODO +/// A request for the node status. +#[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct NodeStatusRequest { pub cooldown_in_milliseconds: u32, diff --git a/bee-inx/src/node/responses.rs b/bee-inx/src/node/responses.rs index 740fca87a3..86e21dcd01 100644 --- a/bee-inx/src/node/responses.rs +++ b/bee-inx/src/node/responses.rs @@ -3,7 +3,7 @@ use crate::{bee, inx, milestone::responses::Milestone, raw::Raw, return_err_if_none}; -/// The [`NodeStatus`] type. +/// Represents the [`NodeStatus`] response. #[derive(Clone, Debug, PartialEq, Eq)] pub struct NodeStatus { /// Signals if the node is healthy. @@ -64,7 +64,8 @@ impl From for inx::NodeStatus { } } -/// The [`NodeConfiguration`] type. +/// Represents the [`NodeConfiguration`] response. +#[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct NodeConfiguration { pub milestone_public_key_count: u32, @@ -108,6 +109,7 @@ impl From for inx::NodeConfiguration { } /// The [`BaseToken`] type. +#[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct BaseToken { pub name: String, @@ -144,6 +146,8 @@ impl From for inx::BaseToken { } } +/// Represents a milestone key range. +#[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct MilestoneKeyRange { pub public_key: Box<[u8]>, @@ -171,6 +175,7 @@ impl From for inx::MilestoneKeyRange { } } +/// Represents a protocol parameters response. #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct ProtocolParameters { diff --git a/bee-inx/src/raw.rs b/bee-inx/src/raw.rs index 6f466cb26b..7242697acd 100644 --- a/bee-inx/src/raw.rs +++ b/bee-inx/src/raw.rs @@ -15,17 +15,20 @@ pub struct Raw { } impl Raw { + /// Returns the inner byte data as-is. #[must_use] pub fn data(self) -> Vec { self.data } + /// Deserializes the inner byte data into `T`. pub fn inner(self, visitor: &T::UnpackVisitor) -> Result { let unpacked = T::unpack_verified(self.data, visitor) .map_err(|e| bee_block::InxError::InvalidRawBytes(format!("{:?}", e)))?; Ok(unpacked) } + /// Deserializes the raw byte data into `T` without verification. pub fn inner_unverified(self) -> Result { let unpacked = T::unpack_unverified(self.data).map_err(|e| bee_block::InxError::InvalidRawBytes(format!("{:?}", e)))?; diff --git a/bee-inx/src/utxo/mod.rs b/bee-inx/src/utxo/mod.rs index 5c1384852c..c147c621b4 100644 --- a/bee-inx/src/utxo/mod.rs +++ b/bee-inx/src/utxo/mod.rs @@ -1,6 +1,7 @@ // Copyright 2022 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +/// A module that provides utxo related INX responses. pub mod responses; use futures::{Stream, StreamExt}; @@ -16,7 +17,7 @@ use crate::{ }; impl Inx { - /// TODO + /// Requests all unspent outputs. pub async fn read_unspent_outputs( &mut self, ) -> Result>, Error> { @@ -28,7 +29,7 @@ impl Inx { .map(try_from_inx_type)) } - /// TODO + /// Creates a feed of ledger updates. pub async fn listen_to_ledger_updates( &mut self, request: MilestoneRangeRequest, @@ -41,7 +42,7 @@ impl Inx { .map(try_from_inx_type)) } - /// TODO + /// Creates a feed of treasury updates. pub async fn listen_to_treasury_updates( &mut self, request: MilestoneRangeRequest, @@ -54,7 +55,7 @@ impl Inx { .map(try_from_inx_type)) } - /// TODO + /// Requests an output by its output id. pub async fn read_output(&mut self, output_id: bee::OutputId) -> Result { Ok(self .client @@ -64,7 +65,7 @@ impl Inx { .try_into()?) } - /// TODO + /// Creates a feed of migration receipts. pub async fn listen_to_migration_receipts( &mut self, ) -> Result, Error>>, Error> { diff --git a/bee-inx/src/utxo/responses.rs b/bee-inx/src/utxo/responses.rs index fba34e97e2..17b244f6f7 100644 --- a/bee-inx/src/utxo/responses.rs +++ b/bee-inx/src/utxo/responses.rs @@ -3,7 +3,7 @@ use crate::{bee, inx, return_err_if_none, Raw}; -/// Represents a new output in the ledger. +/// Represents unspent output response. #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct LedgerOutput { @@ -40,7 +40,7 @@ impl From for inx::LedgerOutput { } } -/// Represents a spent output in the ledger. +/// A spent output response. #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct LedgerSpent { @@ -74,6 +74,7 @@ impl From for inx::LedgerSpent { } } +/// An unspent output response. #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct UnspentOutput { @@ -101,6 +102,7 @@ impl From for inx::UnspentOutput { } } +/// A ledger update response. #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub enum LedgerUpdate { @@ -171,6 +173,7 @@ impl From for inx::LedgerUpdate { } } +/// Represents a ledger update batch marker. #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub struct Marker { @@ -283,14 +286,6 @@ impl From for inx::TreasuryUpdate { } } -// message OutputResponse { -// uint32 ledger_index = 1; -// oneof payload { -// LedgerOutput output = 2; -// LedgerSpent spent = 3; -// } -// } - /// Represents an output response. #[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] @@ -299,6 +294,7 @@ pub struct OutputResponse { pub payload: Option, } +#[allow(missing_docs)] #[derive(Clone, Debug, PartialEq, Eq)] pub enum OutputResponsePayload { LedgerOutput(LedgerOutput), From 25c5f6576e0e46e777e5ec03f1fbb1d3126dba73 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 29 Sep 2022 13:49:23 +0200 Subject: [PATCH 24/25] Format --- bee-inx/src/block/mod.rs | 2 +- bee-inx/src/milestone/requests.rs | 2 +- bee-inx/src/raw.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bee-inx/src/block/mod.rs b/bee-inx/src/block/mod.rs index 06d1093be7..454738cf64 100644 --- a/bee-inx/src/block/mod.rs +++ b/bee-inx/src/block/mod.rs @@ -59,7 +59,7 @@ impl Inx { .into()) } - /// Requests the metadata of the block with the given block id. + /// Requests the metadata of the block with the given block id. pub async fn read_block_metadata(&mut self, block_id: bee::BlockId) -> Result { Ok(self .client diff --git a/bee-inx/src/milestone/requests.rs b/bee-inx/src/milestone/requests.rs index aae957233f..1009093311 100644 --- a/bee-inx/src/milestone/requests.rs +++ b/bee-inx/src/milestone/requests.rs @@ -33,7 +33,7 @@ impl> From for MilestoneRequest { } } -/// A request for a range of milestones by [`MilestoneIndex`]. +/// A request for a range of milestones by [`bee::MilestoneIndex`]. #[derive(Clone, Debug, PartialEq)] pub struct MilestoneRangeRequest(inx::MilestoneRangeRequest); diff --git a/bee-inx/src/raw.rs b/bee-inx/src/raw.rs index 7242697acd..db29cf7a15 100644 --- a/bee-inx/src/raw.rs +++ b/bee-inx/src/raw.rs @@ -15,7 +15,7 @@ pub struct Raw { } impl Raw { - /// Returns the inner byte data as-is. + /// Returns the inner byte data as-is. #[must_use] pub fn data(self) -> Vec { self.data From 463bb58d73d154c704bf606567f0d08ed80a9b7b Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 29 Sep 2022 13:55:28 +0200 Subject: [PATCH 25/25] Bump verion to 1.0.0-rc.1 --- Cargo.lock | 2 +- bee-inx/CHANGELOG.md | 8 ++++++++ bee-inx/Cargo.toml | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 42e01fbe73..409cd66082 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -360,7 +360,7 @@ dependencies = [ [[package]] name = "bee-inx" -version = "1.0.0-beta.6" +version = "1.0.0-rc.1" dependencies = [ "bee-block", "dotenvy", diff --git a/bee-inx/CHANGELOG.md b/bee-inx/CHANGELOG.md index 0048f1ce23..7d8ce33de9 100644 --- a/bee-inx/CHANGELOG.md +++ b/bee-inx/CHANGELOG.md @@ -19,6 +19,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security --> +## 1.0.0-rc.1 - 2022-09-29 + +### Added + +- Missing INX bindings +- Examples +- Documentation + ## 1.0.0-beta.6 - 2022-09-26 ### Added diff --git a/bee-inx/Cargo.toml b/bee-inx/Cargo.toml index 59171573ba..b7bf94c775 100644 --- a/bee-inx/Cargo.toml +++ b/bee-inx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bee-inx" -version = "1.0.0-beta.6" +version = "1.0.0-rc.1" authors = [ "IOTA Stiftung" ] edition = "2021" description = "Rust bindings for IOTA node extensions (INX)"