Skip to content

Commit

Permalink
Add types for ProtocolParameters (#82)
Browse files Browse the repository at this point in the history
* Add types for `ProtocolParameters` and `RentStructure`

* Set crate version to `1.0.0-beta.1`
  • Loading branch information
grtlr authored Jul 15, 2022
1 parent 63599e0 commit c6cdb61
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "inx"
version = "0.4.0"
version = "1.0.0-beta.1"
authors = [ "IOTA Stiftung" ]
edition = "2021"
description = "Rust bindings for IOTA node extensions (INX)"
Expand Down
5 changes: 3 additions & 2 deletions rust/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ mod error;
mod ledger;
mod metadata;
mod milestone;
mod node_status;
mod node;
mod tangle;
mod treasury;

pub use self::{block::*, error::*, ledger::*, metadata::*, milestone::*, node_status::*, treasury::*};
pub use self::{block::*, error::*, ledger::*, metadata::*, milestone::*, node::*, tangle::*, treasury::*};
File renamed without changes.
55 changes: 55 additions & 0 deletions rust/src/types/tangle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use super::Error;
use crate::proto;
use bee_block_stardust as stardust;
use stardust::output::ByteCostConfigBuilder;

impl From<proto::RentStructure> for stardust::output::ByteCostConfig {
fn from(value: proto::RentStructure) -> Self {
ByteCostConfigBuilder::new()
.byte_cost(value.v_byte_cost as u64)
.data_factor(value.v_byte_factor_data as u64)
.key_factor(value.v_byte_factor_key as u64)
.finish()
}
}

/// The [`ProtocolParameters`] type.
#[derive(Clone, Debug, PartialEq)]
pub struct ProtocolParameters {
/// The protocol version of the network.
pub version: u32,
/// The name of the network.
pub network_name: String,
/// The human-readable part of the bech32 format.
pub bech32_hrp: String,
/// Minimum required PoW score.
pub min_pow_score: u32,
/// The below max depth (BMD) parameter of the tip selection algorithm.
pub below_max_depth: u32,
/// Defines the parameters for the byte cost calculation
pub rent_structure: stardust::output::ByteCostConfig,
/// The overall token supply.
pub token_supply: u64,
}

impl TryFrom<proto::ProtocolParameters> for ProtocolParameters {
type Error = Error;

fn try_from(value: proto::ProtocolParameters) -> Result<Self, Error> {
Ok(Self {
version: value.version,
network_name: value.network_name,
bech32_hrp: value.bech32_hrp,
min_pow_score: value.min_po_w_score,
below_max_depth: value.below_max_depth,
rent_structure: value
.rent_structure
.ok_or(Error::MissingField("rent_structure"))?
.into(),
token_supply: value.token_supply,
})
}
}

0 comments on commit c6cdb61

Please sign in to comment.