mirror of
https://github.com/eosswedenorg/thalos
synced 2026-08-25 20:08:13 +02:00
Formatting fix.
This commit is contained in:
parent
953113b456
commit
1e2dda54c8
9 changed files with 440 additions and 448 deletions
13
abi.go
13
abi.go
|
|
@ -1,15 +1,16 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"encoding/json"
|
"time"
|
||||||
eos "github.com/eoscanada/eos-go"
|
|
||||||
redis_cache "github.com/go-redis/cache/v8"
|
|
||||||
"eosio-ship-trace-reader/abi_cache"
|
"eosio-ship-trace-reader/abi_cache"
|
||||||
"eosio-ship-trace-reader/redis"
|
"eosio-ship-trace-reader/redis"
|
||||||
|
|
||||||
|
eos "github.com/eoscanada/eos-go"
|
||||||
|
redis_cache "github.com/go-redis/cache/v8"
|
||||||
)
|
)
|
||||||
|
|
||||||
var abiCache *abi_cache.Cache
|
var abiCache *abi_cache.Cache
|
||||||
|
|
@ -24,7 +25,6 @@ func InitAbiCache(id string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAbi(account eos.AccountName) (*eos.ABI, error) {
|
func GetAbi(account eos.AccountName) (*eos.ABI, error) {
|
||||||
|
|
||||||
key := string(account)
|
key := string(account)
|
||||||
|
|
||||||
abi, err := abiCache.Get(key)
|
abi, err := abiCache.Get(key)
|
||||||
|
|
@ -44,7 +44,6 @@ func GetAbi(account eos.AccountName) (*eos.ABI, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DecodeAction(abi *eos.ABI, data []byte, actionName eos.ActionName) (interface{}, error) {
|
func DecodeAction(abi *eos.ABI, data []byte, actionName eos.ActionName) (interface{}, error) {
|
||||||
|
|
||||||
var v interface{}
|
var v interface{}
|
||||||
|
|
||||||
bytes, err := abi.DecodeAction(data, actionName)
|
bytes, err := abi.DecodeAction(data, actionName)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
|
|
||||||
package abi_cache
|
package abi_cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
"context"
|
"context"
|
||||||
redis_cache "github.com/go-redis/cache/v8"
|
"time"
|
||||||
|
|
||||||
eos "github.com/eoscanada/eos-go"
|
eos "github.com/eoscanada/eos-go"
|
||||||
|
redis_cache "github.com/go-redis/cache/v8"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
|
|
@ -14,7 +14,7 @@ type Cache struct {
|
||||||
prefix string
|
prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(prefix string, options *redis_cache.Options) (*Cache) {
|
func New(prefix string, options *redis_cache.Options) *Cache {
|
||||||
return &Cache{
|
return &Cache{
|
||||||
c: redis_cache.New(options),
|
c: redis_cache.New(options),
|
||||||
ctx: context.Background(),
|
ctx: context.Background(),
|
||||||
|
|
@ -24,7 +24,7 @@ func New(prefix string, options *redis_cache.Options) (*Cache) {
|
||||||
|
|
||||||
func (this *Cache) Get(account string) (*eos.ABI, error) {
|
func (this *Cache) Get(account string) (*eos.ABI, error) {
|
||||||
var v eos.ABI
|
var v eos.ABI
|
||||||
err := this.c.Get(this.ctx, this.key(account), &v);
|
err := this.c.Get(this.ctx, this.key(account), &v)
|
||||||
return &v, err
|
return &v, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,6 +37,6 @@ func (this *Cache) Set(account string, abi *eos.ABI, ttl time.Duration) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Cache) key(account string) (string) {
|
func (this *Cache) key(account string) string {
|
||||||
return this.prefix + "." + account
|
return this.prefix + "." + account
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
|
|
||||||
package abi_cache
|
package abi_cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
"strings"
|
"strings"
|
||||||
"github.com/go-redis/redis/v8"
|
|
||||||
redis_cache "github.com/go-redis/cache/v8"
|
|
||||||
eos "github.com/eoscanada/eos-go"
|
|
||||||
|
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
eos "github.com/eoscanada/eos-go"
|
||||||
|
redis_cache "github.com/go-redis/cache/v8"
|
||||||
|
"github.com/go-redis/redis/v8"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
@ -74,7 +74,6 @@ var abiString = `
|
||||||
`
|
`
|
||||||
|
|
||||||
func TestGetSet(t *testing.T) {
|
func TestGetSet(t *testing.T) {
|
||||||
|
|
||||||
c := New("abi.cache.test", &redis_cache.Options{
|
c := New("abi.cache.test", &redis_cache.Options{
|
||||||
Redis: redis.NewClient(&redis.Options{}),
|
Redis: redis.NewClient(&redis.Options{}),
|
||||||
// Cache 10k keys for 1 minute.
|
// Cache 10k keys for 1 minute.
|
||||||
|
|
@ -147,7 +146,6 @@ func TestGetSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCacheMiss(t *testing.T) {
|
func TestCacheMiss(t *testing.T) {
|
||||||
|
|
||||||
c := New("abi.cache.test", &redis_cache.Options{
|
c := New("abi.cache.test", &redis_cache.Options{
|
||||||
Redis: redis.NewClient(&redis.Options{}),
|
Redis: redis.NewClient(&redis.Options{}),
|
||||||
// Cache 10k keys for 1 minute.
|
// Cache 10k keys for 1 minute.
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const NULL_BLOCK_NUMBER uint32 = 0xffffffff
|
const NULL_BLOCK_NUMBER uint32 = 0xffffffff
|
||||||
|
|
@ -36,7 +35,6 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load(filename string) (Config, error) {
|
func Load(filename string) (Config, error) {
|
||||||
|
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
StartBlockNum: NULL_BLOCK_NUMBER,
|
StartBlockNum: NULL_BLOCK_NUMBER,
|
||||||
EndBlockNum: NULL_BLOCK_NUMBER,
|
EndBlockNum: NULL_BLOCK_NUMBER,
|
||||||
|
|
|
||||||
30
main.go
30
main.go
|
|
@ -1,20 +1,21 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"context"
|
|
||||||
"log"
|
|
||||||
"time"
|
"time"
|
||||||
"github.com/pborman/getopt/v2"
|
|
||||||
"github.com/eosswedenorg-go/pid"
|
|
||||||
"eosio-ship-trace-reader/config"
|
"eosio-ship-trace-reader/config"
|
||||||
"eosio-ship-trace-reader/redis"
|
"eosio-ship-trace-reader/redis"
|
||||||
"eosio-ship-trace-reader/telegram"
|
"eosio-ship-trace-reader/telegram"
|
||||||
|
|
||||||
eos "github.com/eoscanada/eos-go"
|
eos "github.com/eoscanada/eos-go"
|
||||||
shipclient "github.com/eosswedenorg-go/eos-ship-client"
|
shipclient "github.com/eosswedenorg-go/eos-ship-client"
|
||||||
|
"github.com/eosswedenorg-go/pid"
|
||||||
|
"github.com/pborman/getopt/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
|
@ -27,16 +28,16 @@ var chainInfo *eos.InfoResp
|
||||||
|
|
||||||
var shClient *shipclient.ShipClient
|
var shClient *shipclient.ShipClient
|
||||||
|
|
||||||
var eosClient *eos.API
|
var (
|
||||||
var eosClientCtx = context.Background()
|
eosClient *eos.API
|
||||||
|
eosClientCtx = context.Background()
|
||||||
|
)
|
||||||
|
|
||||||
// Reader states
|
// Reader states
|
||||||
const RS_CONNECT = 1
|
const RS_CONNECT = 1
|
||||||
const RS_READ = 2
|
const RS_READ = 2
|
||||||
|
|
||||||
func readerLoop() {
|
func readerLoop() {
|
||||||
|
|
||||||
state := RS_CONNECT
|
state := RS_CONNECT
|
||||||
var recon_cnt uint = 0
|
var recon_cnt uint = 0
|
||||||
|
|
||||||
|
|
@ -59,7 +60,7 @@ func readerLoop() {
|
||||||
|
|
||||||
log.Printf("Trying again in 5 seconds ....")
|
log.Printf("Trying again in 5 seconds ....")
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shClient.SendBlocksRequest()
|
err = shClient.SendBlocksRequest()
|
||||||
|
|
@ -89,7 +90,6 @@ func readerLoop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
|
|
||||||
// Create done and interrupt channels.
|
// Create done and interrupt channels.
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
interrupt := make(chan os.Signal, 1)
|
interrupt := make(chan os.Signal, 1)
|
||||||
|
|
@ -121,8 +121,10 @@ func run() {
|
||||||
shClient.SendCloseMessage()
|
shClient.SendCloseMessage()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-done: log.Println("Closed")
|
case <-done:
|
||||||
case <-time.After(time.Second * 10): log.Println("Timeout");
|
log.Println("Closed")
|
||||||
|
case <-time.After(time.Second * 10):
|
||||||
|
log.Println("Timeout")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
case <-done:
|
case <-done:
|
||||||
|
|
@ -133,7 +135,6 @@ func run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
showHelp := getopt.BoolLong("help", 'h', "display this help text")
|
showHelp := getopt.BoolLong("help", 'h', "display this help text")
|
||||||
|
|
@ -199,7 +200,6 @@ func main() {
|
||||||
redis.Prefix += chainInfo.ChainID.String() + "."
|
redis.Prefix += chainInfo.ChainID.String() + "."
|
||||||
|
|
||||||
if conf.StartBlockNum == config.NULL_BLOCK_NUMBER {
|
if conf.StartBlockNum == config.NULL_BLOCK_NUMBER {
|
||||||
|
|
||||||
if conf.IrreversibleOnly {
|
if conf.IrreversibleOnly {
|
||||||
conf.StartBlockNum = uint32(chainInfo.LastIrreversibleBlockNum)
|
conf.StartBlockNum = uint32(chainInfo.LastIrreversibleBlockNum)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
package redis
|
package redis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_redis "github.com/go-redis/redis/v8"
|
_redis "github.com/go-redis/redis/v8"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -32,23 +32,23 @@ func Client() *_redis.Client {
|
||||||
return rdb
|
return rdb
|
||||||
}
|
}
|
||||||
|
|
||||||
func Key(components ...string) (string) {
|
func Key(components ...string) string {
|
||||||
return Prefix + strings.Join(components, ".")
|
return Prefix + strings.Join(components, ".")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Get(key string) (*_redis.StringCmd) {
|
func Get(key string) *_redis.StringCmd {
|
||||||
return rdb.Get(redisCtx, key)
|
return rdb.Get(redisCtx, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Set(key string, value interface{}, expiration time.Duration) (*_redis.StatusCmd) {
|
func Set(key string, value interface{}, expiration time.Duration) *_redis.StatusCmd {
|
||||||
return rdb.Set(redisCtx, key, value, expiration)
|
return rdb.Set(redisCtx, key, value, expiration)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Publish(channel string, message interface{}) (*_redis.IntCmd) {
|
func Publish(channel string, message interface{}) *_redis.IntCmd {
|
||||||
return rdb.Publish(redisCtx, channel, message)
|
return rdb.Publish(redisCtx, channel, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterPublish(channel string, message interface{}) (*_redis.IntCmd) {
|
func RegisterPublish(channel string, message interface{}) *_redis.IntCmd {
|
||||||
return redis_pipe.Publish(redisCtx, channel, message)
|
return redis_pipe.Publish(redisCtx, channel, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,20 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/eoscanada/eos-go/ship"
|
"log"
|
||||||
|
|
||||||
"eosio-ship-trace-reader/redis"
|
"eosio-ship-trace-reader/redis"
|
||||||
|
"github.com/eoscanada/eos-go/ship"
|
||||||
)
|
)
|
||||||
|
|
||||||
func processBlock(block *ship.GetBlocksResultV0) {
|
func processBlock(block *ship.GetBlocksResultV0) {
|
||||||
|
|
||||||
if block.ThisBlock.BlockNum%100 == 0 {
|
if block.ThisBlock.BlockNum%100 == 0 {
|
||||||
log.Printf("Current: %d, Head: %d\n", block.ThisBlock.BlockNum, block.Head.BlockNum)
|
log.Printf("Current: %d, Head: %d\n", block.ThisBlock.BlockNum, block.Head.BlockNum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func processTraces(traces []*ship.TransactionTraceV0) {
|
func processTraces(traces []*ship.TransactionTraceV0) {
|
||||||
|
|
||||||
for _, trace := range traces {
|
for _, trace := range traces {
|
||||||
|
|
||||||
payload, err := json.Marshal(trace)
|
payload, err := json.Marshal(trace)
|
||||||
|
|
@ -50,7 +48,6 @@ func processTraces(traces []*ship.TransactionTraceV0) {
|
||||||
log.Printf("Failed to get abi for contract %s: %s\n", trace.Act.Account, err)
|
log.Printf("Failed to get abi for contract %s: %s\n", trace.Act.Account, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
payload, err := json.Marshal(act)
|
payload, err := json.Marshal(act)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Failed to encode action:", err)
|
log.Println("Failed to encode action:", err)
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,18 @@
|
||||||
|
|
||||||
package telegram
|
package telegram
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
_api "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
_api "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _bot *_api.BotAPI
|
var (
|
||||||
var _channel int64
|
_bot *_api.BotAPI
|
||||||
var _prefix string
|
_channel int64
|
||||||
|
_prefix string
|
||||||
func Init(prefix string, id string, channel int64) (error) {
|
)
|
||||||
|
|
||||||
|
func Init(prefix string, id string, channel int64) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
_bot, err = _api.NewBotAPI(id)
|
_bot, err = _api.NewBotAPI(id)
|
||||||
|
|
@ -22,8 +23,8 @@ func Init(prefix string, id string, channel int64) (error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Send(message string) (error) {
|
func Send(message string) error {
|
||||||
msg := _api.NewMessage(_channel, fmt.Sprintf("%s: %s", _prefix, message))
|
msg := _api.NewMessage(_channel, fmt.Sprintf("%s: %s", _prefix, message))
|
||||||
_, err := _bot.Send(msg);
|
_, err := _bot.Send(msg)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
types.go
1
types.go
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue