Skip to content

Commit

Permalink
Merge branch 'master' into pre_version_check
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliyu123 authored Jul 15, 2022
2 parents 1c32688 + 7a81c7d commit 9a81b43
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 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.

58 changes: 55 additions & 3 deletions cmd/airdrop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,77 @@ async fn main() -> Result<()> {
.try_into()?;
let is_stc = stc_type_tag().eq(&TypeTag::Struct(token_type.clone()));

let mut total_amount = 0u128;
let airdrop_infos: Vec<AirdropInfo> = {
let mut csv_reader = csv::ReaderBuilder::default()
.has_headers(false)
.from_path(airdrop_file.as_path())?;
let mut leafs = Vec::with_capacity(4096);
for record in csv_reader.deserialize() {
let data: AirdropInfo = record?;
for (idx, record) in csv_reader.records().enumerate() {
let record = record?;
if record.iter().all(|part| part.trim().is_empty()) {
//just skip empty line
continue;
}
match record.len().cmp(&2) {
std::cmp::Ordering::Equal => {}
std::cmp::Ordering::Greater => {
println!(
"[WARN] invalid record: line {}, {:?}, ignore extra field.",
idx, record
);
}
std::cmp::Ordering::Less => {
println!("[WARN] invalid record: line {}, {:?}, skip.", idx, record);
continue;
}
}
let address = match AccountAddress::from_str(record[0].trim()) {
Ok(address) => address,
Err(err) => {
if idx == 0 {
println!("[INFO] skip header line: {}", record.as_slice());
} else {
println!(
"[WARN] invalid record: line {}, {:?}, skip. {}",
idx, record, err
);
}
continue;
}
};
let amount = match u128::from_str(record[1].trim()) {
Ok(amount) => amount,
Err(err) => {
println!(
"[WARN] invalid record: line {}, {:?}, skip. {}",
idx, record, err
);
continue;
}
};
let data = AirdropInfo { address, amount };
if !is_stc && !is_accept_token(data.address, token_type.clone(), &state_client).await? {
println!(
"{} does not accepted the token {}, skip.",
data.address, token_type
);
continue;
}
total_amount += data.amount;
leafs.push(data);
}
leafs
};

println!(
"airdrop {} token {} to {} addresses, total amount: {}",
token_type,
batch_size,
airdrop_infos.len(),
total_amount
);

let private_key: AccountPrivateKey = {
let pass = rpassword::prompt_password_stdout("Please Input Private Key: ")?;
AccountPrivateKey::from_encoded_string(pass.trim())?
Expand Down Expand Up @@ -239,7 +291,7 @@ async fn main() -> Result<()> {
}
};
if txn_info.status != TransactionStatusView::Executed {
eprintln!(
println!(
"txn {:?} error: {:?}, please resume from user: {}",
txn_hash,
txn_info,
Expand Down
12 changes: 6 additions & 6 deletions scripts/import_snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ function import_snapshot() {

download "$net" "$from_dir"

./starcoin_db_exporter apply-snapshot -i "$from_dir" -n "$net" -o "$to_dir"
case_status=$?
if [ $case_status -ne 0 ]; then
echo -e "apply-snapshot $net $from_dir fail"
exit $case_status
fi
./starcoin_db_exporter apply-snapshot -i "$from_dir"/snapshot -n "$net" -o "$to_dir"
case_status=$?
if [ $case_status -ne 0 ]; then
echo -e "apply-snapshot $net $from_dir fail"
exit $case_status
fi
echo -e "$net apply-snapshot succ"
}

Expand Down
2 changes: 1 addition & 1 deletion vm/natives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ log = "0.4.14"
walkdir = "2.3.1"
smallvec = "1.8.1"
tiny-keccak={version="2", features = ["keccak"]}
libsecp256k1 = "0.7.0"
libsecp256k1 = "0.7.1"
arrayref = "0.3"
ripemd160 = "0.9.1"
num_enum = "0.5.7"
Expand Down

0 comments on commit 9a81b43

Please sign in to comment.