request

package
v0.0.0-...-d56c475 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DestinationUtxo    = "UTXO"
	DestinationAccount = "Account"

	BlackHoleAddr = "0000-0000-0000-0000-0000"
)
View Source
const JsonRPCVersion = "2.0"
View Source
const (
	NamespaceSeparator = "."
)

Variables

This section is empty.

Functions

func Omitempty

func Omitempty(v any) any

Omitempty if input type zero value then return nil

Types

type BatchRequest

type BatchRequest struct {
	Req    *Request
	Result any   //response result
	Err    error //response error
}

type BatchRequestParams

type BatchRequestParams struct {
	RequestParams
	Result any //response type
}

type BlockIdOrHash

type BlockIdOrHash struct {
	Id   int64  `json:"id,omitempty"`
	Hash string `json:"hash,omitempty"`
}

BlockIdOrHash block id or block hash must be only choose one

type FileType

type FileType struct {
	Name  string `json:"name"`  //file name
	Type  string `json:"type"`  //data type if exist
	Value string `json:"value"` //if file name is null, save result to value
}

func NewFileType

func NewFileType(fileName string) *FileType

type GetList

type GetList struct {
	ListForm
	Order any `json:"order"`
	Where any `json:"where"`
}

type ID

type ID struct {
	// At most one of Num or Str may be nonzero. If both are zero
	// valued, then IsNum specifies which field's value is to be used
	// as the ID.
	Num uint64
	Str string

	// IsString controls whether the Num or Str field's value should be
	// used as the ID, when both are zero valued. It must always be
	// set to true if the request ID is a string.
	IsString bool
}

ID represents a JSON-RPC 2.0 request ID, which may be either a string or number (or null, which is unsupported).

func IntID

func IntID(i uint64) ID

func StringID

func StringID(s string) ID

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ListForm

type ListForm struct {
	Name string `json:"name"` //table name
	PaginatorForm
	RowForm
}

type MapParams

type MapParams map[string]any

func (*MapParams) Get

func (cp *MapParams) Get(key string) string

func (*MapParams) GetRaw

func (cp *MapParams) GetRaw(key string) any

type Namespace

type Namespace string
const (
	NamespaceRPC Namespace = "rpc"

	NamespaceIBAX  Namespace = "ibax"
	NamespaceAdmin Namespace = "admin"
)

type PaginatorForm

type PaginatorForm struct {
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
}

type Param

type Param json.RawMessage

Params is an ARRAY of json.RawMessages. This is because *Ethereum* RPCs always use arrays is their input parameter; this differs from the official JSONRPC spec, which allows parameters of any type. But, this assumption makes handling Params in our Ethereum API use-cases *so* much easier.

func (Param) MarshalJSON

func (m Param) MarshalJSON() ([]byte, error)

MarshalJSON returns m as the JSON encoding of m.

func (*Param) UnmarshalJSON

func (m *Param) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data.

type Params

type Params []Param

func MakeParams

func MakeParams(params ...any) (Params, error)

MakeParams generates JSONRPC parameters from its inputs, and should be used for complex dynamic data which may fail to marshal, in which case the error is propagated to the caller.

Examples:

params, err := jsonrpc.MakeParams(someComplexObject, "string", true)

func MustParams

func MustParams(params ...any) Params

MakeParams can be used to generate JSONRPC Params field from well-known data, which should not fail.

Examples:

request.Params = jsonrpc.MustParams("latest", true)

func (Params) UnmarshalInto

func (p Params) UnmarshalInto(receivers ...any) error

UnmarshalInto will decode Params into the passed in values, which must be pointer receivers. The type of the passed in value is used to Unmarshal the data. UnmarshalInto will fail if the parameters cannot be converted to the passed-in types.

Example:

var blockNum string
var fullBlock bool
err := request.Params.UnmarshalInto(&blockNum, &fullBlock)

IMPORTANT: While Go will compile with non-pointer receivers, the Unmarshal attempt will *always* fail with an error.

func (Params) UnmarshalSingleParam

func (p Params) UnmarshalSingleParam(pos int, receiver any) error

UnmarshalSingleParam can be used in the (rare) case where only one of the Request.Params is needed. For example we use this in Smart Routing to extract the blockNum value from RPCs without decoding the entire Params array.

Example:

err := request.Params.UnmarshalSingleParam(pos, &blockNum)

type Request

type Request struct {
	JSONRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
	ID      ID     `json:"id"`
	Params  Params `json:"params"`
}

func (Request) MarshalJSON

func (r Request) MarshalJSON() ([]byte, error)

func (*Request) UnmarshalJSON

func (r *Request) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type RequestParams

type RequestParams struct {
	Namespace Namespace
	Name      string
	Params    []any
}

type RowForm

type RowForm struct {
	Columns string `json:"columns"`
}

type UtxoType

type UtxoType int
const (
	TypeContractToUTXO UtxoType = iota //Contract Account transfer UTXO Account
	TypeUTXOToContract                 //UTXO Account transfer Contract Account
	TypeTransfer
)

type WordsLenType

type WordsLenType int
const (
	WordsLenTwelve    WordsLenType = 12
	WordsLenFifteen   WordsLenType = 15
	WordsLenEighteen  WordsLenType = 18
	WordsTwentyOne    WordsLenType = 21
	WordsLenTwentyTwo WordsLenType = 24
)

func (*WordsLenType) GetBitSize

func (w *WordsLenType) GetBitSize() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL