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
ab72803e
Unverified
Commit
ab72803e
authored
May 04, 2020
by
Marius van der Wijden
Committed by
GitHub
May 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi: move U256Bytes to common/math (#21020)
parent
e872083d
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
22 additions
and
48 deletions
+22
-48
abi_test.go
accounts/abi/abi_test.go
+2
-1
template.go
accounts/abi/bind/template.go
+0
-1
numbers.go
accounts/abi/numbers.go
+0
-7
numbers_test.go
accounts/abi/numbers_test.go
+0
-33
pack.go
accounts/abi/pack.go
+3
-3
big.go
common/math/big.go
+6
-0
big_test.go
common/math/big_test.go
+10
-0
oracle.go
contracts/checkpointoracle/contract/oracle.go
+0
-1
signed_data.go
signer/core/signed_data.go
+1
-2
No files found.
accounts/abi/abi_test.go
View file @
ab72803e
...
...
@@ -27,6 +27,7 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
)
...
...
@@ -601,7 +602,7 @@ func TestInputFixedArrayAndVariableInputLength(t *testing.T) {
strvalue
=
common
.
RightPadBytes
([]
byte
(
strin
),
32
)
fixedarrin1value1
=
common
.
LeftPadBytes
(
fixedarrin1
[
0
]
.
Bytes
(),
32
)
fixedarrin1value2
=
common
.
LeftPadBytes
(
fixedarrin1
[
1
]
.
Bytes
(),
32
)
dynarroffset
=
U256
(
big
.
NewInt
(
int64
(
256
+
((
len
(
strin
)
/
32
)
+
1
)
*
32
)))
dynarroffset
=
math
.
U256Bytes
(
big
.
NewInt
(
int64
(
256
+
((
len
(
strin
)
/
32
)
+
1
)
*
32
)))
dynarrlength
=
make
([]
byte
,
32
)
dynarrlength
[
31
]
=
byte
(
len
(
dynarrin
))
dynarrinvalue1
=
common
.
LeftPadBytes
(
dynarrin
[
0
]
.
Bytes
(),
32
)
...
...
accounts/abi/bind/template.go
View file @
ab72803e
...
...
@@ -103,7 +103,6 @@ var (
_ = big.NewInt
_ = strings.NewReader
_ = ethereum.NotFound
_ = abi.U256
_ = bind.Bind
_ = common.Big1
_ = types.BloomLookup
...
...
accounts/abi/numbers.go
View file @
ab72803e
...
...
@@ -21,7 +21,6 @@ import (
"reflect"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
)
var
(
...
...
@@ -37,9 +36,3 @@ var (
int64T
=
reflect
.
TypeOf
(
int64
(
0
))
addressT
=
reflect
.
TypeOf
(
common
.
Address
{})
)
// U256 converts a big Int into a 256bit EVM number.
// This operation is destructive.
func
U256
(
n
*
big
.
Int
)
[]
byte
{
return
math
.
PaddedBigBytes
(
math
.
U256
(
n
),
32
)
}
accounts/abi/numbers_test.go
deleted
100644 → 0
View file @
e872083d
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
abi
import
(
"bytes"
"math/big"
"testing"
)
func
TestNumberTypes
(
t
*
testing
.
T
)
{
ubytes
:=
make
([]
byte
,
32
)
ubytes
[
31
]
=
1
unsigned
:=
U256
(
big
.
NewInt
(
1
))
if
!
bytes
.
Equal
(
unsigned
,
ubytes
)
{
t
.
Errorf
(
"expected %x got %x"
,
ubytes
,
unsigned
)
}
}
accounts/abi/pack.go
View file @
ab72803e
...
...
@@ -69,11 +69,11 @@ func packElement(t Type, reflectValue reflect.Value) []byte {
func
packNum
(
value
reflect
.
Value
)
[]
byte
{
switch
kind
:=
value
.
Kind
();
kind
{
case
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint32
,
reflect
.
Uint64
:
return
U256
(
new
(
big
.
Int
)
.
SetUint64
(
value
.
Uint
()))
return
math
.
U256Bytes
(
new
(
big
.
Int
)
.
SetUint64
(
value
.
Uint
()))
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
return
U256
(
big
.
NewInt
(
value
.
Int
()))
return
math
.
U256Bytes
(
big
.
NewInt
(
value
.
Int
()))
case
reflect
.
Ptr
:
return
U256
(
new
(
big
.
Int
)
.
Set
(
value
.
Interface
()
.
(
*
big
.
Int
)))
return
math
.
U256Bytes
(
new
(
big
.
Int
)
.
Set
(
value
.
Interface
()
.
(
*
big
.
Int
)))
default
:
panic
(
"abi: fatal error"
)
}
...
...
common/math/big.go
View file @
ab72803e
...
...
@@ -184,6 +184,12 @@ func U256(x *big.Int) *big.Int {
return
x
.
And
(
x
,
tt256m1
)
}
// U256Bytes converts a big Int into a 256bit EVM number.
// This operation is destructive.
func
U256Bytes
(
n
*
big
.
Int
)
[]
byte
{
return
PaddedBigBytes
(
U256
(
n
),
32
)
}
// S256 interprets x as a two's complement number.
// x must not exceed 256 bits (the result is undefined if it does) and is not modified.
//
...
...
common/math/big_test.go
View file @
ab72803e
...
...
@@ -212,6 +212,16 @@ func TestU256(t *testing.T) {
}
}
func
TestU256Bytes
(
t
*
testing
.
T
)
{
ubytes
:=
make
([]
byte
,
32
)
ubytes
[
31
]
=
1
unsigned
:=
U256Bytes
(
big
.
NewInt
(
1
))
if
!
bytes
.
Equal
(
unsigned
,
ubytes
)
{
t
.
Errorf
(
"expected %x got %x"
,
ubytes
,
unsigned
)
}
}
func
TestBigEndianByteAt
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
x
string
...
...
contracts/checkpointoracle/contract/oracle.go
View file @
ab72803e
...
...
@@ -20,7 +20,6 @@ var (
_
=
big
.
NewInt
_
=
strings
.
NewReader
_
=
ethereum
.
NotFound
_
=
abi
.
U256
_
=
bind
.
Bind
_
=
common
.
Big1
_
=
types
.
BloomLookup
...
...
signer/core/signed_data.go
View file @
ab72803e
...
...
@@ -31,7 +31,6 @@ import (
"unicode"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
...
...
@@ -587,7 +586,7 @@ func (typedData *TypedData) EncodePrimitiveValue(encType string, encValue interf
if
err
!=
nil
{
return
nil
,
err
}
return
abi
.
U256
(
b
),
nil
return
math
.
U256Bytes
(
b
),
nil
}
return
nil
,
fmt
.
Errorf
(
"unrecognized type '%s'"
,
encType
)
...
...
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