Skip to content

Commit

Permalink
Add silo methods to simple.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
lempire123 committed May 11, 2023
1 parent 3864afb commit 6eb1bed
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 25 deletions.
13 changes: 13 additions & 0 deletions scripts/simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,19 @@ sleep 1
aurora-cli --engine $ENGINE_ACCOUNT factory-set-wnear-address 0x80c6a002756e29b8bf2a587f7d975a726d5de8b9 || error_exit
sleep 1
aurora-cli --engine $ENGINE_ACCOUNT fund-xcc-sub-account 0x43a4969cc2c22d0000c591ff4bd71983ea8a8be9 some_account.near 25.5 || error_exit
# Check that Silo methods work normally.
aurora-cli --engine $ENGINE_ACCOUNT SetFixedGasCost 1 || error_exit
result=$(aurora-cli --engine $ENGINE_ACCOUNT GetFixedGasCost || error_exit)
assert_eq "$result" "1"
aurora-cli --engine $ENGINE_ACCOUNT SetWhitelistStatus "EvmAdmin" true || error_exit
result=$(aurora-cli --engine $ENGINE_ACCOUNT GetWhitelistStatus "EvmAdmin" || error_exit)
assert_eq "$result" "true"
aurora-cli --engine $ENGINE_ACCOUNT SetWhitelistStatus "Address" false || error_exit
result=$(aurora-cli --engine $ENGINE_ACCOUNT GetWhitelistStatus "Address" || error_exit)
assert_eq "$result" "false"
aurora-cli --engine $ENGINE_ACCOUNT AddEntryToWhitelist "WhitelistAddressArgs" "Address" "0x1B16948F011686AE64BB2Ba0477aeFA2Ea97084D" || error_exit
# aurora-cli --engine $ENGINE_ACCOUNT AddEntryToWhitelistBatch || error_exit
aurora-cli --engine $ENGINE_ACCOUNT RemoveEntryFromWhitelist "WhitelistAddressArgs" "Address" "0x1B16948F011686AE64BB2Ba0477aeFA2Ea97084D" || error_exit

# Stop NEAR node and clean up.
finish
66 changes: 42 additions & 24 deletions src/cli/simple/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ use aurora_engine::parameters::{
GetStorageAtArgs, InitCallArgs, NewCallArgs, PausePrecompilesCallArgs, SetOwnerArgs,
TransactionStatus,
};
use aurora_engine::silo::parameters::{
WhitelistArgs, WhitelistKind, WhitelistKindArgs, WhitelistStatusArgs,
};
use aurora_engine::xcc::FundXccArgs;
use aurora_engine_sdk::types::near_account_to_evm_address;
use aurora_engine_silo::silo::parameters::{
WhitelistAccountArgs, WhitelistAddressArgs, WhitelistArgs, WhitelistKind, WhitelistKindArgs,
WhitelistStatusArgs,
};
use aurora_engine_types::account_id::AccountId;
use aurora_engine_types::parameters::engine::SubmitResult;
use aurora_engine_types::types::Address;
use aurora_engine_types::{types::Wei, H256, U256};
Expand Down Expand Up @@ -99,22 +101,22 @@ pub async fn init(
custodian_address: Option<String>,
ft_metadata_path: Option<String>,
) -> anyhow::Result<()> {
let to_account_id = |id: Option<String>| {
id.map_or_else(
|| {
client
.near()
.engine_account_id
.to_string()
.parse()
.map_err(|e| anyhow::anyhow!("{e}"))
},
|id| id.parse().map_err(|e| anyhow::anyhow!("{e}")),
)
};

let owner_id = to_account_id(owner_id)?;
let prover_id = to_account_id(bridge_prover)?;
// let to_account_id = |id: Option<String>| {
// id.map_or_else(
// || {
// client
// .near()
// .engine_account_id
// .to_string()
// .parse()
// .map_err(|e| anyhow::anyhow!("{e}"))
// },
// |id| id.parse().map_err(|e| anyhow::anyhow!("{e}")),
// )
// };

let owner_id = to_account_id(owner_id, &client)?;
let prover_id = to_account_id(bridge_prover, &client)?;

let aurora_init_args = NewCallArgs {
chain_id: H256::from_low_u64_be(chain_id).into(),
Expand Down Expand Up @@ -499,7 +501,7 @@ pub async fn get_fixed_gas_cost(client: Client) -> anyhow::Result<()> {
}

pub async fn set_fixed_gas_cost(client: Client, cost: u64) -> anyhow::Result<()> {
let args = Wei::new(cost).try_to_vec()?;
let args = Wei::new_u64(cost).try_to_vec()?;

ContractCall {
method: "set_fixed_gas_cost",
Expand Down Expand Up @@ -545,7 +547,7 @@ pub async fn add_entry_to_whitelist(
kind: String,
address: String,
) -> anyhow::Result<()> {
let args = get_whitelist_args(whitelistArgs, kind, address)?;
let args = get_whitelist_args(client, whitelistArgs, kind, address)?;

ContractCall {
method: "add_entity_to_whitelist",
Expand All @@ -565,12 +567,14 @@ pub async fn add_entry_to_whitelist_batch(
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()?;

ContractCall {
method: "add_entry_to_whitelist_batch",
Expand All @@ -587,7 +591,7 @@ pub async fn remove_entry_from_whitelist(
kind: String,
address: String,
) -> anyhow::Result<()> {
let args = get_whitelist_args(whitelistArgs, kind, address)?;
let args = get_whitelist_args(client, whitelistArgs, kind, address)?;

ContractCall {
method: "remove_entry_from_whitelist",
Expand Down Expand Up @@ -624,23 +628,37 @@ fn get_kind(kind: String) -> Option<WhitelistKind> {
}

fn get_whitelist_args(
client: Client,
whitelistArgs: String,
kind: String,
address: String,
) -> Option<WhitelistArgs> {
match whitelistArgs.as_str() {
"WhitelistAddressArgs" => Some(WhitelistArgs::WhitelistAddressArgs(WhitelistAddressArgs {
kind: get_kind(kind)?,
address: hex_to_address(address),
address: hex_to_address(&address),
})),
"WhitelistAccountArgs" => Some(WhitelistArgs::WhitelistAccountArgs(WhitelistAccountArgs {
kind: get_kind(kind)?,
account_id: to_account_id(address),
account_id: to_account_id(Some(address), &client)?,
})),
_ => None,
}
}

fn to_account_id(id: Option<String>, client: &Client) -> anyhow::Result<AccountId> {
if let Some(id) = id {
id.parse().map_err(|e| anyhow::anyhow!("{e}"))
} else {
client
.near()
.engine_account_id
.to_string()
.parse()
.map_err(|e| anyhow::anyhow!("{e}"))
}
}

struct HexString(String);

trait FromCallResult {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/simple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ pub async fn run(args: Cli) -> anyhow::Result<()> {
whitelistArgs,
kind,
address,
} => command::add_entity_to_whitelist(client, whitelistArgs, kind, address).await?,
} => command::add_entry_to_whitelist(client, whitelistArgs, kind, address).await?,
Command::AddEntryToWhitelistBatch {
whitelistArgs,
kind,
Expand Down

0 comments on commit 6eb1bed

Please sign in to comment.