diff options
author | obscuren <geffobscura@gmail.com> | 2015-05-13 01:05:33 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-05-13 01:05:33 +0800 |
commit | 8e24378cc1acb074b56de75bf0baf6feb7927677 (patch) | |
tree | 71f866652de6b45da5ad4403b88f5def9a684e36 /rpc/args.go | |
parent | 7d69679935ff8c04aebb60f27074f08c5e84ac95 (diff) | |
parent | 8fe01b4bfa28ad5a1fdde7f9837e8f982843389a (diff) | |
download | go-tangerine-8e24378cc1acb074b56de75bf0baf6feb7927677.tar go-tangerine-8e24378cc1acb074b56de75bf0baf6feb7927677.tar.gz go-tangerine-8e24378cc1acb074b56de75bf0baf6feb7927677.tar.bz2 go-tangerine-8e24378cc1acb074b56de75bf0baf6feb7927677.tar.lz go-tangerine-8e24378cc1acb074b56de75bf0baf6feb7927677.tar.xz go-tangerine-8e24378cc1acb074b56de75bf0baf6feb7927677.tar.zst go-tangerine-8e24378cc1acb074b56de75bf0baf6feb7927677.zip |
Merge branch 'release/0.9.20'v0.9.20
Diffstat (limited to 'rpc/args.go')
-rw-r--r-- | rpc/args.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/rpc/args.go b/rpc/args.go index 58a750415..686872a59 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -166,6 +166,46 @@ type NewTxArgs struct { BlockNumber int64 } +type NewSigArgs struct { + From string + Data string +} + +func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) { + var obj []json.RawMessage + var ext struct { + From string + Data string + } + + // Decode byte slice to array of RawMessages + if err := json.Unmarshal(b, &obj); err != nil { + return NewDecodeParamError(err.Error()) + } + + // Check for sufficient params + if len(obj) < 1 { + return NewInsufficientParamsError(len(obj), 1) + } + + // Decode 0th RawMessage to temporary struct + if err := json.Unmarshal(obj[0], &ext); err != nil { + return NewDecodeParamError(err.Error()) + } + + if len(ext.From) == 0 { + return NewValidationError("from", "is required") + } + + if len(ext.Data) == 0 { + return NewValidationError("data", "is required") + } + + args.From = ext.From + args.Data = ext.Data + return nil +} + func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) { var obj []json.RawMessage var ext struct { |