2018-03-23 20:36:59 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
type (
|
2019-10-22 14:56:03 +00:00
|
|
|
// Params represents the JSON-RPC params.
|
2018-03-23 20:36:59 +00:00
|
|
|
Params []Param
|
|
|
|
)
|
|
|
|
|
2019-11-21 13:42:51 +00:00
|
|
|
// Value returns the param struct for the given
|
2018-03-23 20:36:59 +00:00
|
|
|
// index if it exists.
|
2019-11-21 13:42:51 +00:00
|
|
|
func (p Params) Value(index int) (*Param, bool) {
|
2018-03-23 20:36:59 +00:00
|
|
|
if len(p) > index {
|
|
|
|
return &p[index], true
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
2019-11-21 13:42:51 +00:00
|
|
|
// ValueWithType returns the param struct at the given index if it
|
2018-03-23 20:36:59 +00:00
|
|
|
// exists and matches the given type.
|
2019-11-21 13:42:51 +00:00
|
|
|
func (p Params) ValueWithType(index int, valType paramType) (*Param, bool) {
|
|
|
|
if val, ok := p.Value(index); ok && val.Type == valType {
|
|
|
|
return val, true
|
2018-03-23 20:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil, false
|
|
|
|
}
|