diff --git a/framework/libra-framework/sources/ol_sources/community_wallet_init.move b/framework/libra-framework/sources/ol_sources/community_wallet_init.move index 3e7cf817e..fc0be3358 100644 --- a/framework/libra-framework/sources/ol_sources/community_wallet_init.move +++ b/framework/libra-framework/sources/ol_sources/community_wallet_init.move @@ -83,7 +83,8 @@ module ol_framework::community_wallet_init { /// qualify public fun check_proposed_auths(initial_authorities: vector
, num_signers: u64): bool { - // // enforce n/m multi auth + + // TODO: enforce n/m multi auth such as: // let n = if (len == 3) { 2 } // else { // (MINIMUM_SIGS * len) / MINIMUM_AUTH diff --git a/tools/genesis/tests/fixtures/genesis.blob b/tools/genesis/tests/fixtures/genesis.blob index 57a3cf29b..3429e31e2 100644 Binary files a/tools/genesis/tests/fixtures/genesis.blob and b/tools/genesis/tests/fixtures/genesis.blob differ diff --git a/tools/storage/src/main.rs b/tools/storage/src/main.rs index bc45328a3..dfc8a6299 100644 --- a/tools/storage/src/main.rs +++ b/tools/storage/src/main.rs @@ -3,12 +3,41 @@ use clap::Parser; use diem_db_tool::DBTool; use diem_logger::{Level, Logger}; use diem_push_metrics::MetricsPusher; +use std::path::PathBuf; +use storage::read_snapshot::manifest_to_json; + +#[derive(Parser)] +#[clap(name = "libra storage", author, version)] +#[allow(clippy::large_enum_variant)] +enum StorageCli { + #[clap(subcommand)] + Db(DBTool), + ExportSnapshot { + #[clap(short, long)] + manifest_path: PathBuf, + #[clap(short, long)] + out_path: Option, + }, +} #[tokio::main] async fn main() -> Result<()> { Logger::new().level(Level::Info).init(); let _mp = MetricsPusher::start(vec![]); + match StorageCli::parse() { + StorageCli::Db(tool) => { + tool.run().await?; + } + StorageCli::ExportSnapshot { + manifest_path, + out_path, + } => { + manifest_to_json(manifest_path, out_path).await; + } + } + DBTool::parse().run().await?; + Ok(()) } diff --git a/tools/storage/src/read_snapshot.rs b/tools/storage/src/read_snapshot.rs index 652e6e333..5323641ac 100644 --- a/tools/storage/src/read_snapshot.rs +++ b/tools/storage/src/read_snapshot.rs @@ -7,19 +7,18 @@ use diem_backup_cli::{ }, storage::{FileHandle, FileHandleRef}, }; - -use tokio::{fs::OpenOptions, io::AsyncRead}; - use diem_types::account_address::AccountAddress; use diem_types::account_state::AccountState; use diem_types::state_store::state_key::{StateKey, StateKeyInner}; use diem_types::state_store::state_value::StateValue; - +use libra_types::legacy_types::legacy_recovery_v6; +use serde_json::json; use std::collections::HashMap; use std::{ fs, path::{Path, PathBuf}, }; +use tokio::{fs::OpenOptions, io::AsyncRead}; #[cfg(test)] use libra_types::legacy_types::legacy_recovery_v6::{get_legacy_recovery, AccountRole}; @@ -135,6 +134,34 @@ fn test_parse_manifest() { // dbg!(&r.epoch); } +pub async fn manifest_to_json(manifest_path: PathBuf, out_path: Option) { + let snapshot_manifest = load_snapshot_manifest(&manifest_path).expect("parse manifest"); + let archive_path = manifest_path.parent().unwrap(); + let account_states = accounts_from_snapshot_backup(snapshot_manifest, archive_path) + .await + .expect("could not parse snapshot"); + let mut legacy_recovery_vec = Vec::new(); + for account_state in account_states.iter() { + let legacy_recovery = legacy_recovery_v6::get_legacy_recovery(account_state) + .expect("could not get legacy recovery"); + + legacy_recovery_vec.push(legacy_recovery); + } + + let json = json!(&legacy_recovery_vec); + let out = out_path.unwrap_or(manifest_path.parent().unwrap().join("migration.json")); + fs::write(out, json.to_string()).expect("could not save file"); +} + +#[tokio::test] +async fn test_export() { + use std::str::FromStr; + let this_path = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap(); + let manifest_path = this_path.join("fixtures/state_epoch_79_ver_33217173.795d/state.manifest"); + let export_path = this_path.join("json/v6_migration.json"); + manifest_to_json(manifest_path, Some(export_path)).await; +} + #[tokio::test] async fn test_deserialize_account() { use std::str::FromStr; @@ -147,19 +174,12 @@ async fn test_deserialize_account() { .expect("could not parse snapshot"); let mut legacy_recovery_vec = Vec::new(); for account_state in account_states.iter() { - // println!("----------------------------------------------------"); - // println!("account_address: {:?}", account_state.get_account_address()); let legacy_recovery = get_legacy_recovery(account_state).expect("could not get legacy recovery"); - //println!("legacy_recovery: {:?}", legacy_recovery); + legacy_recovery_vec.push(legacy_recovery); } - // let legacy_recovery_vec_json = - // serde_json::to_string(&legacy_recovery_vec).expect("could not create json for state"); - - // println!("{}", legacy_recovery_vec_json); - // basic validation of the account state let account_count = 23634; assert_eq!(account_states.len(), account_count);