Return error when filter params are not strings

This commit is contained in:
Taylor Gerring 2015-03-16 15:30:31 -04:00
parent 03ac0f18ae
commit 719effa7ec

View File

@ -359,23 +359,29 @@ func (args *FilterOptions) UnmarshalJSON(b []byte) (err error) {
} }
fromstr, ok := obj[0].FromBlock.(string) fromstr, ok := obj[0].FromBlock.(string)
if ok { if !ok {
if fromstr == "latest" { return NewDecodeParamError("FromBlock is not a string")
args.Earliest = 0 }
} else {
args.Earliest = int64(common.Big(obj[0].FromBlock.(string)).Int64()) switch fromstr {
} case "latest":
args.Earliest = 0
default:
args.Earliest = int64(common.Big(obj[0].FromBlock.(string)).Int64())
} }
tostr, ok := obj[0].ToBlock.(string) tostr, ok := obj[0].ToBlock.(string)
if ok { if !ok {
if tostr == "latest" { return NewDecodeParamError("ToBlock is not a string")
args.Latest = 0 }
} else if tostr == "pending" {
args.Latest = -1 switch tostr {
} else { case "latest":
args.Latest = int64(common.Big(obj[0].ToBlock.(string)).Int64()) args.Latest = 0
} case "pending":
args.Latest = -1
default:
args.Latest = int64(common.Big(obj[0].ToBlock.(string)).Int64())
} }
args.Max = int(common.Big(obj[0].Limit).Int64()) args.Max = int(common.Big(obj[0].Limit).Int64())