From 5e44eb78ec9a5d2bda3093ebf37a391c9b1585eb Mon Sep 17 00:00:00 2001 From: lempire123 <61431140+lempire123@users.noreply.github.com> Date: Mon, 15 May 2023 17:48:00 +0200 Subject: [PATCH] read JSON input --- src/cli/simple/command.rs | 32 +++++++++++++------------------- src/cli/simple/mod.rs | 14 ++++---------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/cli/simple/command.rs b/src/cli/simple/command.rs index 4fd6af8..a0559bc 100644 --- a/src/cli/simple/command.rs +++ b/src/cli/simple/command.rs @@ -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; @@ -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; @@ -558,23 +560,15 @@ pub async fn add_entry_to_whitelist( .await } -pub async fn add_entry_to_whitelist_batch( - client: Client, - whitelistArgs: Vec, - kind: Vec, - address: Vec, -) -> anyhow::Result<()> { - let mut args: Vec = 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 = serde_json::from_str(&contents) + .expect("Failed to deserialize JSON") + .try_to_vec()?; ContractCall { method: "add_entry_to_whitelist_batch", diff --git a/src/cli/simple/mod.rs b/src/cli/simple/mod.rs index 3ac7948..2396130 100644 --- a/src/cli/simple/mod.rs +++ b/src/cli/simple/mod.rs @@ -218,9 +218,7 @@ pub enum Command { address: String, }, AddEntryToWhitelistBatch { - whitelistArgs: Vec, - kind: Vec, - address: Vec, + path: String, }, RemoveEntryFromWhitelist { whitelistArgs: String, @@ -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,