Skip to content

Commit

Permalink
read JSON input
Browse files Browse the repository at this point in the history
  • Loading branch information
lempire123 committed May 15, 2023
1 parent a5288b2 commit 5e44eb7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
32 changes: 13 additions & 19 deletions src/cli/simple/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use aurora_engine::parameters::{
GetStorageAtArgs, InitCallArgs, NewCallArgs, PausePrecompilesCallArgs, SetOwnerArgs,
TransactionStatus,
};
use aurora_engine::xcc::FundXccArgs;
use aurora_engine_sdk::types::near_account_to_evm_address;
use aurora_engine::silo::parameters::{
WhitelistAccountArgs, WhitelistAddressArgs, WhitelistArgs, WhitelistKind, WhitelistKindArgs,
WhitelistStatusArgs,
};
use aurora_engine::xcc::FundXccArgs;
use aurora_engine_sdk::types::near_account_to_evm_address;
use aurora_engine_types::account_id::AccountId;
use aurora_engine_types::parameters::engine::SubmitResult;
use aurora_engine_types::types::Address;
Expand All @@ -16,6 +16,8 @@ use borsh::{BorshDeserialize, BorshSerialize};
use near_primitives::views::{CallResult, FinalExecutionStatus};
use serde_json::Value;
use std::fmt::{Display, Formatter};
use std::fs::File;
use std::io::Read;
use std::{path::Path, str::FromStr};

use crate::utils::near_to_yocto;
Expand Down Expand Up @@ -558,23 +560,15 @@ pub async fn add_entry_to_whitelist(
.await
}

pub async fn add_entry_to_whitelist_batch(
client: Client,
whitelistArgs: Vec<String>,
kind: Vec<String>,
address: Vec<String>,
) -> anyhow::Result<()> {
let mut args: Vec<WhitelistArgs> = Vec::new();
for i in 0..whitelistArgs.len() {
let arg = get_whitelist_args(
client,
whitelistArgs[i].clone(),
kind[i].clone(),
address[i].clone(),
)?;
args.push(arg);
}
args.try_to_vec()?;
pub async fn add_entry_to_whitelist_batch(client: Client, path: String) -> anyhow::Result<()> {
let mut file = File::open(path).expect("Failed to open file");
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Failed to read file");

let args: Vec<WhitelistArgs> = serde_json::from_str(&contents)

This comment has been minimized.

Copy link
@aleksuss

aleksuss May 15, 2023

Member

The args should be Vec<u8>. Overall it could be rewritten like this:

let args = std::fs::read_to_string(path)
        .and_then(|string| serde_json::from_str::<Vec<WhitelistArgs>>(&string).map_err(Into::into))
        .and_then(|entries| entries.try_to_vec())?;
.expect("Failed to deserialize JSON")
.try_to_vec()?;

ContractCall {
method: "add_entry_to_whitelist_batch",
Expand Down
14 changes: 4 additions & 10 deletions src/cli/simple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ pub enum Command {
address: String,
},
AddEntryToWhitelistBatch {
whitelistArgs: Vec<String>,
kind: Vec<String>,
address: Vec<String>,
path: String,
},
RemoveEntryFromWhitelist {
whitelistArgs: String,
Expand Down Expand Up @@ -360,14 +358,10 @@ pub async fn run(args: Cli) -> anyhow::Result<()> {
kind,
address,
} => command::add_entry_to_whitelist(client, whitelistArgs, kind, address).await?,
Command::AddEntryToWhitelistBatch {
whitelistArgs,
kind,
address,
} => {
assert!(whitelistArgs.len() == kind.len() && kind.len() == address.len());
command::add_entry_to_whitelist_batch(client, whitelistArgs, kind, address).await?
Command::AddEntryToWhitelistBatch { path } => {
command::add_entry_to_whitelist_batch(client, path).await?
}

Command::RemoveEntryFromWhitelist {
whitelistArgs,
kind,
Expand Down

0 comments on commit 5e44eb7

Please sign in to comment.