-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
144c7ed
commit f011fd5
Showing
53 changed files
with
2,848 additions
and
3,837 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/scroll-tech/go-ethereum/ethclient" | ||
"github.com/scroll-tech/go-ethereum/log" | ||
"github.com/urfave/cli/v2" | ||
|
||
"bridge-history-api/config" | ||
"bridge-history-api/crossmessage/controller/eventfetcher" | ||
"bridge-history-api/utils" | ||
) | ||
|
||
var ( | ||
app *cli.App | ||
) | ||
|
||
func init() { | ||
app = cli.NewApp() | ||
|
||
app.Action = action | ||
app.Name = "Scroll Bridge History API" | ||
app.Usage = "The Scroll Bridge Web Backend" | ||
app.Flags = append(app.Flags, utils.CommonFlags...) | ||
app.Commands = []*cli.Command{} | ||
|
||
app.Before = func(ctx *cli.Context) error { | ||
return utils.LogSetup(ctx) | ||
} | ||
} | ||
|
||
func action(ctx *cli.Context) error { | ||
cfgFile := ctx.String(utils.ConfigFileFlag.Name) | ||
cfg, err := config.NewConfig(cfgFile) | ||
if err != nil { | ||
log.Crit("failed to load config file", "config file", cfgFile, "error", err) | ||
} | ||
subCtx, cancel := context.WithCancel(ctx.Context) | ||
defer cancel() | ||
|
||
l1Client, err := ethclient.Dial(cfg.L1.Endpoint) | ||
if err != nil { | ||
log.Crit("failed to connect to L1 geth", "endpoint", cfg.L1.Endpoint, "err", err) | ||
} | ||
|
||
l2Client, err := ethclient.Dial(cfg.L2.Endpoint) | ||
if err != nil { | ||
log.Crit("failed to connect to L2 geth", "endpoint", cfg.L2.Endpoint, "err", err) | ||
} | ||
|
||
db, err := utils.InitDB(cfg.DB) | ||
if err != nil { | ||
log.Crit("failed to init db", "err", err) | ||
} | ||
defer func() { | ||
if deferErr := utils.CloseDB(db); deferErr != nil { | ||
log.Error("failed to close db", "err", err) | ||
} | ||
}() | ||
if err != nil { | ||
log.Crit("failed to connect to db", "config file", cfgFile, "error", err) | ||
} | ||
|
||
l1MessageFetcher, err := eventfetcher.NewL1MessageFetcher(subCtx, cfg.L1, db, l1Client) | ||
if err != nil { | ||
log.Crit("failed to create L1 cross message fetcher", "error", err) | ||
} | ||
go l1MessageFetcher.Start() | ||
|
||
l2MessageFetcher, err := eventfetcher.NewL2MessageFetcher(subCtx, cfg.L2, db, l2Client) | ||
if err != nil { | ||
log.Crit("failed to create L2 cross message fetcher", "error", err) | ||
} | ||
go l2MessageFetcher.Start() | ||
|
||
// Catch CTRL-C to ensure a graceful shutdown. | ||
interrupt := make(chan os.Signal, 1) | ||
signal.Notify(interrupt, os.Interrupt) | ||
|
||
// Wait until the interrupt signal is received from an OS signal. | ||
<-interrupt | ||
|
||
return nil | ||
} | ||
|
||
// Run event watcher cmd instance. | ||
func Run() { | ||
if err := app.Run(os.Args); err != nil { | ||
_, _ = fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "bridge-history-api/cmd/cross_message_fetcher/app" | ||
|
||
func main() { | ||
app.Run() | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.