From bcc6786a22eeb84c5056e7e250bbe74d8da5e902 Mon Sep 17 00:00:00 2001 From: Alexander Borodulya Date: Mon, 19 Aug 2024 12:15:51 +0300 Subject: [PATCH] feat: Added StartHashchain, PauseContract and ResumeContract commands (#71) --- scripts/simple.sh | 16 +++++++++++++ src/cli/simple/command/mod.rs | 44 +++++++++++++++++++++++++++++++++++ src/cli/simple/mod.rs | 19 +++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/scripts/simple.sh b/scripts/simple.sh index f5e56f8..11e39ac 100755 --- a/scripts/simple.sh +++ b/scripts/simple.sh @@ -178,6 +178,22 @@ result=$(aurora-cli --engine $ENGINE_ACCOUNT view-call -a 0x4cf003049d1a9c4918c7 assert_eq "$result" "5" wait_for_block +# Prerequisites for the start-hashchain command: Change the key manager of ENGINE_ACCOUNT to ENGINE_ACCOUNT +aurora-cli --engine $ENGINE_ACCOUNT set-key-manager $ENGINE_ACCOUNT || error_exit +wait_for_block + +# Prerequisites for the start-hashchain command: The contract must be paused +aurora-cli --engine $ENGINE_ACCOUNT pause-contract +wait_for_block + +# Start Hashchain. The aurora-engine will resume the contract automatically +aurora-cli --engine $ENGINE_ACCOUNT start-hashchain --block-height 0 --block-hashchain 0000000000000000000000000000000000000000000000000000000000000000 +wait_for_block + +# Change the key manager of ENGINE_ACCOUNT back to MANAGER_ACCOUNT +aurora-cli --engine $ENGINE_ACCOUNT set-key-manager $MANAGER_ACCOUNT || error_exit +wait_for_block + # Check read operations. aurora-cli --engine $ENGINE_ACCOUNT get-chain-id || error_exit aurora-cli --engine $ENGINE_ACCOUNT get-owner || error_exit diff --git a/src/cli/simple/command/mod.rs b/src/cli/simple/command/mod.rs index d72f60b..5ab2fdf 100644 --- a/src/cli/simple/command/mod.rs +++ b/src/cli/simple/command/mod.rs @@ -468,6 +468,50 @@ pub async fn register_relayer(context: Context, address: String) -> anyhow::Resu .await } +/// Start hashchain +pub async fn start_hashchain( + context: Context, + block_height: u64, + block_hashchain: String, +) -> anyhow::Result<()> { + let args = borsh::to_vec( + &aurora_engine_types::parameters::engine::StartHashchainArgs { + block_height, + block_hashchain: hex_to_arr(&block_hashchain)?, + }, + )?; + + contract_call!( + "start_hashchain", + "The HashChain has been started successfully", + "Error while starting the HashChain" + ) + .proceed(context, args) + .await +} + +/// Pause contract +pub async fn pause_contract(context: Context) -> anyhow::Result<()> { + contract_call!( + "pause_contract", + "The contract has been paused successfully", + "Error while pausing the contract" + ) + .proceed(context, vec![]) + .await +} + +/// Resume contract +pub async fn resume_contract(context: Context) -> anyhow::Result<()> { + contract_call!( + "resume_contract", + "The contract has been resumed successfully", + "Error while resuming the contract" + ) + .proceed(context, vec![]) + .await +} + /// Return value in storage for key at address. pub async fn get_storage_at(context: Context, address: String, key: String) -> anyhow::Result<()> { let address = hex_to_address(&address)?; diff --git a/src/cli/simple/mod.rs b/src/cli/simple/mod.rs index b00aa4b..d9265ca 100644 --- a/src/cli/simple/mod.rs +++ b/src/cli/simple/mod.rs @@ -111,6 +111,19 @@ pub enum Command { }, /// Register relayer address RegisterRelayer { address: String }, + /// Start hashchain + StartHashchain { + /// Height of the block to start the hashchain + #[arg(long)] + block_height: u64, + /// Hashchain of the block to start the hashchain + #[arg(long)] + block_hashchain: String, + }, + /// Pause contract + PauseContract, + /// Resume contract + ResumeContract, /// Pause precompiles PausePrecompiles { mask: u32 }, /// Resume precompiles @@ -432,6 +445,12 @@ pub async fn run(args: Cli) -> anyhow::Result<()> { Command::GetOwner => command::get_owner(context).await?, Command::SetOwner { account_id } => command::set_owner(context, account_id).await?, Command::RegisterRelayer { address } => command::register_relayer(context, address).await?, + Command::StartHashchain { + block_height, + block_hashchain, + } => command::start_hashchain(context, block_height, block_hashchain).await?, + Command::PauseContract => command::pause_contract(context).await?, + Command::ResumeContract => command::resume_contract(context).await?, Command::GetBridgeProver => command::get_bridge_prover(context).await?, Command::GetNonce { address } => command::get_nonce(context, address).await?, Command::GetCode { address } => command::get_code(context, address).await?,