Skip to content

Commit

Permalink
deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouop0 committed Jun 28, 2024
1 parent 12ac8c5 commit 22b6274
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ go.work
go.work.sum
.idea
.DS_Store
deploy/postgres1
deploy/pg-data
mysql1
meili_data
postgres

2 changes: 1 addition & 1 deletion docs/sql/postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ CREATE TABLE IF NOT EXISTS game_claim_data
);
CREATE INDEX if not exists dispute_game_data_index ON game_claim_data (game_contract, data_index);

-- Table structure for game_claim_data
-- Table structure for game_credit
-- ----------------------------
DROP TABLE if exists game_credit;
CREATE TABLE IF NOT EXISTS game_credit
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
Expand Down Expand Up @@ -78,5 +79,6 @@ require (
golang.org/x/tools v0.21.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.5.7 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
Expand Down Expand Up @@ -278,8 +280,11 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
Expand Down
7 changes: 6 additions & 1 deletion internal/blockchain/blockchain.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package blockchain

import (
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
config "github.com/optimism-java/dispute-explorer/internal/types"
Expand All @@ -26,7 +28,10 @@ func init() {
Register(&event.DisputeGameMove{})
Register(&event.DisputeGameResolved{})
cfg := config.GetConfig()
AddContract(cfg.DisputeGameProxyContract)
disputeGameProxys := strings.Split(cfg.DisputeGameProxyContract, ",")
for _, one := range disputeGameProxys {
AddContract(one)
}
}

func Register(event Event) {
Expand Down
14 changes: 9 additions & 5 deletions internal/handler/latestBlockNumber.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package handler

import (
"context"
"time"

"github.com/optimism-java/dispute-explorer/pkg/rpc"
"github.com/pkg/errors"

"github.com/optimism-java/dispute-explorer/internal/svc"
"github.com/optimism-java/dispute-explorer/pkg/log"
)

func LatestBlackNumber(ctx *svc.ServiceContext) {
for {
latest, err := ctx.L1RPC.BlockNumber(context.Background())
blockJSON, err := rpc.HTTPPostJSON("", ctx.Config.L1RPCUrl, "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getBlockByNumber\",\"params\":[\"finalized\", false],\"id\":1}")
if err != nil {
log.Errorf("[Handle.LatestBlackNumber]Syncing latest block number error: %s\n", err)
log.Errorf("[Handler.LatestBlackNumber] Syncing block by number error: %s\n", errors.WithStack(err))
time.Sleep(3 * time.Second)
continue
}
ctx.LatestBlockNumber = int64(latest)
log.Infof("[Handle.LatestBlackNumber] Syncing latest block number: %d \n", latest)
block := rpc.ParseJSONBlock(string(blockJSON))

ctx.LatestBlockNumber = block.Number()
log.Infof("[Handle.LatestBlackNumber] Syncing latest block number: %d \n", block.Number())
time.Sleep(3 * time.Second)
}
}
4 changes: 2 additions & 2 deletions internal/svc/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"gorm.io/driver/postgres"
"gorm.io/driver/mysql"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
Expand All @@ -27,7 +27,7 @@ type ServiceContext struct {
}

func NewServiceContext(ctx context.Context, cfg *types.Config) *ServiceContext {
storage, err := gorm.Open(postgres.Open(cfg.PostgresqlDataSource), &gorm.Config{
storage, err := gorm.Open(mysql.Open(cfg.MySQLDataSource), &gorm.Config{
Logger: logger.Default.LogMode(logger.Error),
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Config struct {
LogLevel string `env:"LOG_LEVEL" envDefault:"info"`
// "console","json"
LogFormat string `env:"LOG_FORMAT" envDefault:"console"`
PostgresqlDataSource string `env:"POSTGRESQL_DATA_SOURCE" envDefault:"host=localhost port=5433 user=postgres password=postgres dbname=dispute_explorer sslmode=disable"`
PostgresqlDataSource string `env:"POSTGRESQL_DATA_SOURCE" envDefault:"host=localhost port=5435 user=postgres password=postgres dbname=dispute_explorer sslmode=disable"`
MySQLDataSource string `env:"MYSQL_DATA_SOURCE" envDefault:"root:root@tcp(127.0.0.1:3366)/dispute_explorer?charset=utf8mb4&parseTime=True&loc=Local&multiStatements=true"`
MySQLMaxIdleConns int `env:"MYSQL_MAX_IDLE_CONNS" envDefault:"10"`
MySQLMaxOpenConns int `env:"MYSQL_MAX_OPEN_CONNS" envDefault:"20"`
Expand Down

0 comments on commit 22b6274

Please sign in to comment.