1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-08-30 20:58:12 +02:00

Formatting fix.

This commit is contained in:
Henrik Hautakoski 2022-11-28 15:25:21 +01:00
parent 953113b456
commit 1e2dda54c8
9 changed files with 440 additions and 448 deletions

13
abi.go
View file

@ -1,15 +1,16 @@
package main
import (
"time"
"encoding/json"
"errors"
"fmt"
"encoding/json"
eos "github.com/eoscanada/eos-go"
redis_cache "github.com/go-redis/cache/v8"
"time"
"eosio-ship-trace-reader/abi_cache"
"eosio-ship-trace-reader/redis"
eos "github.com/eoscanada/eos-go"
redis_cache "github.com/go-redis/cache/v8"
)
var abiCache *abi_cache.Cache
@ -24,7 +25,6 @@ func InitAbiCache(id string) {
}
func GetAbi(account eos.AccountName) (*eos.ABI, error) {
key := string(account)
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) {
var v interface{}
bytes, err := abi.DecodeAction(data, actionName)

View file

@ -1,11 +1,11 @@
package abi_cache
import (
"time"
"context"
redis_cache "github.com/go-redis/cache/v8"
"time"
eos "github.com/eoscanada/eos-go"
redis_cache "github.com/go-redis/cache/v8"
)
type Cache struct {
@ -14,7 +14,7 @@ type Cache struct {
prefix string
}
func New(prefix string, options *redis_cache.Options) (*Cache) {
func New(prefix string, options *redis_cache.Options) *Cache {
return &Cache{
c: redis_cache.New(options),
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) {
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
}
@ -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
}

View file

@ -1,14 +1,14 @@
package abi_cache
import (
"time"
"strings"
"github.com/go-redis/redis/v8"
redis_cache "github.com/go-redis/cache/v8"
eos "github.com/eoscanada/eos-go"
"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/require"
)
@ -74,7 +74,6 @@ var abiString = `
`
func TestGetSet(t *testing.T) {
c := New("abi.cache.test", &redis_cache.Options{
Redis: redis.NewClient(&redis.Options{}),
// Cache 10k keys for 1 minute.
@ -147,7 +146,6 @@ func TestGetSet(t *testing.T) {
}
func TestCacheMiss(t *testing.T) {
c := New("abi.cache.test", &redis_cache.Options{
Redis: redis.NewClient(&redis.Options{}),
// Cache 10k keys for 1 minute.

View file

@ -1,9 +1,8 @@
package config
import (
"io/ioutil"
"encoding/json"
"io/ioutil"
)
const NULL_BLOCK_NUMBER uint32 = 0xffffffff
@ -36,7 +35,6 @@ type Config struct {
}
func Load(filename string) (Config, error) {
cfg := Config{
StartBlockNum: NULL_BLOCK_NUMBER,
EndBlockNum: NULL_BLOCK_NUMBER,

30
main.go
View file

@ -1,20 +1,21 @@
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"context"
"log"
"time"
"github.com/pborman/getopt/v2"
"github.com/eosswedenorg-go/pid"
"eosio-ship-trace-reader/config"
"eosio-ship-trace-reader/redis"
"eosio-ship-trace-reader/telegram"
eos "github.com/eoscanada/eos-go"
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 eosClient *eos.API
var eosClientCtx = context.Background()
var (
eosClient *eos.API
eosClientCtx = context.Background()
)
// Reader states
const RS_CONNECT = 1
const RS_READ = 2
func readerLoop() {
state := RS_CONNECT
var recon_cnt uint = 0
@ -59,7 +60,7 @@ func readerLoop() {
log.Printf("Trying again in 5 seconds ....")
time.Sleep(5 * time.Second)
break;
break
}
err = shClient.SendBlocksRequest()
@ -89,7 +90,6 @@ func readerLoop() {
}
func run() {
// Create done and interrupt channels.
done := make(chan bool)
interrupt := make(chan os.Signal, 1)
@ -121,8 +121,10 @@ func run() {
shClient.SendCloseMessage()
select {
case <-done: log.Println("Closed")
case <-time.After(time.Second * 10): log.Println("Timeout");
case <-done:
log.Println("Closed")
case <-time.After(time.Second * 10):
log.Println("Timeout")
}
return
case <-done:
@ -133,7 +135,6 @@ func run() {
}
func main() {
var err error
showHelp := getopt.BoolLong("help", 'h', "display this help text")
@ -199,7 +200,6 @@ func main() {
redis.Prefix += chainInfo.ChainID.String() + "."
if conf.StartBlockNum == config.NULL_BLOCK_NUMBER {
if conf.IrreversibleOnly {
conf.StartBlockNum = uint32(chainInfo.LastIrreversibleBlockNum)
} else {

View file

@ -1,10 +1,10 @@
package redis
import (
"strings"
"context"
"strings"
"time"
_redis "github.com/go-redis/redis/v8"
)
@ -32,23 +32,23 @@ func Client() *_redis.Client {
return rdb
}
func Key(components ...string) (string) {
func Key(components ...string) string {
return Prefix + strings.Join(components, ".")
}
func Get(key string) (*_redis.StringCmd) {
func Get(key string) *_redis.StringCmd {
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)
}
func Publish(channel string, message interface{}) (*_redis.IntCmd) {
func Publish(channel string, message interface{}) *_redis.IntCmd {
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)
}

View file

@ -1,22 +1,20 @@
package main
import (
"log"
"encoding/json"
"github.com/eoscanada/eos-go/ship"
"log"
"eosio-ship-trace-reader/redis"
"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 {
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)
}
payload, err := json.Marshal(act)
if err != nil {
log.Println("Failed to encode action:", err)

View file

@ -1,17 +1,18 @@
package telegram
import (
"fmt"
_api "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
var _bot *_api.BotAPI
var _channel int64
var _prefix string
func Init(prefix string, id string, channel int64) (error) {
var (
_bot *_api.BotAPI
_channel int64
_prefix string
)
func Init(prefix string, id string, channel int64) error {
var err error
_bot, err = _api.NewBotAPI(id)
@ -22,8 +23,8 @@ func Init(prefix string, id string, channel int64) (error) {
return err
}
func Send(message string) (error) {
func Send(message string) error {
msg := _api.NewMessage(_channel, fmt.Sprintf("%s: %s", _prefix, message))
_, err := _bot.Send(msg);
_, err := _bot.Send(msg)
return err
}

View file

@ -1,4 +1,3 @@
package main
import (