mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-18 04:40:03 +02:00
Initial commit
This commit is contained in:
commit
164d0a4153
11 changed files with 662 additions and 0 deletions
62
ship_processor.go
Normal file
62
ship_processor.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"encoding/json"
|
||||
"github.com/eoscanada/eos-go/ship"
|
||||
)
|
||||
|
||||
func processBlock(block *ship.GetBlocksResultV0) {
|
||||
|
||||
if block.ThisBlock.BlockNum % 100 == 0 {
|
||||
log.Printf("Current: %d, Head: %d\n", block.ThisBlock.BlockNum, block.Head.BlockNum)
|
||||
}
|
||||
}
|
||||
|
||||
func processTraces(traces []*ship.TransactionTraceV0) {
|
||||
|
||||
for _, trace := range traces {
|
||||
//log.Println("Trace ID:", trace.ID)
|
||||
|
||||
for _, actionTraceVar := range trace.ActionTraces {
|
||||
trace := actionTraceVar.Impl.(*ship.ActionTraceV0)
|
||||
|
||||
act := ActionTrace{
|
||||
Receiver: trace.Receiver,
|
||||
Contract: trace.Act.Account,
|
||||
Action: trace.Act.Name,
|
||||
}
|
||||
|
||||
abi, err := GetAbi(trace.Act.Account)
|
||||
if err == nil {
|
||||
v, err := DecodeAction(abi, trace.Act.Data, trace.Act.Name)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
act.Data = v
|
||||
} else {
|
||||
log.Printf("Failed to get abi for contract %s: %s\n", trace.Act.Account, err)
|
||||
}
|
||||
|
||||
|
||||
payload, err := json.Marshal(act)
|
||||
if err != nil {
|
||||
log.Println("Failed to encode action:")
|
||||
continue
|
||||
}
|
||||
|
||||
channels := []string{
|
||||
RedisKey("actions"),
|
||||
RedisKey(string(act.Contract), "actions"),
|
||||
RedisKey(string(act.Contract), "actions", string(act.Action)),
|
||||
}
|
||||
|
||||
for _, channel := range channels {
|
||||
if err := RedisPublish(channel, payload).Err(); err != nil {
|
||||
log.Printf("Failed to post to channel '%s': %s", channel, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue