Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/feat-2.0' into feat-2.0-fix-va…
Browse files Browse the repository at this point in the history
…lidator-credit

# Conflicts:
#	Makefile
  • Loading branch information
EdHastingsCasperAssociation committed Jun 24, 2024
2 parents 1ae3141 + bdd3306 commit 27e0661
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions utils/global-state-update-gen/src/decode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::{collections::BTreeMap, fmt, fs::File, io::Read};

use clap::ArgMatches;

use casper_types::{
bytesrepr::FromBytes, system::auction::SeigniorageRecipientsSnapshot, CLType,
GlobalStateUpdate, GlobalStateUpdateConfig, Key, StoredValue,
};

struct Entries(BTreeMap<Key, StoredValue>);

impl fmt::Debug for Entries {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut map = f.debug_map();
for (k, v) in &self.0 {
let debug_v: Box<dyn fmt::Debug> = match v {
StoredValue::CLValue(clv) => match clv.cl_type() {
CLType::Map { key, value: _ } if **key == CLType::U64 => {
// this should be the seigniorage recipient snapshot
let snapshot: SeigniorageRecipientsSnapshot = clv.clone().into_t().unwrap();
Box::new(snapshot)
}
_ => Box::new(clv),
},
_ => Box::new(v),
};
map.key(k).value(&debug_v);
}
map.finish()
}
}

pub(crate) fn decode_file(matches: &ArgMatches<'_>) {
let file_name = matches.value_of("file").unwrap();
let mut file = File::open(file_name).unwrap();

let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();

let config: GlobalStateUpdateConfig = toml::from_str(&contents).unwrap();
let update_data: GlobalStateUpdate = config.try_into().unwrap();

println!("validators = {:#?}", &update_data.validators);
let entries: BTreeMap<_, _> = update_data
.entries
.iter()
.map(|(key, bytes)| (*key, StoredValue::from_bytes(bytes).unwrap().0))
.collect();
println!("entries = {:#?}", Entries(entries));
}
15 changes: 14 additions & 1 deletion utils/global-state-update-gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod admins;
mod balances;
mod decode;
mod generic;
mod system_entity_registry;
mod utils;
Expand All @@ -9,7 +10,7 @@ use admins::generate_admins;
use clap::{crate_version, App, Arg, SubCommand};

use crate::{
balances::generate_balances_update, generic::generate_generic_update,
balances::generate_balances_update, decode::decode_file, generic::generate_generic_update,
system_entity_registry::generate_system_entity_registry,
validators::generate_validators_update,
};
Expand Down Expand Up @@ -184,6 +185,17 @@ fn main() {
.number_of_values(1),
),
)
.subcommand(
SubCommand::with_name("decode")
.about("Decodes the global_state.toml file into a readable form")
.arg(
Arg::with_name("file")
.value_name("FILE")
.index(1)
.required(true)
.help("The file to be decoded"),
),
)
.get_matches();

match matches.subcommand() {
Expand All @@ -194,6 +206,7 @@ fn main() {
}
("generic", Some(sub_matches)) => generate_generic_update(sub_matches),
("generate-admins", Some(sub_matches)) => generate_admins(sub_matches),
("decode", Some(sub_matches)) => decode_file(sub_matches),
(subcommand, _) => {
println!("Unknown subcommand: \"{}\"", subcommand);
}
Expand Down

0 comments on commit 27e0661

Please sign in to comment.