Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed May 15, 2024
1 parent 104e653 commit 65f3346
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 27 deletions.
30 changes: 18 additions & 12 deletions packages/cosmos/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,34 +656,34 @@ impl Cosmos {
res.account
.ok_or_else(|| crate::Error::InvalidChainResponse {
message: "no eth account found".to_owned(),
action: action.clone(),
action: action.clone().into(),
})?
.value
.as_ref(),
)
.map_err(|source| crate::Error::InvalidChainResponse {
message: format!("Unable to parse eth_account: {source}"),
action: action.clone(),
action: action.clone().into(),
})?;
eth_account
.base_account
.ok_or_else(|| crate::Error::InvalidChainResponse {
message: "no base account found".to_owned(),
action: action.clone(),
action: action.clone().into(),
})?
} else {
prost::Message::decode(
res.account
.ok_or_else(|| crate::Error::InvalidChainResponse {
message: "no account found".to_owned(),
action: action.clone(),
action: action.clone().into(),
})?
.value
.as_ref(),
)
.map_err(|source| crate::Error::InvalidChainResponse {
message: format!("Unable to parse account: {source}"),
action,
action: action.into(),
})?
};
Ok(base_account)
Expand Down Expand Up @@ -740,18 +740,18 @@ impl Cosmos {
.tx
.ok_or_else(|| crate::Error::InvalidChainResponse {
message: "Missing tx field".to_owned(),
action: action.clone(),
action: action.clone().into(),
})?
.body
.ok_or_else(|| crate::Error::InvalidChainResponse {
message: "Missing tx.body field".to_owned(),
action: action.clone(),
action: action.clone().into(),
})?;
let txres = txres
.tx_response
.ok_or_else(|| crate::Error::InvalidChainResponse {
message: "Missing tx_response field".to_owned(),
action: action.clone(),
action: action.clone().into(),
})?;
Ok((txbody, txres))
}
Expand Down Expand Up @@ -879,7 +879,10 @@ impl Cosmos {
}
Err(match action {
None => crate::Error::WaitForTransactionTimedOut { txhash },
Some(action) => crate::Error::WaitForTransactionTimedOutWhile { txhash, action },
Some(action) => crate::Error::WaitForTransactionTimedOutWhile {
txhash,
action: action.into(),
},
})
}

Expand Down Expand Up @@ -1160,7 +1163,10 @@ impl BlockInfo {
chain_id,
})
})()
.map_err(|message| crate::Error::InvalidChainResponse { message, action })
.map_err(|message| crate::Error::InvalidChainResponse {
message,
action: action.into(),
})
}
}

Expand Down Expand Up @@ -1438,7 +1444,7 @@ impl TxBuilder {
.as_ref()
.ok_or_else(|| crate::Error::InvalidChainResponse {
message: "Missing gas_info in SimulateResponse".to_owned(),
action,
action: action.into(),
})?
.gas_used;

Expand Down Expand Up @@ -1538,7 +1544,7 @@ impl TxBuilder {
let res = tonic.into_inner().tx_response.ok_or_else(|| {
crate::Error::InvalidChainResponse {
message: "Missing inner tx_response".to_owned(),
action: mk_action(),
action: mk_action().into(),
}
})?;

Expand Down
6 changes: 4 additions & 2 deletions packages/cosmos/src/codeid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ impl Cosmos {
action: Action::StoreCode {
txbuilder,
txhash: res.txhash,
},
}
.into(),
}
})?),
)
Expand Down Expand Up @@ -126,7 +127,8 @@ impl Cosmos {
action: Action::StoreCode {
txbuilder,
txhash: res.txhash.clone(),
},
}
.into(),
}
})?);
Ok((res, code_id))
Expand Down
14 changes: 9 additions & 5 deletions packages/cosmos/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ impl CodeId {
action: Action::InstantiateContract {
txbuilder: txbuilder.clone(),
txhash: res.txhash.clone(),
},
}
.into(),
})?;

if addr.get_address_hrp() == self.get_address_hrp() {
Expand All @@ -128,7 +129,8 @@ impl CodeId {
action: Action::InstantiateContract {
txbuilder,
txhash: res.txhash,
},
}
.into(),
})
}
}
Expand Down Expand Up @@ -296,8 +298,10 @@ impl Contract {
)
.await?
.into_inner();
serde_json::from_slice(&res.data)
.map_err(|source| crate::Error::JsonDeserialize { source, action })
serde_json::from_slice(&res.data).map_err(|source| crate::Error::JsonDeserialize {
source,
action: action.into(),
})
}

/// Perform a contract migration with the given message
Expand Down Expand Up @@ -344,7 +348,7 @@ impl Contract {
.contract_info
.ok_or_else(|| crate::Error::InvalidChainResponse {
message: "Missing contract_info field".to_string(),
action,
action: action.into(),
})
}

Expand Down
11 changes: 7 additions & 4 deletions packages/cosmos/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,24 @@ pub enum Error {
)]
JsonDeserialize {
source: serde_json::Error,
action: Action,
action: Box<Action>,
},
#[error(transparent)]
Query(#[from] QueryError),
#[error("Error parsing data returned from chain: {source}. While performing: {action}")]
ChainParse {
source: Box<crate::error::ChainParseError>,
action: Action,
action: Box<Action>,
},
#[error("Invalid response from chain: {message}. While performing: {action}")]
InvalidChainResponse { message: String, action: Action },
InvalidChainResponse {
message: String,
action: Box<Action>,
},
#[error("Timed out waiting for transaction {txhash}")]
WaitForTransactionTimedOut { txhash: String },
#[error("Timed out waiting for transaction {txhash} during {action}")]
WaitForTransactionTimedOutWhile { txhash: String, action: Action },
WaitForTransactionTimedOutWhile { txhash: String, action: Box<Action> },
#[error("Unable to load WASM code from {}: {source}", path.display())]
LoadingWasmFromFile {
path: PathBuf,
Expand Down
6 changes: 3 additions & 3 deletions packages/cosmos/src/osmosis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Cosmos {
source: Box::new(ChainParseError::TxFees {
err: err.to_string(),
}),
action: Action::OsmosisTxFeesInfo,
action: Action::OsmosisTxFeesInfo.into(),
})?,
false => {
let eip_base_fee =
Expand All @@ -69,14 +69,14 @@ impl Cosmos {
source: Box::new(ChainParseError::TxFees {
err: err.to_string(),
}),
action: Action::OsmosisTxFeesInfo,
action: Action::OsmosisTxFeesInfo.into(),
})?;

Decimal::from_atomics(eip_base_fee, 18).map_err(|err| Error::ChainParse {
source: Box::new(ChainParseError::TxFees {
err: err.to_string(),
}),
action: Action::OsmosisTxFeesInfo,
action: Action::OsmosisTxFeesInfo.into(),
})?
}
};
Expand Down
3 changes: 2 additions & 1 deletion packages/cosmos/src/tokenfactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ impl TokenFactory {
action: Action::TokenFactory {
txbuilder,
txhash: res.txhash.clone(),
},
}
.into(),
})?;

Ok((res, denom))
Expand Down

0 comments on commit 65f3346

Please sign in to comment.