Skip to content

Commit

Permalink
Revert "Add conversion from &IbcEvent to abci::Event (#438)" (#494)
Browse files Browse the repository at this point in the history
This reverts commit fd1b643.
  • Loading branch information
plafer authored Mar 3, 2023
1 parent fd1b643 commit 127f129
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 248 deletions.

This file was deleted.

88 changes: 40 additions & 48 deletions crates/ibc/src/core/ics02_client/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ struct ClientIdAttribute {
client_id: ClientId,
}

impl From<&ClientIdAttribute> for abci::EventAttribute {
fn from(attr: &ClientIdAttribute) -> Self {
impl From<ClientIdAttribute> for abci::EventAttribute {
fn from(attr: ClientIdAttribute) -> Self {
(CLIENT_ID_ATTRIBUTE_KEY, attr.client_id.as_str()).into()
}
}
Expand All @@ -67,8 +67,8 @@ struct ClientTypeAttribute {
client_type: ClientType,
}

impl From<&ClientTypeAttribute> for abci::EventAttribute {
fn from(attr: &ClientTypeAttribute) -> Self {
impl From<ClientTypeAttribute> for abci::EventAttribute {
fn from(attr: ClientTypeAttribute) -> Self {
(CLIENT_TYPE_ATTRIBUTE_KEY, attr.client_type.as_str()).into()
}
}
Expand All @@ -91,8 +91,8 @@ struct ConsensusHeightAttribute {
consensus_height: Height,
}

impl From<&ConsensusHeightAttribute> for abci::EventAttribute {
fn from(attr: &ConsensusHeightAttribute) -> Self {
impl From<ConsensusHeightAttribute> for abci::EventAttribute {
fn from(attr: ConsensusHeightAttribute) -> Self {
(CONSENSUS_HEIGHT_ATTRIBUTE_KEY, attr.consensus_height).into()
}
}
Expand All @@ -115,11 +115,11 @@ struct ConsensusHeightsAttribute {
consensus_heights: Vec<Height>,
}

impl From<&ConsensusHeightsAttribute> for abci::EventAttribute {
fn from(attr: &ConsensusHeightsAttribute) -> Self {
impl From<ConsensusHeightsAttribute> for abci::EventAttribute {
fn from(attr: ConsensusHeightsAttribute) -> Self {
let consensus_heights: Vec<String> = attr
.consensus_heights
.iter()
.into_iter()
.map(|consensus_height| consensus_height.to_string())
.collect();
(CONSENSUS_HEIGHTS_ATTRIBUTE_KEY, consensus_heights.join(",")).into()
Expand All @@ -144,11 +144,11 @@ struct HeaderAttribute {
header: Any,
}

impl From<&HeaderAttribute> for abci::EventAttribute {
fn from(attr: &HeaderAttribute) -> Self {
impl From<HeaderAttribute> for abci::EventAttribute {
fn from(attr: HeaderAttribute) -> Self {
(
HEADER_ATTRIBUTE_KEY,
String::from_utf8(hex::encode(&attr.header.value)).unwrap(),
String::from_utf8(hex::encode(attr.header.value)).unwrap(),
)
.into()
}
Expand Down Expand Up @@ -197,14 +197,14 @@ impl CreateClient {
}
}

impl From<&CreateClient> for abci::Event {
fn from(c: &CreateClient) -> Self {
impl From<CreateClient> for abci::Event {
fn from(c: CreateClient) -> Self {
Self {
kind: IbcEventType::CreateClient.as_str().to_owned(),
attributes: vec![
abci::EventAttribute::from(&c.client_id),
abci::EventAttribute::from(&c.client_type),
abci::EventAttribute::from(&c.consensus_height),
c.client_id.into(),
c.client_type.into(),
c.consensus_height.into(),
],
}
}
Expand Down Expand Up @@ -273,16 +273,16 @@ impl UpdateClient {
}
}

impl From<&UpdateClient> for abci::Event {
fn from(u: &UpdateClient) -> Self {
impl From<UpdateClient> for abci::Event {
fn from(u: UpdateClient) -> Self {
Self {
kind: IbcEventType::UpdateClient.as_str().to_owned(),
attributes: vec![
abci::EventAttribute::from(&u.client_id),
abci::EventAttribute::from(&u.client_type),
abci::EventAttribute::from(&u.consensus_height),
abci::EventAttribute::from(&u.consensus_heights),
abci::EventAttribute::from(&u.header),
u.client_id.into(),
u.client_type.into(),
u.consensus_height.into(),
u.consensus_heights.into(),
u.header.into(),
],
}
}
Expand Down Expand Up @@ -326,14 +326,11 @@ impl ClientMisbehaviour {
}
}

impl From<&ClientMisbehaviour> for abci::Event {
fn from(c: &ClientMisbehaviour) -> Self {
impl From<ClientMisbehaviour> for abci::Event {
fn from(c: ClientMisbehaviour) -> Self {
Self {
kind: IbcEventType::ClientMisbehaviour.as_str().to_owned(),
attributes: vec![
abci::EventAttribute::from(&c.client_id),
abci::EventAttribute::from(&c.client_type),
],
attributes: vec![c.client_id.into(), c.client_type.into()],
}
}
}
Expand Down Expand Up @@ -381,14 +378,14 @@ impl UpgradeClient {
}
}

impl From<&UpgradeClient> for abci::Event {
fn from(u: &UpgradeClient) -> Self {
impl From<UpgradeClient> for abci::Event {
fn from(u: UpgradeClient) -> Self {
Self {
kind: IbcEventType::UpgradeClient.as_str().to_owned(),
attributes: vec![
abci::EventAttribute::from(&u.client_id),
abci::EventAttribute::from(&u.client_type),
abci::EventAttribute::from(&u.consensus_height),
u.client_id.into(),
u.client_type.into(),
u.consensus_height.into(),
],
}
}
Expand Down Expand Up @@ -437,39 +434,34 @@ mod tests {
let tests: Vec<Test> = vec![
Test {
kind: IbcEventType::CreateClient,
event: AbciEvent::from(&CreateClient::new(
client_id.clone(),
client_type.clone(),
consensus_height,
)),
event: CreateClient::new(client_id.clone(), client_type.clone(), consensus_height)
.into(),
expected_keys: expected_keys[0..3].to_vec(),
expected_values: expected_values[0..3].to_vec(),
},
Test {
kind: IbcEventType::UpdateClient,
event: AbciEvent::from(&UpdateClient::new(
event: UpdateClient::new(
client_id.clone(),
client_type.clone(),
consensus_height,
consensus_heights,
header,
)),
)
.into(),
expected_keys: expected_keys.clone(),
expected_values: expected_values.clone(),
},
Test {
kind: IbcEventType::UpgradeClient,
event: AbciEvent::from(&UpgradeClient::new(
client_id.clone(),
client_type.clone(),
consensus_height,
)),
event: UpgradeClient::new(client_id.clone(), client_type.clone(), consensus_height)
.into(),
expected_keys: expected_keys[0..3].to_vec(),
expected_values: expected_values[0..3].to_vec(),
},
Test {
kind: IbcEventType::ClientMisbehaviour,
event: AbciEvent::from(&ClientMisbehaviour::new(client_id, client_type)),
event: ClientMisbehaviour::new(client_id, client_type).into(),
expected_keys: expected_keys[0..2].to_vec(),
expected_values: expected_values[0..2].to_vec(),
},
Expand Down
51 changes: 25 additions & 26 deletions crates/ibc/src/core/ics03_connection/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ struct Attributes {
}

/// Convert attributes to Tendermint ABCI tags
impl From<&Attributes> for Vec<abci::EventAttribute> {
fn from(a: &Attributes) -> Self {
impl From<Attributes> for Vec<abci::EventAttribute> {
fn from(a: Attributes) -> Self {
let conn_id = (CONN_ID_ATTRIBUTE_KEY, a.connection_id.as_str()).into();
let client_id = (CLIENT_ID_ATTRIBUTE_KEY, a.client_id.as_str()).into();

Expand Down Expand Up @@ -108,11 +108,11 @@ impl OpenInit {
}
}

impl From<&OpenInit> for abci::Event {
fn from(v: &OpenInit) -> Self {
impl From<OpenInit> for abci::Event {
fn from(v: OpenInit) -> Self {
abci::Event {
kind: IbcEventType::OpenInitConnection.as_str().to_owned(),
attributes: Vec::<abci::EventAttribute>::from(&v.0),
attributes: v.0.into(),
}
}
}
Expand Down Expand Up @@ -163,11 +163,11 @@ impl OpenTry {
}
}

impl From<&OpenTry> for abci::Event {
fn from(v: &OpenTry) -> Self {
impl From<OpenTry> for abci::Event {
fn from(v: OpenTry) -> Self {
abci::Event {
kind: IbcEventType::OpenTryConnection.as_str().to_owned(),
attributes: Vec::<abci::EventAttribute>::from(&v.0),
attributes: v.0.into(),
}
}
}
Expand Down Expand Up @@ -218,11 +218,11 @@ impl OpenAck {
}
}

impl From<&OpenAck> for abci::Event {
fn from(v: &OpenAck) -> Self {
impl From<OpenAck> for abci::Event {
fn from(v: OpenAck) -> Self {
abci::Event {
kind: IbcEventType::OpenAckConnection.as_str().to_owned(),
attributes: Vec::<abci::EventAttribute>::from(&v.0),
attributes: v.0.into(),
}
}
}
Expand Down Expand Up @@ -273,11 +273,11 @@ impl OpenConfirm {
}
}

impl From<&OpenConfirm> for abci::Event {
fn from(v: &OpenConfirm) -> Self {
impl From<OpenConfirm> for abci::Event {
fn from(v: OpenConfirm) -> Self {
abci::Event {
kind: IbcEventType::OpenConfirmConnection.as_str().to_owned(),
attributes: Vec::<abci::EventAttribute>::from(&v.0),
attributes: v.0.into(),
}
}
}
Expand Down Expand Up @@ -318,11 +318,12 @@ mod tests {
let tests: Vec<Test> = vec![
Test {
kind: IbcEventType::OpenInitConnection,
event: AbciEvent::from(&OpenInit::new(
event: OpenInit::new(
conn_id_on_a.clone(),
client_id_on_a.clone(),
client_id_on_b.clone(),
)),
)
.into(),
expected_keys: expected_keys.clone(),
expected_values: expected_values
.iter()
Expand All @@ -332,34 +333,32 @@ mod tests {
},
Test {
kind: IbcEventType::OpenTryConnection,
event: AbciEvent::from(&OpenTry::new(
event: OpenTry::new(
conn_id_on_b.clone(),
client_id_on_b.clone(),
conn_id_on_a.clone(),
client_id_on_a.clone(),
)),
)
.into(),
expected_keys: expected_keys.clone(),
expected_values: expected_values.iter().rev().cloned().collect(),
},
Test {
kind: IbcEventType::OpenAckConnection,
event: AbciEvent::from(&OpenAck::new(
event: OpenAck::new(
conn_id_on_a.clone(),
client_id_on_a.clone(),
conn_id_on_b.clone(),
client_id_on_b.clone(),
)),
)
.into(),
expected_keys: expected_keys.clone(),
expected_values: expected_values.clone(),
},
Test {
kind: IbcEventType::OpenConfirmConnection,
event: AbciEvent::from(&OpenConfirm::new(
conn_id_on_b,
client_id_on_b,
conn_id_on_a,
client_id_on_a,
)),
event: OpenConfirm::new(conn_id_on_b, client_id_on_b, conn_id_on_a, client_id_on_a)
.into(),
expected_keys: expected_keys.clone(),
expected_values: expected_values.iter().rev().cloned().collect(),
},
Expand Down
Loading

0 comments on commit 127f129

Please sign in to comment.