Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
3b95b924
Unverified
Commit
3b95b924
authored
Jun 08, 2023
by
Will Cory
Committed by
GitHub
Jun 08, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5917 from ethereum-optimism/willc/cli
feat(indexer): Add cli app
parents
513db8f0
ba38b15d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
34 deletions
+113
-34
cli.go
indexer/cli/cli.go
+108
-0
main.go
indexer/cmd/indexer-refresh/main.go
+2
-34
example.env
indexer/example.env
+3
-0
No files found.
indexer/cli/cli.go
0 → 100644
View file @
3b95b924
package
cli
import
(
"fmt"
"os"
"github.com/ethereum-optimism/optimism/indexer/config"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/urfave/cli/v2"
)
type
Cli
struct
{
GitVersion
string
GitCommit
string
GitDate
string
app
*
cli
.
App
Flags
[]
cli
.
Flag
}
func
runIndexer
(
ctx
*
cli
.
Context
)
error
{
configPath
:=
ctx
.
String
(
ConfigFlag
.
Name
)
conf
,
err
:=
config
.
LoadConfig
(
configPath
)
fmt
.
Println
(
conf
)
if
err
!=
nil
{
log
.
Crit
(
"Failed to load config"
,
"message"
,
err
)
}
// finish me
return
nil
}
func
runApi
(
ctx
*
cli
.
Context
)
error
{
configPath
:=
ctx
.
String
(
ConfigFlag
.
Name
)
conf
,
err
:=
config
.
LoadConfig
(
configPath
)
fmt
.
Println
(
conf
)
if
err
!=
nil
{
log
.
Crit
(
"Failed to load config"
,
"message"
,
err
)
}
// finish me
return
nil
}
var
(
ConfigFlag
=
&
cli
.
StringFlag
{
Name
:
"config"
,
Value
:
"./indexer.toml"
,
Aliases
:
[]
string
{
"c"
},
Usage
:
"path to config file"
,
EnvVars
:
[]
string
{
"INDEXER_CONFIG"
},
}
// Not used yet. Use this flag to run legacy app instead
// Remove me after indexer is released
IndexerRefreshFlag
=
&
cli
.
BoolFlag
{
Name
:
"indexer-refresh"
,
Value
:
false
,
Aliases
:
[]
string
{
"i"
},
Usage
:
"run new unreleased indexer by passing in flag"
,
EnvVars
:
[]
string
{
"INDEXER_REFRESH"
},
}
)
// make a instance method on Cli called Run that runs cli
// and returns an error
func
(
c
*
Cli
)
Run
(
args
[]
string
)
error
{
return
c
.
app
.
Run
(
args
)
}
func
NewCli
(
GitVersion
string
,
GitCommit
string
,
GitDate
string
)
*
Cli
{
log
.
Root
()
.
SetHandler
(
log
.
LvlFilterHandler
(
log
.
LvlInfo
,
log
.
StreamHandler
(
os
.
Stdout
,
log
.
TerminalFormat
(
true
)),
),
)
flags
:=
[]
cli
.
Flag
{
ConfigFlag
,
}
app
:=
&
cli
.
App
{
Version
:
fmt
.
Sprintf
(
"%s-%s"
,
GitVersion
,
params
.
VersionWithCommit
(
GitCommit
,
GitDate
)),
Description
:
"An indexer of all optimism events with a serving api layer"
,
Commands
:
[]
*
cli
.
Command
{
{
Name
:
"api"
,
Flags
:
flags
,
Description
:
"Runs the api service"
,
Action
:
runApi
,
},
{
Name
:
"indexer"
,
Flags
:
flags
,
Description
:
"Runs the indexing service"
,
Action
:
runIndexer
,
},
},
}
return
&
Cli
{
app
:
app
,
Flags
:
flags
,
}
}
indexer/cmd/indexer-refresh/main.go
View file @
3b95b924
package
main
package
main
import
(
import
(
"fmt"
"os"
"os"
"github.com/ethereum-optimism/optimism/indexer/cli"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/urfave/cli"
"github.com/ethereum-optimism/optimism/indexer"
"github.com/ethereum-optimism/optimism/indexer/config"
"github.com/ethereum-optimism/optimism/indexer/flags"
)
)
var
(
var
(
...
@@ -20,34 +14,8 @@ var (
...
@@ -20,34 +14,8 @@ var (
)
)
func
main
()
{
func
main
()
{
// Set up logger with a default INFO level in case we fail to parse flags.
app
:=
cli
.
NewCli
(
GitVersion
,
GitCommit
,
GitDate
)
// Otherwise the final crtiical log won't show what the parsing error was.
log
.
Root
()
.
SetHandler
(
log
.
LvlFilterHandler
(
log
.
LvlInfo
,
log
.
StreamHandler
(
os
.
Stdout
,
log
.
TerminalFormat
(
true
)),
),
)
// TODO https://linear.app/optimism/issue/DX-55/api-implement-rest-api-with-mocked-data
// don't hardcode this
conf
,
err
:=
config
.
LoadConfig
(
"../../indexer.toml"
)
if
err
!=
nil
{
log
.
Crit
(
"Failed to load config"
,
"message"
,
err
)
}
log
.
Debug
(
"Loaded config"
,
"config"
,
conf
)
app
:=
cli
.
NewApp
()
app
.
Flags
=
[]
cli
.
Flag
{
flags
.
LogLevelFlag
,
flags
.
L1EthRPCFlag
,
flags
.
L2EthRPCFlag
,
flags
.
DBNameFlag
}
app
.
Version
=
fmt
.
Sprintf
(
"%s-%s"
,
GitVersion
,
params
.
VersionWithCommit
(
GitCommit
,
GitDate
))
app
.
Name
=
"indexer"
app
.
Usage
=
"Indexer Service"
app
.
Description
=
"Service for indexing deposits and withdrawals "
+
"by account on L1 and L2"
app
.
Action
=
indexer
.
Main
(
GitVersion
)
if
err
:=
app
.
Run
(
os
.
Args
);
err
!=
nil
{
if
err
:=
app
.
Run
(
os
.
Args
);
err
!=
nil
{
log
.
Crit
(
"Application failed"
,
"message"
,
err
)
log
.
Crit
(
"Application failed"
,
"message"
,
err
)
}
}
...
...
indexer/example.env
View file @
3b95b924
...
@@ -2,5 +2,8 @@
...
@@ -2,5 +2,8 @@
INDEXER_L1_ETH_RPC=FILL_ME_IN
INDEXER_L1_ETH_RPC=FILL_ME_IN
INDEXER_L2_ETH_RPC=FILL_ME_IN
INDEXER_L2_ETH_RPC=FILL_ME_IN
# temporary env variable to enable to new indexer
INDEXER_REFRESH=1
# Fill in to use prisma studio ui with a db other than the default
# Fill in to use prisma studio ui with a db other than the default
# DATABASE_URL=FILL_ME_IN
# DATABASE_URL=FILL_ME_IN
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment