From 00f65bad0af80230f38bd4efe748242172d8f1d3 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Tue, 23 Jul 2024 10:29:19 +0300 Subject: [PATCH] chore: impl serialize config for chain info --- Cargo.lock | 1 + crates/blockifier/Cargo.toml | 1 + crates/blockifier/src/context.rs | 42 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7fbb9d5cf7..8c4e5d9fb0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1005,6 +1005,7 @@ dependencies = [ "num-rational 0.4.2", "num-traits 0.2.19", "once_cell", + "papyrus_config", "paste", "phf", "pretty_assertions", diff --git a/crates/blockifier/Cargo.toml b/crates/blockifier/Cargo.toml index a3395538e1..e01457c0a6 100644 --- a/crates/blockifier/Cargo.toml +++ b/crates/blockifier/Cargo.toml @@ -38,6 +38,7 @@ num-integer.workspace = true num-rational.workspace = true num-traits.workspace = true once_cell.workspace = true +papyrus_config = { path = "../papyrus_config", version = "0.4.0-rc.0"} paste.workspace = true phf.workspace = true rand = { workspace = true, optional = true } diff --git a/crates/blockifier/src/context.rs b/crates/blockifier/src/context.rs index 8f27c3fbdf..13b356ea6d 100644 --- a/crates/blockifier/src/context.rs +++ b/crates/blockifier/src/context.rs @@ -1,3 +1,7 @@ +use std::collections::BTreeMap; + +use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig}; +use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; use serde::{Deserialize, Serialize}; use starknet_api::core::{ChainId, ContractAddress}; @@ -93,6 +97,25 @@ impl Default for ChainInfo { } } +impl SerializeConfig for ChainInfo { + fn dump(&self) -> BTreeMap { + let members = BTreeMap::from_iter([ser_param( + "chain_id", + &self.chain_id, + "The chain ID of the StarkNet chain.", + ParamPrivacyInput::Public, + )]); + + vec![ + members, + append_sub_config_name(self.fee_token_addresses.dump(), "fee_token_addresses"), + ] + .into_iter() + .flatten() + .collect() + } +} + #[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)] pub struct FeeTokenAddresses { pub strk_fee_token_address: ContractAddress, @@ -107,3 +130,22 @@ impl FeeTokenAddresses { } } } + +impl SerializeConfig for FeeTokenAddresses { + fn dump(&self) -> BTreeMap { + BTreeMap::from_iter([ + ser_param( + "strk_fee_token_address", + &self.strk_fee_token_address, + "Address of the STRK fee token.", + ParamPrivacyInput::Public, + ), + ser_param( + "eth_fee_token_address", + &self.eth_fee_token_address, + "Address of the ETH fee token.", + ParamPrivacyInput::Public, + ), + ]) + } +}