github.com/jeffallen/go-ethereum@v1.1.4-0.20150910155051-571d3236c49c/rpc/api/admin_args.go (about)

     1  // Copyright 2015 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package api
    18  
    19  import (
    20  	"encoding/json"
    21  
    22  	"github.com/ethereum/go-ethereum/common/compiler"
    23  	"github.com/ethereum/go-ethereum/rpc/shared"
    24  )
    25  
    26  type AddPeerArgs struct {
    27  	Url string
    28  }
    29  
    30  func (args *AddPeerArgs) UnmarshalJSON(b []byte) (err error) {
    31  	var obj []interface{}
    32  	if err := json.Unmarshal(b, &obj); err != nil {
    33  		return shared.NewDecodeParamError(err.Error())
    34  	}
    35  
    36  	if len(obj) != 1 {
    37  		return shared.NewDecodeParamError("Expected enode as argument")
    38  	}
    39  
    40  	urlstr, ok := obj[0].(string)
    41  	if !ok {
    42  		return shared.NewInvalidTypeError("url", "not a string")
    43  	}
    44  	args.Url = urlstr
    45  
    46  	return nil
    47  }
    48  
    49  type ImportExportChainArgs struct {
    50  	Filename string
    51  }
    52  
    53  func (args *ImportExportChainArgs) UnmarshalJSON(b []byte) (err error) {
    54  	var obj []interface{}
    55  	if err := json.Unmarshal(b, &obj); err != nil {
    56  		return shared.NewDecodeParamError(err.Error())
    57  	}
    58  
    59  	if len(obj) != 1 {
    60  		return shared.NewDecodeParamError("Expected filename as argument")
    61  	}
    62  
    63  	filename, ok := obj[0].(string)
    64  	if !ok {
    65  		return shared.NewInvalidTypeError("filename", "not a string")
    66  	}
    67  	args.Filename = filename
    68  
    69  	return nil
    70  }
    71  
    72  type VerbosityArgs struct {
    73  	Level int
    74  }
    75  
    76  func (args *VerbosityArgs) UnmarshalJSON(b []byte) (err error) {
    77  	var obj []interface{}
    78  	if err := json.Unmarshal(b, &obj); err != nil {
    79  		return shared.NewDecodeParamError(err.Error())
    80  	}
    81  
    82  	if len(obj) != 1 {
    83  		return shared.NewDecodeParamError("Expected enode as argument")
    84  	}
    85  
    86  	level, err := numString(obj[0])
    87  	if err == nil {
    88  		args.Level = int(level.Int64())
    89  	}
    90  
    91  	return nil
    92  }
    93  
    94  type SetSolcArgs struct {
    95  	Path string
    96  }
    97  
    98  func (args *SetSolcArgs) UnmarshalJSON(b []byte) (err error) {
    99  	var obj []interface{}
   100  	if err := json.Unmarshal(b, &obj); err != nil {
   101  		return shared.NewDecodeParamError(err.Error())
   102  	}
   103  
   104  	if len(obj) != 1 {
   105  		return shared.NewDecodeParamError("Expected path as argument")
   106  	}
   107  
   108  	if pathstr, ok := obj[0].(string); ok {
   109  		args.Path = pathstr
   110  		return nil
   111  	}
   112  
   113  	return shared.NewInvalidTypeError("path", "not a string")
   114  }
   115  
   116  type StartRPCArgs struct {
   117  	ListenAddress string
   118  	ListenPort    uint
   119  	CorsDomain    string
   120  	Apis          string
   121  }
   122  
   123  func (args *StartRPCArgs) UnmarshalJSON(b []byte) (err error) {
   124  	var obj []interface{}
   125  	if err := json.Unmarshal(b, &obj); err != nil {
   126  		return shared.NewDecodeParamError(err.Error())
   127  	}
   128  
   129  	args.ListenAddress = "127.0.0.1"
   130  	args.ListenPort = 8545
   131  	args.Apis = "net,eth,web3"
   132  
   133  	if len(obj) >= 1 && obj[0] != nil {
   134  		if addr, ok := obj[0].(string); ok {
   135  			args.ListenAddress = addr
   136  		} else {
   137  			return shared.NewInvalidTypeError("listenAddress", "not a string")
   138  		}
   139  	}
   140  
   141  	if len(obj) >= 2 && obj[1] != nil {
   142  		if port, ok := obj[1].(float64); ok && port >= 0 && port <= 64*1024 {
   143  			args.ListenPort = uint(port)
   144  		} else {
   145  			return shared.NewInvalidTypeError("listenPort", "not a valid port number")
   146  		}
   147  	}
   148  
   149  	if len(obj) >= 3 && obj[2] != nil {
   150  		if corsDomain, ok := obj[2].(string); ok {
   151  			args.CorsDomain = corsDomain
   152  		} else {
   153  			return shared.NewInvalidTypeError("corsDomain", "not a string")
   154  		}
   155  	}
   156  
   157  	if len(obj) >= 4 && obj[3] != nil {
   158  		if apis, ok := obj[3].(string); ok {
   159  			args.Apis = apis
   160  		} else {
   161  			return shared.NewInvalidTypeError("apis", "not a string")
   162  		}
   163  	}
   164  
   165  	return nil
   166  }
   167  
   168  type SleepArgs struct {
   169  	S int
   170  }
   171  
   172  func (args *SleepArgs) UnmarshalJSON(b []byte) (err error) {
   173  
   174  	var obj []interface{}
   175  	if err := json.Unmarshal(b, &obj); err != nil {
   176  		return shared.NewDecodeParamError(err.Error())
   177  	}
   178  	if len(obj) >= 1 {
   179  		if obj[0] != nil {
   180  			if n, err := numString(obj[0]); err == nil {
   181  				args.S = int(n.Int64())
   182  			} else {
   183  				return shared.NewInvalidTypeError("N", "not an integer: "+err.Error())
   184  			}
   185  		} else {
   186  			return shared.NewInsufficientParamsError(0, 1)
   187  		}
   188  	}
   189  	return nil
   190  }
   191  
   192  type SleepBlocksArgs struct {
   193  	N       int64
   194  	Timeout int64
   195  }
   196  
   197  func (args *SleepBlocksArgs) UnmarshalJSON(b []byte) (err error) {
   198  
   199  	var obj []interface{}
   200  	if err := json.Unmarshal(b, &obj); err != nil {
   201  		return shared.NewDecodeParamError(err.Error())
   202  	}
   203  
   204  	args.N = 1
   205  	args.Timeout = 0
   206  	if len(obj) >= 1 && obj[0] != nil {
   207  		if n, err := numString(obj[0]); err == nil {
   208  			args.N = n.Int64()
   209  		} else {
   210  			return shared.NewInvalidTypeError("N", "not an integer: "+err.Error())
   211  		}
   212  	}
   213  
   214  	if len(obj) >= 2 && obj[1] != nil {
   215  		if n, err := numString(obj[1]); err == nil {
   216  			args.Timeout = n.Int64()
   217  		} else {
   218  			return shared.NewInvalidTypeError("Timeout", "not an integer: "+err.Error())
   219  		}
   220  	}
   221  
   222  	return nil
   223  }
   224  
   225  type SetGlobalRegistrarArgs struct {
   226  	NameReg         string
   227  	ContractAddress string
   228  }
   229  
   230  func (args *SetGlobalRegistrarArgs) UnmarshalJSON(b []byte) (err error) {
   231  	var obj []interface{}
   232  	if err := json.Unmarshal(b, &obj); err != nil {
   233  		return shared.NewDecodeParamError(err.Error())
   234  	}
   235  
   236  	if len(obj) == 0 {
   237  		return shared.NewDecodeParamError("Expected namereg address")
   238  	}
   239  
   240  	if len(obj) >= 1 {
   241  		if namereg, ok := obj[0].(string); ok {
   242  			args.NameReg = namereg
   243  		} else {
   244  			return shared.NewInvalidTypeError("NameReg", "not a string")
   245  		}
   246  	}
   247  
   248  	if len(obj) >= 2 && obj[1] != nil {
   249  		if addr, ok := obj[1].(string); ok {
   250  			args.ContractAddress = addr
   251  		} else {
   252  			return shared.NewInvalidTypeError("ContractAddress", "not a string")
   253  		}
   254  	}
   255  
   256  	return nil
   257  }
   258  
   259  type SetHashRegArgs struct {
   260  	HashReg string
   261  	Sender  string
   262  }
   263  
   264  func (args *SetHashRegArgs) UnmarshalJSON(b []byte) (err error) {
   265  	var obj []interface{}
   266  	if err := json.Unmarshal(b, &obj); err != nil {
   267  		return shared.NewDecodeParamError(err.Error())
   268  	}
   269  
   270  	if len(obj) >= 1 && obj[0] != nil {
   271  		if hashreg, ok := obj[0].(string); ok {
   272  			args.HashReg = hashreg
   273  		} else {
   274  			return shared.NewInvalidTypeError("HashReg", "not a string")
   275  		}
   276  	}
   277  
   278  	if len(obj) >= 2 && obj[1] != nil {
   279  		if sender, ok := obj[1].(string); ok {
   280  			args.Sender = sender
   281  		} else {
   282  			return shared.NewInvalidTypeError("Sender", "not a string")
   283  		}
   284  	}
   285  
   286  	return nil
   287  }
   288  
   289  type SetUrlHintArgs struct {
   290  	UrlHint string
   291  	Sender  string
   292  }
   293  
   294  func (args *SetUrlHintArgs) UnmarshalJSON(b []byte) (err error) {
   295  	var obj []interface{}
   296  	if err := json.Unmarshal(b, &obj); err != nil {
   297  		return shared.NewDecodeParamError(err.Error())
   298  	}
   299  
   300  	if len(obj) >= 1 && obj[0] != nil {
   301  		if urlhint, ok := obj[0].(string); ok {
   302  			args.UrlHint = urlhint
   303  		} else {
   304  			return shared.NewInvalidTypeError("UrlHint", "not a string")
   305  		}
   306  	}
   307  
   308  	if len(obj) >= 2 && obj[1] != nil {
   309  		if sender, ok := obj[1].(string); ok {
   310  			args.Sender = sender
   311  		} else {
   312  			return shared.NewInvalidTypeError("Sender", "not a string")
   313  		}
   314  	}
   315  
   316  	return nil
   317  }
   318  
   319  type SaveInfoArgs struct {
   320  	ContractInfo compiler.ContractInfo
   321  	Filename     string
   322  }
   323  
   324  func (args *SaveInfoArgs) UnmarshalJSON(b []byte) (err error) {
   325  	var obj []interface{}
   326  	if err := json.Unmarshal(b, &obj); err != nil {
   327  		return shared.NewDecodeParamError(err.Error())
   328  	}
   329  
   330  	if len(obj) < 2 {
   331  		return shared.NewInsufficientParamsError(len(obj), 2)
   332  	}
   333  
   334  	if jsonraw, err := json.Marshal(obj[0]); err == nil {
   335  		if err = json.Unmarshal(jsonraw, &args.ContractInfo); err != nil {
   336  			return err
   337  		}
   338  	} else {
   339  		return err
   340  	}
   341  
   342  	if filename, ok := obj[1].(string); ok {
   343  		args.Filename = filename
   344  	} else {
   345  		return shared.NewInvalidTypeError("Filename", "not a string")
   346  	}
   347  
   348  	return nil
   349  }
   350  
   351  type RegisterArgs struct {
   352  	Sender         string
   353  	Address        string
   354  	ContentHashHex string
   355  }
   356  
   357  func (args *RegisterArgs) UnmarshalJSON(b []byte) (err error) {
   358  	var obj []interface{}
   359  	if err := json.Unmarshal(b, &obj); err != nil {
   360  		return shared.NewDecodeParamError(err.Error())
   361  	}
   362  
   363  	if len(obj) < 3 {
   364  		return shared.NewInsufficientParamsError(len(obj), 3)
   365  	}
   366  
   367  	if len(obj) >= 1 {
   368  		if sender, ok := obj[0].(string); ok {
   369  			args.Sender = sender
   370  		} else {
   371  			return shared.NewInvalidTypeError("Sender", "not a string")
   372  		}
   373  	}
   374  
   375  	if len(obj) >= 2 {
   376  		if address, ok := obj[1].(string); ok {
   377  			args.Address = address
   378  		} else {
   379  			return shared.NewInvalidTypeError("Address", "not a string")
   380  		}
   381  	}
   382  
   383  	if len(obj) >= 3 {
   384  		if hex, ok := obj[2].(string); ok {
   385  			args.ContentHashHex = hex
   386  		} else {
   387  			return shared.NewInvalidTypeError("ContentHashHex", "not a string")
   388  		}
   389  	}
   390  
   391  	return nil
   392  }
   393  
   394  type RegisterUrlArgs struct {
   395  	Sender      string
   396  	ContentHash string
   397  	Url         string
   398  }
   399  
   400  func (args *RegisterUrlArgs) UnmarshalJSON(b []byte) (err error) {
   401  	var obj []interface{}
   402  	if err := json.Unmarshal(b, &obj); err != nil {
   403  		return shared.NewDecodeParamError(err.Error())
   404  	}
   405  
   406  	if len(obj) >= 1 {
   407  		if sender, ok := obj[0].(string); ok {
   408  			args.Sender = sender
   409  		} else {
   410  			return shared.NewInvalidTypeError("Sender", "not a string")
   411  		}
   412  	}
   413  
   414  	if len(obj) >= 2 {
   415  		if sender, ok := obj[1].(string); ok {
   416  			args.ContentHash = sender
   417  		} else {
   418  			return shared.NewInvalidTypeError("ContentHash", "not a string")
   419  		}
   420  	}
   421  
   422  	if len(obj) >= 3 {
   423  		if sender, ok := obj[2].(string); ok {
   424  			args.Url = sender
   425  		} else {
   426  			return shared.NewInvalidTypeError("Url", "not a string")
   427  		}
   428  	}
   429  
   430  	return nil
   431  }
   432  
   433  type GetContractInfoArgs struct {
   434  	Contract string
   435  }
   436  
   437  func (args *GetContractInfoArgs) UnmarshalJSON(b []byte) (err error) {
   438  	var obj []interface{}
   439  	if err := json.Unmarshal(b, &obj); err != nil {
   440  		return shared.NewDecodeParamError(err.Error())
   441  	}
   442  
   443  	if len(obj) < 1 {
   444  		return shared.NewInsufficientParamsError(len(obj), 1)
   445  	}
   446  
   447  	if len(obj) >= 1 {
   448  		if contract, ok := obj[0].(string); ok {
   449  			args.Contract = contract
   450  		} else {
   451  			return shared.NewInvalidTypeError("Contract", "not a string")
   452  		}
   453  	}
   454  
   455  	return nil
   456  }
   457  
   458  type HttpGetArgs struct {
   459  	Uri  string
   460  	Path string
   461  }
   462  
   463  func (args *HttpGetArgs) UnmarshalJSON(b []byte) (err error) {
   464  	var obj []interface{}
   465  	if err := json.Unmarshal(b, &obj); err != nil {
   466  		return shared.NewDecodeParamError(err.Error())
   467  	}
   468  
   469  	if len(obj) < 1 {
   470  		return shared.NewInsufficientParamsError(len(obj), 1)
   471  	}
   472  
   473  	if len(obj) >= 1 {
   474  		if uri, ok := obj[0].(string); ok {
   475  			args.Uri = uri
   476  		} else {
   477  			return shared.NewInvalidTypeError("Uri", "not a string")
   478  		}
   479  	}
   480  
   481  	if len(obj) >= 2 && obj[1] != nil {
   482  		if path, ok := obj[1].(string); ok {
   483  			args.Path = path
   484  		} else {
   485  			return shared.NewInvalidTypeError("Path", "not a string")
   486  		}
   487  	}
   488  
   489  	return nil
   490  }