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
e593aa62
Commit
e593aa62
authored
May 04, 2023
by
Felipe Andrade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite should support blockorhash
parent
81e93a33
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
10 deletions
+27
-10
rewriter.go
proxyd/rewriter.go
+15
-10
rewriter_test.go
proxyd/rewriter_test.go
+12
-0
No files found.
proxyd/rewriter.go
View file @
e593aa62
...
...
@@ -3,9 +3,8 @@ package proxyd
import
(
"encoding/json"
"errors"
"strings"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
)
type
RewriteContext
struct
{
...
...
@@ -159,15 +158,21 @@ func rewriteTagMap(rctx RewriteContext, m map[string]interface{}, key string) (b
}
func
rewriteTag
(
rctx
RewriteContext
,
current
string
)
(
string
,
bool
,
error
)
{
if
current
==
"latest"
{
jv
,
err
:=
json
.
Marshal
(
current
)
if
err
!=
nil
{
return
""
,
false
,
err
}
var
bnh
rpc
.
BlockNumberOrHash
err
=
bnh
.
UnmarshalJSON
(
jv
)
if
err
!=
nil
{
return
""
,
false
,
err
}
if
bnh
.
BlockNumber
!=
nil
&&
*
bnh
.
BlockNumber
==
rpc
.
LatestBlockNumber
{
return
rctx
.
latest
.
String
(),
true
,
nil
}
else
if
strings
.
HasPrefix
(
current
,
"0x"
)
{
decode
,
err
:=
hexutil
.
DecodeUint64
(
current
)
if
err
!=
nil
{
return
current
,
false
,
err
}
b
:=
hexutil
.
Uint64
(
decode
)
if
b
>
rctx
.
latest
{
}
else
if
bnh
.
BlockNumber
!=
nil
{
if
hexutil
.
Uint64
(
bnh
.
BlockNumber
.
Int64
())
>
rctx
.
latest
{
return
""
,
false
,
ErrRewriteBlockOutOfRange
}
}
...
...
proxyd/rewriter_test.go
View file @
e593aa62
...
...
@@ -334,6 +334,18 @@ func TestRewriteRequest(t *testing.T) {
expected
:
RewriteOverrideError
,
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
...
...
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