Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mina86 committed Oct 10, 2023
1 parent c2b4978 commit ca1aea3
Show file tree
Hide file tree
Showing 9 changed files with 468 additions and 423 deletions.
153 changes: 82 additions & 71 deletions solana/solana-ibc/programs/solana-ibc/src/client_state.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
use super::consensus_state::AnyConsensusState;
use crate::SolanaIbcStorage;
use ibc::{
clients::ics07_tendermint::client_state::ClientState as TmClientState,
core::{
ics02_client::{
client_state::{
ClientStateCommon, ClientStateExecution, ClientStateValidation, UpdateKind,
},
client_type::ClientType,
error::ClientError,
},
ics23_commitment::commitment::{CommitmentPrefix, CommitmentProofBytes, CommitmentRoot},
ics24_host::{
identifier::ClientId,
path::{ClientConsensusStatePath, Path},
},
timestamp::Timestamp,
ContextError, ValidationContext,
},
Any, Height,
use ibc::clients::ics07_tendermint::client_state::ClientState as TmClientState;
use ibc::core::ics02_client::client_state::{
ClientStateCommon, ClientStateExecution, ClientStateValidation, UpdateKind,
};
use ibc_proto::{
ibc::lightclients::tendermint::v1::ClientState as RawTmClientState, protobuf::Protobuf,
use ibc::core::ics02_client::client_type::ClientType;
use ibc::core::ics02_client::error::ClientError;
use ibc::core::ics23_commitment::commitment::{
CommitmentPrefix, CommitmentProofBytes, CommitmentRoot,
};
use ibc::core::ics24_host::identifier::ClientId;
use ibc::core::ics24_host::path::{ClientConsensusStatePath, Path};
use ibc::core::timestamp::Timestamp;
use ibc::core::{ContextError, ValidationContext};
use ibc::{Any, Height};
use ibc_proto::ibc::lightclients::tendermint::v1::ClientState as RawTmClientState;
use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};

const TENDERMINT_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ClientState";
use super::consensus_state::AnyConsensusState;
use crate::SolanaIbcStorage;

const TENDERMINT_CLIENT_STATE_TYPE_URL: &str =
"/ibc.lightclients.tendermint.v1.ClientState";

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub enum AnyClientState {
Expand All @@ -40,11 +35,11 @@ impl TryFrom<Any> for AnyClientState {
fn try_from(raw: Any) -> Result<Self, Self::Error> {
match raw.type_url.as_str() {
TENDERMINT_CLIENT_STATE_TYPE_URL => Ok(AnyClientState::Tendermint(
Protobuf::<RawTmClientState>::decode_vec(&raw.value).map_err(|e| {
ClientError::ClientSpecific {
Protobuf::<RawTmClientState>::decode_vec(&raw.value).map_err(
|e| ClientError::ClientSpecific {
description: e.to_string(),
}
})?,
},
)?,
)),
_ => Err(ClientError::UnknownClientStateType {
client_state_type: raw.type_url,
Expand Down Expand Up @@ -73,9 +68,13 @@ impl ClientStateValidation<SolanaIbcStorage> for AnyClientState {
update_kind: &UpdateKind,
) -> Result<(), ClientError> {
match self {
AnyClientState::Tendermint(client_state) => {
client_state.verify_client_message(ctx, client_id, client_message, update_kind)
}
AnyClientState::Tendermint(client_state) => client_state
.verify_client_message(
ctx,
client_id,
client_message,
update_kind,
),
}
}

Expand All @@ -87,23 +86,31 @@ impl ClientStateValidation<SolanaIbcStorage> for AnyClientState {
update_kind: &UpdateKind,
) -> Result<bool, ClientError> {
match self {
AnyClientState::Tendermint(client_state) => {
client_state.check_for_misbehaviour(ctx, client_id, client_message, update_kind)
}
AnyClientState::Tendermint(client_state) => client_state
.check_for_misbehaviour(
ctx,
client_id,
client_message,
update_kind,
),
}
}

fn status(
&self,
ctx: &SolanaIbcStorage,

Check failure on line 101 in solana/solana-ibc/programs/solana-ibc/src/client_state.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `ctx`

error: unused variable: `ctx` --> solana/solana-ibc/programs/solana-ibc/src/client_state.rs:101:9 | 101 | ctx: &SolanaIbcStorage, | ^^^ help: if this is intentional, prefix it with an underscore: `_ctx` | = note: `-D unused-variables` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_variables)]`
client_id: &ClientId,

Check failure on line 102 in solana/solana-ibc/programs/solana-ibc/src/client_state.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `client_id`

error: unused variable: `client_id` --> solana/solana-ibc/programs/solana-ibc/src/client_state.rs:102:9 | 102 | client_id: &ClientId, | ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_client_id`
) -> Result<ibc::core::ics02_client::client_state::Status, ClientError> {
) -> Result<ibc::core::ics02_client::client_state::Status, ClientError>
{
todo!()
}
}

impl ClientStateCommon for AnyClientState {
fn verify_consensus_state(&self, consensus_state: ibc::Any) -> Result<(), ClientError> {
fn verify_consensus_state(
&self,
consensus_state: ibc::Any,
) -> Result<(), ClientError> {
match self {
AnyClientState::Tendermint(client_state) => {
client_state.verify_consensus_state(consensus_state)
Expand All @@ -113,17 +120,24 @@ impl ClientStateCommon for AnyClientState {

fn client_type(&self) -> ClientType {
match self {
AnyClientState::Tendermint(client_state) => client_state.client_type(),
AnyClientState::Tendermint(client_state) => {
client_state.client_type()
}
}
}

fn latest_height(&self) -> Height {
match self {
AnyClientState::Tendermint(client_state) => client_state.latest_height(),
AnyClientState::Tendermint(client_state) => {
client_state.latest_height()
}
}
}

fn validate_proof_height(&self, proof_height: Height) -> Result<(), ClientError> {
fn validate_proof_height(
&self,
proof_height: Height,
) -> Result<(), ClientError> {
match self {
AnyClientState::Tendermint(client_state) => {
client_state.validate_proof_height(proof_height)
Expand All @@ -140,13 +154,14 @@ impl ClientStateCommon for AnyClientState {
root: &CommitmentRoot,
) -> Result<(), ClientError> {
match self {
AnyClientState::Tendermint(client_state) => client_state.verify_upgrade_client(
upgraded_client_state,
upgraded_consensus_state,
proof_upgrade_client,
proof_upgrade_consensus_state,
root,
),
AnyClientState::Tendermint(client_state) => client_state
.verify_upgrade_client(
upgraded_client_state,
upgraded_consensus_state,
proof_upgrade_client,
proof_upgrade_consensus_state,
root,
),
}
}

Expand Down Expand Up @@ -181,9 +196,7 @@ impl ClientStateCommon for AnyClientState {
}

impl From<TmClientState> for AnyClientState {
fn from(value: TmClientState) -> Self {
AnyClientState::Tendermint(value)
}
fn from(value: TmClientState) -> Self { AnyClientState::Tendermint(value) }
}

impl ClientStateExecution<SolanaIbcStorage> for AnyClientState {
Expand Down Expand Up @@ -221,12 +234,13 @@ impl ClientStateExecution<SolanaIbcStorage> for AnyClientState {
update_kind: &UpdateKind,
) -> Result<(), ClientError> {
match self {
AnyClientState::Tendermint(client_state) => client_state.update_state_on_misbehaviour(
ctx,
client_id,
client_message,
update_kind,
),
AnyClientState::Tendermint(client_state) => client_state
.update_state_on_misbehaviour(
ctx,
client_id,
client_message,
update_kind,
),
}
}

Expand All @@ -238,12 +252,13 @@ impl ClientStateExecution<SolanaIbcStorage> for AnyClientState {
upgraded_consensus_state: Any,
) -> Result<Height, ClientError> {
match self {
AnyClientState::Tendermint(client_state) => client_state.update_state_on_upgrade(
ctx,
client_id,
upgraded_client_state,
upgraded_consensus_state,
),
AnyClientState::Tendermint(client_state) => client_state
.update_state_on_upgrade(
ctx,
client_id,
upgraded_client_state,
upgraded_consensus_state,
),
}
}
}
Expand Down Expand Up @@ -272,12 +287,10 @@ impl ibc::clients::ics07_tendermint::ValidationContext for SolanaIbcStorage {
height: &Height,
) -> Result<Option<Self::AnyConsensusState>, ContextError> {
let end_height = (height.revision_number() + 1, 1 as u64);

Check failure on line 289 in solana/solana-ibc/programs/solana-ibc/src/client_state.rs

View workflow job for this annotation

GitHub Actions / clippy

casting integer literal to `u64` is unnecessary

error: casting integer literal to `u64` is unnecessary --> solana/solana-ibc/programs/solana-ibc/src/client_state.rs:289:57 | 289 | let end_height = (height.revision_number() + 1, 1 as u64); | ^^^^^^^^ help: try: `1_u64` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast = note: `-D clippy::unnecessary-cast` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::unnecessary_cast)]`
match self
.consensus_states
.get(&(client_id.to_string(), end_height))
{
match self.consensus_states.get(&(client_id.to_string(), end_height)) {
Some(data) => {
let result: Self::AnyConsensusState = serde_json::from_str(data).unwrap();
let result: Self::AnyConsensusState =
serde_json::from_str(data).unwrap();
Ok(Some(result))
}
None => Err(ContextError::ClientError(
Expand All @@ -292,12 +305,10 @@ impl ibc::clients::ics07_tendermint::ValidationContext for SolanaIbcStorage {
height: &Height,
) -> Result<Option<Self::AnyConsensusState>, ContextError> {
let end_height = (height.revision_number(), 1 as u64);

Check failure on line 307 in solana/solana-ibc/programs/solana-ibc/src/client_state.rs

View workflow job for this annotation

GitHub Actions / clippy

casting integer literal to `u64` is unnecessary

error: casting integer literal to `u64` is unnecessary --> solana/solana-ibc/programs/solana-ibc/src/client_state.rs:307:53 | 307 | let end_height = (height.revision_number(), 1 as u64); | ^^^^^^^^ help: try: `1_u64` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
match self
.consensus_states
.get(&(client_id.to_string(), end_height))
{
match self.consensus_states.get(&(client_id.to_string(), end_height)) {
Some(data) => {
let result: Self::AnyConsensusState = serde_json::from_str(data).unwrap();
let result: Self::AnyConsensusState =
serde_json::from_str(data).unwrap();
Ok(Some(result))
}
None => Err(ContextError::ClientError(
Expand Down
44 changes: 22 additions & 22 deletions solana/solana-ibc/programs/solana-ibc/src/consensus_state.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use ibc::{
clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState,
core::{
ics02_client::{consensus_state::ConsensusState, error::ClientError},
ics23_commitment::commitment::CommitmentRoot,
timestamp::Timestamp,
},
};
use ibc_proto::{
google::protobuf::Any,
ibc::lightclients::tendermint::v1::ConsensusState as RawTmConsensusState,
protobuf::Protobuf,
};
use ibc::clients::ics07_tendermint::consensus_state::ConsensusState as TmConsensusState;
use ibc::core::ics02_client::consensus_state::ConsensusState;
use ibc::core::ics02_client::error::ClientError;
use ibc::core::ics23_commitment::commitment::CommitmentRoot;
use ibc::core::timestamp::Timestamp;
use ibc_proto::google::protobuf::Any;
use ibc_proto::ibc::lightclients::tendermint::v1::ConsensusState as RawTmConsensusState;
use ibc_proto::protobuf::Protobuf;
use serde::{Deserialize, Serialize};

const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str = "/ibc.lightclients.tendermint.v1.ConsensusState";
const TENDERMINT_CONSENSUS_STATE_TYPE_URL: &str =
"/ibc.lightclients.tendermint.v1.ConsensusState";

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
Expand All @@ -28,13 +24,14 @@ impl TryFrom<Any> for AnyConsensusState {

fn try_from(value: Any) -> Result<Self, Self::Error> {
match value.type_url.as_str() {
TENDERMINT_CONSENSUS_STATE_TYPE_URL => Ok(AnyConsensusState::Tendermint(
Protobuf::<RawTmConsensusState>::decode_vec(&value.value).map_err(|e| {
ClientError::ClientSpecific {
TENDERMINT_CONSENSUS_STATE_TYPE_URL => {
Ok(AnyConsensusState::Tendermint(
Protobuf::<RawTmConsensusState>::decode_vec(&value.value)
.map_err(|e| ClientError::ClientSpecific {
description: e.to_string(),
}
})?,
)),
})?,
))
}
_ => Err(ClientError::UnknownConsensusStateType {
consensus_state_type: value.type_url.clone(),
}),
Expand Down Expand Up @@ -88,9 +85,12 @@ impl TryInto<ibc::clients::ics07_tendermint::consensus_state::ConsensusState>

fn try_into(
self,
) -> Result<ibc::clients::ics07_tendermint::consensus_state::ConsensusState, Self::Error> {
) -> Result<
ibc::clients::ics07_tendermint::consensus_state::ConsensusState,
Self::Error,
> {
match self {
AnyConsensusState::Tendermint(value) => Ok(value),
}
}
}
}
Loading

0 comments on commit ca1aea3

Please sign in to comment.