rpc

package
v0.0.0-...-4502c18 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: GPL-3.0 Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrParseError returned if invalid JSON was received by the server.
	// An error occurred on the server while parsing the JSON text.
	ErrParseError = err(-32700, "Parse Error")

	/// ErrInvalidRequest returned if JSON sent is not a valid Request object.
	ErrInvalidRequest = err(-32600, "Invalid Request")

	// ErrMethodNotFound returned if method does not exist / is not available.
	ErrMethodNotFound = err(-32601, "Method not found")

	// ErrInvalidParams returned if received invalid method parameter(s).
	ErrInvalidParams = err(-32602, "Invalid method parameter(s)")

	// ErrInternalError returned if occurred internal JSON-RPC error.
	ErrInternalError = err(-32603, "Internal error")
)
View Source
var (
	ErrTxNotFound = err(0, rawdb.ErrTxNotFound.Error())
)

Functions

func GetMethod

func GetMethod(method string) (func() Executer, bool)

func Register

func Register(name string, factory func() Executer)

Register a registers a new method.

func SetConfig

func SetConfig(config *config.Config)

SetConfig must be called before any methods are executed.

Types

type Args

type Args []byte

Args is necessary at the stage of receiving json, because to determine the necessary parameters, you first need to know what method should be called.

func (*Args) Bytes

func (a *Args) Bytes() []byte

Bytes return bytes array.

func (*Args) UnmarshalJSON

func (a *Args) UnmarshalJSON(b []byte) error

UnmarshalJSON allows you to put json "as is" in text form, then deserialize as soon as the method is known.

type CreateTxRequest

type CreateTxRequest struct {
	Secret  string `json:"secret"`
	Address string `json:"address"`
	Amount  uint64 `json:"amount"`
}

type DefaultError

type DefaultError struct {
	C int32  `json:"code"`
	M string `json:"message"`
}

func (*DefaultError) Code

func (e *DefaultError) Code() int32

func (*DefaultError) Message

func (e *DefaultError) Message() string

type Error

type Error interface {
	Code() int32
	Message() string
}

type Executer

type Executer interface {
	// contains filtered or unexported methods
}

Executer at its core the request object that consists of the necessary fields.

type GetAccPubKeyRequest

type GetAccPubKeyRequest struct {
	Secret string `json:"secret"`
}

type GetChainRequest

type GetChainRequest struct {
	Id string `json:"id"`
}

type GetPeersRequest

type GetPeersRequest struct {
	Limit int `json:"limit"`
}

type GetSnapShotRequest

type GetSnapShotRequest struct {
	Id     string `json:"id"`
	Height int    `json:"height"`
}

type GetTxListRequest

type GetTxListRequest struct {
	Limit int `json:"limit"`
}

type GetTxRequest

type GetTxRequest struct {
	Id types.Hash `json:"id"`
}

type InsufficientDataEvent

type InsufficientDataEvent struct {
	events.Event
	Chain types.Hash
	To    types.Hash
	Peer  *peer.Peer
}

func (*InsufficientDataEvent) GetObject

func (e *InsufficientDataEvent) GetObject(obj interface{}) error

func (*InsufficientDataEvent) SetData

func (e *InsufficientDataEvent) SetData(chain types.Hash, to types.Hash, peer *peer.Peer)

type LastSnapShotRequest

type LastSnapShotRequest struct{}

type ListSnapShotRequest

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

type LoadChainRequest

type LoadChainRequest struct {
	Chain string `json:"chain"`
	Start int    `json:"start"`
	Limit int    `json:"limit"`
}

type LoadChainResponse

type LoadChainResponse struct {
	Chain string      `json:"chain"`
	Start int         `json:"start"`
	Limit int         `json:"limit"`
	Txs   []*types.Tx `json:"txs"`
}

type OpenAccRequest

type OpenAccRequest struct {
	PublicKey string `json:"publicKey"`
}

type PingRequest

type PingRequest string

PingRequest is a small way to check if the node is responding.

type PostTxRequest

type PostTxRequest struct {
	types.Tx
}

type Request

type Request struct {
	Id     int32       `json:"id"`
	Method string      `json:"method"`
	Params interface{} `json:"params,omitempty"`
	Peer   *peer.Peer  `json:"peer,omitempty"`
}

Request is the basic structure for JSON RPC requests.

func (*Request) Response

func (req *Request) Response(result interface{}, err Error) *Response

Response returns the answer and makes it easy to create answers.

type Response

type Response struct {
	Id     int32       `json:"id"`
	Error  Error       `json:"error,omitempty"`
	Result interface{} `json:"result,omitempty"`
	Peer   *peer.Peer  `json:"peer,omitempty"`
}

Response is the basic structure for JSON RPC responses.

func ExecuteRequest

func ExecuteRequest(request *Request, args *Args) *Response

ExecuteRequest executes RPC request and returns a response if the method is not valid anyway, the response will return with the corresponding error.

Directories

Path Synopsis
net

Jump to

Keyboard shortcuts

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