rpc

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2019 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RPCErrorServerError    = -32000
	RPCErrorInvalidRequest = -32600
	RPCErrorMethodNotFound = -32601
	RPCErrorInvalidParams  = -32602
	RPCErrorInternalError  = -32603
	RPCErrorParseError     = -32700
)

JSON-RPC 2.0 error codes.

View Source
const (
	GALLACTIC = "gallactic."

	GET_ACCOUNTS        = GALLACTIC + "getAccounts"
	GET_ACCOUNT         = GALLACTIC + "getAccount"
	GET_VALIDATOR       = GALLACTIC + "getValidator"
	GET_STORAGE         = GALLACTIC + "getStorage"
	GET_STORAGE_AT      = GALLACTIC + "getStorageAt"
	GET_STATUS          = GALLACTIC + "getStatus"
	GET_LATEST_BLOCK    = GALLACTIC + "getLatestBlock"
	GET_BLOCKS          = GALLACTIC + "getBlocks"
	GET_BLOCK           = GALLACTIC + "getBlock"
	GET_CONSENSUS_STATE = GALLACTIC + "getConsensusState"
	GET_VALIDATORS      = GALLACTIC + "getValidators"
	GET_NETWORK_INFO    = GALLACTIC + "getNetworkInfo"
	GET_CHAIN_ID        = GALLACTIC + "getChainId"
	GET_PEERS           = GALLACTIC + "getPeers"
	GET_GENESIS         = GALLACTIC + "getGenesis"
	BROADCAST_TX        = GALLACTIC + "broadcastTx"
	GET_UNCONFIRMED_TXS = GALLACTIC + "getUnconfirmedTxs"
	GET_BLOCK_TXS       = GALLACTIC + "getBlockTxs"
	GET_LastBlock_Info  = GALLACTIC + "getLastBlockInfo"
)
View Source
const MaxBlockLookback = 1000

Magic! Should probably be configurable, but not shouldn't be so huge we end up DoSing ourselves.

Variables

This section is empty.

Functions

func GetMethods

func GetMethods(codec Codec, service *Service) map[string]RequestHandlerFunc

func GetRangeFilter

func GetRangeFilter(op, fName string) (func(a, b uint64) bool, error)

func GetStringFilter

func GetStringFilter(op, fName string) (func(s0, s1 string) bool, error)

func NewCORSMiddleware

func NewCORSMiddleware(options rpcConf.CORS) gin.HandlerFunc

func ParseNumberValue

func ParseNumberValue(value string) (uint64, error)

Types

type AccountBalanceFilter

type AccountBalanceFilter struct {
	// contains filtered or unexported fields
}

Filter for account balance. Ops: All

func (*AccountBalanceFilter) Configure

func (abf *AccountBalanceFilter) Configure(fd *FilterData) error

func (*AccountBalanceFilter) Match

func (abf *AccountBalanceFilter) Match(v interface{}) bool

type AccountCodeFilter

type AccountCodeFilter struct {
	// contains filtered or unexported fields
}

Filter for account code. Ops: == or != Could be used to match against nil, to see if an account is a contract account.

func (*AccountCodeFilter) Configure

func (acf *AccountCodeFilter) Configure(fd *FilterData) error

func (*AccountCodeFilter) Match

func (acf *AccountCodeFilter) Match(v interface{}) bool

type AccountOutput

type AccountOutput struct {
	Account *account.Account
}

type AccountsOutput

type AccountsOutput struct {
	BlockHeight uint64
	Accounts    []*account.Account
}

type AddressInput

type AddressInput struct {
	Address crypto.Address `json:"address"`
}

type Block

type Block struct {
	*tmTypes.Block
}

Needed for amino handling of interface types

func (Block) MarshalJSON

func (b Block) MarshalJSON() ([]byte, error)

func (*Block) UnmarshalJSON

func (b *Block) UnmarshalJSON(data []byte) (err error)

type BlockInfoInput added in v0.5.0

type BlockInfoInput struct {
	BlockWithin string `json:"blockWithin"`
}

type BlockInput

type BlockInput struct {
	Height uint64 `json:"height"`
}

type BlockMeta

type BlockMeta struct {
	*tmTypes.BlockMeta
}

func (BlockMeta) MarshalJSON

func (bm BlockMeta) MarshalJSON() ([]byte, error)

func (*BlockMeta) UnmarshalJSON

func (bm *BlockMeta) UnmarshalJSON(data []byte) (err error)

type BlockOutput

type BlockOutput struct {
	BlockMeta *BlockMeta
	Block     *Block
}

type BlockTxsOutput

type BlockTxsOutput struct {
	Count int
	Txs   []txs.Envelope
}

type BlocksInput

type BlocksInput struct {
	MinHeight uint64 `json:"minHeight"`
	MaxHeight uint64 `json:"maxHeight"`
}

type BlocksOutput

type BlocksOutput struct {
	LastHeight uint64
	BlockMetas []*tmTypes.BlockMeta
}

type BroadcastTxOutput

type BroadcastTxOutput struct {
	txs.Receipt
}

func (BroadcastTxOutput) MarshalJSON

func (rbt BroadcastTxOutput) MarshalJSON() ([]byte, error)

func (BroadcastTxOutput) UnmarshalJSON

func (rbt BroadcastTxOutput) UnmarshalJSON(data []byte) (err error)

type ChainIdOutput

type ChainIdOutput struct {
	ChainName   string
	ChainId     string
	GenesisHash binary.HexBytes
}

type Codec

type Codec interface {
	EncodeBytes(interface{}) ([]byte, error)
	Encode(interface{}, io.Writer) error
	DecodeBytes(interface{}, []byte) error
	Decode(interface{}, io.Reader) error
}

func NewTCodec

func NewTCodec() Codec

Get a new codec.

type CompositeFilter

type CompositeFilter struct {
	// contains filtered or unexported fields
}

Filter made up of many filters.

func (*CompositeFilter) Match

func (cf *CompositeFilter) Match(v interface{}) bool

func (*CompositeFilter) SetData

func (cf *CompositeFilter) SetData(filters []Filter)

type ConfigurableFilter

type ConfigurableFilter interface {
	Filter
	Configure(*FilterData) error
}

A filter that can be configured with in-data.

type DumpConsensusStateOutput

type DumpConsensusStateOutput struct {
	RoundState      consensusTypes.RoundStateSimple
	PeerRoundStates []*consensusTypes.PeerRoundState
}

type DumpstorageOutput

type DumpstorageOutput struct {
	StorageItems []StorageItem
}

type Filter

type Filter interface {
	Match(v interface{}) bool
}

Filters based on fields.

type FilterData

type FilterData struct {
	Field string `json:"field"`
	Op    string `json:"op"`
	Value string `json:"value"`
}

Used to filter. Op can be any of the following: The usual relative operators: <, >, <=, >=, ==, != (where applicable) A range parameter (see: https://help.github.com/articles/search-syntax/)

type FilterFactory

type FilterFactory struct {
	// contains filtered or unexported fields
}

Used to generate filters based on filter data. Keeping separate pools for "edge cases" (Composite and MatchAll)

func NewAccountFilterFactory

func NewAccountFilterFactory() *FilterFactory

func NewFilterFactory

func NewFilterFactory() *FilterFactory

func (*FilterFactory) NewFilter

func (ff *FilterFactory) NewFilter(fdArr []*FilterData) (Filter, error)

Creates a new filter given the input data array. If the array is zero length or nil, an empty filter will be returned that returns true on all matches. If the array is of size 1, a regular filter is returned, otherwise a CompositeFieldFilter is returned, which is a special filter that contains a number of other filters. It implements AccountFieldFilter, and will match an account only if all the sub-filters matches.

func (*FilterFactory) RegisterFilterPool

func (ff *FilterFactory) RegisterFilterPool(fieldName string, pool *sync.Pool)

type FilterListInput

type FilterListInput struct {
	Filters []*FilterData `json:"filters"`
}

type GenesisOutput

type GenesisOutput struct {
	Genesis *proposal.Genesis
}

type HttpService

type HttpService interface {
	Process(*http.Request, http.ResponseWriter)
}

func NewJSONService

func NewJSONService(codec Codec, service *Service) HttpService

Create a new JSON-RPC 2.0 service for gallactic

type JSONService

type JSONService struct {
	// contains filtered or unexported fields
}

func (*JSONService) Process

func (js *JSONService) Process(r *http.Request, w http.ResponseWriter)

Process a request.

type JsonRpcServer

type JsonRpcServer struct {
	// contains filtered or unexported fields
}

Server used to handle JSON-RPC 2.0 requests. Implements server.Server

func NewJSONServer

func NewJSONServer(service HttpService) *JsonRpcServer

Create a new JsonRpcServer

func (*JsonRpcServer) Running

func (jrs *JsonRpcServer) Running() bool

Is the server currently running?

func (*JsonRpcServer) Shutdown

func (jrs *JsonRpcServer) Shutdown(ctx context.Context) error

Shut the server down. Does nothing.

func (*JsonRpcServer) Start

func (jrs *JsonRpcServer) Start(config *rpcConfig.ServerConfig, router *gin.Engine)

Start adds the rpc path to the router.

type LastBlockInfoOutput

type LastBlockInfoOutput struct {
	LastBlockHeight uint64
	LastBlockTime   time.Time
	LastBlockHash   binary.HexBytes
}

type MatchAllFilter

type MatchAllFilter struct{}

Rubberstamps everything.

func (*MatchAllFilter) Match

func (maf *MatchAllFilter) Match(v interface{}) bool

type NetInfoOutput

type NetInfoOutput struct {
	Listening bool
	Listeners []string
	Peers     []*Peer
}

func (*NetInfoOutput) Decode added in v0.4.0

func (info *NetInfoOutput) Decode(bs []byte) error

func (*NetInfoOutput) Encode added in v0.4.0

func (info *NetInfoOutput) Encode() ([]byte, error)

protobuf marshal,unmarshal and size methods

func (*NetInfoOutput) Marshal added in v0.4.0

func (info *NetInfoOutput) Marshal() ([]byte, error)

func (*NetInfoOutput) MarshalTo added in v0.4.0

func (info *NetInfoOutput) MarshalTo(data []byte) (int, error)

func (NetInfoOutput) Size added in v0.4.0

func (info NetInfoOutput) Size() int

func (*NetInfoOutput) Unmarshal added in v0.4.0

func (info *NetInfoOutput) Unmarshal(bs []byte) error

type Peer

type Peer struct {
	NodeInfo   p2p.NodeInfo
	IsOutbound bool
}

func (*Peer) Decode added in v0.3.0

func (p *Peer) Decode(bs []byte) error

func (*Peer) Encode added in v0.3.0

func (p *Peer) Encode() ([]byte, error)

protobuf marshal,unmarshal and size methods

func (*Peer) Marshal added in v0.3.0

func (p *Peer) Marshal() ([]byte, error)

func (*Peer) MarshalTo added in v0.3.0

func (p *Peer) MarshalTo(data []byte) (int, error)

func (Peer) Size added in v0.3.0

func (p Peer) Size() int

func (*Peer) Unmarshal added in v0.3.0

func (p *Peer) Unmarshal(bs []byte) error

protobuf marshal,unmarshal and size methods

type PeersInput

type PeersInput struct {
	Address crypto.Address `json:"address"`
}

type PeersOutput

type PeersOutput struct {
	Peers []*Peer
}

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

RPCError MUST be included in the Response object if an error occurred

func (RPCError) Error

func (err RPCError) Error() string

type RPCErrorResponse

type RPCErrorResponse struct {
	Error   *RPCError `json:"error"`
	Id      string    `json:"id"`
	JSONRPC string    `json:"jsonrpc"`
}

RPCErrorResponse MUST NOT contain the result member if an error occurred

func (*RPCErrorResponse) AssertIsRPCResponse

func (rpcErrorResponse *RPCErrorResponse) AssertIsRPCResponse() bool

AssertIsRPCResponse implements a marker method for RPCErrorResponse to implement the interface RPCResponse

type RPCRequest

type RPCRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params"`
	Id      string          `json:"id"`
}

Request and Response objects. Id is a string. Error data not used. Refer to JSON-RPC specification http://www.jsonrpc.org/specification

func NewRPCRequest

func NewRPCRequest(id string, method string, params json.RawMessage) *RPCRequest

Create a new RPC request. This is the generic struct that is passed to RPC methods

type RPCResponse

type RPCResponse interface {
	AssertIsRPCResponse() bool
}

RPCResponse MUST follow the JSON-RPC specification for Response object reference: http://www.jsonrpc.org/specification#response_object

func NewRPCErrorResponse

func NewRPCErrorResponse(id string, code int, message string) RPCResponse

NewRPCErrorResponse creates a new error-response object from the error code and message

func NewRPCResponse

func NewRPCResponse(id string, res interface{}) RPCResponse

NewRPCResponse creates a new response object from a result

type RPCResultResponse

type RPCResultResponse struct {
	Result  interface{} `json:"result"`
	Id      string      `json:"id"`
	JSONRPC string      `json:"jsonrpc"`
}

RPCResultResponse MUST NOT contain the error member if no error occurred

func (*RPCResultResponse) AssertIsRPCResponse

func (rpcResultResponse *RPCResultResponse) AssertIsRPCResponse() bool

AssertIsRPCResponse implements a marker method for RPCResultResponse to implement the interface RPCResponse

type RequestHandlerFunc

type RequestHandlerFunc func(request *RPCRequest, requester interface{}) (interface{}, int, error)

Used to handle requests. interface{} param is a wildcard used for example with socket events.

type ServeProcess

type ServeProcess struct {
	// contains filtered or unexported fields
}

The ServeProcess wraps all the Servers. Starting it will add all the server handlers to the router and start listening for incoming requests. There is also startup and shutdown events that can be listened to, on top of any events that the servers may have (the default websocket server has events for monitoring sessions. Startup event listeners should be added before calling 'Start()'. Stop event listeners can be added up to the point where the server is stopped and the event is fired.

func NewServeProcess

func NewServeProcess(config *rpcConf.ServerConfig,
	servers ...Server) (*ServeProcess, error)

Creates a new serve process.

func (*ServeProcess) Shutdown

func (serveProcess *ServeProcess) Shutdown(ctx context.Context) error

Stop will release the port, process any remaining requests up until the timeout duration is passed, at which point it will abort them and shut down.

func (*ServeProcess) Start

func (serveProcess *ServeProcess) Start() error

Initializes all the servers and starts listening for connections.

func (*ServeProcess) StartEventChannel

func (serveProcess *ServeProcess) StartEventChannel() <-chan struct{}

Get a start-event channel from the server. The start event is fired after the Start() function is called, and after the server has started listening for incoming connections. An error here .

func (*ServeProcess) StopEventChannel

func (serveProcess *ServeProcess) StopEventChannel() <-chan struct{}

Get a stop-event channel from the server. The event happens after the Stop() function has been called, and after the timeout has passed. When the timeout has passed it will wait for confirmation from the http.Server, which normally takes a very short time (milliseconds).

type Server

type Server interface {
	Start(*rpcConf.ServerConfig, *gin.Engine)
	Running() bool
	Shutdown(ctx context.Context) error
}

A server serves a number of different http calls.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Base service that provides implementation for all underlying RPC methods

func NewService

func NewService(ctx context.Context, blockchain *blockchain.Blockchain,
	transactor *execution.Transactor, nView *query.NodeView) *Service

func (*Service) BlockchainInfo

func (s *Service) BlockchainInfo() *blockchain.Blockchain

func (*Service) ChainIdentifiers

func (s *Service) ChainIdentifiers() (*ChainIdOutput, error)

func (*Service) DumpConsensusState

func (s *Service) DumpConsensusState() (*DumpConsensusStateOutput, error)

func (*Service) DumpStorage

func (s *Service) DumpStorage(address crypto.Address) (*DumpstorageOutput, error)

func (*Service) Genesis

func (s *Service) Genesis() *GenesisOutput

func (*Service) GetAccount

func (s *Service) GetAccount(address crypto.Address) (*AccountOutput, error)

func (*Service) GetBlock

func (s *Service) GetBlock(height uint64) (*BlockOutput, error)

func (*Service) GetStorage

func (s *Service) GetStorage(address crypto.Address, key []byte) (*StorageOutput, error)

func (*Service) GetValidator added in v0.3.0

func (s *Service) GetValidator(address crypto.Address) (*ValidatorOutput, error)

func (*Service) LastBlockInfo

func (s *Service) LastBlockInfo(blockWithin string) (*LastBlockInfoOutput, error)

func (*Service) ListAccounts

func (s *Service) ListAccounts(predicate func(*account.Account) bool) (*AccountsOutput, error)

func (*Service) ListBlockTxs

func (s *Service) ListBlockTxs(height uint64) (*BlockTxsOutput, error)

func (*Service) ListBlocks

func (s *Service) ListBlocks(minHeight, maxHeight uint64) (*BlocksOutput, error)

Returns the current blockchain height and metadata for a range of blocks between minHeight and maxHeight. Only returns maxBlockLookback block metadata from the top of the range of blocks. Passing 0 for maxHeight sets the upper height of the range to the current blockchain height.

func (*Service) ListUnconfirmedTxs

func (s *Service) ListUnconfirmedTxs(maxTxs int) (*UnconfirmedTxsOutput, error)

func (*Service) ListValidators

func (s *Service) ListValidators() (*ValidatorsOutput, error)

func (*Service) NetInfo

func (s *Service) NetInfo() (*NetInfoOutput, error)

func (*Service) Peers

func (s *Service) Peers() (*PeersOutput, error)

func (*Service) State

func (s *Service) State() *state.State

func (*Service) Status

func (s *Service) Status() (*StatusOutput, error)

func (*Service) Transactor

func (s *Service) Transactor() *execution.Transactor

type StatusOutput

type StatusOutput struct {
	NodeInfo          p2p.NodeInfo
	GenesisHash       binary.HexBytes
	PubKey            crypto.PublicKey
	LatestBlockHash   binary.HexBytes
	LatestBlockHeight uint64
	LatestBlockTime   int64
	NodeVersion       string
}

type StorageAtInput

type StorageAtInput struct {
	Address crypto.Address  `json:"address"`
	Key     binary.HexBytes `json:"key"`
}

type StorageItem

type StorageItem struct {
	Key   binary.HexBytes
	Value binary.HexBytes
}

type StorageOutput

type StorageOutput struct {
	Key   binary.HexBytes
	Value binary.HexBytes
}

type TCodec

type TCodec struct {
}

Codec that uses tendermints 'binary' package for JSON.

func (*TCodec) Decode

func (codec *TCodec) Decode(v interface{}, r io.Reader) error

Decode from an io.Reader.

func (*TCodec) DecodeBytes

func (codec *TCodec) DecodeBytes(v interface{}, bs []byte) error

Decode from a byte array.

func (*TCodec) Encode

func (codec *TCodec) Encode(v interface{}, w io.Writer) error

Encode to an io.Writer.

func (*TCodec) EncodeBytes

func (codec *TCodec) EncodeBytes(v interface{}) ([]byte, error)

Encode to a byte array.

type UnconfirmedTxsOutput

type UnconfirmedTxsOutput struct {
	Count int
	Txs   []*txs.Envelope
}

type ValidatorOutput added in v0.3.0

type ValidatorOutput struct {
	Validator *validator.Validator
}

type ValidatorsOutput

type ValidatorsOutput struct {
	BlockHeight         uint64
	BondedValidators    []*validator.Validator
	UnbondingValidators []*validator.Validator
}

Directories

Path Synopsis
proto3
Package proto3 is a reverse proxy.
Package proto3 is a reverse proxy.

Jump to

Keyboard shortcuts

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