Skip to content

Commit

Permalink
Deduplicate RPC domain types (#922)
Browse files Browse the repository at this point in the history
* Replace rpc TmEvent and Attribute structs with tendermint domain types

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add changelog entry

Signed-off-by: Thane Thomson <connect@thanethomson.com>
  • Loading branch information
thanethomson authored Jul 12, 2021
1 parent 1efe42c commit a748118
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `[tendermint-rpc]` Remove the `TmEvent` and `Attribute` structs and replace
them with their equivalent domain types from the `tendermint` crate
([#918](https://github.com/informalsystems/tendermint-rs/issues/918))
23 changes: 3 additions & 20 deletions rpc/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tendermint::{
abci::responses::{BeginBlock, EndBlock},
Block,
};
use tendermint::abci::responses::{BeginBlock, EndBlock};
use tendermint::Block;

use crate::query::EventType;
use crate::{response::Wrapper, Response};
Expand Down Expand Up @@ -74,20 +72,5 @@ pub struct TxResult {
pub log: Option<String>,
pub gas_wanted: Option<String>,
pub gas_used: Option<String>,
pub events: Vec<TmEvent>,
}

/// Tendermint ABCI Events
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct TmEvent {
#[serde(rename = "type")]
pub event_type: String,
pub attributes: Vec<Attribute>,
}

/// Event Attributes
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Attribute {
pub key: String,
pub value: String,
pub events: Vec<tendermint::abci::Event>,
}
90 changes: 55 additions & 35 deletions rpc/tests/kvstore_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,14 +1025,18 @@ fn incoming_fixtures() {
assert!(tx_result.result.gas_wanted.is_none());
assert!(tx_result.result.gas_used.is_none());
assert_eq!(tx_result.result.events.len(), 1);
assert_eq!(tx_result.result.events[0].event_type, "app");
assert_eq!(tx_result.result.events[0].type_str, "app");
for attr in &tx_result.result.events[0].attributes {
match attr.key.as_str() {
"Y3JlYXRvcg==" => assert_eq!(attr.value, "Q29zbW9zaGkgTmV0b3dva28="),
"a2V5" => assert_eq!(attr.value, "dHgw"),
"aW5kZXhfa2V5" => assert_eq!(attr.value, "aW5kZXggaXMgd29ya2luZw=="),
"bm9pbmRleF9rZXk=" => {
assert_eq!(attr.value, "aW5kZXggaXMgd29ya2luZw==")
match attr.key.as_ref() {
"creator" => {
assert_eq!(attr.value.as_ref(), "Cosmoshi Netowoko")
}
"key" => assert_eq!(attr.value.as_ref(), "tx0"),
"index_key" => {
assert_eq!(attr.value.as_ref(), "index is working")
}
"noindex_key" => {
assert_eq!(attr.value.as_ref(), "index is working")
}
_ => panic!("unknown attribute found {}", attr.key),
}
Expand Down Expand Up @@ -1065,14 +1069,18 @@ fn incoming_fixtures() {
assert!(tx_result.result.gas_wanted.is_none());
assert!(tx_result.result.gas_used.is_none());
assert_eq!(tx_result.result.events.len(), 1);
assert_eq!(tx_result.result.events[0].event_type, "app");
assert_eq!(tx_result.result.events[0].type_str, "app");
for attr in &tx_result.result.events[0].attributes {
match attr.key.as_str() {
"Y3JlYXRvcg==" => assert_eq!(attr.value, "Q29zbW9zaGkgTmV0b3dva28="),
"a2V5" => assert_eq!(attr.value, "dHgx"),
"aW5kZXhfa2V5" => assert_eq!(attr.value, "aW5kZXggaXMgd29ya2luZw=="),
"bm9pbmRleF9rZXk=" => {
assert_eq!(attr.value, "aW5kZXggaXMgd29ya2luZw==")
match attr.key.as_ref() {
"creator" => {
assert_eq!(attr.value.as_ref(), "Cosmoshi Netowoko")
}
"key" => assert_eq!(attr.value.as_ref(), "tx1"),
"index_key" => {
assert_eq!(attr.value.as_ref(), "index is working")
}
"noindex_key" => {
assert_eq!(attr.value.as_ref(), "index is working")
}
_ => panic!("unknown attribute found {}", attr.key),
}
Expand Down Expand Up @@ -1105,14 +1113,18 @@ fn incoming_fixtures() {
assert!(tx_result.result.gas_wanted.is_none());
assert!(tx_result.result.gas_used.is_none());
assert_eq!(tx_result.result.events.len(), 1);
assert_eq!(tx_result.result.events[0].event_type, "app");
assert_eq!(tx_result.result.events[0].type_str, "app");
for attr in &tx_result.result.events[0].attributes {
match attr.key.as_str() {
"Y3JlYXRvcg==" => assert_eq!(attr.value, "Q29zbW9zaGkgTmV0b3dva28="),
"a2V5" => assert_eq!(attr.value, "dHgy"),
"aW5kZXhfa2V5" => assert_eq!(attr.value, "aW5kZXggaXMgd29ya2luZw=="),
"bm9pbmRleF9rZXk=" => {
assert_eq!(attr.value, "aW5kZXggaXMgd29ya2luZw==")
match attr.key.as_ref() {
"creator" => {
assert_eq!(attr.value.as_ref(), "Cosmoshi Netowoko")
}
"key" => assert_eq!(attr.value.as_ref(), "tx2"),
"index_key" => {
assert_eq!(attr.value.as_ref(), "index is working")
}
"noindex_key" => {
assert_eq!(attr.value.as_ref(), "index is working")
}
_ => panic!("unknown attribute found {}", attr.key),
}
Expand Down Expand Up @@ -1145,14 +1157,18 @@ fn incoming_fixtures() {
assert!(tx_result.result.gas_wanted.is_none());
assert!(tx_result.result.gas_used.is_none());
assert_eq!(tx_result.result.events.len(), 1);
assert_eq!(tx_result.result.events[0].event_type, "app");
assert_eq!(tx_result.result.events[0].type_str, "app");
for attr in &tx_result.result.events[0].attributes {
match attr.key.as_str() {
"Y3JlYXRvcg==" => assert_eq!(attr.value, "Q29zbW9zaGkgTmV0b3dva28="),
"a2V5" => assert_eq!(attr.value, "dHgz"),
"aW5kZXhfa2V5" => assert_eq!(attr.value, "aW5kZXggaXMgd29ya2luZw=="),
"bm9pbmRleF9rZXk=" => {
assert_eq!(attr.value, "aW5kZXggaXMgd29ya2luZw==")
match attr.key.as_ref() {
"creator" => {
assert_eq!(attr.value.as_ref(), "Cosmoshi Netowoko")
}
"key" => assert_eq!(attr.value.as_ref(), "tx3"),
"index_key" => {
assert_eq!(attr.value.as_ref(), "index is working")
}
"noindex_key" => {
assert_eq!(attr.value.as_ref(), "index is working")
}
_ => panic!("unknown attribute found {}", attr.key),
}
Expand Down Expand Up @@ -1185,14 +1201,18 @@ fn incoming_fixtures() {
assert!(tx_result.result.gas_wanted.is_none());
assert!(tx_result.result.gas_used.is_none());
assert_eq!(tx_result.result.events.len(), 1);
assert_eq!(tx_result.result.events[0].event_type, "app");
assert_eq!(tx_result.result.events[0].type_str, "app");
for attr in &tx_result.result.events[0].attributes {
match attr.key.as_str() {
"Y3JlYXRvcg==" => assert_eq!(attr.value, "Q29zbW9zaGkgTmV0b3dva28="),
"a2V5" => assert_eq!(attr.value, "dHg0"),
"aW5kZXhfa2V5" => assert_eq!(attr.value, "aW5kZXggaXMgd29ya2luZw=="),
"bm9pbmRleF9rZXk=" => {
assert_eq!(attr.value, "aW5kZXggaXMgd29ya2luZw==")
match attr.key.as_ref() {
"creator" => {
assert_eq!(attr.value.as_ref(), "Cosmoshi Netowoko")
}
"key" => assert_eq!(attr.value.as_ref(), "tx4"),
"index_key" => {
assert_eq!(attr.value.as_ref(), "index is working")
}
"noindex_key" => {
assert_eq!(attr.value.as_ref(), "index is working")
}
_ => panic!("unknown attribute found {}", attr.key),
}
Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/abci/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct DeliverTx {
}

/// Event
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct Event {
/// Event type
#[serde(rename = "type")]
Expand Down

0 comments on commit a748118

Please sign in to comment.