2022-07-07 14:41:01 +00:00
|
|
|
package params
|
2018-03-23 20:36:59 +00:00
|
|
|
|
|
|
|
import (
|
2019-11-26 10:13:17 +00:00
|
|
|
"bytes"
|
2020-07-07 19:35:03 +00:00
|
|
|
"encoding/base64"
|
2019-11-21 14:42:02 +00:00
|
|
|
"encoding/hex"
|
2019-11-21 13:42:51 +00:00
|
|
|
"encoding/json"
|
2020-08-06 14:44:08 +00:00
|
|
|
"errors"
|
2018-03-23 20:36:59 +00:00
|
|
|
"fmt"
|
2022-02-09 12:13:15 +00:00
|
|
|
"math/big"
|
2020-03-25 14:23:13 +00:00
|
|
|
"strconv"
|
2020-08-27 09:07:02 +00:00
|
|
|
"strings"
|
2019-11-21 13:42:51 +00:00
|
|
|
|
2022-06-15 18:23:29 +00:00
|
|
|
"github.com/google/uuid"
|
2020-06-10 11:45:55 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
2022-07-22 16:09:29 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2018-03-23 20:36:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2019-10-22 14:56:03 +00:00
|
|
|
// Param represents a param either passed to
|
2022-04-20 18:30:09 +00:00
|
|
|
// the server or to be sent to a server using
|
2018-03-23 20:36:59 +00:00
|
|
|
// the client.
|
|
|
|
Param struct {
|
2021-10-28 11:10:18 +00:00
|
|
|
json.RawMessage
|
2023-04-03 10:34:24 +00:00
|
|
|
cache any
|
2018-03-23 20:36:59 +00:00
|
|
|
}
|
2019-11-21 13:42:51 +00:00
|
|
|
|
2019-11-26 10:13:17 +00:00
|
|
|
// FuncParam represents a function argument parameter used in the
|
|
|
|
// invokefunction RPC method.
|
|
|
|
FuncParam struct {
|
2020-02-21 14:34:18 +00:00
|
|
|
Type smartcontract.ParamType `json:"type"`
|
2020-03-03 14:22:15 +00:00
|
|
|
Value Param `json:"value"`
|
2019-11-26 10:13:17 +00:00
|
|
|
}
|
2019-11-21 13:42:51 +00:00
|
|
|
)
|
|
|
|
|
2021-10-28 11:10:18 +00:00
|
|
|
var (
|
|
|
|
jsonNullBytes = []byte("null")
|
|
|
|
jsonFalseBytes = []byte("false")
|
|
|
|
jsonTrueBytes = []byte("true")
|
|
|
|
errMissingParameter = errors.New("parameter is missing")
|
|
|
|
errNotAString = errors.New("not a string")
|
|
|
|
errNotAnInt = errors.New("not an integer")
|
|
|
|
errNotABool = errors.New("not a boolean")
|
|
|
|
errNotAnArray = errors.New("not an array")
|
2018-03-23 20:36:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (p Param) String() string {
|
2021-10-28 11:10:18 +00:00
|
|
|
str, _ := p.GetString()
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetStringStrict returns a string value of the parameter.
|
2021-10-28 11:10:18 +00:00
|
|
|
func (p *Param) GetStringStrict() (string, error) {
|
|
|
|
if p == nil {
|
|
|
|
return "", errMissingParameter
|
|
|
|
}
|
|
|
|
if p.IsNull() {
|
|
|
|
return "", errNotAString
|
|
|
|
}
|
2021-10-28 14:24:38 +00:00
|
|
|
if p.cache == nil {
|
|
|
|
var s string
|
|
|
|
err := json.Unmarshal(p.RawMessage, &s)
|
|
|
|
if err != nil {
|
|
|
|
return "", errNotAString
|
|
|
|
}
|
|
|
|
p.cache = s
|
2021-10-28 11:10:18 +00:00
|
|
|
}
|
2021-10-28 14:24:38 +00:00
|
|
|
if s, ok := p.cache.(string); ok {
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
return "", errNotAString
|
2019-11-21 13:42:51 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetString returns a string value of the parameter or tries to cast the parameter to a string value.
|
2020-06-04 11:58:47 +00:00
|
|
|
func (p *Param) GetString() (string, error) {
|
|
|
|
if p == nil {
|
|
|
|
return "", errMissingParameter
|
|
|
|
}
|
2021-10-28 11:10:18 +00:00
|
|
|
if p.IsNull() {
|
|
|
|
return "", errNotAString
|
|
|
|
}
|
2021-10-28 14:24:38 +00:00
|
|
|
if p.cache == nil {
|
|
|
|
var s string
|
|
|
|
err := json.Unmarshal(p.RawMessage, &s)
|
|
|
|
if err == nil {
|
|
|
|
p.cache = s
|
|
|
|
} else {
|
2022-02-09 12:13:15 +00:00
|
|
|
var i int64
|
2021-10-28 14:24:38 +00:00
|
|
|
err = json.Unmarshal(p.RawMessage, &i)
|
|
|
|
if err == nil {
|
|
|
|
p.cache = i
|
|
|
|
} else {
|
|
|
|
var b bool
|
|
|
|
err = json.Unmarshal(p.RawMessage, &b)
|
|
|
|
if err == nil {
|
|
|
|
p.cache = b
|
|
|
|
} else {
|
|
|
|
return "", errNotAString
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-28 11:10:18 +00:00
|
|
|
}
|
2021-10-28 14:24:38 +00:00
|
|
|
switch t := p.cache.(type) {
|
|
|
|
case string:
|
|
|
|
return t, nil
|
2022-02-09 12:13:15 +00:00
|
|
|
case int64:
|
|
|
|
return strconv.FormatInt(t, 10), nil
|
2021-10-28 14:24:38 +00:00
|
|
|
case bool:
|
|
|
|
if t {
|
2021-10-28 11:10:18 +00:00
|
|
|
return "true", nil
|
|
|
|
}
|
|
|
|
return "false", nil
|
2021-10-28 14:24:38 +00:00
|
|
|
default:
|
|
|
|
return "", errNotAString
|
2021-10-28 11:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBooleanStrict returns boolean value of the parameter.
|
|
|
|
func (p *Param) GetBooleanStrict() (bool, error) {
|
|
|
|
if p == nil {
|
|
|
|
return false, errMissingParameter
|
|
|
|
}
|
|
|
|
if bytes.Equal(p.RawMessage, jsonTrueBytes) {
|
2021-10-28 14:24:38 +00:00
|
|
|
p.cache = true
|
2021-10-28 11:10:18 +00:00
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
if bytes.Equal(p.RawMessage, jsonFalseBytes) {
|
2021-10-28 14:24:38 +00:00
|
|
|
p.cache = false
|
2021-10-28 11:10:18 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
return false, errNotABool
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetBoolean returns a boolean value of the parameter or tries to cast the parameter to a bool value.
|
2021-10-28 11:10:18 +00:00
|
|
|
func (p *Param) GetBoolean() (bool, error) {
|
|
|
|
if p == nil {
|
|
|
|
return false, errMissingParameter
|
|
|
|
}
|
|
|
|
if p.IsNull() {
|
|
|
|
return false, errNotABool
|
|
|
|
}
|
|
|
|
var b bool
|
2021-10-28 14:24:38 +00:00
|
|
|
if p.cache == nil {
|
|
|
|
err := json.Unmarshal(p.RawMessage, &b)
|
|
|
|
if err == nil {
|
|
|
|
p.cache = b
|
|
|
|
} else {
|
|
|
|
var s string
|
|
|
|
err = json.Unmarshal(p.RawMessage, &s)
|
|
|
|
if err == nil {
|
|
|
|
p.cache = s
|
|
|
|
} else {
|
2022-02-09 12:13:15 +00:00
|
|
|
var i int64
|
2021-10-28 14:24:38 +00:00
|
|
|
err = json.Unmarshal(p.RawMessage, &i)
|
|
|
|
if err == nil {
|
|
|
|
p.cache = i
|
|
|
|
} else {
|
|
|
|
return false, errNotABool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-28 11:10:18 +00:00
|
|
|
}
|
2021-10-28 14:24:38 +00:00
|
|
|
switch t := p.cache.(type) {
|
|
|
|
case bool:
|
|
|
|
return t, nil
|
|
|
|
case string:
|
|
|
|
return t != "", nil
|
2022-02-09 12:13:15 +00:00
|
|
|
case int64:
|
2021-10-28 14:24:38 +00:00
|
|
|
return t != 0, nil
|
|
|
|
default:
|
|
|
|
return false, errNotABool
|
2019-11-26 10:13:17 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-21 13:42:51 +00:00
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetIntStrict returns an int value of the parameter if the parameter is an integer.
|
2021-10-28 11:10:18 +00:00
|
|
|
func (p *Param) GetIntStrict() (int, error) {
|
2020-06-04 12:43:37 +00:00
|
|
|
if p == nil {
|
2021-10-28 11:10:18 +00:00
|
|
|
return 0, errMissingParameter
|
|
|
|
}
|
|
|
|
if p.IsNull() {
|
|
|
|
return 0, errNotAnInt
|
2020-06-04 12:43:37 +00:00
|
|
|
}
|
2022-02-09 12:13:15 +00:00
|
|
|
value, err := p.fillIntCache()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
2021-10-28 14:24:38 +00:00
|
|
|
}
|
2022-02-09 12:13:15 +00:00
|
|
|
if i, ok := value.(int64); ok && i == int64(int(i)) {
|
|
|
|
return int(i), nil
|
2021-10-28 11:10:18 +00:00
|
|
|
}
|
2021-10-28 14:24:38 +00:00
|
|
|
return 0, errNotAnInt
|
2020-06-04 12:43:37 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 10:34:24 +00:00
|
|
|
func (p *Param) fillIntCache() (any, error) {
|
2022-02-09 12:13:15 +00:00
|
|
|
if p.cache != nil {
|
|
|
|
return p.cache, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// We could also try unmarshalling to uint64, but JSON reliably supports numbers
|
|
|
|
// up to 53 bits in size.
|
|
|
|
var i int64
|
|
|
|
err := json.Unmarshal(p.RawMessage, &i)
|
|
|
|
if err == nil {
|
|
|
|
p.cache = i
|
|
|
|
return i, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var s string
|
|
|
|
err = json.Unmarshal(p.RawMessage, &s)
|
|
|
|
if err == nil {
|
|
|
|
p.cache = s
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var b bool
|
|
|
|
err = json.Unmarshal(p.RawMessage, &b)
|
|
|
|
if err == nil {
|
|
|
|
p.cache = b
|
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
return nil, errNotAnInt
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetInt returns an int value of the parameter or tries to cast the parameter to an int value.
|
2020-06-04 11:58:47 +00:00
|
|
|
func (p *Param) GetInt() (int, error) {
|
|
|
|
if p == nil {
|
|
|
|
return 0, errMissingParameter
|
|
|
|
}
|
2021-10-28 11:10:18 +00:00
|
|
|
if p.IsNull() {
|
|
|
|
return 0, errNotAnInt
|
|
|
|
}
|
2022-02-09 12:13:15 +00:00
|
|
|
value, err := p.fillIntCache()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
2019-11-26 10:13:17 +00:00
|
|
|
}
|
2022-02-09 12:13:15 +00:00
|
|
|
switch t := value.(type) {
|
|
|
|
case int64:
|
|
|
|
if t == int64(int(t)) {
|
|
|
|
return int(t), nil
|
|
|
|
}
|
|
|
|
return 0, errNotAnInt
|
2021-10-28 14:24:38 +00:00
|
|
|
case string:
|
|
|
|
return strconv.Atoi(t)
|
|
|
|
case bool:
|
|
|
|
if t {
|
|
|
|
return 1, nil
|
2021-10-28 11:10:18 +00:00
|
|
|
}
|
2021-10-28 14:24:38 +00:00
|
|
|
return 0, nil
|
|
|
|
default:
|
2022-02-09 12:13:15 +00:00
|
|
|
panic("unreachable")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetBigInt returns a big-integer value of the parameter.
|
2022-02-09 12:13:15 +00:00
|
|
|
func (p *Param) GetBigInt() (*big.Int, error) {
|
|
|
|
if p == nil {
|
|
|
|
return nil, errMissingParameter
|
|
|
|
}
|
|
|
|
if p.IsNull() {
|
|
|
|
return nil, errNotAnInt
|
|
|
|
}
|
|
|
|
value, err := p.fillIntCache()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
switch t := value.(type) {
|
|
|
|
case int64:
|
|
|
|
return big.NewInt(t), nil
|
|
|
|
case string:
|
|
|
|
bi, ok := new(big.Int).SetString(t, 10)
|
|
|
|
if !ok {
|
|
|
|
return nil, errNotAnInt
|
|
|
|
}
|
|
|
|
return bi, nil
|
|
|
|
case bool:
|
|
|
|
if t {
|
|
|
|
return big.NewInt(1), nil
|
|
|
|
}
|
|
|
|
return new(big.Int), nil
|
|
|
|
default:
|
|
|
|
panic("unreachable")
|
2021-10-28 11:10:18 +00:00
|
|
|
}
|
2019-11-26 10:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetArray returns a slice of Params stored in the parameter.
|
2020-06-04 11:58:47 +00:00
|
|
|
func (p *Param) GetArray() ([]Param, error) {
|
|
|
|
if p == nil {
|
|
|
|
return nil, errMissingParameter
|
|
|
|
}
|
2021-10-28 11:10:18 +00:00
|
|
|
if p.IsNull() {
|
|
|
|
return nil, errNotAnArray
|
2021-08-05 14:56:17 +00:00
|
|
|
}
|
2021-10-28 14:24:38 +00:00
|
|
|
if p.cache == nil {
|
|
|
|
a := []Param{}
|
|
|
|
err := json.Unmarshal(p.RawMessage, &a)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errNotAnArray
|
|
|
|
}
|
|
|
|
p.cache = a
|
|
|
|
}
|
|
|
|
if a, ok := p.cache.([]Param); ok {
|
|
|
|
return a, nil
|
2021-08-05 14:56:17 +00:00
|
|
|
}
|
2021-10-28 14:24:38 +00:00
|
|
|
return nil, errNotAnArray
|
2019-11-26 10:13:17 +00:00
|
|
|
}
|
2019-11-21 13:42:51 +00:00
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetUint256 returns a Uint256 value of the parameter.
|
2020-06-04 11:58:47 +00:00
|
|
|
func (p *Param) GetUint256() (util.Uint256, error) {
|
2019-11-26 10:13:17 +00:00
|
|
|
s, err := p.GetString()
|
|
|
|
if err != nil {
|
|
|
|
return util.Uint256{}, err
|
2019-11-21 13:42:51 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 09:07:02 +00:00
|
|
|
return util.Uint256DecodeStringLE(strings.TrimPrefix(s, "0x"))
|
2019-11-21 13:42:51 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetUint160FromHex returns a Uint160 value of the parameter encoded in hex.
|
2020-06-04 11:58:47 +00:00
|
|
|
func (p *Param) GetUint160FromHex() (util.Uint160, error) {
|
2019-11-26 10:13:17 +00:00
|
|
|
s, err := p.GetString()
|
|
|
|
if err != nil {
|
|
|
|
return util.Uint160{}, err
|
|
|
|
}
|
|
|
|
|
2021-11-10 11:31:13 +00:00
|
|
|
return util.Uint160DecodeStringLE(strings.TrimPrefix(s, "0x"))
|
2019-11-26 10:13:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetUint160FromAddress returns a Uint160 value of the parameter that was
|
2019-11-26 10:13:17 +00:00
|
|
|
// supplied as an address.
|
2020-06-04 11:58:47 +00:00
|
|
|
func (p *Param) GetUint160FromAddress() (util.Uint160, error) {
|
2019-11-26 10:13:17 +00:00
|
|
|
s, err := p.GetString()
|
|
|
|
if err != nil {
|
|
|
|
return util.Uint160{}, err
|
|
|
|
}
|
|
|
|
|
2019-12-25 14:34:18 +00:00
|
|
|
return address.StringToUint160(s)
|
2019-11-26 10:13:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetUint160FromAddressOrHex returns a Uint160 value of the parameter that was
|
2020-07-03 15:40:45 +00:00
|
|
|
// supplied either as raw hex or as an address.
|
|
|
|
func (p *Param) GetUint160FromAddressOrHex() (util.Uint160, error) {
|
|
|
|
u, err := p.GetUint160FromHex()
|
|
|
|
if err == nil {
|
|
|
|
return u, err
|
|
|
|
}
|
|
|
|
return p.GetUint160FromAddress()
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetFuncParam returns the current parameter as a function call parameter.
|
2020-06-04 11:58:47 +00:00
|
|
|
func (p *Param) GetFuncParam() (FuncParam, error) {
|
|
|
|
if p == nil {
|
|
|
|
return FuncParam{}, errMissingParameter
|
|
|
|
}
|
2021-10-28 14:24:38 +00:00
|
|
|
// This one doesn't need to be cached, it's used only once.
|
2021-10-28 11:10:18 +00:00
|
|
|
fp := FuncParam{}
|
|
|
|
err := json.Unmarshal(p.RawMessage, &fp)
|
|
|
|
return fp, err
|
2019-11-26 10:13:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetBytesHex returns a []byte value of the parameter if
|
2019-11-21 14:42:02 +00:00
|
|
|
// it is a hex-encoded string.
|
2020-06-04 11:58:47 +00:00
|
|
|
func (p *Param) GetBytesHex() ([]byte, error) {
|
2019-11-26 10:13:17 +00:00
|
|
|
s, err := p.GetString()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2019-11-21 14:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return hex.DecodeString(s)
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// GetBytesBase64 returns a []byte value of the parameter if
|
2020-07-07 19:35:03 +00:00
|
|
|
// it is a base64-encoded string.
|
|
|
|
func (p *Param) GetBytesBase64() ([]byte, error) {
|
|
|
|
s, err := p.GetString()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return base64.StdEncoding.DecodeString(s)
|
|
|
|
}
|
|
|
|
|
2022-07-22 16:09:29 +00:00
|
|
|
// GetSignerWithWitness returns a neorpc.SignerWithWitness value of the parameter.
|
|
|
|
func (p *Param) GetSignerWithWitness() (neorpc.SignerWithWitness, error) {
|
2021-10-28 14:24:38 +00:00
|
|
|
// This one doesn't need to be cached, it's used only once.
|
2022-07-22 16:09:29 +00:00
|
|
|
c := neorpc.SignerWithWitness{}
|
2022-07-07 14:41:01 +00:00
|
|
|
err := json.Unmarshal(p.RawMessage, &c)
|
2021-08-05 14:56:17 +00:00
|
|
|
if err != nil {
|
2022-07-22 16:09:29 +00:00
|
|
|
return neorpc.SignerWithWitness{}, fmt.Errorf("not a signer: %w", err)
|
2021-08-05 14:56:17 +00:00
|
|
|
}
|
2020-06-10 11:45:55 +00:00
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2021-04-19 08:53:01 +00:00
|
|
|
// GetSignersWithWitnesses returns a slice of SignerWithWitness with CalledByEntry
|
2022-04-20 18:30:09 +00:00
|
|
|
// scope from an array of Uint160 or an array of serialized transaction.Signer stored
|
2021-04-19 08:53:01 +00:00
|
|
|
// in the parameter.
|
2020-12-14 12:23:39 +00:00
|
|
|
func (p Param) GetSignersWithWitnesses() ([]transaction.Signer, []transaction.Witness, error) {
|
2020-06-10 11:45:55 +00:00
|
|
|
hashes, err := p.GetArray()
|
|
|
|
if err != nil {
|
2020-12-14 12:23:39 +00:00
|
|
|
return nil, nil, err
|
2020-06-10 11:45:55 +00:00
|
|
|
}
|
2020-07-29 16:57:38 +00:00
|
|
|
signers := make([]transaction.Signer, len(hashes))
|
2020-12-14 12:23:39 +00:00
|
|
|
witnesses := make([]transaction.Witness, len(hashes))
|
2020-06-10 11:45:55 +00:00
|
|
|
// try to extract hashes first
|
|
|
|
for i, h := range hashes {
|
|
|
|
var u util.Uint160
|
|
|
|
u, err = h.GetUint160FromHex()
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
2020-07-29 16:57:38 +00:00
|
|
|
signers[i] = transaction.Signer{
|
2020-06-10 11:45:55 +00:00
|
|
|
Account: u,
|
2021-04-19 08:53:01 +00:00
|
|
|
Scopes: transaction.CalledByEntry,
|
2020-06-10 11:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
for i, h := range hashes {
|
2020-12-14 12:23:39 +00:00
|
|
|
signerWithWitness, err := h.GetSignerWithWitness()
|
2020-06-10 11:45:55 +00:00
|
|
|
if err != nil {
|
2020-12-14 12:23:39 +00:00
|
|
|
return nil, nil, err
|
2020-06-10 11:45:55 +00:00
|
|
|
}
|
2020-12-14 12:23:39 +00:00
|
|
|
signers[i] = signerWithWitness.Signer
|
|
|
|
witnesses[i] = signerWithWitness.Witness
|
2020-06-10 11:45:55 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-14 12:23:39 +00:00
|
|
|
return signers, witnesses, nil
|
2020-06-10 11:45:55 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// IsNull returns whether the parameter represents JSON nil value.
|
2021-10-28 11:10:18 +00:00
|
|
|
func (p *Param) IsNull() bool {
|
|
|
|
return bytes.Equal(p.RawMessage, jsonNullBytes)
|
2018-03-23 20:36:59 +00:00
|
|
|
}
|
2020-12-14 12:23:39 +00:00
|
|
|
|
2022-06-15 18:23:29 +00:00
|
|
|
// GetUUID returns UUID from parameter.
|
|
|
|
func (p *Param) GetUUID() (uuid.UUID, error) {
|
|
|
|
s, err := p.GetString()
|
|
|
|
if err != nil {
|
|
|
|
return uuid.UUID{}, err
|
|
|
|
}
|
|
|
|
id, err := uuid.Parse(s)
|
|
|
|
if err != nil {
|
|
|
|
return uuid.UUID{}, fmt.Errorf("not a valid UUID: %w", err)
|
|
|
|
}
|
|
|
|
return id, nil
|
|
|
|
}
|