rpc

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGrpcLimits = 128
	DefaultHTTPLimits = 128
)

Define const

Variables

View Source
var (
	ErrAPINotSupported = errors.New("api not supported")
)

Functions

func MakeTxRawMsgsForSign added in v0.3.0

func MakeTxRawMsgsForSign(tx *types.Transaction, utxos ...*rpcpb.Utxo) ([][]byte, error)

MakeTxRawMsgsForSign make tx raw msg for sign

func ParseAddrFrom added in v0.3.1

func ParseAddrFrom(
	sc *script.Script, txHash *crypto.HashType, idx uint32, tr ChainTxReader,
) (string, error)

ParseAddrFrom parse addr from scriptPubkey

func RegisterGatewayHandler

func RegisterGatewayHandler(name string, h GatewayHandler)

RegisterGatewayHandler registers a new http gateway handler for gRPC service

func RegisterService

func RegisterService(name string, s Service)

RegisterService registers a new gRPC service

func RegisterServiceWithGatewayHandler

func RegisterServiceWithGatewayHandler(name string, s Service, h GatewayHandler)

RegisterServiceWithGatewayHandler registers a gRPC service with gateway handler

Types

type ChainBlockReader added in v0.3.0

type ChainBlockReader interface {
	ChainTxReader
	// LoadBlockInfoByTxHash(crypto.HashType) (*types.Block, *types.Transaction, error)
	ReadBlockFromDB(*crypto.HashType) (*types.Block, int, error)
	EternalBlock() *types.Block
	TailBlock() *types.Block
	GetLogs(from, to uint32, topicslist [][][]byte) ([]*types.Log, error)
	FilterLogs(logs []*types.Log, topicslist [][][]byte) ([]*types.Log, error)
	TailState() *state.StateDB
	GetEvmByHeight(msg types.Message, height uint32) (*vm.EVM, func() error, error)
}

ChainBlockReader defines chain block reader interface

type ChainTxReader added in v0.3.0

type ChainTxReader interface {
	LoadBlockInfoByTxHash(crypto.HashType) (*types.Block, *types.Transaction, error)
	GetDataFromDB([]byte) ([]byte, error)
	GetTxReceipt(*crypto.HashType) (*types.Receipt, error)
}

ChainTxReader defines chain tx reader interface

type Config

type Config struct {
	Enabled         bool       `mapstructure:"enabled"`
	Address         string     `mapstructure:"address"`
	Port            int        `mapstructure:"port"`
	HTTP            HTTPConfig `mapstructure:"http"`
	GrpcLimits      int        `mapstructure:"grpc_limits"`
	HTTPLimits      int        `mapstructure:"http_limits"`
	HTTPCors        []string   `mapstructure:"http_cors"`
	FaucetKeyFile   string     `mapstructure:"faucet_keyfile"`
	SubScribeBlocks bool       `mapstructure:"subscribe_blocks"`
	SubScribeLogs   bool       `mapstructure:"subscribe_logs"`
}

Config defines the configurations of rpc server

type GRPCServer

type GRPCServer interface {
	GetChainReader() service.ChainReader
	GetTxHandler() service.TxHandler
	GetWalletAgent() service.WalletAgent
	GetEventBus() eventbus.Bus
	Proc() goprocess.Process
	Stop()
}

GRPCServer interface breaks cycle import dependency

type GatewayHandler

type GatewayHandler func(context.Context, *runtime.ServeMux, string, []grpc.DialOption) error

GatewayHandler defines the register func of http gateway handler for gRPC service

type HTTPConfig

type HTTPConfig struct {
	Address string `mapstructure:"address"`
	Port    int    `mapstructure:"port"`
}

HTTPConfig defines the address/port of rest api over http

type Server

type Server struct {
	ChainReader service.ChainReader
	TxHandler   service.TxHandler
	WalletAgent service.WalletAgent
	// contains filtered or unexported fields
}

Server defines the rpc server

func NewServer

func NewServer(parent goprocess.Process, cfg *Config,
	cr service.ChainReader, txh service.TxHandler,
	wa service.WalletAgent, bus eventbus.Bus) *Server

NewServer creates a RPC server instance.

func (*Server) GetChainReader

func (s *Server) GetChainReader() service.ChainReader

GetChainReader returns an interface to observe chain state

func (*Server) GetEventBus

func (s *Server) GetEventBus() eventbus.Bus

GetEventBus returns a interface to publish events

func (*Server) GetTxHandler

func (s *Server) GetTxHandler() service.TxHandler

GetTxHandler returns a handler to deal with transactions

func (*Server) GetWalletAgent added in v0.3.0

func (s *Server) GetWalletAgent() service.WalletAgent

GetWalletAgent returns the wallet related service handler

func (*Server) Proc

func (s *Server) Proc() goprocess.Process

Proc returns the goprocess

func (*Server) Run

func (s *Server) Run() error

Run gRPC service

func (*Server) Stop

func (s *Server) Stop()

Stop gRPC service

type Service

type Service func(s *Server)

Service defines the grpc service func

type TxPoolReader added in v0.3.0

type TxPoolReader interface {
	GetTxByHash(hash *crypto.HashType) (*types.TxWrap, bool)
}

TxPoolReader defines tx pool reader interface

Jump to

Keyboard shortcuts

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