Skip to content

Commit 6c4984b

Browse files
committed
[all resource export] cargo fmt
1 parent 95a6d8b commit 6c4984b

File tree

3 files changed

+14
-34
lines changed

3 files changed

+14
-34
lines changed

cmd/resource-code-exporter/src/export.rs

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ mod test {
112112
// println!("Record: {:?}", record);
113113
has_data = true;
114114
}
115-
116115
assert!(has_data, "CSV should contain exported data");
117116
Ok(())
118117
}

cmd/resource-code-exporter/src/import.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use starcoin_types::{
88
use std::path::{Path, PathBuf};
99
use std::sync::Arc;
1010

11-
pub fn import_from_db_path(db_path: &PathBuf, csv_path: &PathBuf) -> anyhow::Result<()> {
11+
pub fn import(csv_path: &PathBuf, db_path: &PathBuf) -> anyhow::Result<()> {
1212
let db_storage = DBStorage::open_with_cfs(
1313
&db_path,
1414
StorageVersion::current_version()
@@ -21,11 +21,11 @@ pub fn import_from_db_path(db_path: &PathBuf, csv_path: &PathBuf) -> anyhow::Res
2121
let storage = Storage::new(StorageInstance::new_db_instance(db_storage))?;
2222
let storage = Arc::new(storage);
2323
let statedb = ChainStateDB::new(storage.clone(), None);
24-
import(&statedb, csv_path)
24+
import_from_statedb(&statedb, csv_path)
2525
}
2626

2727
/// Import resources and code from CSV file to a new statedb
28-
pub fn import(statedb: &ChainStateDB, csv_path: &Path) -> anyhow::Result<()> {
28+
pub fn import_from_statedb(statedb: &ChainStateDB, csv_path: &Path) -> anyhow::Result<()> {
2929
// Read CSV file
3030
let mut csv_reader = csv::Reader::from_path(csv_path)?;
3131
let mut expected_state_root = None;

cmd/resource-code-exporter/src/main.rs

+11-30
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ mod import;
66

77
use clap::{Parser, Subcommand};
88
use std::path::PathBuf;
9-
use starcoin_storage::{db_storage::DBStorage, storage::StorageInstance, Storage, StorageVersion};
10-
use starcoin_statedb::ChainStateDB;
11-
use std::sync::Arc;
129

1310
#[derive(Parser)]
14-
#[clap(name = "resource-code-exporter", about = "Export and import state data")]
11+
#[clap(
12+
name = "resource-code-exporter",
13+
about = "Export and import state data"
14+
)]
1515
struct Cli {
1616
#[clap(subcommand)]
1717
command: Commands,
@@ -24,7 +24,7 @@ enum Commands {
2424
#[clap(long, short = 'o', parse(from_os_str))]
2525
/// Output file path, e.g. accounts.csv
2626
output: PathBuf,
27-
27+
2828
#[clap(long, short = 'i', parse(from_os_str))]
2929
/// Starcoin node db path, e.g. ~/.starcoin/barnard/starcoindb/db/starcoindb
3030
db_path: PathBuf,
@@ -37,9 +37,9 @@ enum Commands {
3737
Import {
3838
#[clap(long, short = 'i', parse(from_os_str))]
3939
/// Input CSV file path
40-
input: PathBuf,
41-
42-
#[clap(long, short = 'o', parse(from_os_str))]
40+
csv_input: PathBuf,
41+
42+
#[clap(long, short = 'd', parse(from_os_str))]
4343
/// Output database path
4444
db_path: PathBuf,
4545
},
@@ -54,29 +54,10 @@ fn main() -> anyhow::Result<()> {
5454
db_path,
5555
block_id,
5656
} => {
57-
export::export(
58-
db_path.display().to_string().as_str(),
59-
&output,
60-
block_id,
61-
)?;
57+
export::export(db_path.display().to_string().as_str(), &output, block_id)?;
6258
}
63-
Commands::Import { input, db_path } => {
64-
// Create new statedb for import
65-
let db_storage = DBStorage::open_with_cfs(
66-
&db_path,
67-
StorageVersion::current_version()
68-
.get_column_family_names()
69-
.to_vec(),
70-
false,
71-
Default::default(),
72-
None,
73-
)?;
74-
let storage = Storage::new(StorageInstance::new_db_instance(db_storage))?;
75-
let storage = Arc::new(storage);
76-
let statedb = ChainStateDB::new(storage.clone(), None);
77-
78-
// Import data
79-
import::import(&statedb, &input)?;
59+
Commands::Import { csv_input, db_path } => {
60+
import::import(&csv_input, &db_path)?;
8061
}
8162
}
8263

0 commit comments

Comments
 (0)