mirror of
https://github.com/eosswedenorg/thalos
synced 2026-07-03 11:53:41 +02:00
ship_processor.go: move encodeMessage to transport/message/encoding.go
This commit is contained in:
parent
f589f5c0ed
commit
5c5d7e57a9
2 changed files with 21 additions and 14 deletions
|
|
@ -2,12 +2,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"eosio-ship-trace-reader/abi"
|
"eosio-ship-trace-reader/abi"
|
||||||
"eosio-ship-trace-reader/transport"
|
"eosio-ship-trace-reader/transport"
|
||||||
|
"eosio-ship-trace-reader/transport/message"
|
||||||
"github.com/eoscanada/eos-go/ship"
|
"github.com/eoscanada/eos-go/ship"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -17,17 +17,6 @@ type ShipReader struct {
|
||||||
publisher transport.Publisher
|
publisher transport.Publisher
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeMessage(v interface{}) ([]byte, bool) {
|
|
||||||
payload, err := json.Marshal(v)
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).
|
|
||||||
WithField("v", v).
|
|
||||||
Warn("Failed to encode message to json")
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
return payload, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reader *ShipReader) queueMessage(channel transport.ChannelInterface, payload []byte) bool {
|
func (reader *ShipReader) queueMessage(channel transport.ChannelInterface, payload []byte) bool {
|
||||||
key := reader.ns.NewKey(channel)
|
key := reader.ns.NewKey(channel)
|
||||||
err := reader.publisher.Publish(key.String(), payload)
|
err := reader.publisher.Publish(key.String(), payload)
|
||||||
|
|
@ -39,7 +28,7 @@ func (reader *ShipReader) queueMessage(channel transport.ChannelInterface, paylo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reader *ShipReader) encodeQueue(channel transport.ChannelInterface, v interface{}) bool {
|
func (reader *ShipReader) encodeQueue(channel transport.ChannelInterface, v interface{}) bool {
|
||||||
if payload, ok := encodeMessage(v); ok {
|
if payload, ok := message.Encode(v); ok {
|
||||||
if reader.queueMessage(channel, payload) {
|
if reader.queueMessage(channel, payload) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +85,7 @@ func (reader *ShipReader) processTraces(traces []*ship.TransactionTraceV0) {
|
||||||
log.WithError(err).Errorf("Failed to get abi for contract %s", act_trace.Act.Account)
|
log.WithError(err).Errorf("Failed to get abi for contract %s", act_trace.Act.Account)
|
||||||
}
|
}
|
||||||
|
|
||||||
payload, ok := encodeMessage(act)
|
payload, ok := message.Encode(act)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
18
transport/message/encoder.go
Normal file
18
transport/message/encoder.go
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
package message
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Encode(v interface{}) ([]byte, bool) {
|
||||||
|
payload, err := json.Marshal(v)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).
|
||||||
|
WithField("v", v).
|
||||||
|
Warn("Failed to encode message to json")
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
return payload, true
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue