args.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. package rpc
  2. import "encoding/json"
  3. import "github.com/ethereum/go-ethereum/core"
  4. type GetBlockArgs struct {
  5. BlockNumber int32
  6. Hash string
  7. }
  8. func (obj *GetBlockArgs) UnmarshalJSON(b []byte) (err error) {
  9. argint, argstr := int32(0), ""
  10. if err = json.Unmarshal(b, &argint); err == nil {
  11. obj.BlockNumber = argint
  12. return
  13. }
  14. if err = json.Unmarshal(b, &argstr); err == nil {
  15. obj.Hash = argstr
  16. return
  17. }
  18. return NewErrorResponse(ErrorDecodeArgs)
  19. }
  20. func (obj *GetBlockArgs) requirements() error {
  21. if obj.BlockNumber == 0 && obj.Hash == "" {
  22. return NewErrorResponse("GetBlock requires either a block 'number' or a block 'hash' as argument")
  23. }
  24. return nil
  25. }
  26. type NewTxArgs struct {
  27. From string `json:"from"`
  28. To string `json:"to"`
  29. Value string `json:"value"`
  30. Gas string `json:"gas"`
  31. GasPrice string `json:"gasPrice"`
  32. Data string `json:"data"`
  33. }
  34. func (a *NewTxArgs) requirements() error {
  35. if a.Gas == "" {
  36. return NewErrorResponse("Transact requires a 'gas' value as argument")
  37. }
  38. if a.GasPrice == "" {
  39. return NewErrorResponse("Transact requires a 'gasprice' value as argument")
  40. }
  41. return nil
  42. }
  43. type PushTxArgs struct {
  44. Tx string `json:"tx"`
  45. }
  46. func (obj *PushTxArgs) UnmarshalJSON(b []byte) (err error) {
  47. arg0 := ""
  48. if err = json.Unmarshal(b, arg0); err == nil {
  49. obj.Tx = arg0
  50. return
  51. }
  52. return NewErrorResponse(ErrorDecodeArgs)
  53. }
  54. func (a *PushTxArgs) requirementsPushTx() error {
  55. if a.Tx == "" {
  56. return NewErrorResponse("PushTx requires a 'tx' as argument")
  57. }
  58. return nil
  59. }
  60. type GetStorageArgs struct {
  61. Address string
  62. }
  63. func (obj *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
  64. if err = json.Unmarshal(b, &obj.Address); err != nil {
  65. return NewErrorResponse(ErrorDecodeArgs)
  66. }
  67. return
  68. }
  69. func (a *GetStorageArgs) requirements() error {
  70. if len(a.Address) == 0 {
  71. return NewErrorResponse("GetStorageAt requires an 'address' value as argument")
  72. }
  73. return nil
  74. }
  75. type GetStateArgs struct {
  76. Address string
  77. Key string
  78. }
  79. func (obj *GetStateArgs) UnmarshalJSON(b []byte) (err error) {
  80. arg0 := ""
  81. if err = json.Unmarshal(b, arg0); err == nil {
  82. obj.Address = arg0
  83. return
  84. }
  85. return NewErrorResponse(ErrorDecodeArgs)
  86. }
  87. func (a *GetStateArgs) requirements() error {
  88. if a.Address == "" {
  89. return NewErrorResponse("GetStorageAt requires an 'address' value as argument")
  90. }
  91. if a.Key == "" {
  92. return NewErrorResponse("GetStorageAt requires an 'key' value as argument")
  93. }
  94. return nil
  95. }
  96. type GetStorageAtRes struct {
  97. Key string `json:"key"`
  98. Value string `json:"value"`
  99. }
  100. type GetTxCountArgs struct {
  101. Address string `json:"address"`
  102. }
  103. // type GetTxCountRes struct {
  104. // Nonce int `json:"nonce"`
  105. // }
  106. func (obj *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) {
  107. arg0 := ""
  108. if err = json.Unmarshal(b, arg0); err == nil {
  109. obj.Address = arg0
  110. return
  111. }
  112. return NewErrorResponse("Could not determine JSON parameters")
  113. }
  114. func (a *GetTxCountArgs) requirements() error {
  115. if a.Address == "" {
  116. return NewErrorResponse("GetTxCountAt requires an 'address' value as argument")
  117. }
  118. return nil
  119. }
  120. // type GetPeerCountRes struct {
  121. // PeerCount int `json:"peerCount"`
  122. // }
  123. // type GetListeningRes struct {
  124. // IsListening bool `json:"isListening"`
  125. // }
  126. // type GetCoinbaseRes struct {
  127. // Coinbase string `json:"coinbase"`
  128. // }
  129. // type GetMiningRes struct {
  130. // IsMining bool `json:"isMining"`
  131. // }
  132. type GetBalanceArgs struct {
  133. Address string
  134. }
  135. func (obj *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) {
  136. arg0 := ""
  137. if err = json.Unmarshal(b, &arg0); err == nil {
  138. obj.Address = arg0
  139. return
  140. }
  141. return NewErrorResponse("Could not determine JSON parameters")
  142. }
  143. func (a *GetBalanceArgs) requirements() error {
  144. if a.Address == "" {
  145. return NewErrorResponse("GetBalanceAt requires an 'address' value as argument")
  146. }
  147. return nil
  148. }
  149. type BalanceRes struct {
  150. Balance string `json:"balance"`
  151. Address string `json:"address"`
  152. }
  153. type GetCodeAtArgs struct {
  154. Address string
  155. }
  156. func (obj *GetCodeAtArgs) UnmarshalJSON(b []byte) (err error) {
  157. arg0 := ""
  158. if err = json.Unmarshal(b, &arg0); err == nil {
  159. obj.Address = arg0
  160. return
  161. }
  162. return NewErrorResponse(ErrorDecodeArgs)
  163. }
  164. func (a *GetCodeAtArgs) requirements() error {
  165. if a.Address == "" {
  166. return NewErrorResponse("GetCodeAt requires an 'address' value as argument")
  167. }
  168. return nil
  169. }
  170. type Sha3Args struct {
  171. Data string
  172. }
  173. func (obj *Sha3Args) UnmarshalJSON(b []byte) (err error) {
  174. if err = json.Unmarshal(b, &obj.Data); err != nil {
  175. return NewErrorResponse(ErrorDecodeArgs)
  176. }
  177. return
  178. }
  179. type FilterOptions struct {
  180. Earliest int64
  181. Latest int64
  182. Address string
  183. Topics []string
  184. Skip int
  185. Max int
  186. }
  187. func toFilterOptions(options *FilterOptions) core.FilterOptions {
  188. var opts core.FilterOptions
  189. opts.Earliest = options.Earliest
  190. opts.Latest = options.Latest
  191. opts.Address = fromHex(options.Address)
  192. opts.Topics = make([][]byte, len(options.Topics))
  193. for i, topic := range options.Topics {
  194. opts.Topics[i] = fromHex(topic)
  195. }
  196. return opts
  197. }
  198. type FilterChangedArgs struct {
  199. n int
  200. }
  201. type DbArgs struct {
  202. Database string
  203. Key string
  204. Value string
  205. }
  206. func (a *DbArgs) requirements() error {
  207. if len(a.Database) == 0 {
  208. return NewErrorResponse("DbPutArgs requires an 'Database' value as argument")
  209. }
  210. if len(a.Key) == 0 {
  211. return NewErrorResponse("DbPutArgs requires an 'Key' value as argument")
  212. }
  213. return nil
  214. }
  215. type WhisperMessageArgs struct {
  216. Payload string
  217. To string
  218. From string
  219. Topics []string
  220. Priority uint32
  221. Ttl uint32
  222. }