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
- Variables
- type BlockFilter
- type Error
- func NewError(code int64, message string, data string) *Error
- func NewInternalServerError(data string) *Error
- func NewInvalidParamsError(data string) *Error
- func NewInvalidRequestError(data string) *Error
- func NewMethodNotFoundError(data string) *Error
- func NewParseError(data string) *Error
- func NewRPCError(message string, data string) *Error
- func NewSubmitError(code int64, message string) *Error
- func WrapErrorWithData(e *Error, data string) *Error
- type EventID
- type ExecutionFilter
- type Header
- type HeaderAndError
- type Notification
- type NotificationFilter
- type Request
- type Response
- type SignerWithWitness
- type TxFilter
Constants ¶
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.
const (
// JSONRPCVersion is the only JSON-RPC protocol version supported.
JSONRPCVersion = "2.0"
)
const (
// RPCErrorCode is returned on RPC request processing error.
RPCErrorCode = -100
)
RPC error codes defined by the Neo JSON-RPC specification extension.
Variables ¶
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 NewInternalServerError ¶
NewInternalServerError creates a new error with code -32603.
func NewInvalidParamsError ¶
NewInvalidParamsError creates a new error with code -32602.
func NewInvalidRequestError ¶
NewInvalidRequestError creates a new error with code -32600.
func NewMethodNotFoundError ¶
NewMethodNotFoundError creates a new error with code -32601.
func NewParseError ¶
NewParseError creates a new error with code -32700.
func NewRPCError ¶
NewRPCError creates a new error with code -100.
func NewSubmitError ¶
NewSubmitError creates a new error with specified error code and error message.
func WrapErrorWithData ¶
WrapErrorWithData returns copy of the given error with the specified data and cause. It does not modify the source error.
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 ¶
GetEventIDFromString converts an input string into an EventID if it's possible.
func (EventID) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*EventID) UnmarshalJSON ¶
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 ¶
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 ¶
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.