github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/services/rpcsrv/params/params.go (about) 1 package params 2 3 import ( 4 "encoding/json" 5 "fmt" 6 ) 7 8 type ( 9 // Params represents the JSON-RPC params. 10 Params []Param 11 ) 12 13 // FromAny allows to create Params for a slice of abstract values (by 14 // JSON-marshaling them). 15 func FromAny(arr []any) (Params, error) { 16 var res Params 17 for i := range arr { 18 b, err := json.Marshal(arr[i]) 19 if err != nil { 20 return nil, fmt.Errorf("wrong parameter %d: %w", i, err) 21 } 22 res = append(res, Param{RawMessage: json.RawMessage(b)}) 23 } 24 return res, nil 25 } 26 27 // Value returns the param struct for the given 28 // index if it exists. 29 func (p Params) Value(index int) *Param { 30 if len(p) > index { 31 return &p[index] 32 } 33 34 return nil 35 } 36 37 func (p Params) String() string { 38 return fmt.Sprintf("%v", []Param(p)) 39 }