response

package
v0.98.2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidParams represents a generic 'invalid parameters' error.
	ErrInvalidParams = NewInvalidParamsError("", nil)
	// 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 Abstract added in v0.92.0

type Abstract struct {
	HeaderAndError
	Result interface{} `json:"result,omitempty"`
}

Abstract represents abstract JSON-RPC 2.0 response, it differs from Raw in that Result field is an interface here.

func (Abstract) RunForErrors added in v0.92.0

func (a Abstract) RunForErrors(f func(jsonErr *Error))

RunForErrors implements AbstractResult interface.

type AbstractBatch added in v0.92.0

type AbstractBatch []Abstract

AbstractBatch represents abstract JSON-RPC 2.0 batch-response.

func (AbstractBatch) RunForErrors added in v0.92.0

func (ab AbstractBatch) RunForErrors(f func(jsonErr *Error))

RunForErrors implements AbstractResult interface.

type AbstractResult added in v0.78.2

type AbstractResult interface {
	RunForErrors(f func(jsonErr *Error))
}

AbstractResult is an interface which represents either single JSON-RPC 2.0 response or batch JSON-RPC 2.0 response.

type Error

type Error struct {
	Code     int64  `json:"code"`
	HTTPCode int    `json:"-"`
	Cause    error  `json:"-"`
	Message  string `json:"message"`
	Data     string `json:"data,omitempty"`
}

Error object for outputting JSON-RPC 2.0 errors.

func NewError

func NewError(code int64, httpCode int, message string, data string, cause error) *Error

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

func NewInternalServerError

func NewInternalServerError(data string, cause error) *Error

NewInternalServerError creates a new error with code -32603.

func NewInvalidParamsError

func NewInvalidParamsError(data string, cause error) *Error

NewInvalidParamsError creates a new error with code -32602.

func NewInvalidRequestError

func NewInvalidRequestError(data string, cause error) *Error

NewInvalidRequestError creates a new error with code -32600.

func NewMethodNotFoundError

func NewMethodNotFoundError(data string, cause error) *Error

NewMethodNotFoundError creates a new error with code -32601.

func NewParseError

func NewParseError(data string, cause error) *Error

NewParseError creates a new error with code -32700.

func NewRPCError

func NewRPCError(message string, data string, cause error) *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 added in v0.94.0

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

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

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

type EventID added in v0.75.0

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 `transaction_added` event.
	TransactionEventID
	// NotificationEventID represents `notification_from_execution` events.
	NotificationEventID
	// ExecutionEventID is used for `transaction_executed` events.
	ExecutionEventID
	// NotaryRequestEventID is used for `notary_request_event` event.
	NotaryRequestEventID
	// MissedEventID notifies user of missed events.
	MissedEventID EventID = 255
)

func GetEventIDFromString added in v0.75.0

func GetEventIDFromString(s string) (EventID, error)

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

func (EventID) MarshalJSON added in v0.75.0

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

MarshalJSON implements json.Marshaler interface.

func (EventID) String added in v0.75.0

func (e EventID) String() string

String is a good old Stringer implementation.

func (*EventID) UnmarshalJSON added in v0.75.0

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

UnmarshalJSON implements json.Unmarshaler interface.

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 added in v0.75.0

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.

type Raw

type Raw 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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