-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ComposableFi/dz/2
feat: query cosmos account for nonce porting code from beaker
- Loading branch information
Showing
11 changed files
with
103 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod support; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod signer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use cosmrs::crypto::secp256k1::SigningKey; | ||
|
||
pub fn from_mnemonic(phrase: &str, derivation_path: &str) -> Result<SigningKey, String> { | ||
let seed = bip32::Mnemonic::new(phrase, bip32::Language::English) | ||
.expect("mnemonic") | ||
.to_seed(""); | ||
let xprv = bip32::XPrv::derive_from_path(seed, &derivation_path.parse().expect("parse")) | ||
.expect("derived"); | ||
let signer_priv: SigningKey = xprv.into(); | ||
Ok(signer_priv) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod cli; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,42 @@ | ||
use crate::prelude::*; | ||
|
||
use cosmos_sdk_proto::cosmwasm::wasm::v1::msg_client::MsgClient; | ||
use cosmos_sdk_proto::cosmwasm::wasm::v1::query_client::QueryClient; | ||
|
||
use cosmos_sdk_proto::cosmos::auth::v1beta1::QueryAccountRequest; | ||
use tonic::transport::Channel; | ||
|
||
pub type WriteClient = MsgClient<Channel>; | ||
pub type ReadClient = QueryClient<Channel>; | ||
pub type CosmWasmWriteClient = cosmos_sdk_proto::cosmwasm::wasm::v1::msg_client::MsgClient<Channel>; | ||
pub type CosmWasmReadClient = | ||
cosmos_sdk_proto::cosmwasm::wasm::v1::query_client::QueryClient<Channel>; | ||
|
||
pub type CosmosQueryClient = | ||
cosmos_sdk_proto::cosmos::auth::v1beta1::query_client::QueryClient<Channel>; | ||
|
||
pub async fn create_wasm_query_client(rpc: &str) -> QueryClient<Channel> { | ||
pub async fn create_cosmos_query_client(rpc: &str) -> CosmosQueryClient { | ||
use cosmos_sdk_proto::cosmos::auth::v1beta1::query_client::*; | ||
use cosmos_sdk_proto::cosmos::auth::v1beta1::*; | ||
let url = tonic::transport::Endpoint::from_str(rpc).expect("url"); | ||
QueryClient::connect(url).await.expect("connected") | ||
} | ||
|
||
pub async fn create_wasm_write_client(rpc: &str) -> MsgClient<Channel> { | ||
pub async fn query_cosmos_account(rpc: &str, address : String) -> cosmos_sdk_proto::cosmos::auth::v1beta1::BaseAccount { | ||
use cosmos_sdk_proto::traits::Message; | ||
use cosmos_sdk_proto::cosmos::auth::v1beta1::*; | ||
let mut client = create_cosmos_query_client(rpc).await; | ||
let account = client.account(QueryAccountRequest { | ||
address, | ||
}).await.expect("account").into_inner(); | ||
BaseAccount::decode(account.account.expect("some").value.as_slice()).expect("decode") | ||
} | ||
|
||
pub async fn create_wasm_query_client(rpc: &str) -> CosmWasmReadClient { | ||
let url = tonic::transport::Endpoint::from_str(rpc).expect("url"); | ||
cosmos_sdk_proto::cosmwasm::wasm::v1::query_client::QueryClient::connect(url) | ||
.await | ||
.expect("connected") | ||
} | ||
|
||
pub async fn create_wasm_write_client(rpc: &str) -> CosmWasmWriteClient { | ||
let url = tonic::transport::Endpoint::from_str(rpc).expect("url"); | ||
MsgClient::connect(url).await.expect("connected") | ||
cosmos_sdk_proto::cosmwasm::wasm::v1::msg_client::MsgClient::connect(url) | ||
.await | ||
.expect("connected") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod args; | ||
pub mod cosmos; | ||
pub mod beaker; |