Skip to content

Commit

Permalink
validate validator address & fetch their account sequence for optiona…
Browse files Browse the repository at this point in the history
…l nonce (#101)
  • Loading branch information
levicook authored Jul 26, 2021
1 parent ab75758 commit 7957a83
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions orchestrator/gorc/src/commands/sign_delegate_keys.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use crate::{application::APP, prelude::*};
use abscissa_core::{Application, Command, Options, Runnable};
use cosmos_gravity::query;
use gravity_proto::gravity as proto;
use gravity_utils::connection_prep::create_rpc_connections;
use orchestrator::main_loop::{ETH_ORACLE_LOOP_SPEED, ETH_SIGNER_LOOP_SPEED};
use relayer::main_loop::LOOP_SPEED as RELAYER_LOOP_SPEED;
use std::cmp::min;
use std::time::Duration;

#[derive(Command, Debug, Default, Options)]
pub struct SignDelegateKeysCmd {
Expand All @@ -26,32 +22,24 @@ impl Runnable for SignDelegateKeysCmd {
let key = config.load_clarity_key(name.clone());

let val = self.args.get(1).expect("validator-address is required");
// TODO(levi) ensure this is a valoper address for the next release
let address = val.parse().expect("Could not parse address");

let cosmos_prefix = config.cosmos.prefix.clone();

let timeout = min(
min(ETH_SIGNER_LOOP_SPEED, ETH_ORACLE_LOOP_SPEED),
RELAYER_LOOP_SPEED,
);

let nonce = match self.args.get(2) {
Some(nonce) => nonce.clone(),
let nonce: u64 = match self.args.get(2) {
Some(nonce) => nonce.parse().expect("cannot parse nonce"),
None => {
let connections = create_rpc_connections(
cosmos_prefix,
Some(config.cosmos.grpc.clone()),
Some(config.ethereum.rpc.clone()),
let timeout = Duration::from_secs(10);
let contact = deep_space::Contact::new(
&config.cosmos.grpc,
timeout,
&config.cosmos.prefix,
)
.await;
let mut grpc = connections.grpc.clone().unwrap();
let valset = query::get_latest_valset(&mut grpc).await;
let valset = valset.unwrap().expect("Valset cannot be retrieved");
valset.nonce.to_string()
.expect("Could not create contact");

let account_info = contact.get_account_info(address).await;
let account_info = account_info.expect("Did not receive account info");
account_info.sequence
}
};
let nonce = nonce.parse::<u64>().expect("cannot parse nonce");

let msg = proto::DelegateKeysSignMsg {
validator_address: val.clone(),
Expand All @@ -71,4 +59,4 @@ impl Runnable for SignDelegateKeysCmd {
std::process::exit(1);
});
}
}
}

0 comments on commit 7957a83

Please sign in to comment.