Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream merge up to 1.9.15 #1504

Merged
merged 102 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
46698d7
params: begin v1.9.15 release cycle
karalabe May 13, 2020
677724a
cmd: fix log contexts (#21077)
SatpalSandhu61 May 13, 2020
f3f1e59
accounts/abi: simplify reflection logic (#21058)
MariusVanDerWijden May 13, 2020
3666da8
console: fix unlockAccount argument count check (#21081)
fjl May 14, 2020
e0987f6
cmd/clef, signer/core: password input fixes (#20960)
holiman May 19, 2020
d5b7d1c
accounts: add blockByNumberNoLock() to avoid double-lock (#20983)
BurtonQin May 19, 2020
0a99efa
whisper: use canonical import name of package go-ethereum (#21099)
ucwong May 20, 2020
65ce550
trie: extend range proofs with non-existence (#21000)
rjl493456442 May 20, 2020
b4a2681
les, les/lespay: implement new server pool (#20758)
zsfelfoldi May 22, 2020
48e3b95
miner: replace use of 'self' as receiver name (#21113)
ucwong May 25, 2020
4f2784b
all: fix typos in comments (#21118)
tbm May 25, 2020
25a661e
consensus/clique: remove redundant pair of parentheses (#21104)
yutianwu May 25, 2020
e868add
core/vm: improve jumpdest lookup (#21123)
holiman May 25, 2020
befecc9
consensus/ethash: fix flaky test by reading seal results (#21085)
meowsbits May 25, 2020
dbf6b8a
cmd/utils: fix default DNS discovery configuration (#21124)
fjl May 25, 2020
2f66a8d
metrics/prometheus: define TYPE once, add tests (#21068)
riptl May 26, 2020
7ddb402
ethdb/leveldb: use timer instead of time.After (#21066)
ucwong May 26, 2020
81e9cae
ethstats: avoid blocking chan when received invalid stats request (#2…
duanhao0814 May 26, 2020
070a5e1
trie: fix for range proof (#21107)
rjl493456442 May 26, 2020
4873a9d
build: upgrade to golangci lint v1.27.0 (#21127)
fjl May 26, 2020
9219e0f
eth: interrupt chain insertion on shutdown (#21114)
fjl May 26, 2020
b2c59e2
consensus/clique: make internal error private (#21132)
six-days May 27, 2020
389da6a
trie: enforce monotonic range in prover and return end marker (#21130)
rjl493456442 May 27, 2020
a5eee8d
eth/downloader: more context in errors (#21067)
holiman May 29, 2020
a35382d
metrics: replace gosigar with gopsutil (#21041)
renaynay Jun 2, 2020
cd57d5c
core/vm: EIP-2315, JUMPSUB for the EVM (#20619)
gcolvin Jun 2, 2020
723bd8c
p2p/discover: move discv4 encoding to new 'v4wire' package (#21147)
fjl Jun 2, 2020
d98c42c
rpc: send websocket ping when connection is idle (#21142)
fjl Jun 2, 2020
5f6f5e3
console: handle undefined + null in console funcs (#21160)
gballet Jun 2, 2020
3f649d4
core: collect NewTxsEvent items without holding reorg lock (#21145)
cheng762 Jun 2, 2020
4fc6785
core/vm, crypto/bls12381, params: add bls12-381 elliptic curve precom…
kilic Jun 3, 2020
890757f
cmd, core, params: inital support for yolo-v1 testnet (#21154)
holiman Jun 3, 2020
f52ff0f
cmd/geth: fix the fork orders for DAO tests
karalabe Jun 3, 2020
8b83125
Merge pull request #21162 from karalabe/daofork-order-check-fix
karalabe Jun 3, 2020
469b873
acounts/keystore, cmd/faucet: fix faucet double import, fix twitter url
karalabe Jun 4, 2020
201e345
Merge pull request #21172 from karalabe/faucet-twitter-mobile
karalabe Jun 4, 2020
b1b75f0
accounts/keystore, cmd/faucet: return old account to allow unlock
karalabe Jun 4, 2020
cefa2ab
Merge pull request #21173 from karalabe/faucet-delete-oldaccs
karalabe Jun 4, 2020
4b2ff14
go.mod: upgrade go-duktape to hide unused function warning (#21168)
ucwong Jun 4, 2020
9d93535
node: missing comma on toml tags (#21187)
mcortesi Jun 8, 2020
55f30db
core/vm, crypt/bls12381: fixed comments in bls (#21182)
MariusVanDerWijden Jun 8, 2020
88125d8
core: fix typo in comments (#21181)
evertonfraga Jun 8, 2020
0b3f3be
internal/ethapi: return revert reason for eth_call (#21083)
MariusVanDerWijden Jun 8, 2020
a5c827a
params: update CHTs for 1.9.15 release
karalabe Jun 8, 2020
6512334
Merge pull request #21188 from karalabe/cht-1.9.15
karalabe Jun 8, 2020
0f77f34
params: go-ethereum v1.9.15 stable
fjl Jun 8, 2020
079787f
Merge remote-tracking branch 'origin/master' into hbandura/merge-upst…
hbandura Apr 6, 2021
1bf93b6
Merge commit '46698d7' into hbandura/merge-upstream-1.9.15
hbandura Apr 6, 2021
ca19d07
Merge commit '677724a' into hbandura/merge-upstream-1.9.15
hbandura Apr 6, 2021
3344022
Merge commit 'f3f1e59' into hbandura/merge-upstream-1.9.15
hbandura Apr 6, 2021
9d3a5af
Merge commit '3666da8' into hbandura/merge-upstream-1.9.15
hbandura Apr 6, 2021
ac7aafe
Merge commit 'e0987f6' into hbandura/merge-upstream-1.9.15
hbandura Apr 6, 2021
80092b0
Merge commit 'd5b7d1c' into hbandura/merge-upstream-1.9.15
hbandura Apr 6, 2021
a8cf38e
Merge commit '0a99efa' into hbandura/merge-upstream-1.9.15
hbandura Apr 6, 2021
037cf43
Merge commit '65ce550' into hbandura/merge-upstream-1.9.15
hbandura Apr 6, 2021
67c2eab
Merge commit 'b4a2681' into hbandura/merge-upstream-1.9.15
hbandura Apr 7, 2021
0b0f16f
Merge commit '48e3b95' into hbandura/merge-upstream-1.9.15
hbandura Apr 7, 2021
e2154c6
Merge commit '4f2784b' into hbandura/merge-upstream-1.9.15
hbandura Apr 7, 2021
a445689
Merge commit '25a661e' into hbandura/merge-upstream-1.9.15
hbandura Apr 7, 2021
3117be9
Merge commit 'e868add' into hbandura/merge-upstream-1.9.15
hbandura Apr 7, 2021
90f31b2
Merge commit 'befecc9' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
48e0b7b
Merge commit 'dbf6b8a' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
b965279
Merge commit '2f66a8d' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
761bd2b
Merge commit '7ddb402' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
9da4880
Merge commit '81e9cae' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
fb7e765
Merge commit '070a5e1' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
2455ced
Merge commit '4873a9d' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
c3ff459
Merge commit '9219e0f' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
cee3b2e
Merge commit 'b2c59e2' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
3e4129c
Merge commit '389da6a' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
0c7c07c
Merge branch 'hbandura/merge-upstream-1.9.14' into hbandura/merge-ups…
hbandura Apr 8, 2021
096528d
Merge commit 'a5eee8d' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
68950e7
Merge commit 'a35382d' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
9ff2501
Merge commit 'cd57d5c' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
cdf2571
Merge commit '723bd8c' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
7b74ff3
Merge commit 'd98c42c' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
4b3fc47
Merge commit '5f6f5e3' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
eed8dc5
Merge commit '3f649d4' into hbandura/merge-upstream-1.9.15
hbandura Apr 8, 2021
e851960
Merge commit '4fc6785' into hbandura/merge-upstream-1.9.15
hbandura Apr 9, 2021
3baaf0a
Merge commit '890757f' into hbandura/merge-upstream-1.9.15
hbandura Apr 9, 2021
71343c3
Merge commit 'f52ff0f' into hbandura/merge-upstream-1.9.15
hbandura Apr 9, 2021
3031bf9
Merge commit '8b83125' into hbandura/merge-upstream-1.9.15
hbandura Apr 9, 2021
f0963e6
Merge commit '469b873' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
f77bdca
Merge commit '201e345' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
a2ce8db
Merge commit 'b1b75f0' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
9fcc977
Merge commit 'cefa2ab' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
59c7a6c
Merge commit '4b2ff14' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
37f1220
Merge commit '9d93535' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
2c14d7e
Merge commit '55f30db' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
4c6a5c7
Merge commit '88125d8' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
064a5d5
Merge commit '0b3f3be' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
f277c85
Merge commit 'a5c827a' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
09b73da
Merge commit '6512334' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
ac5acab
Merge commit '0f77f34' into hbandura/merge-upstream-1.9.15
hbandura Apr 12, 2021
2e60b17
Merge remote-tracking branch 'origin/master' into hbandura/merge-upst…
hbandura Apr 14, 2021
9d03427
Update golangci-lint version in circleci yaml config
hbandura Apr 15, 2021
e5b3623
Revert golangci to 1.25
hbandura Apr 15, 2021
6fa5182
Fix lint issues
hbandura Apr 15, 2021
f74fc2a
Fix lint gosec
hbandura Apr 15, 2021
e69d1ef
Add missing counter
hbandura Apr 15, 2021
8e8f023
Remove clientDiscoveredNodesCounter
hbandura Apr 21, 2021
2a37c8e
Merge remote-tracking branch 'origin/master' into hbandura/merge-upst…
hbandura Apr 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file configures github.com/golangci/golangci-lint.

run:
timeout: 2m
timeout: 3m
tests: true
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
Expand Down
138 changes: 22 additions & 116 deletions accounts/abi/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,149 +122,55 @@ func (arguments Arguments) UnpackIntoMap(v map[string]interface{}, data []byte)
return nil
}

// unpack sets the unmarshalled value to go format.
// Note the dst here must be settable.
func unpack(t *Type, dst interface{}, src interface{}) error {
var (
dstVal = reflect.ValueOf(dst).Elem()
srcVal = reflect.ValueOf(src)
)
tuple, typ := false, t
for {
if typ.T == SliceTy || typ.T == ArrayTy {
typ = typ.Elem
continue
}
tuple = typ.T == TupleTy
break
}
if !tuple {
return set(dstVal, srcVal)
}

// Dereferences interface or pointer wrapper
dstVal = indirectInterfaceOrPtr(dstVal)

switch t.T {
case TupleTy:
if dstVal.Kind() != reflect.Struct {
return fmt.Errorf("abi: invalid dst value for unpack, want struct, got %s", dstVal.Kind())
}
fieldmap, err := mapArgNamesToStructFields(t.TupleRawNames, dstVal)
if err != nil {
return err
}
for i, elem := range t.TupleElems {
fname := fieldmap[t.TupleRawNames[i]]
field := dstVal.FieldByName(fname)
if !field.IsValid() {
return fmt.Errorf("abi: field %s can't found in the given value", t.TupleRawNames[i])
}
if err := unpack(elem, field.Addr().Interface(), srcVal.Field(i).Interface()); err != nil {
return err
}
}
return nil
case SliceTy:
if dstVal.Kind() != reflect.Slice {
return fmt.Errorf("abi: invalid dst value for unpack, want slice, got %s", dstVal.Kind())
}
slice := reflect.MakeSlice(dstVal.Type(), srcVal.Len(), srcVal.Len())
for i := 0; i < slice.Len(); i++ {
if err := unpack(t.Elem, slice.Index(i).Addr().Interface(), srcVal.Index(i).Interface()); err != nil {
return err
}
}
dstVal.Set(slice)
case ArrayTy:
if dstVal.Kind() != reflect.Array {
return fmt.Errorf("abi: invalid dst value for unpack, want array, got %s", dstVal.Kind())
}
array := reflect.New(dstVal.Type()).Elem()
for i := 0; i < array.Len(); i++ {
if err := unpack(t.Elem, array.Index(i).Addr().Interface(), srcVal.Index(i).Interface()); err != nil {
return err
}
}
dstVal.Set(array)
}
return nil
}

// unpackAtomic unpacks ( hexdata -> go ) a single value
func (arguments Arguments) unpackAtomic(v interface{}, marshalledValues interface{}) error {
nonIndexedArgs := arguments.NonIndexed()
if len(nonIndexedArgs) == 0 {
return nil
}
argument := nonIndexedArgs[0]
elem := reflect.ValueOf(v).Elem()
dst := reflect.ValueOf(v).Elem()
src := reflect.ValueOf(marshalledValues)

if elem.Kind() == reflect.Struct && argument.Type.T != TupleTy {
fieldmap, err := mapArgNamesToStructFields([]string{argument.Name}, elem)
if err != nil {
return err
}
field := elem.FieldByName(fieldmap[argument.Name])
if !field.IsValid() {
return fmt.Errorf("abi: field %s can't be found in the given value", argument.Name)
}
return unpack(&argument.Type, field.Addr().Interface(), marshalledValues)
if dst.Kind() == reflect.Struct && src.Kind() != reflect.Struct {
return set(dst.Field(0), src)
}
return unpack(&argument.Type, elem.Addr().Interface(), marshalledValues)
return set(dst, src)
}

// unpackTuple unpacks ( hexdata -> go ) a batch of values.
func (arguments Arguments) unpackTuple(v interface{}, marshalledValues []interface{}) error {
var (
value = reflect.ValueOf(v).Elem()
typ = value.Type()
kind = value.Kind()
nonIndexedArgs = arguments.NonIndexed()
)
if err := requireUnpackKind(value, len(nonIndexedArgs), arguments); err != nil {
return err
}
value := reflect.ValueOf(v).Elem()
nonIndexedArgs := arguments.NonIndexed()

// If the interface is a struct, get of abi->struct_field mapping
var abi2struct map[string]string
if kind == reflect.Struct {
switch value.Kind() {
case reflect.Struct:
argNames := make([]string, len(nonIndexedArgs))
for i, arg := range nonIndexedArgs {
argNames[i] = arg.Name
}
var err error
if abi2struct, err = mapArgNamesToStructFields(argNames, value); err != nil {
abi2struct, err := mapArgNamesToStructFields(argNames, value)
if err != nil {
return err
}
}
for i, arg := range nonIndexedArgs {
switch kind {
case reflect.Struct:
for i, arg := range nonIndexedArgs {
field := value.FieldByName(abi2struct[arg.Name])
if !field.IsValid() {
return fmt.Errorf("abi: field %s can't be found in the given value", arg.Name)
}
if err := unpack(&arg.Type, field.Addr().Interface(), marshalledValues[i]); err != nil {
if err := set(field, reflect.ValueOf(marshalledValues[i])); err != nil {
return err
}
case reflect.Slice, reflect.Array:
if value.Len() < i {
return fmt.Errorf("abi: insufficient number of arguments for unpack, want %d, got %d", len(arguments), value.Len())
}
v := value.Index(i)
if err := requireAssignable(v, reflect.ValueOf(marshalledValues[i])); err != nil {
return err
}
if err := unpack(&arg.Type, v.Addr().Interface(), marshalledValues[i]); err != nil {
}
case reflect.Slice, reflect.Array:
if value.Len() < len(marshalledValues) {
return fmt.Errorf("abi: insufficient number of arguments for unpack, want %d, got %d", len(arguments), value.Len())
}
for i := range nonIndexedArgs {
if err := set(value.Index(i), reflect.ValueOf(marshalledValues[i])); err != nil {
return err
}
default:
return fmt.Errorf("abi:[2] cannot unmarshal tuple in to %v", typ)
}
default:
return fmt.Errorf("abi:[2] cannot unmarshal tuple in to %v", value.Type())
}
return nil

}

// UnpackValues can be used to unpack ABI-encoded hexdata according to the ABI-specification,
Expand Down
12 changes: 9 additions & 3 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type SimulatedBackend struct {

mu sync.Mutex
pendingBlock *types.Block // Currently pending block that will be imported on request
pendingState *state.StateDB // Currently pending state that will be the active on on request
pendingState *state.StateDB // Currently pending state that will be the active on request

events *filters.EventSystem // Event system for filtering log events live

Expand Down Expand Up @@ -133,11 +133,11 @@ func (b *SimulatedBackend) stateByBlockNumber(ctx context.Context, blockNumber *
if blockNumber == nil || blockNumber.Cmp(b.blockchain.CurrentBlock().Number()) == 0 {
return b.blockchain.State()
}
block, err := b.BlockByNumber(ctx, blockNumber)
block, err := b.blockByNumberNoLock(ctx, blockNumber)
if err != nil {
return nil, err
}
return b.blockchain.StateAt(block.Hash())
return b.blockchain.StateAt(block.Root())
}

// CodeAt returns the code associated with a certain account in the blockchain.
Expand Down Expand Up @@ -244,6 +244,12 @@ func (b *SimulatedBackend) BlockByNumber(ctx context.Context, number *big.Int) (
b.mu.Lock()
defer b.mu.Unlock()

return b.blockByNumberNoLock(ctx, number)
}

// blockByNumberNoLock retrieves a block from the database by number, caching it
// (associated with its hash) if found without Lock.
func (b *SimulatedBackend) blockByNumberNoLock(ctx context.Context, number *big.Int) (*types.Block, error) {
if number == nil || number.Cmp(b.pendingBlock.Number()) == 0 {
return b.blockchain.CurrentBlock(), nil
}
Expand Down
10 changes: 10 additions & 0 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ func TestSimulatedBackend_NonceAt(t *testing.T) {
if newNonce != nonce+uint64(1) {
t.Errorf("received incorrect nonce. expected 1, got %v", nonce)
}
// create some more blocks
sim.Commit()
// Check that we can get data for an older block/state
newNonce, err = sim.NonceAt(bgCtx, testAddr, big.NewInt(1))
if err != nil {
t.Fatalf("could not get nonce for test addr: %v", err)
}
if newNonce != nonce+uint64(1) {
t.Fatalf("received incorrect nonce. expected 1, got %v", nonce)
}
}

func TestSimulatedBackend_SendTransaction(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type TransactOpts struct {
Nonce *big.Int // Nonce to use for the transaction execution (nil = use pending state)
Signer SignerFn // Method to use for signing the transaction (mandatory)

Value *big.Int // Funds to transfer along along the transaction (nil = 0 = no funds)
Value *big.Int // Funds to transfer along the transaction (nil = 0 = no funds)
GasPrice *big.Int // Gas price to use for the transaction execution (nil = gas price oracle)
FeeCurrency *common.Address // Fee currency to be used for transaction (nil = default currency = Celo Gold)
GatewayFeeRecipient *common.Address // Address to which gateway fees should be paid (nil = no gateway fees are paid)
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type tmplField struct {
SolKind abi.Type // Raw abi type information
}

// tmplStruct is a wrapper around an abi.tuple contains a auto-generated
// tmplStruct is a wrapper around an abi.tuple contains an auto-generated
// struct name.
type tmplStruct struct {
Name string // Auto-generated struct name(before solidity v0.5.11) or raw name.
Expand Down
4 changes: 2 additions & 2 deletions accounts/abi/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,14 @@ func TestEventTupleUnpack(t *testing.T) {
&[]interface{}{common.Address{}, new(big.Int)},
&[]interface{}{},
jsonEventPledge,
"abi: insufficient number of elements in the list/array for unpack, want 3, got 2",
"abi: insufficient number of arguments for unpack, want 3, got 2",
"Can not unpack Pledge event into too short slice",
}, {
pledgeData1,
new(map[string]interface{}),
&[]interface{}{},
jsonEventPledge,
"abi: cannot unmarshal tuple into map[string]interface {}",
"abi:[2] cannot unmarshal tuple in to map[string]interface {}",
"Can not unpack Pledge event into map",
}, {
mixedCaseData1,
Expand Down
73 changes: 46 additions & 27 deletions accounts/abi/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package abi

import (
"errors"
"fmt"
"math/big"
"reflect"
Expand All @@ -32,14 +33,6 @@ func indirect(v reflect.Value) reflect.Value {
return v
}

// indirectInterfaceOrPtr recursively dereferences the value until value is not interface.
func indirectInterfaceOrPtr(v reflect.Value) reflect.Value {
if (v.Kind() == reflect.Interface || v.Kind() == reflect.Ptr) && v.Elem().IsValid() {
return indirect(v.Elem())
}
return v
}

// reflectIntType returns the reflect using the given size and
// unsignedness.
func reflectIntType(unsigned bool, size int) reflect.Type {
Expand Down Expand Up @@ -90,7 +83,11 @@ func set(dst, src reflect.Value) error {
case srcType.AssignableTo(dstType) && dst.CanSet():
dst.Set(src)
case dstType.Kind() == reflect.Slice && srcType.Kind() == reflect.Slice && dst.CanSet():
setSlice(dst, src)
return setSlice(dst, src)
case dstType.Kind() == reflect.Array:
return setArray(dst, src)
case dstType.Kind() == reflect.Struct:
return setStruct(dst, src)
default:
return fmt.Errorf("abi: cannot unmarshal %v in to %v", src.Type(), dst.Type())
}
Expand All @@ -100,33 +97,55 @@ func set(dst, src reflect.Value) error {
// setSlice attempts to assign src to dst when slices are not assignable by default
// e.g. src: [][]byte -> dst: [][15]byte
// setSlice ignores if we cannot copy all of src' elements.
func setSlice(dst, src reflect.Value) {
func setSlice(dst, src reflect.Value) error {
slice := reflect.MakeSlice(dst.Type(), src.Len(), src.Len())
for i := 0; i < src.Len(); i++ {
reflect.Copy(slice.Index(i), src.Index(i))
if src.Index(i).Kind() == reflect.Struct {
if err := set(slice.Index(i), src.Index(i)); err != nil {
return err
}
} else {
// e.g. [][32]uint8 to []common.Hash
if err := set(slice.Index(i), src.Index(i)); err != nil {
return err
}
}
}
if dst.CanSet() {
dst.Set(slice)
return nil
}
dst.Set(slice)
return errors.New("Cannot set slice, destination not settable")
}

// requireAssignable assures that `dest` is a pointer and it's not an interface.
func requireAssignable(dst, src reflect.Value) error {
if dst.Kind() != reflect.Ptr && dst.Kind() != reflect.Interface {
return fmt.Errorf("abi: cannot unmarshal %v into %v", src.Type(), dst.Type())
func setArray(dst, src reflect.Value) error {
array := reflect.New(dst.Type()).Elem()
min := src.Len()
if src.Len() > dst.Len() {
min = dst.Len()
}
return nil
for i := 0; i < min; i++ {
if err := set(array.Index(i), src.Index(i)); err != nil {
return err
}
}
if dst.CanSet() {
dst.Set(array)
return nil
}
return errors.New("Cannot set array, destination not settable")
}

// requireUnpackKind verifies preconditions for unpacking `args` into `kind`
func requireUnpackKind(v reflect.Value, minLength int, args Arguments) error {
switch v.Kind() {
case reflect.Struct:
case reflect.Slice, reflect.Array:
if v.Len() < minLength {
return fmt.Errorf("abi: insufficient number of elements in the list/array for unpack, want %d, got %d",
minLength, v.Len())
func setStruct(dst, src reflect.Value) error {
for i := 0; i < src.NumField(); i++ {
srcField := src.Field(i)
dstField := dst.Field(i)
if !dstField.IsValid() || !srcField.IsValid() {
return fmt.Errorf("Could not find src field: %v value: %v in destination", srcField.Type().Name(), srcField)
}
if err := set(dstField, srcField); err != nil {
return err
}
default:
return fmt.Errorf("abi: cannot unmarshal tuple into %v", v.Type())
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
typ.Elem = &embeddedType
typ.stringKind = embeddedType.stringKind + sliced
} else if len(intz) == 1 {
// is a array
// is an array
typ.T = ArrayTy
typ.Elem = &embeddedType
typ.Size, err = strconv.Atoi(intz[0])
Expand Down
Loading