-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add types for
ProtocolParameters
(#82)
* Add types for `ProtocolParameters` and `RentStructure` * Set crate version to `1.0.0-beta.1`
- Loading branch information
Showing
4 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} | ||
} |