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
a7e24c93
Unverified
Commit
a7e24c93
authored
Apr 17, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: minimal debug-namespace RPC client bindings
parent
4739b0f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
0 deletions
+79
-0
debug_client.go
op-node/sources/debug_client.go
+49
-0
mock_debug_client.go
op-node/testutils/mock_debug_client.go
+30
-0
No files found.
op-node/sources/debug_client.go
0 → 100644
View file @
a7e24c93
package
sources
import
(
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/rawdb"
)
type
DebugClient
struct
{
callContext
CallContextFn
}
func
NewDebugClient
(
callContext
CallContextFn
)
*
DebugClient
{
return
&
DebugClient
{
callContext
}
}
func
(
o
*
DebugClient
)
NodeByHash
(
ctx
context
.
Context
,
hash
common
.
Hash
)
([]
byte
,
error
)
{
// MPT nodes are stored as the hash of the node (with no prefix)
node
,
err
:=
o
.
dbGet
(
ctx
,
hash
[
:
])
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to retrieve state MPT node: %w"
,
err
)
}
return
node
,
nil
}
func
(
o
*
DebugClient
)
CodeByHash
(
ctx
context
.
Context
,
hash
common
.
Hash
)
([]
byte
,
error
)
{
// First try retrieving with the new code prefix
code
,
err
:=
o
.
dbGet
(
ctx
,
append
(
append
(
make
([]
byte
,
0
),
rawdb
.
CodePrefix
...
),
hash
[
:
]
...
))
if
err
!=
nil
{
// Fallback to the legacy un-prefixed version
code
,
err
=
o
.
dbGet
(
ctx
,
hash
[
:
])
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to retrieve contract code, using new and legacy keys, with codehash %s: %w"
,
hash
,
err
)
}
}
return
code
,
nil
}
func
(
o
*
DebugClient
)
dbGet
(
ctx
context
.
Context
,
key
[]
byte
)
([]
byte
,
error
)
{
var
node
hexutil
.
Bytes
err
:=
o
.
callContext
(
ctx
,
&
node
,
"debug_dbGet"
,
hexutil
.
Encode
(
key
))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"fetch error %x: %w"
,
key
,
err
)
}
return
node
,
nil
}
op-node/testutils/mock_debug_client.go
0 → 100644
View file @
a7e24c93
package
testutils
import
(
"context"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/mock"
)
type
MockDebugClient
struct
{
mock
.
Mock
}
func
(
m
*
MockDebugClient
)
ExpectNodeByHash
(
hash
common
.
Hash
,
res
[]
byte
,
err
error
)
{
m
.
Mock
.
On
(
"NodeByHash"
,
hash
)
.
Once
()
.
Return
(
res
,
&
err
)
}
func
(
m
*
MockDebugClient
)
NodeByHash
(
ctx
context
.
Context
,
hash
common
.
Hash
)
([]
byte
,
error
)
{
out
:=
m
.
Mock
.
MethodCalled
(
"NodeByHash"
,
hash
)
return
out
[
0
]
.
([]
byte
),
*
out
[
1
]
.
(
*
error
)
}
func
(
m
*
MockDebugClient
)
ExpectCodeByHash
(
hash
common
.
Hash
,
res
[]
byte
,
err
error
)
{
m
.
Mock
.
On
(
"CodeByHash"
,
hash
)
.
Once
()
.
Return
(
res
,
&
err
)
}
func
(
m
*
MockDebugClient
)
CodeByHash
(
ctx
context
.
Context
,
hash
common
.
Hash
)
([]
byte
,
error
)
{
out
:=
m
.
Mock
.
MethodCalled
(
"CodeByHash"
,
hash
)
return
out
[
0
]
.
([]
byte
),
*
out
[
1
]
.
(
*
error
)
}
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