Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert EventAttribute types #85

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions abci/example/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ func (app *Application) handleTx(tx []byte) *types.ExecTxResult {
{
Type: "app",
Attributes: []types.EventAttribute{
{Key: "creator", Value: "Cosmoshi Netowoko", Index: true},
{Key: "key", Value: key, Index: true},
{Key: "index_key", Value: "index is working", Index: true},
{Key: "noindex_key", Value: "index is working", Index: false},
{Key: []byte("creator"), Value: []byte("Cosmoshi Netowoko"), Index: true},
{Key: []byte("key"), Value: []byte(key), Index: true},
{Key: []byte("index_key"), Value: []byte("index is working"), Index: true},
{Key: []byte("noindex_key"), Value: []byte("index is working"), Index: false},
},
},
}
Expand Down
498 changes: 250 additions & 248 deletions abci/types/types.pb.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions internal/eventbus/event_bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (b *EventBus) Publish(eventValue string, eventData types.EventData) error {
Type: tokens[0],
Attributes: []abci.EventAttribute{
{
Key: tokens[1],
Value: eventValue,
Key: []byte(tokens[1]),
Value: []byte(eventValue),
},
},
}
Expand Down Expand Up @@ -137,8 +137,8 @@ func (b *EventBus) PublishEventTx(data types.EventDataTx) error {
Type: tokens[0],
Attributes: []abci.EventAttribute{
{
Key: tokens[1],
Value: fmt.Sprintf("%X", types.Tx(data.Tx).Hash()),
Key: []byte(tokens[1]),
Value: []byte(fmt.Sprintf("%X", types.Tx(data.Tx).Hash())),
},
},
})
Expand All @@ -148,8 +148,8 @@ func (b *EventBus) PublishEventTx(data types.EventDataTx) error {
Type: tokens[0],
Attributes: []abci.EventAttribute{
{
Key: tokens[1],
Value: fmt.Sprintf("%d", data.Height),
Key: []byte(tokens[1]),
Value: []byte(fmt.Sprintf("%d", data.Height)),
},
},
})
Expand Down
28 changes: 14 additions & 14 deletions internal/eventbus/event_bus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestEventBusPublishEventTx(t *testing.T) {
result := abci.ExecTxResult{
Data: []byte("bar"),
Events: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}},
{Type: "testType", Attributes: []abci.EventAttribute{{Key:[]byte( "baz"), Value: []byte("1")}}},
},
}

Expand Down Expand Up @@ -86,8 +86,8 @@ func TestEventBusPublishEventNewBlock(t *testing.T) {
resultFinalizeBlock := abci.ResponseFinalizeBlock{
Events: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{
{Key: "baz", Value: "1"},
{Key: "foz", Value: "2"},
{Key: []byte("baz"), Value: []byte("1")},
{Key: []byte("foz"), Value: []byte("2")},
}},
},
}
Expand Down Expand Up @@ -140,25 +140,25 @@ func TestEventBusPublishEventTxDuplicateKeys(t *testing.T) {
{
Type: "transfer",
Attributes: []abci.EventAttribute{
{Key: "sender", Value: "foo"},
{Key: "recipient", Value: "bar"},
{Key: "amount", Value: "5"},
{Key: []byte("sender"), Value: []byte("foo")},
{Key: []byte("recipient"), Value: []byte("bar")},
{Key: []byte("amount"), Value: []byte("5")},
},
},
{
Type: "transfer",
Attributes: []abci.EventAttribute{
{Key: "sender", Value: "baz"},
{Key: "recipient", Value: "cat"},
{Key: "amount", Value: "13"},
{Key: []byte("sender"), Value: []byte("baz")},
{Key: []byte("recipient"), Value: []byte("cat")},
{Key: []byte("amount"), Value: []byte("13")},
},
},
{
Type: "withdraw.rewards",
Attributes: []abci.EventAttribute{
{Key: "address", Value: "bar"},
{Key: "source", Value: "iceman"},
{Key: "amount", Value: "33"},
{Key: []byte("address"), Value: []byte("bar")},
{Key: []byte("source"), Value: []byte("iceman")},
{Key: []byte("amount"), Value: []byte("33")},
},
},
},
Expand Down Expand Up @@ -255,8 +255,8 @@ func TestEventBusPublishEventNewBlockHeader(t *testing.T) {
resultFinalizeBlock := abci.ResponseFinalizeBlock{
Events: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{
{Key: "baz", Value: "1"},
{Key: "foz", Value: "2"},
{Key: []byte("baz"), Value: []byte("1")},
{Key: []byte("foz"), Value: []byte("2")},
}},
},
}
Expand Down
6 changes: 3 additions & 3 deletions internal/eventlog/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func makeEvents(etype string, data types.EventData) []abci.Event {
base := []abci.Event{{
Type: tmTypeTag,
Attributes: []abci.EventAttribute{{
Key: tmTypeKey, Value: etype,
Key: []byte(tmTypeKey), Value: []byte(etype),
}},
}}
if evt, ok := data.(ABCIEventer); ok {
Expand All @@ -69,8 +69,8 @@ func FindType(events []abci.Event) (string, bool) {
continue
}
for _, attr := range evt.Attributes {
if attr.Key == tmTypeKey {
return attr.Value, true
if string(attr.Key) == tmTypeKey {
return string(attr.Value), true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pubsub/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestExample(t *testing.T) {
events := []abci.Event{
{
Type: "abci.account",
Attributes: []abci.EventAttribute{{Key: "name", Value: "John"}},
Attributes: []abci.EventAttribute{{Key: []byte("name"), Value: []byte("John")}},
},
}
require.NoError(t, s.PublishWithEvents(pubstring("Tombstone"), events))
Expand Down
22 changes: 11 additions & 11 deletions internal/pubsub/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestDifferentClients(t *testing.T) {

events := []abci.Event{{
Type: "tm.events",
Attributes: []abci.EventAttribute{{Key: "type", Value: "NewBlock"}},
Attributes: []abci.EventAttribute{{Key: []byte("type"), Value: []byte("NewBlock")}},
}}

require.NoError(t, s.PublishWithEvents(pubstring("Iceman"), events))
Expand All @@ -187,11 +187,11 @@ func TestDifferentClients(t *testing.T) {
events = []abci.Event{
{
Type: "tm.events",
Attributes: []abci.EventAttribute{{Key: "type", Value: "NewBlock"}},
Attributes: []abci.EventAttribute{{Key: []byte("type"), Value: []byte("NewBlock")}},
},
{
Type: "abci.account",
Attributes: []abci.EventAttribute{{Key: "name", Value: "Igor"}},
Attributes: []abci.EventAttribute{{Key: []byte("name"), Value: []byte("Igor")}},
},
}

Expand All @@ -207,7 +207,7 @@ func TestDifferentClients(t *testing.T) {

events = []abci.Event{{
Type: "tm.events",
Attributes: []abci.EventAttribute{{Key: "type", Value: "NewRoundStep"}},
Attributes: []abci.EventAttribute{{Key: []byte("type"), Value: []byte("NewRoundStep")}},
}}

require.NoError(t, s.PublishWithEvents(pubstring("Valeria Richards"), events))
Expand Down Expand Up @@ -244,17 +244,17 @@ func TestSubscribeDuplicateKeys(t *testing.T) {
{
Type: "transfer",
Attributes: []abci.EventAttribute{
{Key: "sender", Value: "foo"},
{Key: "sender", Value: "bar"},
{Key: "sender", Value: "baz"},
{Key: []byte("sender"), Value: []byte("foo")},
{Key: []byte("sender"), Value: []byte("bar")},
{Key: []byte("sender"), Value: []byte("baz")},
},
},
{
Type: "withdraw",
Attributes: []abci.EventAttribute{
{Key: "rewards", Value: "1"},
{Key: "rewards", Value: "17"},
{Key: "rewards", Value: "22"},
{Key: []byte("rewards"), Value: []byte("1")},
{Key: []byte("rewards"), Value: []byte("17")},
{Key: []byte("rewards"), Value: []byte("22")},
},
},
}
Expand All @@ -280,7 +280,7 @@ func TestClientSubscribesTwice(t *testing.T) {
q := query.MustCompile(`tm.events.type='NewBlock'`)
events := []abci.Event{{
Type: "tm.events",
Attributes: []abci.EventAttribute{{Key: "type", Value: "NewBlock"}},
Attributes: []abci.EventAttribute{{Key: []byte("type"), Value: []byte("NewBlock")}},
}}

sub1 := newTestSub(t).must(s.SubscribeWithArgs(ctx, pubsub.SubscribeArgs{
Expand Down
16 changes: 8 additions & 8 deletions internal/pubsub/query/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ var testEvents = []types.Event{
{
Type: "tm.events",
Attributes: []types.EventAttribute{{
Key: "index",
Value: "25",
Key: []byte("index"),
Value: []byte("25"),
}, {
Key: "type",
Value: "NewBlock",
Key: []byte("type"),
Value: []byte("NewBlock"),
}},
},
{
Type: "abci.account",
Attributes: []types.EventAttribute{{
Key: "name",
Value: "Anya",
Key: []byte("name"),
Value: []byte("Anya"),
}, {
Key: "name",
Value: "Igor",
Key: []byte("name"),
Value: []byte("Igor"),
}},
},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/pubsub/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func (c condition) findAttr(event types.Event) ([]string, bool) {
}
var vals []string
for _, attr := range event.Attributes {
fullName := event.Type + "." + attr.Key
fullName := event.Type + "." + string(attr.Key)
if fullName == c.tag {
vals = append(vals, attr.Value)
vals = append(vals, string(attr.Value))
}
}
return vals, false
Expand Down
32 changes: 16 additions & 16 deletions internal/pubsub/query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@ var apiEvents = []types.Event{
{
Type: "tm",
Attributes: []types.EventAttribute{
{Key: "event", Value: "Tx"},
{Key: "hash", Value: "XYZ"},
{Key: "height", Value: "5"},
{Key: []byte("event"), Value: []byte("Tx")},
{Key: []byte("hash"), Value: []byte("XYZ")},
{Key: []byte("height"), Value: []byte("5")},
},
},
{
Type: "rewards.withdraw",
Attributes: []types.EventAttribute{
{Key: "address", Value: "AddrA"},
{Key: "source", Value: "SrcX"},
{Key: "amount", Value: "100"},
{Key: "balance", Value: "1500"},
{Key: []byte("address"), Value: []byte("AddrA")},
{Key: []byte("source"), Value: []byte("SrcX")},
{Key: []byte("amount"), Value: []byte("100")},
{Key: []byte("balance"), Value: []byte("1500")},
},
},
{
Type: "rewards.withdraw",
Attributes: []types.EventAttribute{
{Key: "address", Value: "AddrB"},
{Key: "source", Value: "SrcY"},
{Key: "amount", Value: "45"},
{Key: "balance", Value: "999"},
{Key: []byte("address"), Value: []byte("AddrB")},
{Key: []byte("source"), Value: []byte("SrcY")},
{Key: []byte("amount"), Value: []byte("45")},
{Key: []byte("balance"), Value: []byte("999")},
},
},
{
Type: "transfer",
Attributes: []types.EventAttribute{
{Key: "sender", Value: "AddrC"},
{Key: "recipient", Value: "AddrD"},
{Key: "amount", Value: "160"},
{Key: []byte("sender"), Value: []byte("AddrC")},
{Key: []byte("recipient"), Value: []byte("AddrD")},
{Key: []byte("amount"), Value: []byte("160")},
},
},
}
Expand Down Expand Up @@ -242,8 +242,8 @@ func newTestEvent(s string) types.Event {
for _, kv := range parts[1:] {
key, val := splitKV(kv)
event.Attributes = append(event.Attributes, types.EventAttribute{
Key: key,
Value: val,
Key: []byte(key),
Value: []byte(val),
})
}
return event
Expand Down
4 changes: 2 additions & 2 deletions internal/state/indexer/block/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,13 @@ func (idx *BlockerIndexer) indexEvents(batch dbm.Batch, events []abci.Event, typ
}

// index iff the event specified index:true and it's not a reserved event
compositeKey := fmt.Sprintf("%s.%s", event.Type, attr.Key)
compositeKey := fmt.Sprintf("%s.%s", event.Type, string(attr.Key))
if compositeKey == types.BlockHeightKey {
return fmt.Errorf("event type and attribute key \"%s\" is reserved; please use a different key", compositeKey)
}

if attr.GetIndex() {
key, err := eventKey(compositeKey, typ, attr.Value, height)
key, err := eventKey(compositeKey, typ, string(attr.Value), height)
if err != nil {
return fmt.Errorf("failed to create block index key: %w", err)
}
Expand Down
16 changes: 8 additions & 8 deletions internal/state/indexer/block/kv/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func TestBlockIndexer(t *testing.T) {
Type: "finalize_event1",
Attributes: []abci.EventAttribute{
{
Key: "proposer",
Value: "FCAA001",
Key: []byte("proposer"),
Value: []byte("FCAA001"),
Index: true,
},
},
Expand All @@ -36,8 +36,8 @@ func TestBlockIndexer(t *testing.T) {
Type: "finalize_event2",
Attributes: []abci.EventAttribute{
{
Key: "foo",
Value: "100",
Key: []byte("foo"),
Value: []byte("100"),
Index: true,
},
},
Expand All @@ -59,8 +59,8 @@ func TestBlockIndexer(t *testing.T) {
Type: "finalize_event1",
Attributes: []abci.EventAttribute{
{
Key: "proposer",
Value: "FCAA001",
Key: []byte("proposer"),
Value: []byte("FCAA001"),
Index: true,
},
},
Expand All @@ -69,8 +69,8 @@ func TestBlockIndexer(t *testing.T) {
Type: "finalize_event2",
Attributes: []abci.EventAttribute{
{
Key: "foo",
Value: fmt.Sprintf("%d", i),
Key: []byte("foo"),
Value: []byte(fmt.Sprintf("%d", i)),
Index: index,
},
},
Expand Down
Loading