neorpc

package
v0.100.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 8 Imported by: 7

Documentation

Overview

Package neorpc contains a set of types used for JSON-RPC communication with Neo servers. It defines basic request/response types as well as a set of errors and additional parameters used for specific requests/responses.

Index

Constants

View Source
const (
	// InternalServerErrorCode is returned for internal RPC server error.
	InternalServerErrorCode = -32603
	// BadRequestCode is returned on parse error.
	BadRequestCode = -32700
	// InvalidRequestCode is returned on invalid request.
	InvalidRequestCode = -32600
	// MethodNotFoundCode is returned on unknown method calling.
	MethodNotFoundCode = -32601
	// InvalidParamsCode is returned on request with invalid params.
	InvalidParamsCode = -32602
)

Standard RPC error codes defined by the JSON-RPC 2.0 specification.

View Source
const (
	// JSONRPCVersion is the only JSON-RPC protocol version supported.
	JSONRPCVersion = "2.0"
)
View Source
const (
	// RPCErrorCode is returned on RPC request processing error.
	RPCErrorCode = -100
)

RPC error codes defined by the Neo JSON-RPC specification extension.

Variables

View Source
var (
	// ErrInvalidParams represents a generic 'invalid parameters' error.
	ErrInvalidParams = NewInvalidParamsError("invalid params")
	// ErrUnknownBlock is returned if requested block is not found.
	ErrUnknownBlock = NewError(RPCErrorCode, "Unknown block", "")
	// ErrUnknownTransaction is returned if requested transaction is not found.
	ErrUnknownTransaction = NewError(RPCErrorCode, "Unknown transaction", "")
	// ErrUnknownHeader is returned when requested header is not found.
	ErrUnknownHeader = NewError(RPCErrorCode, "Unknown header", "")
	// ErrUnknownScriptContainer is returned when requested block or transaction is not found.
	ErrUnknownScriptContainer = NewError(RPCErrorCode, "Unknown script container", "")
	// ErrUnknownStateRoot is returned when requested state root is not found.
	ErrUnknownStateRoot = NewError(RPCErrorCode, "Unknown state root", "")
	// ErrAlreadyExists represents SubmitError with code -501.
	ErrAlreadyExists = NewSubmitError(-501, "Block or transaction already exists and cannot be sent repeatedly.")
	// ErrOutOfMemory represents SubmitError with code -502.
	ErrOutOfMemory = NewSubmitError(-502, "The memory pool is full and no more transactions can be sent.")
	// ErrUnableToVerify represents SubmitError with code -503.
	ErrUnableToVerify = NewSubmitError(-503, "The block cannot be validated.")
	// ErrValidationFailed represents SubmitError with code -504.
	ErrValidationFailed = NewSubmitError(-504, "Block or transaction validation failed.")
	// ErrPolicyFail represents SubmitError with code -505.
	ErrPolicyFail = NewSubmitError(-505, "One of the Policy filters failed.")
	// ErrUnknown represents SubmitError with code -500.
	ErrUnknown = NewSubmitError(-500, "Unknown error.")
)

Functions

This section is empty.

Types

type BlockFilter

type BlockFilter struct {
	Primary *int    `json:"primary,omitempty"`
	Since   *uint32 `json:"since,omitempty"`
	Till    *uint32 `json:"till,omitempty"`
}

BlockFilter is a wrapper structure for the block event filter. It allows to filter blocks by primary index and/or by block index (allowing blocks since/till the specified index inclusively). nil value treated as missing filter.

type Error

type Error struct {
	Code    int64  `json:"code"`
	Message string `json:"message"`
	Data    string `json:"data,omitempty"`
}

Error represents JSON-RPC 2.0 error type.

func NewError

func NewError(code int64, message string, data string) *Error

NewError is an Error constructor that takes Error contents from its parameters.

func NewInternalServerError

func NewInternalServerError(data string) *Error

NewInternalServerError creates a new error with code -32603.

func NewInvalidParamsError

func NewInvalidParamsError(data string) *Error

NewInvalidParamsError creates a new error with code -32602.

func NewInvalidRequestError

func NewInvalidRequestError(data string) *Error

NewInvalidRequestError creates a new error with code -32600.

func NewMethodNotFoundError

func NewMethodNotFoundError(data string) *Error

NewMethodNotFoundError creates a new error with code -32601.

func NewParseError

func NewParseError(data string) *Error

NewParseError creates a new error with code -32700.

func NewRPCError

func NewRPCError(message string, data string) *Error

NewRPCError creates a new error with code -100.

func NewSubmitError

func NewSubmitError(code int64, message string) *Error

NewSubmitError creates a new error with specified error code and error message.

func WrapErrorWithData

func WrapErrorWithData(e *Error, data string) *Error

WrapErrorWithData returns copy of the given error with the specified data and cause. It does not modify the source error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) Is

func (e *Error) Is(target error) bool

Is denotes whether the error matches the target one.

type EventID

type EventID byte

EventID represents an event type happening on the chain.

const (
	// InvalidEventID is an invalid event id that is the default value of
	// EventID. It's only used as an initial value similar to nil.
	InvalidEventID EventID = iota
	// BlockEventID is a `block_added` event.
	BlockEventID
	// TransactionEventID corresponds to the `transaction_added` event.
	TransactionEventID
	// NotificationEventID represents `notification_from_execution` events.
	NotificationEventID
	// ExecutionEventID is used for `transaction_executed` events.
	ExecutionEventID
	// NotaryRequestEventID is used for the `notary_request_event` event.
	NotaryRequestEventID
	// MissedEventID notifies user of missed events.
	MissedEventID EventID = 255
)

func GetEventIDFromString

func GetEventIDFromString(s string) (EventID, error)

GetEventIDFromString converts an input string into an EventID if it's possible.

func (EventID) MarshalJSON

func (e EventID) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (EventID) String

func (e EventID) String() string

String is a good old Stringer implementation.

func (*EventID) UnmarshalJSON

func (e *EventID) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type ExecutionFilter

type ExecutionFilter struct {
	State     *string       `json:"state,omitempty"`
	Container *util.Uint256 `json:"container,omitempty"`
}

ExecutionFilter is a wrapper structure used for transaction and persisting scripts execution events. It allows to choose failing or successful transactions and persisting scripts based on their VM state and/or to choose execution event with the specified container. nil value treated as missing filter.

type Header struct {
	ID      json.RawMessage `json:"id"`
	JSONRPC string          `json:"jsonrpc"`
}

Header is a generic JSON-RPC 2.0 response header (ID and JSON-RPC version).

type HeaderAndError

type HeaderAndError struct {
	Header
	Error *Error `json:"error,omitempty"`
}

HeaderAndError adds an Error (that can be empty) to the Header, it's used to construct type-specific responses.

type Notification

type Notification struct {
	JSONRPC string        `json:"jsonrpc"`
	Event   EventID       `json:"method"`
	Payload []interface{} `json:"params"`
}

Notification is a type used to represent wire format of events, they're special in that they look like requests but they don't have IDs and their "method" is actually an event name.

func (*Notification) EventID added in v0.99.5

func (n *Notification) EventID() EventID

EventID implements EventContainer interface and returns notification ID.

func (*Notification) EventPayload added in v0.99.5

func (n *Notification) EventPayload() interface{}

EventPayload implements EventContainer interface and returns notification object.

type NotificationFilter

type NotificationFilter struct {
	Contract *util.Uint160 `json:"contract,omitempty"`
	Name     *string       `json:"name,omitempty"`
}

NotificationFilter is a wrapper structure representing a filter used for notifications generated during transaction execution. Notifications can be filtered by contract hash and/or by name. nil value treated as missing filter.

type Request

type Request struct {
	// JSONRPC is the protocol version, only valid when it contains JSONRPCVersion.
	JSONRPC string `json:"jsonrpc"`
	// Method is the method being called.
	Method string `json:"method"`
	// Params is a set of method-specific parameters passed to the call. They
	// can be anything as long as they can be marshaled to JSON correctly and
	// used by the method implementation on the server side. While JSON-RPC
	// technically allows it to be an object, all Neo calls expect params
	// to be an array.
	Params []interface{} `json:"params"`
	// ID is an identifier associated with this request. JSON-RPC itself allows
	// any strings to be used for it as well, but NeoGo RPC client uses numeric
	// identifiers.
	ID uint64 `json:"id"`
}

Request represents JSON-RPC request. It's generic enough to be used in many generic JSON-RPC communication scenarios, yet at the same time it's tailored for NeoGo RPC Client needs.

type Response

type Response struct {
	HeaderAndError
	Result json.RawMessage `json:"result,omitempty"`
}

Raw represents a standard raw JSON-RPC 2.0 response: http://www.jsonrpc.org/specification#response_object.

type SignerWithWitness

type SignerWithWitness struct {
	transaction.Signer
	transaction.Witness
}

SignerWithWitness represents transaction's signer with the corresponding witness.

func (*SignerWithWitness) MarshalJSON

func (s *SignerWithWitness) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*SignerWithWitness) UnmarshalJSON

func (s *SignerWithWitness) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type TxFilter

type TxFilter struct {
	Sender *util.Uint160 `json:"sender,omitempty"`
	Signer *util.Uint160 `json:"signer,omitempty"`
}

TxFilter is a wrapper structure for the transaction event filter. It allows to filter transactions by senders and/or signers. nil value treated as missing filter.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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