Documentation ¶
Index ¶
- Variables
- func NewChainListener(c int) apitypes.Listener
- func NewGRPCBlockListener(handler streamHandler, errChan chan error) apitypes.Responder
- func NewGRPCLogListener(in *logfilter.LogFilter, handler streamHandler, errChan chan error) apitypes.Responder
- func NewWeb3BlockListener(handler streamHandler) apitypes.Responder
- func NewWeb3LogListener(filter *logfilter.LogFilter, handler streamHandler) apitypes.Responder
- func RecoveryInterceptor() grpc_recovery.Option
- func WithStreamContext(ctx context.Context) context.Context
- type BroadcastOutbound
- type Config
- type CoreService
- type GRPCServer
- type HTTPServer
- type Option
- type ReadCache
- type ReadKey
- type ServerV2
- type StreamBlocksServer
- type StreamContext
- type Web3Handler
- type WebsocketHandler
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = Config{ UseRDS: false, GRPCPort: 14014, HTTPPort: 15014, WebSocketPort: 16014, TpsWindow: 10, GasStation: gasstation.DefaultConfig, RangeQueryLimit: 1000, BatchRequestLimit: _defaultBatchRequestLimit, WebsocketRateLimit: 5, ListenerLimit: 5000, }
DefaultConfig is the default config
var ( // ErrNotFound indicates the record isn't found ErrNotFound = errors.New("not found") )
Functions ¶
func NewChainListener ¶
NewChainListener returns a new blockchain chainListener
func NewGRPCBlockListener ¶
NewGRPCBlockListener returns a new gRPC block listener
func NewGRPCLogListener ¶
func NewGRPCLogListener(in *logfilter.LogFilter, handler streamHandler, errChan chan error) apitypes.Responder
NewGRPCLogListener returns a new log listener
func NewWeb3BlockListener ¶
NewWeb3BlockListener returns a new websocket block listener
func NewWeb3LogListener ¶
NewWeb3LogListener returns a new websocket block listener
func RecoveryInterceptor ¶
func RecoveryInterceptor() grpc_recovery.Option
RecoveryInterceptor handles panic to a custom error
Types ¶
type BroadcastOutbound ¶
BroadcastOutbound sends a broadcast message to the whole network
type Config ¶
type Config struct { UseRDS bool `yaml:"useRDS"` GRPCPort int `yaml:"port"` HTTPPort int `yaml:"web3port"` WebSocketPort int `yaml:"webSocketPort"` RedisCacheURL string `yaml:"redisCacheURL"` TpsWindow int `yaml:"tpsWindow"` GasStation gasstation.Config `yaml:"gasStation"` RangeQueryLimit uint64 `yaml:"rangeQueryLimit"` Tracer tracer.Config `yaml:"tracer"` // BatchRequestLimit is the maximum number of requests in a batch. BatchRequestLimit int `yaml:"batchRequestLimit"` // WebsocketRateLimit is the maximum number of messages per second per client. WebsocketRateLimit int `yaml:"websocketRateLimit"` // ListenerLimit is the maximum number of listeners. ListenerLimit int `yaml:"listenerLimit"` }
Config is the api service config
type CoreService ¶
type CoreService interface { // Account returns the metadata of an account Account(addr address.Address) (*iotextypes.AccountMeta, *iotextypes.BlockIdentifier, error) // ChainMeta returns blockchain metadata ChainMeta() (*iotextypes.ChainMeta, string, error) // ServerMeta gets the server metadata ServerMeta() (packageVersion string, packageCommitID string, gitStatus string, goVersion string, buildTime string) // SendAction is the API to send an action to blockchain. SendAction(ctx context.Context, in *iotextypes.Action) (string, error) // ReadContract reads the state in a contract address specified by the slot ReadContract(ctx context.Context, callerAddr address.Address, sc action.Envelope) (string, *iotextypes.Receipt, error) // ReadState reads state on blockchain ReadState(protocolID string, height string, methodName []byte, arguments [][]byte) (*iotexapi.ReadStateResponse, error) // SuggestGasPrice suggests gas price SuggestGasPrice() (uint64, error) // SuggestGasTipCap suggests gas tip cap SuggestGasTipCap() (*big.Int, error) // EstimateGasForAction estimates gas for action EstimateGasForAction(ctx context.Context, in *iotextypes.Action) (uint64, error) // EpochMeta gets epoch metadata EpochMeta(epochNum uint64) (*iotextypes.EpochData, uint64, []*iotexapi.BlockProducerInfo, error) // RawBlocks gets raw block data RawBlocks(startHeight uint64, count uint64, withReceipts bool, withTransactionLogs bool) ([]*iotexapi.BlockInfo, error) // ElectionBuckets returns the native election buckets. ElectionBuckets(epochNum uint64) ([]*iotextypes.ElectionBucket, error) // ReceiptByActionHash returns receipt by action hash ReceiptByActionHash(h hash.Hash256) (*action.Receipt, error) // TransactionLogByActionHash returns transaction log by action hash TransactionLogByActionHash(actHash string) (*iotextypes.TransactionLog, error) // TransactionLogByBlockHeight returns transaction log by block height TransactionLogByBlockHeight(blockHeight uint64) (*iotextypes.BlockIdentifier, *iotextypes.TransactionLogs, error) // Start starts the API server Start(ctx context.Context) error // Stop stops the API server Stop(ctx context.Context) error // Actions returns actions within the range Actions(start uint64, count uint64) ([]*iotexapi.ActionInfo, error) // TODO: unify the three get action by hash methods: Action, ActionByActionHash, PendingActionByActionHash // Action returns action by action hash Action(actionHash string, checkPending bool) (*iotexapi.ActionInfo, error) // ActionsByAddress returns all actions associated with an address ActionsByAddress(addr address.Address, start uint64, count uint64) ([]*iotexapi.ActionInfo, error) // ActionByActionHash returns action by action hash ActionByActionHash(h hash.Hash256) (*action.SealedEnvelope, *block.Block, uint32, error) // PendingActionByActionHash returns action by action hash PendingActionByActionHash(h hash.Hash256) (*action.SealedEnvelope, error) // ActPoolActions returns the all Transaction Identifiers in the actpool ActionsInActPool(actHashes []string) ([]*action.SealedEnvelope, error) // BlockByHeightRange returns blocks within the height range BlockByHeightRange(uint64, uint64) ([]*apitypes.BlockWithReceipts, error) // BlockByHeight returns the block and its receipt from block height BlockByHeight(uint64) (*apitypes.BlockWithReceipts, error) // BlockByHash returns the block and its receipt BlockByHash(string) (*apitypes.BlockWithReceipts, error) // UnconfirmedActionsByAddress returns all unconfirmed actions in actpool associated with an address UnconfirmedActionsByAddress(address string, start uint64, count uint64) ([]*iotexapi.ActionInfo, error) // EstimateMigrateStakeGasConsumption estimates gas for migrate stake EstimateMigrateStakeGasConsumption(context.Context, *action.MigrateStake, address.Address) (uint64, []byte, error) // EstimateGasForNonExecution estimates action gas except execution EstimateGasForNonExecution(action.Action) (uint64, error) // EstimateExecutionGasConsumption estimate gas consumption for execution action EstimateExecutionGasConsumption(ctx context.Context, sc action.Envelope, callerAddr address.Address, opts ...protocol.SimulateOption) (uint64, []byte, error) // LogsInBlockByHash filter logs in the block by hash LogsInBlockByHash(filter *logfilter.LogFilter, blockHash hash.Hash256) ([]*action.Log, error) // LogsInRange filter logs among [start, end] blocks LogsInRange(filter *logfilter.LogFilter, start, end, paginationSize uint64) ([]*action.Log, []hash.Hash256, error) // Genesis returns the genesis of the chain Genesis() genesis.Genesis // EVMNetworkID returns the network id of evm EVMNetworkID() uint32 // ChainID returns the chain id of evm ChainID() uint32 // ReadContractStorage reads contract's storage ReadContractStorage(ctx context.Context, addr address.Address, key []byte) ([]byte, error) // ChainListener returns the instance of Listener ChainListener() apitypes.Listener // SimulateExecution simulates execution SimulateExecution(context.Context, address.Address, action.Envelope) ([]byte, *action.Receipt, error) // SyncingProgress returns the syncing status of node SyncingProgress() (uint64, uint64, uint64) // TipHeight returns the tip of the chain TipHeight() uint64 // PendingNonce returns the pending nonce of an account PendingNonce(address.Address) (uint64, error) // ReceiveBlock broadcasts the block to api subscribers ReceiveBlock(blk *block.Block) error // BlockHashByBlockHeight returns block hash by block height BlockHashByBlockHeight(blkHeight uint64) (hash.Hash256, error) // TraceTransaction returns the trace result of a transaction TraceTransaction(ctx context.Context, actHash string, config *tracers.TraceConfig) ([]byte, *action.Receipt, any, error) // TraceCall returns the trace result of a call TraceCall(ctx context.Context, callerAddr address.Address, blkNumOrHash any, contractAddress string, nonce uint64, amount *big.Int, gasLimit uint64, data []byte, config *tracers.TraceConfig) ([]byte, *action.Receipt, any, error) // Track tracks the api call Track(ctx context.Context, start time.Time, method string, size int64, success bool) // BlobSidecarsByHeight returns blob sidecars by height BlobSidecarsByHeight(height uint64) ([]*apitypes.BlobSidecarResult, error) }
CoreService provides api interface for user to interact with blockchain data
type GRPCServer ¶
type GRPCServer struct {
// contains filtered or unexported fields
}
GRPCServer contains grpc server
func NewGRPCServer ¶
func NewGRPCServer(core CoreService, bds *blockDAOService, grpcPort int) *GRPCServer
NewGRPCServer creates a new grpc server
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
HTTPServer crates a http server
func NewHTTPServer ¶
func NewHTTPServer(route string, port int, handler http.Handler) *HTTPServer
NewHTTPServer creates a new http server
type Option ¶
type Option func(cfg *coreService)
Option is the option to override the api config
func WithAPIStats ¶
func WithAPIStats(stats *nodestats.APILocalStats) Option
WithAPIStats is the option to return RPC stats through API.
func WithBroadcastOutbound ¶
func WithBroadcastOutbound(broadcastHandler BroadcastOutbound) Option
WithBroadcastOutbound is the option to broadcast msg outbound
func WithNativeElection ¶
WithNativeElection is the option to return native election data through API.
type ReadCache ¶
type ReadCache struct {
// contains filtered or unexported fields
}
ReadCache stores read results
type ReadKey ¶
type ReadKey struct { Name string `json:"name,omitempty"` Height string `json:"height,omitempty"` Method []byte `json:"method,omitempty"` Args [][]byte `json:"args,omitempty"` }
ReadKey represents a read key
type ServerV2 ¶
type ServerV2 struct {
// contains filtered or unexported fields
}
ServerV2 provides api for user to interact with blockchain data
func NewServerV2 ¶
func NewServerV2( cfg Config, chain blockchain.Blockchain, bs blocksync.BlockSync, sf factory.Factory, dao blockdao.BlockDAO, indexer blockindex.Indexer, bfIndexer blockindex.BloomFilterIndexer, actPool actpool.ActPool, registry *protocol.Registry, getBlockTime evm.GetBlockTime, opts ...Option, ) (*ServerV2, error)
NewServerV2 creates a new server with coreService and GRPC Server
func (*ServerV2) CoreService ¶
func (svr *ServerV2) CoreService() CoreService
CoreService returns the coreservice of the api
func (*ServerV2) ReceiveBlock ¶
ReceiveBlock receives the new block
type StreamBlocksServer ¶
type StreamBlocksServer interface { grpc.ServerStream Send(*iotexapi.StreamBlocksResponse) error }
StreamBlocksServer defines the interface of a rpc stream server
type StreamContext ¶
type StreamContext struct {
// contains filtered or unexported fields
}
func StreamFromContext ¶
func StreamFromContext(ctx context.Context) (*StreamContext, bool)
func (*StreamContext) AddListener ¶
func (sc *StreamContext) AddListener(id string)
func (*StreamContext) ListenerIDs ¶
func (sc *StreamContext) ListenerIDs() []string
func (*StreamContext) RemoveListener ¶
func (sc *StreamContext) RemoveListener(id string)
type Web3Handler ¶
type Web3Handler interface {
HandlePOSTReq(context.Context, io.Reader, apitypes.Web3ResponseWriter) error
}
Web3Handler handle JRPC request
func NewWeb3Handler ¶
func NewWeb3Handler(core CoreService, cacheURL string, batchRequestLimit int) Web3Handler
NewWeb3Handler creates a handle to process web3 requests
type WebsocketHandler ¶
type WebsocketHandler struct {
// contains filtered or unexported fields
}
WebsocketHandler handles requests from websocket protocol
func NewWebsocketHandler ¶
func NewWebsocketHandler(coreService CoreService, web3Handler Web3Handler, limiter *rate.Limiter) *WebsocketHandler
NewWebsocketHandler creates a new websocket handler
func (*WebsocketHandler) ServeHTTP ¶
func (wsSvr *WebsocketHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)