Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Feb 15, 2024
1 parent 97fdc62 commit fb7c0b0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ impl KeyStoreBackend {
Self::Os(key) => {
let priv_key = get_priv_key_from_os(key)?;
let signature: Signature = priv_key.try_sign(data).unwrap();
Ok(signature.to_bytes().try_into()?)
Ok(signature.to_bytes().into())
}
Self::Memory(key) => {
let priv_key = get_priv_key_from_memory(key)?;
let signature: Signature = priv_key.try_sign(data).unwrap();
Ok(signature.to_bytes().try_into()?)
Ok(signature.to_bytes().into())
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/cli/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl Transaction {
let rewards = crate::query::get_rewards(&account, rpc_endpoint).await?;

let validator = delegations
.get(0)
.first()
.context("delegator should have atleast one validator")?
.0
.clone();
Expand Down Expand Up @@ -229,7 +229,7 @@ impl Transaction {
crate::query::get_delegated(&account, rpc_endpoint).await?;

delegations
.get(0)
.first()
.context("delegator should have atleast one validator")?
.0
.clone()
Expand Down Expand Up @@ -409,7 +409,8 @@ impl Transaction {
timeout_height: None,
timeout_timestamp: (chrono::Utc::now()
+ chrono::Duration::minutes(10))
.timestamp_nanos()
.timestamp_nanos_opt()
.context("error while converting time")?
as u64,
};
(account_acc, vec![Any::try_pack(ibc_transfer)?])
Expand Down
6 changes: 5 additions & 1 deletion src/cli/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ pub fn custom_coin(coin_str: &str) -> Result<Coin> {

pub fn custom_io_string(json_str: &str) -> Result<String> {
Ok(match json_str {
"-" => std::io::stdin().lock().lines().flatten().collect(),
"-" => std::io::stdin()
.lock()
.lines()
.map_while(std::io::Result::ok)
.collect(),
_ if json_str.starts_with('@') => {
std::fs::read_to_string(json_str.strip_prefix('@').context("should never arise")?)?
}
Expand Down
13 changes: 6 additions & 7 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,14 @@ pub async fn get_cosmos_directory_name(chain_id: &str) -> Result<String> {
.as_array()
.context("no vec value")?
.iter()
.filter_map(|v| {
(v.pointer("/chain_id")?.as_str()? == chain_id).then(|| {
v.pointer("/name")
.and_then(|k| k.as_str())
.expect("name in chains data")
})
.filter_map(|v| (v.pointer("/chain_id")?.as_str()? == chain_id).then_some(v))
.map(|v| {
v.pointer("/name")
.and_then(|k| k.as_str())
.context("name in chains data")
})
.next()
.context("at least one chain")?;
.context("at least one chain")??;

Ok(format!("https://rpc.cosmos.directory/{chain_name}"))
}
Expand Down

0 comments on commit fb7c0b0

Please sign in to comment.