diff --git a/orchestrator/ethereum_gravity/src/utils.rs b/orchestrator/ethereum_gravity/src/utils.rs index 70d12adbc..ce2ce9a8a 100644 --- a/orchestrator/ethereum_gravity/src/utils.rs +++ b/orchestrator/ethereum_gravity/src/utils.rs @@ -1,4 +1,4 @@ -use clarity::abi::Token; +use clarity::abi::{Token, encode_call}; use clarity::Uint256; use clarity::{abi::encode_tokens, Address as EthAddress}; use gravity_utils::error::GravityError; @@ -114,13 +114,11 @@ pub async fn get_valset_nonce( caller_address: EthAddress, web3: &Web3, ) -> Result { + + let payload = encode_call("state_lastValsetNonce()", &[]).unwrap(); + let val = web3 - .contract_call( - contract_address, - "state_lastValsetNonce()", - &[], - caller_address, None - ) + .simulate_transaction(contract_address, 0u8.into(), payload, caller_address, None) .await?; // the go represents all nonces as u64, there's no // reason they should ever overflow without a user @@ -138,12 +136,14 @@ pub async fn get_tx_batch_nonce( caller_address: EthAddress, web3: &Web3, ) -> Result { + let payload = encode_call("lastBatchNonce(address)", &[erc20_contract_address.into()]).unwrap(); let val = web3 - .contract_call( + .simulate_transaction( gravity_contract_address, - "lastBatchNonce(address)", - &[erc20_contract_address.into()], - caller_address, None + 0u8.into(), + payload, + caller_address, + None, ) .await?; // the go represents all nonces as u64, there's no @@ -162,12 +162,18 @@ pub async fn get_logic_call_nonce( caller_address: EthAddress, web3: &Web3, ) -> Result { + let payload = encode_call( + "lastLogicCallNonce(bytes32)", + &[Token::Bytes(invalidation_id)], + ) + .unwrap(); let val = web3 - .contract_call( + .simulate_transaction( gravity_contract_address, - "lastLogicCallNonce(bytes32)", - &[Token::Bytes(invalidation_id)], - caller_address, None + 0u8.into(), + payload, + caller_address, + None, ) .await?; // the go represents all nonces as u64, there's no @@ -185,12 +191,14 @@ pub async fn get_event_nonce( caller_address: EthAddress, web3: &Web3, ) -> Result { + let payload = encode_call("state_lastEventNonce()", &[]).unwrap(); let val = web3 - .contract_call( + .simulate_transaction( gravity_contract_address, - "state_lastEventNonce()", - &[], - caller_address, None + 0u8.into(), + payload, + caller_address, + None, ) .await?; // the go represents all nonces as u64, there's no @@ -207,11 +215,16 @@ pub async fn get_gravity_id( contract_address: EthAddress, caller_address: EthAddress, web3: &Web3, -) -> Result, Web3Error> { +) -> Result { + let payload = encode_call("state_gravityId()", &[]).unwrap(); let val = web3 - .contract_call(contract_address, "state_gravityId()", &[], caller_address, None) + .simulate_transaction(contract_address, 0u8.into(), payload, caller_address, None) .await?; - Ok(val) + let gravity_id = String::from_utf8(val); + match gravity_id { + Ok(val) => Ok(val), + Err(e) => Err(Web3Error::BadResponse(e.to_string())), + } } /// Gets the ERC20 symbol, should maybe be upstreamed @@ -220,9 +233,12 @@ pub async fn get_erc20_symbol( caller_address: EthAddress, web3: &Web3, ) -> Result { + + let payload = encode_call("symbol()", &[]).unwrap(); + let val_symbol = web3 - .contract_call(contract_address, "symbol()", &[], caller_address, None) - .await?; + .simulate_transaction(contract_address, 0u8.into(), payload, caller_address, None) + .await?; // Pardon the unwrap, but this is temporary code, intended only for the tests, to help them // deal with a deprecated feature (the symbol), which will be removed soon Ok(String::from_utf8(val_symbol).unwrap()) diff --git a/orchestrator/orchestrator/src/main_loop.rs b/orchestrator/orchestrator/src/main_loop.rs index 3b1f6fa4f..fdfd97961 100644 --- a/orchestrator/orchestrator/src/main_loop.rs +++ b/orchestrator/orchestrator/src/main_loop.rs @@ -219,7 +219,6 @@ pub async fn eth_signer_main_loop( return; } let gravity_id = gravity_id.unwrap(); - let gravity_id = String::from_utf8(gravity_id).expect("Invalid GravityID"); loop { let loop_start = Instant::now(); diff --git a/orchestrator/relayer/src/main_loop.rs b/orchestrator/relayer/src/main_loop.rs index 0a48405d4..d8a8604aa 100644 --- a/orchestrator/relayer/src/main_loop.rs +++ b/orchestrator/relayer/src/main_loop.rs @@ -41,7 +41,6 @@ pub async fn relayer_main_loop( return; } let gravity_id = gravity_id.unwrap(); - let gravity_id = String::from_utf8(gravity_id.clone()).expect("Invalid GravityID"); relay_valsets( current_eth_valset.clone(),