2015-11-20 12:45:37 +00:00
|
|
|
// 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 (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Argument holds the name of the argument and the corresponding type.
|
|
|
|
// Types are used when packing and testing arguments.
|
|
|
|
type Argument struct {
|
2016-01-27 07:38:53 +00:00
|
|
|
Name string
|
|
|
|
Type Type
|
|
|
|
Indexed bool // indexed is only used by events
|
2015-11-20 12:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Argument) UnmarshalJSON(data []byte) error {
|
|
|
|
var extarg struct {
|
2017-01-05 13:03:50 +00:00
|
|
|
Name string
|
|
|
|
Type string
|
2016-12-22 00:51:20 +00:00
|
|
|
Indexed bool
|
2015-11-20 12:45:37 +00:00
|
|
|
}
|
|
|
|
err := json.Unmarshal(data, &extarg)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("argument json err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
a.Type, err = NewType(extarg.Type)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
a.Name = extarg.Name
|
2016-12-22 00:51:20 +00:00
|
|
|
a.Indexed = extarg.Indexed
|
2015-11-20 12:45:37 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2017-11-10 01:30:26 +00:00
|
|
|
|
|
|
|
func countNonIndexedArguments(args []Argument) int {
|
|
|
|
out := 0
|
|
|
|
for i := range args {
|
|
|
|
if !args[i].Indexed {
|
|
|
|
out++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|