Skip to content

Commit

Permalink
Merge pull request #11 from tokamak-network/refactor-code
Browse files Browse the repository at this point in the history
Refactor code
  • Loading branch information
0x6e616d authored Aug 8, 2024
2 parents 54fd320 + bd527db commit e87ec07
Show file tree
Hide file tree
Showing 30 changed files with 2,735 additions and 878 deletions.
48 changes: 20 additions & 28 deletions cmd/app/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (

const (
NetworkFlagName = "network"
L1RpcUrlFlagName = "l1-rpc"
L1WsRpcUrlFlagName = "l1-ws-rpc"
L2RpcUrlFlagName = "l2-rpc"
L2WsRpcUrlFlagName = "l2-ws-rpc"
L1StandardBridgeFlagName = "l1-standard-bridge-address"
L2StandardBridgeFlagName = "l2-standard-bridge-address"
Expand All @@ -18,8 +16,9 @@ const (
SlackUrlFlagName = "slack-url"
L1ExplorerUrlFlagName = "l1-explorer-url"
L2ExplorerUrlFlagName = "l2-explorer-url"
OffFlagName = "slack-on-off"
TokenAddressesFlagName = "token-addresses"
L1TokenAddresses = "l1-token-addresses"
L2TokenAddresses = "l2-token-addresses"
RedisAddressFlagName = "redis-address"
)

var (
Expand All @@ -28,24 +27,12 @@ var (
Usage: "Network name",
EnvVars: []string{"NETWORK"},
}
L1RpcFlag = &cli.StringFlag{
Name: L1RpcUrlFlagName,
Usage: "L1 RPC url",
Value: "http://localhost:8545",
EnvVars: []string{"L1_RPC"},
}
L1WsRpcFlag = &cli.StringFlag{
Name: L1WsRpcUrlFlagName,
Usage: "L1 RPC url",
Value: "ws://localhost:8546",
EnvVars: []string{"L1_WS_RPC"},
}
L2RPCFlag = &cli.StringFlag{
Name: L2RpcUrlFlagName,
Usage: "L2 RPC url",
Value: "http://localhost:9545",
EnvVars: []string{"L2_RPC"},
}
L2WsRpcFlag = &cli.StringFlag{
Name: L2WsRpcUrlFlagName,
Usage: "L2 Ws RPC url",
Expand Down Expand Up @@ -88,24 +75,28 @@ var (
Usage: "L2 explorer url",
EnvVars: []string{"L2_EXPLORER_URL"},
}
OffFlag = &cli.BoolFlag{
Name: OffFlagName,
Usage: "Slack active",
EnvVars: []string{"OFF"},
L1TokenAddressesFlag = &cli.StringSliceFlag{
Name: L1TokenAddresses,
Usage: "List of L1 tokens address to get symbol and decimals",
EnvVars: []string{"L1_TOKEN_ADDRESSES"},
}
L2TokenAddressesFlag = &cli.StringSliceFlag{
Name: L2TokenAddresses,
Usage: "List of L2 tokens address to get symbol and decimals",
EnvVars: []string{"L2_TOKEN_ADDRESSES"},
}
TokenAddressesFlag = &cli.StringSliceFlag{
Name: TokenAddressesFlagName,
Usage: "List of addresses to get symbol and decimals",
EnvVars: []string{"TOKEN_ADDRESSES"},
RedisAddressFlag = &cli.StringFlag{
Name: RedisAddressFlagName,
EnvVars: []string{
"REDIS_ADDRESS",
},
}
)

func Flags() []cli.Flag {
return []cli.Flag{
NetworkFlag,
L1RpcFlag,
L1WsRpcFlag,
L2RPCFlag,
L2WsRpcFlag,
L1StandardBridgeFlag,
L2StandardBridgeFlag,
Expand All @@ -114,7 +105,8 @@ func Flags() []cli.Flag {
SlackUrlFlag,
L1ExplorerUrlFlag,
L2ExplorerUrlFlag,
OffFlag,
TokenAddressesFlag,
L1TokenAddressesFlag,
L2TokenAddressesFlag,
RedisAddressFlag,
}
}
28 changes: 19 additions & 9 deletions cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"os"

"github.com/urfave/cli/v2"

"github.com/tokamak-network/tokamak-thanos-event-listener/cmd/app/flags"
thanosnotif "github.com/tokamak-network/tokamak-thanos-event-listener/internal/app/thanos-notif"
"github.com/tokamak-network/tokamak-thanos-event-listener/internal/pkg/redis"
"github.com/tokamak-network/tokamak-thanos-event-listener/pkg/log"

"github.com/urfave/cli/v2"
)

func main() {
Expand All @@ -24,7 +25,7 @@ func main() {
},
}
if err := app.Run(os.Args); err != nil {
log.GetLogger().Fatalw("Failed to start the application", "err", err)
log.GetLogger().Fatalw("Failed to start the application", "error", err)
}
}

Expand All @@ -33,9 +34,7 @@ func startListener(ctx *cli.Context) error {

config := &thanosnotif.Config{
Network: ctx.String(flags.NetworkFlagName),
L1Rpc: ctx.String(flags.L1RpcUrlFlagName),
L1WsRpc: ctx.String(flags.L1WsRpcUrlFlagName),
L2Rpc: ctx.String(flags.L2RpcUrlFlagName),
L2WsRpc: ctx.String(flags.L2WsRpcUrlFlagName),
L1StandardBridge: ctx.String(flags.L1StandardBridgeFlagName),
L2StandardBridge: ctx.String(flags.L2StandardBridgeFlagName),
Expand All @@ -44,13 +43,24 @@ func startListener(ctx *cli.Context) error {
SlackURL: ctx.String(flags.SlackUrlFlagName),
L1ExplorerUrl: ctx.String(flags.L1ExplorerUrlFlagName),
L2ExplorerUrl: ctx.String(flags.L2ExplorerUrlFlagName),
OFF: ctx.Bool(flags.OffFlagName),
TokenAddresses: ctx.StringSlice(flags.TokenAddressesFlagName),
L1TokenAddresses: ctx.StringSlice(flags.L1TokenAddresses),
L2TokenAddresses: ctx.StringSlice(flags.L2TokenAddresses),
RedisConfig: redis.Config{
Addresses: ctx.String(flags.RedisAddressFlagName),
},
}

if err := config.Validate(); err != nil {
log.GetLogger().Fatalw("Failed to start the application", "error", err)
}

log.GetLogger().Infow("Set up configuration", "config", config)

app := thanosnotif.New(config)
app, err := thanosnotif.New(ctx.Context, config)
if err != nil {
log.GetLogger().Errorw("Failed to start the application", "error", err)
return err
}

return app.Start()
return app.Start(ctx.Context)
}
13 changes: 13 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.8'

services:
redis:
image: redis:6
container_name: redis
ports:
- "6379:6379"
volumes:
- redis_data:/data

volumes:
redis_data:
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ require (
github.com/bits-and-blooms/bloom/v3 v3.7.0
github.com/ethereum-optimism/optimism/op-bindings v0.10.14
github.com/ethereum/go-ethereum v1.14.0
github.com/go-redis/redis/v8 v8.11.5
github.com/stretchr/testify v1.8.4
github.com/tokamak-network/tokamak-thanos v0.0.0-20240704090822-2d66a7cf788f
github.com/urfave/cli/v2 v2.27.1
go.uber.org/zap v1.27.0
golang.org/x/sync v0.7.0
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240222155908-ab073f6aa74f // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -29,6 +35,7 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
Expand All @@ -41,7 +48,6 @@ require (
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/tools v0.21.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
Expand Down
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5il
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/ethereum-optimism/optimism/op-bindings v0.10.14 h1:SMMnMdNb1QIhJDyvk7QMUv+crAP4UHHoSYBOASBDIjM=
github.com/ethereum-optimism/optimism/op-bindings v0.10.14/go.mod h1:9ZSUq/rjlzp3uYyBN4sZmhTc3oZgDVqJ4wrUja7vj6c=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240222155908-ab073f6aa74f h1:L2ub0d0iW2Nqwh1r9WxMqebgZf7rU+wHuVCv21uAGx8=
Expand All @@ -69,6 +71,8 @@ github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnR
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand All @@ -77,6 +81,8 @@ github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOW
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8 h1:Ep/joEub9YwcjRY6ND3+Y/w0ncE540RtGatVhtZL0/Q=
github.com/google/gofuzz v1.2.1-0.20220503160820-4a35382e8fc8/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
Expand Down Expand Up @@ -122,8 +128,14 @@ github.com/mitchellh/pointerstructure v1.2.1/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8oh
github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY=
github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU=
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -182,6 +194,8 @@ golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -203,6 +217,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
Loading

0 comments on commit e87ec07

Please sign in to comment.