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
a85aca84
Commit
a85aca84
authored
Jan 25, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Break out binary / indexing logic into separate packages
parent
05364a2a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
7 deletions
+56
-7
main.go
op-chain-ops/cmd/eof-crawler/main.go
+47
-0
README.md
op-chain-ops/eof/README.md
+2
-2
eof_crawler.go
op-chain-ops/eof/eof_crawler.go
+7
-5
No files found.
op-chain-ops/cmd/eof-crawler/main.go
0 → 100644
View file @
a85aca84
package
main
import
(
"errors"
"os"
"github.com/mattn/go-isatty"
"github.com/urfave/cli/v2"
"github.com/ethereum-optimism/optimism/op-chain-ops/eof"
"github.com/ethereum/go-ethereum/log"
)
func
main
()
{
log
.
Root
()
.
SetHandler
(
log
.
StreamHandler
(
os
.
Stderr
,
log
.
TerminalFormat
(
isatty
.
IsTerminal
(
os
.
Stderr
.
Fd
()))))
app
:=
&
cli
.
App
{
Name
:
"eof-crawler"
,
Usage
:
"Scan a Geth database for EOF-prefixed contracts"
,
Flags
:
[]
cli
.
Flag
{
&
cli
.
StringFlag
{
Name
:
"db-path"
,
Usage
:
"Path to the geth LevelDB"
,
},
&
cli
.
StringFlag
{
Name
:
"out"
,
Value
:
"eof-contracts.json"
,
Usage
:
"Path to the output file"
,
},
},
Action
:
func
(
ctx
*
cli
.
Context
)
error
{
dbPath
:=
ctx
.
String
(
"db-path"
)
if
len
(
dbPath
)
==
0
{
return
errors
.
New
(
"Must specify a db-path"
)
}
out
:=
ctx
.
String
(
"out"
)
eof
.
IndexEOFContracts
(
dbPath
,
out
)
return
nil
},
}
if
err
:=
app
.
Run
(
os
.
Args
);
err
!=
nil
{
log
.
Crit
(
"error indexing state"
,
"err"
,
err
)
}
}
op-chain-ops/eof
-crawler
/README.md
→
op-chain-ops/eof/README.md
View file @
a85aca84
...
@@ -6,6 +6,6 @@ Simple CLI tool to scan all accounts in a geth LevelDB for contracts that begin
...
@@ -6,6 +6,6 @@ Simple CLI tool to scan all accounts in a geth LevelDB for contracts that begin
1.
Pass the directory of the Geth DB into the tool
1.
Pass the directory of the Geth DB into the tool
```
sh
```
sh
go run
eof_crawler.go <db_path>
go run
./cmd/eof-crawler/main.go
--db-path
<db_path>
[
--out
<out_file>]
```
```
2.
Once the indexing has completed, an array of all EOF-prefixed contracts will be written to
`eof_contracts.json`
.
2.
Once the indexing has completed, an array of all EOF-prefixed contracts will be written to
`eof_contracts.json`
or the designated output file
.
op-chain-ops/eof
-crawler
/eof_crawler.go
→
op-chain-ops/eof/eof_crawler.go
View file @
a85aca84
package
main
package
eof
import
(
import
(
"bytes"
"bytes"
...
@@ -31,9 +31,11 @@ type Account struct {
...
@@ -31,9 +31,11 @@ type Account struct {
// emptyCodeHash is the known hash of an account with no code.
// emptyCodeHash is the known hash of an account with no code.
var
emptyCodeHash
=
crypto
.
Keccak256
(
nil
)
var
emptyCodeHash
=
crypto
.
Keccak256
(
nil
)
func
main
()
{
// IndexEOFContracts indexes all the EOF contracts in the state trie of the head block
// for the given db and writes them to a JSON file.
func
IndexEOFContracts
(
dbPath
string
,
out
string
)
{
// Open an existing Ethereum database
// Open an existing Ethereum database
db
,
err
:=
rawdb
.
NewLevelDBDatabase
(
os
.
Args
[
1
]
,
16
,
16
,
""
,
true
)
db
,
err
:=
rawdb
.
NewLevelDBDatabase
(
dbPath
,
16
,
16
,
""
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalf
(
"Failed to open database: %v"
,
err
)
log
.
Fatalf
(
"Failed to open database: %v"
,
err
)
}
}
...
@@ -126,10 +128,10 @@ func main() {
...
@@ -126,10 +128,10 @@ func main() {
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalf
(
"Cannot marshal EOF contracts: %v"
,
err
)
log
.
Fatalf
(
"Cannot marshal EOF contracts: %v"
,
err
)
}
}
err
=
os
.
WriteFile
(
"eof_contracts.json"
,
file
,
0644
)
err
=
os
.
WriteFile
(
out
,
file
,
0644
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalf
(
"Failed to write EOF contracts array to file: %v"
,
err
)
log
.
Fatalf
(
"Failed to write EOF contracts array to file: %v"
,
err
)
}
}
log
.
Printf
(
"Wrote list of EOF contracts to `
eof_contracts.json`"
)
log
.
Printf
(
"Wrote list of EOF contracts to `
%v`"
,
out
)
}
}
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