forked from TrueCloudLab/neoneo-go
6b21ad9922
Everywhere including examples, external interop APIs, bindings generators code and in other valuable places. A couple of `interface{}` usages are intentionally left in the CHANGELOG.md, documentation and tests.
39 lines
740 B
Go
39 lines
740 B
Go
package params
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
type (
|
|
// Params represents the JSON-RPC params.
|
|
Params []Param
|
|
)
|
|
|
|
// FromAny allows to create Params for a slice of abstract values (by
|
|
// JSON-marshaling them).
|
|
func FromAny(arr []any) (Params, error) {
|
|
var res Params
|
|
for i := range arr {
|
|
b, err := json.Marshal(arr[i])
|
|
if err != nil {
|
|
return nil, fmt.Errorf("wrong parameter %d: %w", i, err)
|
|
}
|
|
res = append(res, Param{RawMessage: json.RawMessage(b)})
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
// Value returns the param struct for the given
|
|
// index if it exists.
|
|
func (p Params) Value(index int) *Param {
|
|
if len(p) > index {
|
|
return &p[index]
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (p Params) String() string {
|
|
return fmt.Sprintf("%v", []Param(p))
|
|
}
|