Skip to content

Commit

Permalink
Update web30
Browse files Browse the repository at this point in the history
  • Loading branch information
zmanian committed Sep 16, 2021
1 parent ebf421c commit 55fec9f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
64 changes: 40 additions & 24 deletions orchestrator/ethereum_gravity/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -114,13 +114,11 @@ pub async fn get_valset_nonce(
caller_address: EthAddress,
web3: &Web3,
) -> Result<u64, Web3Error> {

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
Expand All @@ -138,12 +136,14 @@ pub async fn get_tx_batch_nonce(
caller_address: EthAddress,
web3: &Web3,
) -> Result<u64, Web3Error> {
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
Expand All @@ -162,12 +162,18 @@ pub async fn get_logic_call_nonce(
caller_address: EthAddress,
web3: &Web3,
) -> Result<u64, Web3Error> {
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
Expand All @@ -185,12 +191,14 @@ pub async fn get_event_nonce(
caller_address: EthAddress,
web3: &Web3,
) -> Result<u64, Web3Error> {
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
Expand All @@ -207,11 +215,16 @@ pub async fn get_gravity_id(
contract_address: EthAddress,
caller_address: EthAddress,
web3: &Web3,
) -> Result<Vec<u8>, Web3Error> {
) -> Result<String, Web3Error> {
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
Expand All @@ -220,9 +233,12 @@ pub async fn get_erc20_symbol(
caller_address: EthAddress,
web3: &Web3,
) -> Result<String, GravityError> {

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())
Expand Down
1 change: 0 additions & 1 deletion orchestrator/orchestrator/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion orchestrator/relayer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 55fec9f

Please sign in to comment.