| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- package rpc
- import "encoding/json"
- import "github.com/ethereum/go-ethereum/core"
- type GetBlockArgs struct {
- BlockNumber int32
- Hash string
- }
- func (obj *GetBlockArgs) UnmarshalJSON(b []byte) (err error) {
- argint, argstr := int32(0), ""
- if err = json.Unmarshal(b, &argint); err == nil {
- obj.BlockNumber = argint
- return
- }
- if err = json.Unmarshal(b, &argstr); err == nil {
- obj.Hash = argstr
- return
- }
- return NewErrorResponse(ErrorDecodeArgs)
- }
- func (obj *GetBlockArgs) requirements() error {
- if obj.BlockNumber == 0 && obj.Hash == "" {
- return NewErrorResponse("GetBlock requires either a block 'number' or a block 'hash' as argument")
- }
- return nil
- }
- type NewTxArgs struct {
- From string `json:"from"`
- To string `json:"to"`
- Value string `json:"value"`
- Gas string `json:"gas"`
- GasPrice string `json:"gasPrice"`
- Data string `json:"data"`
- }
- func (a *NewTxArgs) requirements() error {
- if a.Gas == "" {
- return NewErrorResponse("Transact requires a 'gas' value as argument")
- }
- if a.GasPrice == "" {
- return NewErrorResponse("Transact requires a 'gasprice' value as argument")
- }
- return nil
- }
- type PushTxArgs struct {
- Tx string `json:"tx"`
- }
- func (obj *PushTxArgs) UnmarshalJSON(b []byte) (err error) {
- arg0 := ""
- if err = json.Unmarshal(b, arg0); err == nil {
- obj.Tx = arg0
- return
- }
- return NewErrorResponse(ErrorDecodeArgs)
- }
- func (a *PushTxArgs) requirementsPushTx() error {
- if a.Tx == "" {
- return NewErrorResponse("PushTx requires a 'tx' as argument")
- }
- return nil
- }
- type GetStorageArgs struct {
- Address string
- }
- func (obj *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
- if err = json.Unmarshal(b, &obj.Address); err != nil {
- return NewErrorResponse(ErrorDecodeArgs)
- }
- return
- }
- func (a *GetStorageArgs) requirements() error {
- if len(a.Address) == 0 {
- return NewErrorResponse("GetStorageAt requires an 'address' value as argument")
- }
- return nil
- }
- type GetStateArgs struct {
- Address string
- Key string
- }
- func (obj *GetStateArgs) UnmarshalJSON(b []byte) (err error) {
- arg0 := ""
- if err = json.Unmarshal(b, arg0); err == nil {
- obj.Address = arg0
- return
- }
- return NewErrorResponse(ErrorDecodeArgs)
- }
- func (a *GetStateArgs) requirements() error {
- if a.Address == "" {
- return NewErrorResponse("GetStorageAt requires an 'address' value as argument")
- }
- if a.Key == "" {
- return NewErrorResponse("GetStorageAt requires an 'key' value as argument")
- }
- return nil
- }
- type GetStorageAtRes struct {
- Key string `json:"key"`
- Value string `json:"value"`
- }
- type GetTxCountArgs struct {
- Address string `json:"address"`
- }
- // type GetTxCountRes struct {
- // Nonce int `json:"nonce"`
- // }
- func (obj *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) {
- arg0 := ""
- if err = json.Unmarshal(b, arg0); err == nil {
- obj.Address = arg0
- return
- }
- return NewErrorResponse("Could not determine JSON parameters")
- }
- func (a *GetTxCountArgs) requirements() error {
- if a.Address == "" {
- return NewErrorResponse("GetTxCountAt requires an 'address' value as argument")
- }
- return nil
- }
- // type GetPeerCountRes struct {
- // PeerCount int `json:"peerCount"`
- // }
- // type GetListeningRes struct {
- // IsListening bool `json:"isListening"`
- // }
- // type GetCoinbaseRes struct {
- // Coinbase string `json:"coinbase"`
- // }
- // type GetMiningRes struct {
- // IsMining bool `json:"isMining"`
- // }
- type GetBalanceArgs struct {
- Address string
- }
- func (obj *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) {
- arg0 := ""
- if err = json.Unmarshal(b, &arg0); err == nil {
- obj.Address = arg0
- return
- }
- return NewErrorResponse("Could not determine JSON parameters")
- }
- func (a *GetBalanceArgs) requirements() error {
- if a.Address == "" {
- return NewErrorResponse("GetBalanceAt requires an 'address' value as argument")
- }
- return nil
- }
- type BalanceRes struct {
- Balance string `json:"balance"`
- Address string `json:"address"`
- }
- type GetCodeAtArgs struct {
- Address string
- }
- func (obj *GetCodeAtArgs) UnmarshalJSON(b []byte) (err error) {
- arg0 := ""
- if err = json.Unmarshal(b, &arg0); err == nil {
- obj.Address = arg0
- return
- }
- return NewErrorResponse(ErrorDecodeArgs)
- }
- func (a *GetCodeAtArgs) requirements() error {
- if a.Address == "" {
- return NewErrorResponse("GetCodeAt requires an 'address' value as argument")
- }
- return nil
- }
- type Sha3Args struct {
- Data string
- }
- func (obj *Sha3Args) UnmarshalJSON(b []byte) (err error) {
- if err = json.Unmarshal(b, &obj.Data); err != nil {
- return NewErrorResponse(ErrorDecodeArgs)
- }
- return
- }
- type FilterOptions struct {
- Earliest int64
- Latest int64
- Address string
- Topics []string
- Skip int
- Max int
- }
- func toFilterOptions(options *FilterOptions) core.FilterOptions {
- var opts core.FilterOptions
- opts.Earliest = options.Earliest
- opts.Latest = options.Latest
- opts.Address = fromHex(options.Address)
- opts.Topics = make([][]byte, len(options.Topics))
- for i, topic := range options.Topics {
- opts.Topics[i] = fromHex(topic)
- }
- return opts
- }
- type FilterChangedArgs struct {
- n int
- }
- type DbArgs struct {
- Database string
- Key string
- Value string
- }
- func (a *DbArgs) requirements() error {
- if len(a.Database) == 0 {
- return NewErrorResponse("DbPutArgs requires an 'Database' value as argument")
- }
- if len(a.Key) == 0 {
- return NewErrorResponse("DbPutArgs requires an 'Key' value as argument")
- }
- return nil
- }
- type WhisperMessageArgs struct {
- Payload string
- To string
- From string
- Topics []string
- Priority uint32
- Ttl uint32
- }
|