go-ethereum/rpc/api/admin_args.go

491 lines
11 KiB
Go
Raw Normal View History

2015-07-06 19:54:22 -05:00
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
2015-07-06 19:54:22 -05:00
//
// go-ethereum 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,
2015-07-06 19:54:22 -05:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2015-07-06 19:54:22 -05:00
// 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/>.
2015-07-06 19:54:22 -05:00
2015-06-09 09:06:51 -05:00
package api
import (
"encoding/json"
"github.com/ethereum/go-ethereum/common/compiler"
2015-06-09 09:06:51 -05:00
"github.com/ethereum/go-ethereum/rpc/shared"
)
type AddPeerArgs struct {
Url string
}
func (args *AddPeerArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) != 1 {
return shared.NewDecodeParamError("Expected enode as argument")
}
urlstr, ok := obj[0].(string)
if !ok {
return shared.NewInvalidTypeError("url", "not a string")
}
args.Url = urlstr
return nil
}
type ImportExportChainArgs struct {
Filename string
}
func (args *ImportExportChainArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) != 1 {
return shared.NewDecodeParamError("Expected filename as argument")
}
filename, ok := obj[0].(string)
if !ok {
return shared.NewInvalidTypeError("filename", "not a string")
}
args.Filename = filename
return nil
}
type VerbosityArgs struct {
Level int
}
func (args *VerbosityArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) != 1 {
return shared.NewDecodeParamError("Expected enode as argument")
}
2015-06-10 04:29:52 -05:00
level, err := numString(obj[0])
if err == nil {
2015-06-09 09:06:51 -05:00
args.Level = int(level.Int64())
}
return nil
}
type SetSolcArgs struct {
Path string
}
func (args *SetSolcArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) != 1 {
return shared.NewDecodeParamError("Expected path as argument")
}
if pathstr, ok := obj[0].(string); ok {
args.Path = pathstr
return nil
}
return shared.NewInvalidTypeError("path", "not a string")
}
2015-06-22 05:47:32 -05:00
type StartRPCArgs struct {
ListenAddress string
ListenPort uint
CorsDomain string
Apis string
}
func (args *StartRPCArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
args.ListenAddress = "127.0.0.1"
args.ListenPort = 8545
args.Apis = "net,eth,web3"
if len(obj) >= 1 && obj[0] != nil {
2015-06-22 05:47:32 -05:00
if addr, ok := obj[0].(string); ok {
args.ListenAddress = addr
} else {
return shared.NewInvalidTypeError("listenAddress", "not a string")
}
}
if len(obj) >= 2 && obj[1] != nil {
2015-06-22 05:47:32 -05:00
if port, ok := obj[1].(float64); ok && port >= 0 && port <= 64*1024 {
args.ListenPort = uint(port)
} else {
return shared.NewInvalidTypeError("listenPort", "not a valid port number")
}
}
if len(obj) >= 3 && obj[2] != nil {
2015-06-22 05:47:32 -05:00
if corsDomain, ok := obj[2].(string); ok {
args.CorsDomain = corsDomain
} else {
return shared.NewInvalidTypeError("corsDomain", "not a string")
}
}
if len(obj) >= 4 && obj[3] != nil {
2015-06-22 05:47:32 -05:00
if apis, ok := obj[3].(string); ok {
args.Apis = apis
} else {
return shared.NewInvalidTypeError("apis", "not a string")
}
}
return nil
}
2015-07-02 10:38:48 -05:00
type SleepArgs struct {
S int
}
func (args *SleepArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) >= 1 {
if obj[0] != nil {
if n, err := numString(obj[0]); err == nil {
args.S = int(n.Int64())
} else {
return shared.NewInvalidTypeError("N", "not an integer: "+err.Error())
}
} else {
return shared.NewInsufficientParamsError(0, 1)
}
}
return nil
}
type SleepBlocksArgs struct {
N int64
Timeout int64
}
func (args *SleepBlocksArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
args.N = 1
args.Timeout = 0
2015-07-02 10:38:48 -05:00
if len(obj) >= 1 && obj[0] != nil {
if n, err := numString(obj[0]); err == nil {
args.N = n.Int64()
} else {
2015-07-02 10:38:48 -05:00
return shared.NewInvalidTypeError("N", "not an integer: "+err.Error())
}
}
2015-07-02 10:38:48 -05:00
if len(obj) >= 2 && obj[1] != nil {
if n, err := numString(obj[1]); err == nil {
args.Timeout = n.Int64()
} else {
2015-07-02 10:38:48 -05:00
return shared.NewInvalidTypeError("Timeout", "not an integer: "+err.Error())
}
}
return nil
}
type SetGlobalRegistrarArgs struct {
NameReg string
ContractAddress string
}
func (args *SetGlobalRegistrarArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) == 0 {
return shared.NewDecodeParamError("Expected namereg address")
}
if len(obj) >= 1 {
if namereg, ok := obj[0].(string); ok {
args.NameReg = namereg
} else {
return shared.NewInvalidTypeError("NameReg", "not a string")
}
}
if len(obj) >= 2 && obj[1] != nil {
if addr, ok := obj[1].(string); ok {
args.ContractAddress = addr
} else {
return shared.NewInvalidTypeError("ContractAddress", "not a string")
}
}
return nil
}
type SetHashRegArgs struct {
HashReg string
Sender string
}
func (args *SetHashRegArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) >= 1 && obj[0] != nil {
if hashreg, ok := obj[0].(string); ok {
args.HashReg = hashreg
} else {
return shared.NewInvalidTypeError("HashReg", "not a string")
}
}
if len(obj) >= 2 && obj[1] != nil {
if sender, ok := obj[1].(string); ok {
args.Sender = sender
} else {
return shared.NewInvalidTypeError("Sender", "not a string")
}
}
return nil
}
type SetUrlHintArgs struct {
UrlHint string
Sender string
}
func (args *SetUrlHintArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) >= 1 && obj[0] != nil {
if urlhint, ok := obj[0].(string); ok {
args.UrlHint = urlhint
} else {
return shared.NewInvalidTypeError("UrlHint", "not a string")
}
}
if len(obj) >= 2 && obj[1] != nil {
if sender, ok := obj[1].(string); ok {
args.Sender = sender
} else {
return shared.NewInvalidTypeError("Sender", "not a string")
}
}
return nil
}
type SaveInfoArgs struct {
ContractInfo compiler.ContractInfo
Filename string
}
func (args *SaveInfoArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) < 2 {
return shared.NewInsufficientParamsError(len(obj), 2)
}
if jsonraw, err := json.Marshal(obj[0]); err == nil {
if err = json.Unmarshal(jsonraw, &args.ContractInfo); err != nil {
return err
}
} else {
return err
}
if filename, ok := obj[1].(string); ok {
args.Filename = filename
} else {
return shared.NewInvalidTypeError("Filename", "not a string")
}
return nil
}
type RegisterArgs struct {
Sender string
Address string
ContentHashHex string
}
func (args *RegisterArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) < 3 {
return shared.NewInsufficientParamsError(len(obj), 3)
}
if len(obj) >= 1 {
if sender, ok := obj[0].(string); ok {
args.Sender = sender
} else {
return shared.NewInvalidTypeError("Sender", "not a string")
}
}
if len(obj) >= 2 {
if address, ok := obj[1].(string); ok {
args.Address = address
} else {
return shared.NewInvalidTypeError("Address", "not a string")
}
}
if len(obj) >= 3 {
if hex, ok := obj[2].(string); ok {
args.ContentHashHex = hex
} else {
return shared.NewInvalidTypeError("ContentHashHex", "not a string")
}
}
return nil
}
type RegisterUrlArgs struct {
Sender string
ContentHash string
Url string
}
func (args *RegisterUrlArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) >= 1 {
if sender, ok := obj[0].(string); ok {
args.Sender = sender
} else {
return shared.NewInvalidTypeError("Sender", "not a string")
}
}
if len(obj) >= 2 {
if sender, ok := obj[1].(string); ok {
args.ContentHash = sender
} else {
return shared.NewInvalidTypeError("ContentHash", "not a string")
}
}
if len(obj) >= 3 {
if sender, ok := obj[2].(string); ok {
args.Url = sender
} else {
return shared.NewInvalidTypeError("Url", "not a string")
}
}
return nil
}
type GetContractInfoArgs struct {
Contract string
}
func (args *GetContractInfoArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) < 1 {
return shared.NewInsufficientParamsError(len(obj), 1)
}
if len(obj) >= 1 {
if contract, ok := obj[0].(string); ok {
args.Contract = contract
} else {
return shared.NewInvalidTypeError("Contract", "not a string")
}
}
return nil
}
type HttpGetArgs struct {
Uri string
Path string
}
func (args *HttpGetArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
if err := json.Unmarshal(b, &obj); err != nil {
return shared.NewDecodeParamError(err.Error())
}
if len(obj) < 1 {
return shared.NewInsufficientParamsError(len(obj), 1)
}
if len(obj) >= 1 {
if uri, ok := obj[0].(string); ok {
args.Uri = uri
} else {
return shared.NewInvalidTypeError("Uri", "not a string")
}
}
if len(obj) >= 2 && obj[1] != nil {
if path, ok := obj[1].(string); ok {
args.Path = path
} else {
return shared.NewInvalidTypeError("Path", "not a string")
}
}
return nil
}