|
|
@ -172,13 +172,8 @@ type NewSigArgs struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) { |
|
|
|
func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) { |
|
|
|
var obj []json.RawMessage |
|
|
|
var obj []interface{} |
|
|
|
var ext struct { |
|
|
|
|
|
|
|
From string |
|
|
|
|
|
|
|
Data string |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Decode byte slice to array of RawMessages
|
|
|
|
|
|
|
|
if err := json.Unmarshal(b, &obj); err != nil { |
|
|
|
if err := json.Unmarshal(b, &obj); err != nil { |
|
|
|
return NewDecodeParamError(err.Error()) |
|
|
|
return NewDecodeParamError(err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
@ -188,21 +183,26 @@ func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) { |
|
|
|
return NewInsufficientParamsError(len(obj), 1) |
|
|
|
return NewInsufficientParamsError(len(obj), 1) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Decode 0th RawMessage to temporary struct
|
|
|
|
from, ok := obj[0].(string) |
|
|
|
if err := json.Unmarshal(obj[0], &ext); err != nil { |
|
|
|
if !ok { |
|
|
|
return NewDecodeParamError(err.Error()) |
|
|
|
return NewInvalidTypeError("from", "not a string") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
args.From = from |
|
|
|
|
|
|
|
|
|
|
|
if len(ext.From) == 0 { |
|
|
|
if len(args.From) == 0 { |
|
|
|
return NewValidationError("from", "is required") |
|
|
|
return NewValidationError("from", "is required") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(ext.Data) == 0 { |
|
|
|
data, ok := obj[1].(string) |
|
|
|
|
|
|
|
if !ok { |
|
|
|
|
|
|
|
return NewInvalidTypeError("data", "not a string") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
args.Data = data |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(args.Data) == 0 { |
|
|
|
return NewValidationError("data", "is required") |
|
|
|
return NewValidationError("data", "is required") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
args.From = ext.From |
|
|
|
|
|
|
|
args.Data = ext.Data |
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|