Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
张蕾
Geth-Modification
Commits
5b792e0f
Unverified
Commit
5b792e0f
authored
May 22, 2023
by
Chawin Aiemvaravutigul
Committed by
GitHub
May 22, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi: add ErrorById (#27277)
Adds `ErrorById` lookup
parent
b46d37ea
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
1 deletion
+40
-1
abi.go
accounts/abi/abi.go
+11
-0
abi_test.go
accounts/abi/abi_test.go
+28
-0
error.go
accounts/abi/error.go
+1
-1
No files found.
accounts/abi/abi.go
View file @
5b792e0f
...
...
@@ -222,6 +222,17 @@ func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
return
nil
,
fmt
.
Errorf
(
"no event with id: %#x"
,
topic
.
Hex
())
}
// ErrorByID looks up an error by the 4-byte id,
// returns nil if none found.
func
(
abi
*
ABI
)
ErrorByID
(
sigdata
[
4
]
byte
)
(
*
Error
,
error
)
{
for
_
,
errABI
:=
range
abi
.
Errors
{
if
bytes
.
Equal
(
errABI
.
ID
[
:
4
],
sigdata
[
:
])
{
return
&
errABI
,
nil
}
}
return
nil
,
fmt
.
Errorf
(
"no error with id: %#x"
,
sigdata
[
:
])
}
// HasFallback returns an indicator whether a fallback function is included.
func
(
abi
*
ABI
)
HasFallback
()
bool
{
return
abi
.
Fallback
.
Type
==
Fallback
...
...
accounts/abi/abi_test.go
View file @
5b792e0f
...
...
@@ -1057,6 +1057,34 @@ func TestABI_EventById(t *testing.T) {
}
}
func
TestABI_ErrorByID
(
t
*
testing
.
T
)
{
abi
,
err
:=
JSON
(
strings
.
NewReader
(
`[
{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"MyError1","type":"error"},
{"inputs":[{"components":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"string","name":"b","type":"string"},{"internalType":"address","name":"c","type":"address"}],"internalType":"struct MyError.MyStruct","name":"x","type":"tuple"},{"internalType":"address","name":"y","type":"address"},{"components":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"string","name":"b","type":"string"},{"internalType":"address","name":"c","type":"address"}],"internalType":"struct MyError.MyStruct","name":"z","type":"tuple"}],"name":"MyError2","type":"error"},
{"inputs":[{"internalType":"uint256[]","name":"x","type":"uint256[]"}],"name":"MyError3","type":"error"}
]`
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
name
,
m
:=
range
abi
.
Errors
{
a
:=
fmt
.
Sprintf
(
"%v"
,
&
m
)
var
id
[
4
]
byte
copy
(
id
[
:
],
m
.
ID
[
:
4
])
m2
,
err
:=
abi
.
ErrorByID
(
id
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to look up ABI error: %v"
,
err
)
}
b
:=
fmt
.
Sprintf
(
"%v"
,
m2
)
if
a
!=
b
{
t
.
Errorf
(
"Error %v (id %x) not 'findable' by id in ABI"
,
name
,
id
)
}
}
// test unsuccessful lookups
if
_
,
err
=
abi
.
ErrorByID
([
4
]
byte
{});
err
==
nil
{
t
.
Error
(
"Expected error: no error with this id"
)
}
}
// TestDoubleDuplicateMethodNames checks that if transfer0 already exists, there won't be a name
// conflict and that the second transfer method will be renamed transfer1.
func
TestDoubleDuplicateMethodNames
(
t
*
testing
.
T
)
{
...
...
accounts/abi/error.go
View file @
5b792e0f
...
...
@@ -78,7 +78,7 @@ func NewError(name string, inputs Arguments) Error {
}
}
func
(
e
*
Error
)
String
()
string
{
func
(
e
Error
)
String
()
string
{
return
e
.
str
}
...
...
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