@@ -7,19 +7,18 @@ use diem_backup_cli::{
77 } ,
88 storage:: { FileHandle , FileHandleRef } ,
99} ;
10-
11- use tokio:: { fs:: OpenOptions , io:: AsyncRead } ;
12-
1310use diem_types:: account_address:: AccountAddress ;
1411use diem_types:: account_state:: AccountState ;
1512use diem_types:: state_store:: state_key:: { StateKey , StateKeyInner } ;
1613use diem_types:: state_store:: state_value:: StateValue ;
17-
14+ use libra_types:: legacy_types:: legacy_recovery_v6;
15+ use serde_json:: json;
1816use std:: collections:: HashMap ;
1917use std:: {
2018 fs,
2119 path:: { Path , PathBuf } ,
2220} ;
21+ use tokio:: { fs:: OpenOptions , io:: AsyncRead } ;
2322
2423#[ cfg( test) ]
2524use libra_types:: legacy_types:: legacy_recovery_v6:: { get_legacy_recovery, AccountRole } ;
@@ -135,6 +134,34 @@ fn test_parse_manifest() {
135134 // dbg!(&r.epoch);
136135}
137136
137+ pub async fn manifest_to_json ( manifest_path : PathBuf , out_path : Option < PathBuf > ) {
138+ let snapshot_manifest = load_snapshot_manifest ( & manifest_path) . expect ( "parse manifest" ) ;
139+ let archive_path = manifest_path. parent ( ) . unwrap ( ) ;
140+ let account_states = accounts_from_snapshot_backup ( snapshot_manifest, archive_path)
141+ . await
142+ . expect ( "could not parse snapshot" ) ;
143+ let mut legacy_recovery_vec = Vec :: new ( ) ;
144+ for account_state in account_states. iter ( ) {
145+ let legacy_recovery = legacy_recovery_v6:: get_legacy_recovery ( account_state)
146+ . expect ( "could not get legacy recovery" ) ;
147+
148+ legacy_recovery_vec. push ( legacy_recovery) ;
149+ }
150+
151+ let json = json ! ( & legacy_recovery_vec) ;
152+ let out = out_path. unwrap_or ( manifest_path. parent ( ) . unwrap ( ) . join ( "migration.json" ) ) ;
153+ fs:: write ( out, json. to_string ( ) ) . expect ( "could not save file" ) ;
154+ }
155+
156+ #[ tokio:: test]
157+ async fn test_export ( ) {
158+ use std:: str:: FromStr ;
159+ let this_path = PathBuf :: from_str ( env ! ( "CARGO_MANIFEST_DIR" ) ) . unwrap ( ) ;
160+ let manifest_path = this_path. join ( "fixtures/state_epoch_79_ver_33217173.795d/state.manifest" ) ;
161+ let export_path = this_path. join ( "json/v6_migration.json" ) ;
162+ manifest_to_json ( manifest_path, Some ( export_path) ) . await ;
163+ }
164+
138165#[ tokio:: test]
139166async fn test_deserialize_account ( ) {
140167 use std:: str:: FromStr ;
@@ -147,19 +174,12 @@ async fn test_deserialize_account() {
147174 . expect ( "could not parse snapshot" ) ;
148175 let mut legacy_recovery_vec = Vec :: new ( ) ;
149176 for account_state in account_states. iter ( ) {
150- // println!("----------------------------------------------------");
151- // println!("account_address: {:?}", account_state.get_account_address());
152177 let legacy_recovery =
153178 get_legacy_recovery ( account_state) . expect ( "could not get legacy recovery" ) ;
154- //println!("legacy_recovery: {:?}", legacy_recovery);
179+
155180 legacy_recovery_vec. push ( legacy_recovery) ;
156181 }
157182
158- // let legacy_recovery_vec_json =
159- // serde_json::to_string(&legacy_recovery_vec).expect("could not create json for state");
160-
161- // println!("{}", legacy_recovery_vec_json);
162-
163183 // basic validation of the account state
164184 let account_count = 23634 ;
165185 assert_eq ! ( account_states. len( ) , account_count) ;
0 commit comments