mirror of
https://github.com/eosswedenorg/thalos
synced 2026-07-03 11:53:41 +02:00
app/ship_processor.go: Include Blocknum and Timestamp in ActionTrace messages.
This commit is contained in:
parent
ae6f3f11a9
commit
4ec78c38df
1 changed files with 68 additions and 65 deletions
|
|
@ -43,7 +43,9 @@ func SpawnProccessor(shipStream *shipclient.Stream, writer api.Writer, abi *abi.
|
||||||
|
|
||||||
// Attach handlers
|
// Attach handlers
|
||||||
shipStream.BlockHandler = processor.processBlock
|
shipStream.BlockHandler = processor.processBlock
|
||||||
shipStream.TraceHandler = processor.processTraces
|
|
||||||
|
// Needed because if nil, traces will not be included in the response from ship.
|
||||||
|
shipStream.TraceHandler = func([]*ship.TransactionTraceV0) {}
|
||||||
|
|
||||||
return processor
|
return processor
|
||||||
}
|
}
|
||||||
|
|
@ -77,83 +79,81 @@ func (processor *ShipProcessor) processBlock(block *ship.GetBlocksResultV0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
processor.encodeQueue(api.HeartbeatChannel, hb)
|
processor.encodeQueue(api.HeartbeatChannel, hb)
|
||||||
|
|
||||||
err := processor.writer.Flush()
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Error("Failed to send messages")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (processor *ShipProcessor) processTraces(traces []*ship.TransactionTraceV0) {
|
// Process traces
|
||||||
for _, trace := range traces {
|
if block.Traces != nil && len(block.Traces.Elem) > 0 {
|
||||||
|
for _, trace := range block.Traces.AsTransactionTracesV0() {
|
||||||
|
|
||||||
processor.encodeQueue(api.TransactionChannel, trace)
|
processor.encodeQueue(api.TransactionChannel, trace)
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
for _, actionTraceVar := range trace.ActionTraces {
|
for _, actionTraceVar := range trace.ActionTraces {
|
||||||
var act_trace *ship.ActionTraceV1
|
var act_trace *ship.ActionTraceV1
|
||||||
|
|
||||||
if trace_v0, ok := actionTraceVar.Impl.(*ship.ActionTraceV0); ok {
|
if trace_v0, ok := actionTraceVar.Impl.(*ship.ActionTraceV0); ok {
|
||||||
// convert to v1
|
// convert to v1
|
||||||
act_trace = &ship.ActionTraceV1{
|
act_trace = &ship.ActionTraceV1{
|
||||||
ActionOrdinal: trace_v0.ActionOrdinal,
|
ActionOrdinal: trace_v0.ActionOrdinal,
|
||||||
CreatorActionOrdinal: trace_v0.CreatorActionOrdinal,
|
CreatorActionOrdinal: trace_v0.CreatorActionOrdinal,
|
||||||
Receipt: trace_v0.Receipt,
|
Receipt: trace_v0.Receipt,
|
||||||
Receiver: trace_v0.Receiver,
|
Receiver: trace_v0.Receiver,
|
||||||
Act: trace_v0.Act,
|
Act: trace_v0.Act,
|
||||||
ContextFree: trace_v0.ContextFree,
|
ContextFree: trace_v0.ContextFree,
|
||||||
Elapsed: trace_v0.Elapsed,
|
Elapsed: trace_v0.Elapsed,
|
||||||
Console: trace_v0.Console,
|
Console: trace_v0.Console,
|
||||||
AccountRamDeltas: trace_v0.AccountRamDeltas,
|
AccountRamDeltas: trace_v0.AccountRamDeltas,
|
||||||
Except: trace_v0.Except,
|
Except: trace_v0.Except,
|
||||||
ErrorCode: trace_v0.ErrorCode,
|
ErrorCode: trace_v0.ErrorCode,
|
||||||
ReturnValue: []byte{},
|
ReturnValue: []byte{},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
act_trace = actionTraceVar.Impl.(*ship.ActionTraceV1)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
act_trace = actionTraceVar.Impl.(*ship.ActionTraceV1)
|
|
||||||
}
|
|
||||||
|
|
||||||
act := message.ActionTrace{
|
act := message.ActionTrace{
|
||||||
TxID: trace.ID.String(),
|
TxID: trace.ID.String(),
|
||||||
Name: act_trace.Act.Name.String(),
|
BlockNum: block.Block.BlockNumber(),
|
||||||
Contract: act_trace.Act.Account.String(),
|
Timestamp: block.Block.Timestamp.Time.UTC(),
|
||||||
Receiver: act_trace.Receiver.String(),
|
Name: act_trace.Act.Name.String(),
|
||||||
HexData: hex.EncodeToString(act_trace.Act.Data),
|
Contract: act_trace.Act.Account.String(),
|
||||||
}
|
Receiver: act_trace.Receiver.String(),
|
||||||
|
HexData: hex.EncodeToString(act_trace.Act.Data),
|
||||||
|
}
|
||||||
|
|
||||||
for _, auth := range act_trace.Act.Authorization {
|
for _, auth := range act_trace.Act.Authorization {
|
||||||
act.Authorization = append(act.Authorization, message.PermissionLevel{
|
act.Authorization = append(act.Authorization, message.PermissionLevel{
|
||||||
Actor: auth.Actor.String(),
|
Actor: auth.Actor.String(),
|
||||||
Permission: auth.Permission.String(),
|
Permission: auth.Permission.String(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
ABI, err := processor.abi.GetAbi(act_trace.Act.Account)
|
ABI, err := processor.abi.GetAbi(act_trace.Act.Account)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
data, err := ABI.DecodeAction(act_trace.Act.Data, act_trace.Act.Name)
|
data, err := ABI.DecodeAction(act_trace.Act.Data, act_trace.Act.Name)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Warn("Failed to decode action")
|
||||||
|
}
|
||||||
|
act.Data = data
|
||||||
|
} else {
|
||||||
|
log.WithError(err).Errorf("Failed to get abi for contract %s", act_trace.Act.Account)
|
||||||
|
}
|
||||||
|
|
||||||
|
payload, err := processor.encode(act)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Warn("Failed to decode action")
|
continue
|
||||||
}
|
}
|
||||||
act.Data = data
|
|
||||||
} else {
|
|
||||||
log.WithError(err).Errorf("Failed to get abi for contract %s", act_trace.Act.Account)
|
|
||||||
}
|
|
||||||
|
|
||||||
payload, err := processor.encode(act)
|
channels := []api.Channel{
|
||||||
if err != nil {
|
api.ActionChannel{}.Channel(),
|
||||||
continue
|
api.ActionChannel{Name: act.Name}.Channel(),
|
||||||
}
|
api.ActionChannel{Contract: act.Contract}.Channel(),
|
||||||
|
api.ActionChannel{Name: act.Name, Contract: act.Contract}.Channel(),
|
||||||
|
}
|
||||||
|
|
||||||
channels := []api.Channel{
|
for _, channel := range channels {
|
||||||
api.ActionChannel{}.Channel(),
|
processor.queueMessage(channel, payload)
|
||||||
api.ActionChannel{Name: act.Name}.Channel(),
|
}
|
||||||
api.ActionChannel{Contract: act.Contract}.Channel(),
|
|
||||||
api.ActionChannel{Name: act.Name, Contract: act.Contract}.Channel(),
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, channel := range channels {
|
|
||||||
processor.queueMessage(channel, payload)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -164,6 +164,9 @@ func (processor *ShipProcessor) processTraces(traces []*ship.TransactionTraceV0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (processor *ShipProcessor) processTraces([]*ship.TransactionTraceV0) {
|
||||||
|
}
|
||||||
|
|
||||||
func (processor *ShipProcessor) Close() error {
|
func (processor *ShipProcessor) Close() error {
|
||||||
return processor.writer.Close()
|
return processor.writer.Close()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue