Skip to content

Commit

Permalink
feat: set Data on mempool pubsub messages (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Dec 27, 2023
1 parent 5f4d3af commit b1c9a1d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mempool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ The following PubSub messages are emitted:

```json
{
"data": nil,
"data": JSON(<MSG>),
"attributes": {
"message_type": "mempool_tx_msg",
"chain_id": "<CHAIN-ID>",
Expand Down
9 changes: 8 additions & 1 deletion mempool/ante/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ante
import (
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -88,10 +89,16 @@ func (d PubSubDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, n

results := make([]*pubsub.PublishResult, len(msgs))
for i, msg := range msgs {
msgBz, err := json.Marshal(msg)
if err != nil {
d.logger.Error("failed to JSON encode tx message", "err", err)
continue
}

results[i] = d.topic.Publish(
context.Background(),
&pubsub.Message{
Data: nil, // TODO(bez): Should we publish the entire tx or just the message?
Data: msgBz,
Attributes: map[string]string{
mempool.AttrKeyMsgType: mempool.MsgTypeCheckTxMsg,
mempool.AttrKeyChainID: ctx.ChainID(),
Expand Down
9 changes: 8 additions & 1 deletion mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mempool
import (
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -95,10 +96,16 @@ func (mp *PubSubMempool) Insert(ctx context.Context, tx sdk.Tx) error {

results := make([]*pubsub.PublishResult, len(msgs))
for i, msg := range msgs {
msgBz, err := json.Marshal(msg)
if err != nil {
mp.logger.Error("failed to JSON encode tx message", "err", err)
continue
}

results[i] = mp.topic.Publish(
context.Background(),
&pubsub.Message{
Data: nil, // TODO(bez): Should we publish the entire tx or just the message?
Data: msgBz,
Attributes: map[string]string{
AttrKeyMsgType: MsgTypeCheckTxMsg,
AttrKeyChainID: mp.chainID,
Expand Down

0 comments on commit b1c9a1d

Please sign in to comment.