Skip to content

Commit

Permalink
fix: render allocs
Browse files Browse the repository at this point in the history
  • Loading branch information
vcastellm committed Sep 19, 2024
1 parent 561d69c commit 7c63de3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions crates/cdk/src/allocs_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ pub struct Wrapper {

#[derive(Serialize, Deserialize, Debug)]
struct Output {
#[serde(rename = "contractName")]
#[serde(rename = "contractName", skip_serializing_if = "Option::is_none")]
contract_name: Option<String>,
#[serde(rename = "accountName", skip_serializing_if = "Option::is_none")]
account_name: Option<String>,
balance: Option<String>,
nonce: Option<String>,
code: Option<String>,
Expand All @@ -55,20 +57,21 @@ pub fn render_allocs(genesis_file_path: &str) -> Result<Rendered> {
let wrapper: Wrapper = serde_json::from_str(&data)
.with_context(|| format!("couldn't parse JSON from {}", display))?;

let mut outputs: Vec<Output> = Vec::new();
let mut outputs: HashMap<String, Output> = HashMap::new();

for input in wrapper.genesis.clone() {
let output = Output {
contract_name: input.contract_name,
account_name: input.account_name,
balance: Some(input.balance),
nonce: Some(input.nonce),
code: input.bytecode,
storage: input.storage.map(|s| serde_json::to_value(s).unwrap()),
};
outputs.push(output);
outputs.insert(input.address, output);
}

outputs.sort_by(|a, b| a.contract_name.cmp(&b.contract_name));
// outputs.sort_by(|a, b| a.contract_name.cmp(&b.contract_name));

Ok(Rendered {
output: serde_json::to_string_pretty(&outputs)
Expand Down
4 changes: 2 additions & 2 deletions crates/cdk/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) struct Cli {
short,
value_hint = ValueHint::FilePath,
global = true,
default_value = "config/example-config.toml",
required = true,
env = "CDK_CONFIG_PATH"
)]
pub(crate) config: PathBuf,
Expand All @@ -23,7 +23,7 @@ pub(crate) struct Cli {
short = 'g',
value_hint = ValueHint::FilePath,
global = true,
default_value = "config/genesis.json",
required = true,
env = "CDK_GENESIS_PATH"
)]
pub(crate) chain: PathBuf,
Expand Down

0 comments on commit 7c63de3

Please sign in to comment.