personal_args.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. package api
  17. import (
  18. "encoding/json"
  19. "github.com/ethereum/go-ethereum/rpc/shared"
  20. )
  21. type NewAccountArgs struct {
  22. Passphrase *string
  23. }
  24. func (args *NewAccountArgs) UnmarshalJSON(b []byte) (err error) {
  25. var obj []interface{}
  26. if err := json.Unmarshal(b, &obj); err != nil {
  27. return shared.NewDecodeParamError(err.Error())
  28. }
  29. if len(obj) >= 1 && obj[0] != nil {
  30. if passphrasestr, ok := obj[0].(string); ok {
  31. args.Passphrase = &passphrasestr
  32. } else {
  33. return shared.NewInvalidTypeError("passphrase", "not a string")
  34. }
  35. }
  36. return nil
  37. }
  38. type UnlockAccountArgs struct {
  39. Address string
  40. Passphrase *string
  41. Duration int
  42. }
  43. func (args *UnlockAccountArgs) UnmarshalJSON(b []byte) (err error) {
  44. var obj []interface{}
  45. if err := json.Unmarshal(b, &obj); err != nil {
  46. return shared.NewDecodeParamError(err.Error())
  47. }
  48. args.Duration = 0
  49. if len(obj) < 1 {
  50. return shared.NewInsufficientParamsError(len(obj), 1)
  51. }
  52. if addrstr, ok := obj[0].(string); ok {
  53. args.Address = addrstr
  54. } else {
  55. return shared.NewInvalidTypeError("address", "not a string")
  56. }
  57. if len(obj) >= 2 && obj[1] != nil {
  58. if passphrasestr, ok := obj[1].(string); ok {
  59. args.Passphrase = &passphrasestr
  60. } else {
  61. return shared.NewInvalidTypeError("passphrase", "not a string")
  62. }
  63. }
  64. if len(obj) >= 3 && obj[2] != nil {
  65. if duration, ok := obj[2].(float64); ok {
  66. args.Duration = int(duration)
  67. }
  68. }
  69. return nil
  70. }