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
cc7866f2
Commit
cc7866f2
authored
Jan 25, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bubble up errors
Lint lint x2
parent
a85aca84
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
12 deletions
+13
-12
main.go
op-chain-ops/cmd/eof-crawler/main.go
+1
-3
eof_crawler.go
op-chain-ops/eof/eof_crawler.go
+12
-9
No files found.
op-chain-ops/cmd/eof-crawler/main.go
View file @
cc7866f2
...
...
@@ -35,9 +35,7 @@ func main() {
}
out
:=
ctx
.
String
(
"out"
)
eof
.
IndexEOFContracts
(
dbPath
,
out
)
return
nil
return
eof
.
IndexEOFContracts
(
dbPath
,
out
)
},
}
...
...
op-chain-ops/eof/eof_crawler.go
View file @
cc7866f2
...
...
@@ -3,6 +3,8 @@ package eof
import
(
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
"os"
"time"
...
...
@@ -33,11 +35,11 @@ var emptyCodeHash = crypto.Keccak256(nil)
// 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
)
{
func
IndexEOFContracts
(
dbPath
string
,
out
string
)
error
{
// Open an existing Ethereum database
db
,
err
:=
rawdb
.
NewLevelDBDatabase
(
dbPath
,
16
,
16
,
""
,
true
)
if
err
!=
nil
{
log
.
Fatalf
(
"Failed to open database: %v
"
,
err
)
return
fmt
.
Errorf
(
"Failed to open database: %w
"
,
err
)
}
stateDB
:=
state
.
NewDatabase
(
db
)
...
...
@@ -45,17 +47,17 @@ func IndexEOFContracts(dbPath string, out string) {
hash
:=
rawdb
.
ReadHeadBlockHash
(
db
)
number
:=
rawdb
.
ReadHeaderNumber
(
db
,
hash
)
if
number
==
nil
{
log
.
Fatalf
(
"Failed to retrieve head block number"
)
return
errors
.
New
(
"Failed to retrieve head block number"
)
}
head
:=
rawdb
.
ReadBlock
(
db
,
hash
,
*
number
)
if
head
==
nil
{
log
.
Fatalf
(
"Failed to retrieve head block"
)
return
errors
.
New
(
"Failed to retrieve head block"
)
}
// Retrieve the state belonging to the head block
st
,
err
:=
trie
.
New
(
trie
.
StateTrieID
(
head
.
Root
()),
trie
.
NewDatabase
(
db
))
if
err
!=
nil
{
log
.
Fatalf
(
"Failed to retrieve account trie: %v
"
,
err
)
return
fmt
.
Errorf
(
"Failed to retrieve state trie: %w
"
,
err
)
}
log
.
Printf
(
"Indexing state trie at head block #%d [0x%x]"
,
*
number
,
hash
)
...
...
@@ -72,7 +74,7 @@ func IndexEOFContracts(dbPath string, out string) {
var
data
types
.
StateAccount
err
:=
rlp
.
DecodeBytes
(
it
.
Value
,
&
data
)
if
err
!=
nil
{
log
.
Fatalf
(
"Failed to decode state account: %v
"
,
err
)
return
fmt
.
Errorf
(
"Failed to decode state account: %w
"
,
err
)
}
// Check to see if the account has any code associated with it before performing
...
...
@@ -103,7 +105,7 @@ func IndexEOFContracts(dbPath string, out string) {
// Attempt to get the code of the account from the trie
code
,
err
:=
stateDB
.
ContractCode
(
crypto
.
Keccak256Hash
(
addrBytes
),
common
.
BytesToHash
(
data
.
CodeHash
))
if
err
!=
nil
{
log
.
Fatalf
(
"Could not load code for account %x: %v
"
,
addr
,
err
)
return
fmt
.
Errorf
(
"Could not load code for account %x: %w
"
,
addr
,
err
)
}
// Check if the contract's runtime bytecode starts with the EOF prefix.
...
...
@@ -126,12 +128,13 @@ func IndexEOFContracts(dbPath string, out string) {
// Write the EOF contracts to a file
file
,
err
:=
json
.
MarshalIndent
(
eofContracts
,
""
,
" "
)
if
err
!=
nil
{
log
.
Fatalf
(
"Cannot marshal EOF contracts: %v
"
,
err
)
return
fmt
.
Errorf
(
"Cannot marshal EOF contracts: %w
"
,
err
)
}
err
=
os
.
WriteFile
(
out
,
file
,
0644
)
if
err
!=
nil
{
log
.
Fatalf
(
"Failed to write EOF contracts array to file: %v
"
,
err
)
return
fmt
.
Errorf
(
"Failed to write EOF contracts array to file: %w
"
,
err
)
}
log
.
Printf
(
"Wrote list of EOF contracts to `%v`"
,
out
)
return
nil
}
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