Skip to content

Commit

Permalink
Added support to specify key file and account sequence for the tax ra…
Browse files Browse the repository at this point in the history
…w conn-init command (#47)
  • Loading branch information
andynog committed Oct 23, 2020
1 parent 3202d00 commit a75b1ec
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
23 changes: 20 additions & 3 deletions relayer-cli/src/commands/tx/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,32 @@ pub struct TxRawConnInitCmd {
#[options(free, help = "identifier of the source connection")]
src_connection_id: Option<String>,

#[options(help = "identifier of the destination connection", short = "d")]
#[options(free, help = "identifier of the destination connection")]
dest_connection_id: Option<String>,

#[options(free, help = "key file for the signer")]
#[options(help= "account sequence of the signer", short = "s")]
account_sequence: Option<String>,

#[options(help = "key file for the signer", short = "k")]
signer_key: Option<String>,

}

impl TxRawConnInitCmd {
fn validate_options(&self, config: &Config) -> Result<ConnectionOpenInitOptions, String> {

// Get the account sequence
let parsed = self
.account_sequence
.clone()
.ok_or_else(|| "missing account sequence".to_string())?
.parse::<u64>();

let acct_seq = match parsed {
Ok(v) => v,
Err(e) => return Err("invalid account sequence number".to_string())
};

// Get content of key seed file
let key_filename = self
.signer_key
Expand Down Expand Up @@ -107,7 +123,8 @@ impl TxRawConnInitCmd {
dest_connection_id,
src_chain_config: src_chain_config.clone(),
dest_chain_config: dest_chain_config.clone(),
signer_key: key_file_contents
signer_key: key_file_contents,
account_sequence: acct_seq
};

Ok(opts)
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub trait Chain {
fn query(&self, data: Path, height: Height, prove: bool) -> Result<Vec<u8>, Self::Error>;

/// send a transaction with `msgs` to chain.
fn send(&mut self, msg_type: String, msg: Vec<u8>, key: KeyEntry, memo: String, timeout_height: u64) -> Result<Vec<u8>, Self::Error>;
fn send(&mut self, msg_type: String, msg: Vec<u8>, key: KeyEntry, acct_seq: u64, memo: String, timeout_height: u64) -> Result<Vec<u8>, Self::Error>;

/// Returns the chain's identifier
fn id(&self) -> &ChainId {
Expand Down
4 changes: 2 additions & 2 deletions relayer/src/chain/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Chain for CosmosSDKChain {
}

/// Send a transaction that includes the specified messages
fn send(&mut self, msg_type: String, msg_bytes: Vec<u8>, key: KeyEntry, memo: String, timeout_height: u64) -> Result<Vec<u8>, Error> {
fn send(&mut self, msg_type: String, msg_bytes: Vec<u8>, key: KeyEntry, acct_seq: u64, memo: String, timeout_height: u64) -> Result<Vec<u8>, Error> {

// Create a proto any message
let mut proto_msgs: Vec<Any> = Vec::new();
Expand Down Expand Up @@ -125,7 +125,7 @@ impl Chain for CosmosSDKChain {
let signer_info = SignerInfo {
public_key: Some(pk_any),
mode_info: mode,
sequence: 10,
sequence: acct_seq,
};

// Gas Fee
Expand Down
3 changes: 2 additions & 1 deletion relayer/src/tx/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ pub fn create_client(opts: CreateClientOptions) -> Result<Vec<u8>, Error> {

let msg_type = "/ibc.client.MsgCreateClient".to_ascii_lowercase();

let response = dest_chain.send(msg_type, new_msg.get_sign_bytes(), key, "".to_string(), 0)
// TODO - Replace logic to fetch the proper account sequence via CLI parameter
let response = dest_chain.send(msg_type, new_msg.get_sign_bytes(), key, 0, "".to_string(), 0)
.map_err(|e| Kind::MessageTransaction("failed to create client".to_string()).context(e))?;

let response = vec![];
Expand Down
4 changes: 2 additions & 2 deletions relayer/src/tx/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct ConnectionOpenInitOptions {
pub src_chain_config: ChainConfig,
pub dest_chain_config: ChainConfig,
pub signer_key: String,
pub account_sequence: u64
}

pub fn conn_init(opts: ConnectionOpenInitOptions) -> Result<Vec<u8>, Error> {
Expand All @@ -44,15 +45,14 @@ pub fn conn_init(opts: ConnectionOpenInitOptions) -> Result<Vec<u8>, Error> {
client_id: opts.src_client_id,
connection_id: opts.src_connection_id,
counterparty: counterparty.unwrap(),
// TODO - add to opts
version: "".to_string(),
signer,
};

let msg_type = "/ibc.core.connection.v1.MsgConnectionOpenInit".to_string();

// Send message
let response = dest_chain.send(msg_type, msg.get_sign_bytes(), key, "".to_string(), 0)
let response = dest_chain.send(msg_type, msg.get_sign_bytes(), key, opts.account_sequence, "".to_string(), 0)
.map_err(|e| Kind::MessageTransaction("failed to initialize open connection".to_string()).context(e))?;

Ok(response)
Expand Down

0 comments on commit a75b1ec

Please sign in to comment.