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
9ce04745
Unverified
Commit
9ce04745
authored
Mar 30, 2023
by
rjl493456442
Committed by
GitHub
Mar 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: fix json marshaller MixedcaseAddress (#26998)
Fix the json marshaller of MixedcaseAddress
parent
50317bda
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
types.go
common/types.go
+1
-1
types_test.go
common/types_test.go
+26
-1
No files found.
common/types.go
View file @
9ce04745
...
...
@@ -400,7 +400,7 @@ func (ma *MixedcaseAddress) UnmarshalJSON(input []byte) error {
}
// MarshalJSON marshals the original value
func
(
ma
*
MixedcaseAddress
)
MarshalJSON
()
([]
byte
,
error
)
{
func
(
ma
MixedcaseAddress
)
MarshalJSON
()
([]
byte
,
error
)
{
if
strings
.
HasPrefix
(
ma
.
original
,
"0x"
)
||
strings
.
HasPrefix
(
ma
.
original
,
"0X"
)
{
return
json
.
Marshal
(
fmt
.
Sprintf
(
"0x%s"
,
ma
.
original
[
2
:
]))
}
...
...
common/types_test.go
View file @
9ce04745
...
...
@@ -154,6 +154,31 @@ func BenchmarkAddressHex(b *testing.B) {
}
}
// Test checks if the customized json marshaller of MixedcaseAddress object
// is invoked correctly. In golang the struct pointer will inherit the
// non-pointer receiver methods, the reverse is not true. In the case of
// MixedcaseAddress, it must define the MarshalJSON method in the object
// but not the pointer level, so that this customized marshalled can be used
// for both MixedcaseAddress object and pointer.
func
TestMixedcaseAddressMarshal
(
t
*
testing
.
T
)
{
var
(
output
string
input
=
"0xae967917c465db8578ca9024c205720b1a3651A9"
)
addr
,
err
:=
NewMixedcaseAddressFromString
(
input
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
blob
,
err
:=
json
.
Marshal
(
*
addr
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
json
.
Unmarshal
(
blob
,
&
output
)
if
output
!=
input
{
t
.
Fatal
(
"Failed to marshal/unmarshal MixedcaseAddress object"
)
}
}
func
TestMixedcaseAccount_Address
(
t
*
testing
.
T
)
{
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md
// Note: 0X{checksum_addr} is not valid according to spec above
...
...
@@ -177,7 +202,7 @@ func TestMixedcaseAccount_Address(t *testing.T) {
}
}
//These should throw exceptions:
//
These should throw exceptions:
var
r2
[]
MixedcaseAddress
for
_
,
r
:=
range
[]
string
{
`["0x11111111111111111111122222222222233333"]`
,
// Too short
...
...
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