Skip to content

Commit

Permalink
feat: Added StartHashchain, PauseContract and ResumeContract commands (
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-borodulya committed Aug 19, 2024
1 parent 6fb4602 commit bcc6786
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scripts/simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions src/cli/simple/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
19 changes: 19 additions & 0 deletions src/cli/simple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?,
Expand Down

0 comments on commit bcc6786

Please sign in to comment.