eth_args.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. package api
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/big"
  6. "github.com/ethereum/go-ethereum/common"
  7. "github.com/ethereum/go-ethereum/core/state"
  8. "github.com/ethereum/go-ethereum/rpc/shared"
  9. )
  10. const (
  11. defaultLogLimit = 100
  12. defaultLogOffset = 0
  13. )
  14. type GetBalanceArgs struct {
  15. Address string
  16. BlockNumber int64
  17. }
  18. func (args *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) {
  19. var obj []interface{}
  20. if err := json.Unmarshal(b, &obj); err != nil {
  21. return shared.NewDecodeParamError(err.Error())
  22. }
  23. if len(obj) < 1 {
  24. return shared.NewInsufficientParamsError(len(obj), 1)
  25. }
  26. addstr, ok := obj[0].(string)
  27. if !ok {
  28. return shared.NewInvalidTypeError("address", "not a string")
  29. }
  30. args.Address = addstr
  31. if len(obj) > 1 {
  32. if err := blockHeight(obj[1], &args.BlockNumber); err != nil {
  33. return err
  34. }
  35. } else {
  36. args.BlockNumber = -1
  37. }
  38. return nil
  39. }
  40. type GetStorageArgs struct {
  41. Address string
  42. BlockNumber int64
  43. }
  44. func (args *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
  45. var obj []interface{}
  46. if err := json.Unmarshal(b, &obj); err != nil {
  47. return shared.NewDecodeParamError(err.Error())
  48. }
  49. if len(obj) < 1 {
  50. return shared.NewInsufficientParamsError(len(obj), 1)
  51. }
  52. addstr, ok := obj[0].(string)
  53. if !ok {
  54. return shared.NewInvalidTypeError("address", "not a string")
  55. }
  56. args.Address = addstr
  57. if len(obj) > 1 {
  58. if err := blockHeight(obj[1], &args.BlockNumber); err != nil {
  59. return err
  60. }
  61. } else {
  62. args.BlockNumber = -1
  63. }
  64. return nil
  65. }
  66. type GetStorageAtArgs struct {
  67. Address string
  68. BlockNumber int64
  69. Key string
  70. }
  71. func (args *GetStorageAtArgs) UnmarshalJSON(b []byte) (err error) {
  72. var obj []interface{}
  73. if err := json.Unmarshal(b, &obj); err != nil {
  74. return shared.NewDecodeParamError(err.Error())
  75. }
  76. if len(obj) < 2 {
  77. return shared.NewInsufficientParamsError(len(obj), 2)
  78. }
  79. addstr, ok := obj[0].(string)
  80. if !ok {
  81. return shared.NewInvalidTypeError("address", "not a string")
  82. }
  83. args.Address = addstr
  84. keystr, ok := obj[1].(string)
  85. if !ok {
  86. return shared.NewInvalidTypeError("key", "not a string")
  87. }
  88. args.Key = keystr
  89. if len(obj) > 2 {
  90. if err := blockHeight(obj[2], &args.BlockNumber); err != nil {
  91. return err
  92. }
  93. } else {
  94. args.BlockNumber = -1
  95. }
  96. return nil
  97. }
  98. type GetTxCountArgs struct {
  99. Address string
  100. BlockNumber int64
  101. }
  102. func (args *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) {
  103. var obj []interface{}
  104. if err := json.Unmarshal(b, &obj); err != nil {
  105. return shared.NewDecodeParamError(err.Error())
  106. }
  107. if len(obj) < 1 {
  108. return shared.NewInsufficientParamsError(len(obj), 1)
  109. }
  110. addstr, ok := obj[0].(string)
  111. if !ok {
  112. return shared.NewInvalidTypeError("address", "not a string")
  113. }
  114. args.Address = addstr
  115. if len(obj) > 1 {
  116. if err := blockHeight(obj[1], &args.BlockNumber); err != nil {
  117. return err
  118. }
  119. } else {
  120. args.BlockNumber = -1
  121. }
  122. return nil
  123. }
  124. type HashArgs struct {
  125. Hash string
  126. }
  127. func (args *HashArgs) UnmarshalJSON(b []byte) (err error) {
  128. var obj []interface{}
  129. if err := json.Unmarshal(b, &obj); err != nil {
  130. return shared.NewDecodeParamError(err.Error())
  131. }
  132. if len(obj) < 1 {
  133. return shared.NewInsufficientParamsError(len(obj), 1)
  134. }
  135. arg0, ok := obj[0].(string)
  136. if !ok {
  137. return shared.NewInvalidTypeError("hash", "not a string")
  138. }
  139. args.Hash = arg0
  140. return nil
  141. }
  142. type BlockNumArg struct {
  143. BlockNumber int64
  144. }
  145. func (args *BlockNumArg) UnmarshalJSON(b []byte) (err error) {
  146. var obj []interface{}
  147. if err := json.Unmarshal(b, &obj); err != nil {
  148. return shared.NewDecodeParamError(err.Error())
  149. }
  150. if len(obj) < 1 {
  151. return shared.NewInsufficientParamsError(len(obj), 1)
  152. }
  153. if err := blockHeight(obj[0], &args.BlockNumber); err != nil {
  154. return err
  155. }
  156. return nil
  157. }
  158. type GetDataArgs struct {
  159. Address string
  160. BlockNumber int64
  161. }
  162. func (args *GetDataArgs) UnmarshalJSON(b []byte) (err error) {
  163. var obj []interface{}
  164. if err := json.Unmarshal(b, &obj); err != nil {
  165. return shared.NewDecodeParamError(err.Error())
  166. }
  167. if len(obj) < 1 {
  168. return shared.NewInsufficientParamsError(len(obj), 1)
  169. }
  170. addstr, ok := obj[0].(string)
  171. if !ok {
  172. return shared.NewInvalidTypeError("address", "not a string")
  173. }
  174. args.Address = addstr
  175. if len(obj) > 1 {
  176. if err := blockHeight(obj[1], &args.BlockNumber); err != nil {
  177. return err
  178. }
  179. } else {
  180. args.BlockNumber = -1
  181. }
  182. return nil
  183. }
  184. type NewSigArgs struct {
  185. From string
  186. Data string
  187. }
  188. func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) {
  189. var obj []interface{}
  190. if err := json.Unmarshal(b, &obj); err != nil {
  191. return shared.NewDecodeParamError(err.Error())
  192. }
  193. // Check for sufficient params
  194. if len(obj) < 1 {
  195. return shared.NewInsufficientParamsError(len(obj), 1)
  196. }
  197. from, ok := obj[0].(string)
  198. if !ok {
  199. return shared.NewInvalidTypeError("from", "not a string")
  200. }
  201. args.From = from
  202. if len(args.From) == 0 {
  203. return shared.NewValidationError("from", "is required")
  204. }
  205. data, ok := obj[1].(string)
  206. if !ok {
  207. return shared.NewInvalidTypeError("data", "not a string")
  208. }
  209. args.Data = data
  210. if len(args.Data) == 0 {
  211. return shared.NewValidationError("data", "is required")
  212. }
  213. return nil
  214. }
  215. type NewTxArgs struct {
  216. From string
  217. To string
  218. Nonce *big.Int
  219. Value *big.Int
  220. Gas *big.Int
  221. GasPrice *big.Int
  222. Data string
  223. BlockNumber int64
  224. }
  225. func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
  226. var obj []json.RawMessage
  227. var ext struct {
  228. From string
  229. To string
  230. Nonce interface{}
  231. Value interface{}
  232. Gas interface{}
  233. GasPrice interface{}
  234. Data string
  235. }
  236. // Decode byte slice to array of RawMessages
  237. if err := json.Unmarshal(b, &obj); err != nil {
  238. return shared.NewDecodeParamError(err.Error())
  239. }
  240. // Check for sufficient params
  241. if len(obj) < 1 {
  242. return shared.NewInsufficientParamsError(len(obj), 1)
  243. }
  244. // Decode 0th RawMessage to temporary struct
  245. if err := json.Unmarshal(obj[0], &ext); err != nil {
  246. return shared.NewDecodeParamError(err.Error())
  247. }
  248. if len(ext.From) == 0 {
  249. return shared.NewValidationError("from", "is required")
  250. }
  251. args.From = ext.From
  252. args.To = ext.To
  253. args.Data = ext.Data
  254. var num *big.Int
  255. if ext.Nonce != nil {
  256. num, err = numString(ext.Nonce)
  257. if err != nil {
  258. return err
  259. }
  260. }
  261. args.Nonce = num
  262. if ext.Value == nil {
  263. num = big.NewInt(0)
  264. } else {
  265. num, err = numString(ext.Value)
  266. if err != nil {
  267. return err
  268. }
  269. }
  270. args.Value = num
  271. num = nil
  272. if ext.Gas == nil {
  273. num = big.NewInt(0)
  274. } else {
  275. if num, err = numString(ext.Gas); err != nil {
  276. return err
  277. }
  278. }
  279. args.Gas = num
  280. num = nil
  281. if ext.GasPrice == nil {
  282. num = big.NewInt(0)
  283. } else {
  284. if num, err = numString(ext.GasPrice); err != nil {
  285. return err
  286. }
  287. }
  288. args.GasPrice = num
  289. // Check for optional BlockNumber param
  290. if len(obj) > 1 {
  291. if err := blockHeightFromJson(obj[1], &args.BlockNumber); err != nil {
  292. return err
  293. }
  294. } else {
  295. args.BlockNumber = -1
  296. }
  297. return nil
  298. }
  299. type SourceArgs struct {
  300. Source string
  301. }
  302. func (args *SourceArgs) UnmarshalJSON(b []byte) (err error) {
  303. var obj []interface{}
  304. if err := json.Unmarshal(b, &obj); err != nil {
  305. return shared.NewDecodeParamError(err.Error())
  306. }
  307. if len(obj) < 1 {
  308. return shared.NewInsufficientParamsError(len(obj), 1)
  309. }
  310. arg0, ok := obj[0].(string)
  311. if !ok {
  312. return shared.NewInvalidTypeError("source code", "not a string")
  313. }
  314. args.Source = arg0
  315. return nil
  316. }
  317. type CallArgs struct {
  318. From string
  319. To string
  320. Value *big.Int
  321. Gas *big.Int
  322. GasPrice *big.Int
  323. Data string
  324. BlockNumber int64
  325. }
  326. func (args *CallArgs) UnmarshalJSON(b []byte) (err error) {
  327. var obj []json.RawMessage
  328. var ext struct {
  329. From string
  330. To string
  331. Value interface{}
  332. Gas interface{}
  333. GasPrice interface{}
  334. Data string
  335. }
  336. // Decode byte slice to array of RawMessages
  337. if err := json.Unmarshal(b, &obj); err != nil {
  338. return shared.NewDecodeParamError(err.Error())
  339. }
  340. // Check for sufficient params
  341. if len(obj) < 1 {
  342. return shared.NewInsufficientParamsError(len(obj), 1)
  343. }
  344. // Decode 0th RawMessage to temporary struct
  345. if err := json.Unmarshal(obj[0], &ext); err != nil {
  346. return shared.NewDecodeParamError(err.Error())
  347. }
  348. args.From = ext.From
  349. if len(ext.To) == 0 {
  350. return shared.NewValidationError("to", "is required")
  351. }
  352. args.To = ext.To
  353. var num *big.Int
  354. if ext.Value == nil {
  355. num = big.NewInt(0)
  356. } else {
  357. if num, err = numString(ext.Value); err != nil {
  358. return err
  359. }
  360. }
  361. args.Value = num
  362. if ext.Gas == nil {
  363. num = big.NewInt(0)
  364. } else {
  365. if num, err = numString(ext.Gas); err != nil {
  366. return err
  367. }
  368. }
  369. args.Gas = num
  370. if ext.GasPrice == nil {
  371. num = big.NewInt(0)
  372. } else {
  373. if num, err = numString(ext.GasPrice); err != nil {
  374. return err
  375. }
  376. }
  377. args.GasPrice = num
  378. args.Data = ext.Data
  379. // Check for optional BlockNumber param
  380. if len(obj) > 1 {
  381. if err := blockHeightFromJson(obj[1], &args.BlockNumber); err != nil {
  382. return err
  383. }
  384. } else {
  385. args.BlockNumber = -1
  386. }
  387. return nil
  388. }
  389. type HashIndexArgs struct {
  390. Hash string
  391. Index int64
  392. }
  393. func (args *HashIndexArgs) UnmarshalJSON(b []byte) (err error) {
  394. var obj []interface{}
  395. if err := json.Unmarshal(b, &obj); err != nil {
  396. return shared.NewDecodeParamError(err.Error())
  397. }
  398. if len(obj) < 2 {
  399. return shared.NewInsufficientParamsError(len(obj), 2)
  400. }
  401. arg0, ok := obj[0].(string)
  402. if !ok {
  403. return shared.NewInvalidTypeError("hash", "not a string")
  404. }
  405. args.Hash = arg0
  406. arg1, ok := obj[1].(string)
  407. if !ok {
  408. return shared.NewInvalidTypeError("index", "not a string")
  409. }
  410. args.Index = common.Big(arg1).Int64()
  411. return nil
  412. }
  413. type BlockNumIndexArgs struct {
  414. BlockNumber int64
  415. Index int64
  416. }
  417. func (args *BlockNumIndexArgs) UnmarshalJSON(b []byte) (err error) {
  418. var obj []interface{}
  419. if err := json.Unmarshal(b, &obj); err != nil {
  420. return shared.NewDecodeParamError(err.Error())
  421. }
  422. if len(obj) < 2 {
  423. return shared.NewInsufficientParamsError(len(obj), 2)
  424. }
  425. if err := blockHeight(obj[0], &args.BlockNumber); err != nil {
  426. return err
  427. }
  428. var arg1 *big.Int
  429. if arg1, err = numString(obj[1]); err != nil {
  430. return err
  431. }
  432. args.Index = arg1.Int64()
  433. return nil
  434. }
  435. type GetBlockByHashArgs struct {
  436. BlockHash string
  437. IncludeTxs bool
  438. }
  439. func (args *GetBlockByHashArgs) UnmarshalJSON(b []byte) (err error) {
  440. var obj []interface{}
  441. if err := json.Unmarshal(b, &obj); err != nil {
  442. return shared.NewDecodeParamError(err.Error())
  443. }
  444. if len(obj) < 2 {
  445. return shared.NewInsufficientParamsError(len(obj), 2)
  446. }
  447. argstr, ok := obj[0].(string)
  448. if !ok {
  449. return shared.NewInvalidTypeError("blockHash", "not a string")
  450. }
  451. args.BlockHash = argstr
  452. args.IncludeTxs = obj[1].(bool)
  453. return nil
  454. }
  455. type GetBlockByNumberArgs struct {
  456. BlockNumber int64
  457. IncludeTxs bool
  458. }
  459. func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
  460. var obj []interface{}
  461. if err := json.Unmarshal(b, &obj); err != nil {
  462. return shared.NewDecodeParamError(err.Error())
  463. }
  464. if len(obj) < 2 {
  465. return shared.NewInsufficientParamsError(len(obj), 2)
  466. }
  467. if err := blockHeight(obj[0], &args.BlockNumber); err != nil {
  468. return err
  469. }
  470. args.IncludeTxs = obj[1].(bool)
  471. return nil
  472. }
  473. type BlockFilterArgs struct {
  474. Earliest int64
  475. Latest int64
  476. Address []string
  477. Topics [][]string
  478. Skip int
  479. Max int
  480. }
  481. func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) {
  482. var obj []struct {
  483. FromBlock interface{} `json:"fromBlock"`
  484. ToBlock interface{} `json:"toBlock"`
  485. Limit interface{} `json:"limit"`
  486. Offset interface{} `json:"offset"`
  487. Address interface{} `json:"address"`
  488. Topics interface{} `json:"topics"`
  489. }
  490. if err = json.Unmarshal(b, &obj); err != nil {
  491. return shared.NewDecodeParamError(err.Error())
  492. }
  493. if len(obj) < 1 {
  494. return shared.NewInsufficientParamsError(len(obj), 1)
  495. }
  496. // args.Earliest, err = toNumber(obj[0].ToBlock)
  497. // if err != nil {
  498. // return shared.NewDecodeParamError(fmt.Sprintf("FromBlock %v", err))
  499. // }
  500. // args.Latest, err = toNumber(obj[0].FromBlock)
  501. // if err != nil {
  502. // return shared.NewDecodeParamError(fmt.Sprintf("ToBlock %v", err))
  503. var num int64
  504. var numBig *big.Int
  505. // if blank then latest
  506. if obj[0].FromBlock == nil {
  507. num = -1
  508. } else {
  509. if err := blockHeight(obj[0].FromBlock, &num); err != nil {
  510. return err
  511. }
  512. }
  513. // if -2 or other "silly" number, use latest
  514. if num < 0 {
  515. args.Earliest = -1 //latest block
  516. } else {
  517. args.Earliest = num
  518. }
  519. // if blank than latest
  520. if obj[0].ToBlock == nil {
  521. num = -1
  522. } else {
  523. if err := blockHeight(obj[0].ToBlock, &num); err != nil {
  524. return err
  525. }
  526. }
  527. args.Latest = num
  528. if obj[0].Limit == nil {
  529. numBig = big.NewInt(defaultLogLimit)
  530. } else {
  531. if numBig, err = numString(obj[0].Limit); err != nil {
  532. return err
  533. }
  534. }
  535. args.Max = int(numBig.Int64())
  536. if obj[0].Offset == nil {
  537. numBig = big.NewInt(defaultLogOffset)
  538. } else {
  539. if numBig, err = numString(obj[0].Offset); err != nil {
  540. return err
  541. }
  542. }
  543. args.Skip = int(numBig.Int64())
  544. if obj[0].Address != nil {
  545. marg, ok := obj[0].Address.([]interface{})
  546. if ok {
  547. v := make([]string, len(marg))
  548. for i, arg := range marg {
  549. argstr, ok := arg.(string)
  550. if !ok {
  551. return shared.NewInvalidTypeError(fmt.Sprintf("address[%d]", i), "is not a string")
  552. }
  553. v[i] = argstr
  554. }
  555. args.Address = v
  556. } else {
  557. argstr, ok := obj[0].Address.(string)
  558. if ok {
  559. v := make([]string, 1)
  560. v[0] = argstr
  561. args.Address = v
  562. } else {
  563. return shared.NewInvalidTypeError("address", "is not a string or array")
  564. }
  565. }
  566. }
  567. if obj[0].Topics != nil {
  568. other, ok := obj[0].Topics.([]interface{})
  569. if ok {
  570. topicdbl := make([][]string, len(other))
  571. for i, iv := range other {
  572. if argstr, ok := iv.(string); ok {
  573. // Found a string, push into first element of array
  574. topicsgl := make([]string, 1)
  575. topicsgl[0] = argstr
  576. topicdbl[i] = topicsgl
  577. } else if argarray, ok := iv.([]interface{}); ok {
  578. // Found an array of other
  579. topicdbl[i] = make([]string, len(argarray))
  580. for j, jv := range argarray {
  581. if v, ok := jv.(string); ok {
  582. topicdbl[i][j] = v
  583. } else if jv == nil {
  584. topicdbl[i][j] = ""
  585. } else {
  586. return shared.NewInvalidTypeError(fmt.Sprintf("topic[%d][%d]", i, j), "is not a string")
  587. }
  588. }
  589. } else if iv == nil {
  590. topicdbl[i] = []string{""}
  591. } else {
  592. return shared.NewInvalidTypeError(fmt.Sprintf("topic[%d]", i), "not a string or array")
  593. }
  594. }
  595. args.Topics = topicdbl
  596. return nil
  597. } else {
  598. return shared.NewInvalidTypeError("topic", "is not a string or array")
  599. }
  600. }
  601. return nil
  602. }
  603. type FilterIdArgs struct {
  604. Id int
  605. }
  606. func (args *FilterIdArgs) UnmarshalJSON(b []byte) (err error) {
  607. var obj []interface{}
  608. if err := json.Unmarshal(b, &obj); err != nil {
  609. return shared.NewDecodeParamError(err.Error())
  610. }
  611. if len(obj) < 1 {
  612. return shared.NewInsufficientParamsError(len(obj), 1)
  613. }
  614. var num *big.Int
  615. if num, err = numString(obj[0]); err != nil {
  616. return err
  617. }
  618. args.Id = int(num.Int64())
  619. return nil
  620. }
  621. type LogRes struct {
  622. Address *hexdata `json:"address"`
  623. Topics []*hexdata `json:"topics"`
  624. Data *hexdata `json:"data"`
  625. BlockNumber *hexnum `json:"blockNumber"`
  626. LogIndex *hexnum `json:"logIndex"`
  627. BlockHash *hexdata `json:"blockHash"`
  628. TransactionHash *hexdata `json:"transactionHash"`
  629. TransactionIndex *hexnum `json:"transactionIndex"`
  630. }
  631. func NewLogRes(log *state.Log) LogRes {
  632. var l LogRes
  633. l.Topics = make([]*hexdata, len(log.Topics))
  634. for j, topic := range log.Topics {
  635. l.Topics[j] = newHexData(topic)
  636. }
  637. l.Address = newHexData(log.Address)
  638. l.Data = newHexData(log.Data)
  639. l.BlockNumber = newHexNum(log.Number)
  640. l.LogIndex = newHexNum(log.Index)
  641. l.TransactionHash = newHexData(log.TxHash)
  642. l.TransactionIndex = newHexNum(log.TxIndex)
  643. l.BlockHash = newHexData(log.BlockHash)
  644. return l
  645. }
  646. func NewLogsRes(logs state.Logs) (ls []LogRes) {
  647. ls = make([]LogRes, len(logs))
  648. for i, log := range logs {
  649. ls[i] = NewLogRes(log)
  650. }
  651. return
  652. }
  653. func NewHashesRes(hs []common.Hash) []string {
  654. hashes := make([]string, len(hs))
  655. for i, hash := range hs {
  656. hashes[i] = hash.Hex()
  657. }
  658. return hashes
  659. }
  660. type SubmitWorkArgs struct {
  661. Nonce uint64
  662. Header string
  663. Digest string
  664. }
  665. func (args *SubmitWorkArgs) UnmarshalJSON(b []byte) (err error) {
  666. var obj []interface{}
  667. if err = json.Unmarshal(b, &obj); err != nil {
  668. return shared.NewDecodeParamError(err.Error())
  669. }
  670. if len(obj) < 3 {
  671. return shared.NewInsufficientParamsError(len(obj), 3)
  672. }
  673. var objstr string
  674. var ok bool
  675. if objstr, ok = obj[0].(string); !ok {
  676. return shared.NewInvalidTypeError("nonce", "not a string")
  677. }
  678. args.Nonce = common.String2Big(objstr).Uint64()
  679. if objstr, ok = obj[1].(string); !ok {
  680. return shared.NewInvalidTypeError("header", "not a string")
  681. }
  682. args.Header = objstr
  683. if objstr, ok = obj[2].(string); !ok {
  684. return shared.NewInvalidTypeError("digest", "not a string")
  685. }
  686. args.Digest = objstr
  687. return nil
  688. }