diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-06-11 22:41:43 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-06-11 22:41:43 +0800 |
commit | e2c2d8e15ebef85c77f7486f92c6430ca6f30785 (patch) | |
tree | 1cd237e5aba5453c641a8d631cffd96c9eb08757 /rpc/api/personal_args.go | |
parent | 6609d45ef48ce1c2d2b0e73fa8fe5190d36e3920 (diff) | |
parent | b3c07f167f8b82d1079abe6e15cd1f480712b030 (diff) | |
download | dexon-e2c2d8e15ebef85c77f7486f92c6430ca6f30785.tar dexon-e2c2d8e15ebef85c77f7486f92c6430ca6f30785.tar.gz dexon-e2c2d8e15ebef85c77f7486f92c6430ca6f30785.tar.bz2 dexon-e2c2d8e15ebef85c77f7486f92c6430ca6f30785.tar.lz dexon-e2c2d8e15ebef85c77f7486f92c6430ca6f30785.tar.xz dexon-e2c2d8e15ebef85c77f7486f92c6430ca6f30785.tar.zst dexon-e2c2d8e15ebef85c77f7486f92c6430ca6f30785.zip |
Merge pull request #1239 from bas-vk/rpc-apis
RPC refactoring
Diffstat (limited to 'rpc/api/personal_args.go')
-rw-r--r-- | rpc/api/personal_args.go | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/rpc/api/personal_args.go b/rpc/api/personal_args.go new file mode 100644 index 000000000..b3e683638 --- /dev/null +++ b/rpc/api/personal_args.go @@ -0,0 +1,92 @@ +package api + +import ( + "encoding/json" + + "github.com/ethereum/go-ethereum/rpc/shared" +) + +type NewAccountArgs struct { + Passphrase string +} + +func (args *NewAccountArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + if len(obj) < 1 { + return shared.NewInsufficientParamsError(len(obj), 1) + } + + if passhrase, ok := obj[0].(string); ok { + args.Passphrase = passhrase + return nil + } + + return shared.NewInvalidTypeError("passhrase", "not a string") +} + +type DeleteAccountArgs struct { + Address string + Passphrase string +} + +func (args *DeleteAccountArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + if len(obj) < 2 { + return shared.NewInsufficientParamsError(len(obj), 2) + } + + if addr, ok := obj[0].(string); ok { + args.Address = addr + } else { + return shared.NewInvalidTypeError("address", "not a string") + } + + if passhrase, ok := obj[1].(string); ok { + args.Passphrase = passhrase + } else { + return shared.NewInvalidTypeError("passhrase", "not a string") + } + + return nil +} + +type UnlockAccountArgs struct { + Address string + Passphrase string + Duration int +} + +func (args *UnlockAccountArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + if err := json.Unmarshal(b, &obj); err != nil { + return shared.NewDecodeParamError(err.Error()) + } + + args.Duration = -1 + + if len(obj) < 2 { + return shared.NewInsufficientParamsError(len(obj), 2) + } + + if addrstr, ok := obj[0].(string); ok { + args.Address = addrstr + } else { + return shared.NewInvalidTypeError("address", "not a string") + } + + if passphrasestr, ok := obj[1].(string); ok { + args.Passphrase = passphrasestr + } else { + return shared.NewInvalidTypeError("passphrase", "not a string") + } + + return nil +} |