diff --git a/CHANGELOG.md b/CHANGELOG.md index 89bc8b589a..525df87b2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,8 @@ - [ibc-relayer] - Replaced `rust-crypto` & `bitcoin-wallet` deprecated dependencies ([#352]) + - Fix for hard-coded account number ([#752]) + - Fix for chains that don't have `cosmos` account prefix ([#416]) - [ibc-relayer-cli] - Hermes guide: improved installation guideline ([#672]) @@ -58,6 +60,7 @@ - [nothing yet] [#352]: https://github.com/informalsystems/ibc-rs/issues/352 +[#416]: https://github.com/informalsystems/ibc-rs/issues/416 [#561]: https://github.com/informalsystems/ibc-rs/issues/561 [#599]: https://github.com/informalsystems/ibc-rs/issues/599 [#630]: https://github.com/informalsystems/ibc-rs/issues/630 @@ -69,6 +72,7 @@ [#700]: https://github.com/informalsystems/ibc-rs/pull/700 [#702]: https://github.com/informalsystems/ibc-rs/issues/702 [#740]: https://github.com/informalsystems/ibc-rs/issues/740 +[#752]: https://github.com/informalsystems/ibc-rs/issues/752 ## v0.1.1 *February 17, 2021* diff --git a/relayer/src/chain/cosmos.rs b/relayer/src/chain/cosmos.rs index 32fb163ab3..49d267f8c8 100644 --- a/relayer/src/chain/cosmos.rs +++ b/relayer/src/chain/cosmos.rs @@ -159,6 +159,8 @@ impl CosmosSdkChain { let mut pk_buf = Vec::new(); prost::Message::encode(&key.public_key.public_key.to_bytes(), &mut pk_buf).unwrap(); + crate::time!("PK {:?}", hex::encode(key.public_key.public_key.to_bytes())); + // Create a MsgSend proto Any message let pk_any = Any { type_url: "/cosmos.crypto.secp256k1.PubKey".to_string(), @@ -181,7 +183,7 @@ impl CosmosSdkChain { // Gas Fee let coin = Coin { denom: "stake".to_string(), - amount: "1000".to_string(), + amount: "10000".to_string(), }; let fee = Some(Fee { @@ -204,7 +206,7 @@ impl CosmosSdkChain { body_bytes: body_buf.clone(), auth_info_bytes: auth_buf.clone(), chain_id: self.config.clone().id.to_string(), - account_number: 0, + account_number: acct_response.account_number, }; // A protobuf serialization of a SignDoc @@ -223,6 +225,8 @@ impl CosmosSdkChain { let mut txraw_buf = Vec::new(); prost::Message::encode(&tx_raw, &mut txraw_buf).unwrap(); + crate::time!("TxRAW {:?}", hex::encode(txraw_buf.clone())); + let response = self .block_on(broadcast_tx_commit(self, txraw_buf)) .map_err(|e| Kind::Rpc(self.config.rpc_addr.clone()).context(e))?; diff --git a/relayer/src/keyring/store.rs b/relayer/src/keyring/store.rs index 6191168579..956858fced 100644 --- a/relayer/src/keyring/store.rs +++ b/relayer/src/keyring/store.rs @@ -45,8 +45,16 @@ pub enum StoreBackend { pub trait KeyRingOperations: Sized { fn init(backend: StoreBackend, chain_config: ChainConfig) -> Result; - fn key_from_seed_file(&self, key_file_content: &str) -> Result; - fn key_from_mnemonic(&self, mnemonic_words: &str) -> Result; + fn key_from_seed_file( + &self, + key_file_content: &str, + chain_config: &ChainConfig, + ) -> Result; + fn key_from_mnemonic( + &self, + mnemonic_words: &str, + chain_config: &ChainConfig, + ) -> Result; fn get_key(&self) -> Result; fn add_key(&self, key_contents: &str) -> Result<(), Error>; fn sign_msg(&self, msg: Vec) -> Vec; @@ -97,7 +105,11 @@ impl KeyRingOperations for KeyRing { } /// Get key from seed file - fn key_from_seed_file(&self, key_file_content: &str) -> Result { + fn key_from_seed_file( + &self, + key_file_content: &str, + chain_config: &ChainConfig, + ) -> Result { let key_json: Value = serde_json::from_str(key_file_content).map_err(|e| Kind::InvalidKey.context(e))?; @@ -111,7 +123,7 @@ impl KeyRingOperations for KeyRing { match mnemonic { Some(v) => { key = self - .key_from_mnemonic(v) + .key_from_mnemonic(v, chain_config) .map_err(|e| Kind::InvalidMnemonic.context(e))?; Ok(key) } @@ -127,7 +139,11 @@ impl KeyRingOperations for KeyRing { } /// Add a key entry in the store using a mnemonic. - fn key_from_mnemonic(&self, mnemonic_words: &str) -> Result { + fn key_from_mnemonic( + &self, + mnemonic_words: &str, + chain_config: &ChainConfig, + ) -> Result { let mnemonic = Mnemonic::from_phrase(mnemonic_words, Language::English) .map_err(|e| Kind::InvalidMnemonic.context(e))?; let seed = Seed::new(&mnemonic, ""); @@ -145,8 +161,12 @@ impl KeyRingOperations for KeyRing { let address = get_address(public_key); // Get Bech32 account - let account = bech32::encode("cosmos", address.to_base32(), Variant::Bech32) - .map_err(|e| Kind::Bech32Account.context(e))?; + let account = bech32::encode( + chain_config.account_prefix.as_str(), + address.to_base32(), + Variant::Bech32, + ) + .map_err(|e| Kind::Bech32Account.context(e))?; let key = KeyEntry { public_key, @@ -171,9 +191,10 @@ impl KeyRingOperations for KeyRing { let key_content = store.get(chain_config.key_name.as_str()); match key_content { Some(k) => { - let key_entry = self.key_from_seed_file(k).map_err(|_| { - Kind::KeyStoreOperation.context("failed to get key entry") - })?; + let key_entry = + self.key_from_seed_file(k, chain_config).map_err(|_| { + Kind::KeyStoreOperation.context("failed to get key entry") + })?; Ok(key_entry) } None => Err(Kind::InvalidKey.into()), @@ -200,11 +221,11 @@ impl KeyRingOperations for KeyRing { let mut file_contents = String::new(); file.read_to_string(&mut file_contents) .map_err(|_| Kind::KeyStoreOperation.context("cannot ready key file"))?; - let key_entry = - self.key_from_seed_file(file_contents.as_str()) - .map_err(|_| { - Kind::KeyStoreOperation.context("error getting key from file") - })?; + let key_entry = self + .key_from_seed_file(file_contents.as_str(), chain_config) + .map_err(|_| { + Kind::KeyStoreOperation.context("error getting key from file") + })?; Ok(key_entry) } else { Err(Kind::KeyStoreOperation diff --git a/relayer/src/keys/add.rs b/relayer/src/keys/add.rs index 6dc7ec96d9..13937e9208 100644 --- a/relayer/src/keys/add.rs +++ b/relayer/src/keys/add.rs @@ -26,7 +26,9 @@ pub fn add_key(opts: KeysAddOptions) -> Result { .map_err(|_| Kind::KeyBase.context("error reading the key file"))?; // Check if it's a valid Key seed file - let key_entry = chain.keybase().key_from_seed_file(&key_contents); + let key_entry = chain + .keybase() + .key_from_seed_file(&key_contents, chain.config()); match key_entry { Ok(k) => {