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
bc2a9844
Unverified
Commit
bc2a9844
authored
May 04, 2023
by
OptimismBot
Committed by
GitHub
May 04, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5618 from ethereum-optimism/felipe/rewrite-blockorhash
proxyd/fix: rewrite should support BlockNumberOrHash
parents
ec104d37
1026a46e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
9 deletions
+27
-9
rewriter.go
proxyd/rewriter.go
+15
-9
rewriter_test.go
proxyd/rewriter_test.go
+12
-0
No files found.
proxyd/rewriter.go
View file @
bc2a9844
...
@@ -3,9 +3,9 @@ package proxyd
...
@@ -3,9 +3,9 @@ package proxyd
import
(
import
(
"encoding/json"
"encoding/json"
"errors"
"errors"
"strings"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
)
)
type
RewriteContext
struct
{
type
RewriteContext
struct
{
...
@@ -159,15 +159,21 @@ func rewriteTagMap(rctx RewriteContext, m map[string]interface{}, key string) (b
...
@@ -159,15 +159,21 @@ func rewriteTagMap(rctx RewriteContext, m map[string]interface{}, key string) (b
}
}
func
rewriteTag
(
rctx
RewriteContext
,
current
string
)
(
string
,
bool
,
error
)
{
func
rewriteTag
(
rctx
RewriteContext
,
current
string
)
(
string
,
bool
,
error
)
{
if
current
==
"latest"
{
jv
,
err
:=
json
.
Marshal
(
current
)
return
rctx
.
latest
.
String
(),
true
,
nil
if
err
!=
nil
{
}
else
if
strings
.
HasPrefix
(
current
,
"0x"
)
{
return
""
,
false
,
err
decode
,
err
:=
hexutil
.
DecodeUint64
(
current
)
}
var
bnh
rpc
.
BlockNumberOrHash
err
=
bnh
.
UnmarshalJSON
(
jv
)
if
err
!=
nil
{
if
err
!=
nil
{
return
current
,
false
,
err
return
""
,
false
,
err
}
}
b
:=
hexutil
.
Uint64
(
decode
)
if
b
>
rctx
.
latest
{
if
bnh
.
BlockNumber
!=
nil
&&
*
bnh
.
BlockNumber
==
rpc
.
LatestBlockNumber
{
return
rctx
.
latest
.
String
(),
true
,
nil
}
else
if
bnh
.
BlockNumber
!=
nil
{
if
hexutil
.
Uint64
(
bnh
.
BlockNumber
.
Int64
())
>
rctx
.
latest
{
return
""
,
false
,
ErrRewriteBlockOutOfRange
return
""
,
false
,
ErrRewriteBlockOutOfRange
}
}
}
}
...
...
proxyd/rewriter_test.go
View file @
bc2a9844
...
@@ -334,6 +334,18 @@ func TestRewriteRequest(t *testing.T) {
...
@@ -334,6 +334,18 @@ func TestRewriteRequest(t *testing.T) {
expected
:
RewriteOverrideError
,
expected
:
RewriteOverrideError
,
expectedErr
:
ErrRewriteBlockOutOfRange
,
expectedErr
:
ErrRewriteBlockOutOfRange
,
},
},
{
name
:
"eth_getStorageAt using rpc.BlockNumberOrHash"
,
args
:
args
{
rctx
:
RewriteContext
{
latest
:
hexutil
.
Uint64
(
100
)},
req
:
&
RPCReq
{
Method
:
"eth_getStorageAt"
,
Params
:
mustMarshalJSON
([]
string
{
"0xae851f927ee40de99aabb7461c00f9622ab91d60"
,
"0x65a7ed542fb37fe237fdfbdd70b31598523fe5b32879e307bae27a0bd9581c08"
,
"0x1c4840bcb3de3ac403c0075b46c2c47d4396c5b624b6e1b2874ec04e8879b483"
})},
res
:
nil
,
},
expected
:
RewriteNone
,
},
}
}
// generalize tests for other methods with same interface and behavior
// generalize tests for other methods with same interface and behavior
...
...
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