api

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: Apache-2.0 Imports: 82 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	UseRDS:            false,
	GRPCPort:          14014,
	HTTPPort:          15014,
	WebSocketPort:     16014,
	TpsWindow:         10,
	GasStation:        gasstation.DefaultConfig,
	RangeQueryLimit:   1000,
	BatchRequestLimit: _defaultBatchRequestLimit,
}

DefaultConfig is the default config

View Source
var (
	// ErrNotFound indicates the record isn't found
	ErrNotFound = errors.New("not found")
)

Functions

func NewChainListener added in v0.7.1

func NewChainListener(c int) apitypes.Listener

NewChainListener returns a new blockchain chainListener

func NewGRPCBlockListener added in v1.8.1

func NewGRPCBlockListener(handler streamHandler, errChan chan error) apitypes.Responder

NewGRPCBlockListener returns a new gRPC block listener

func NewGRPCLogListener added in v1.8.1

func NewGRPCLogListener(in *logfilter.LogFilter, handler streamHandler, errChan chan error) apitypes.Responder

NewGRPCLogListener returns a new log listener

func NewWeb3BlockListener added in v1.8.1

func NewWeb3BlockListener(handler streamHandler) apitypes.Responder

NewWeb3BlockListener returns a new websocket block listener

func NewWeb3LogListener added in v1.8.1

func NewWeb3LogListener(filter *logfilter.LogFilter, handler streamHandler) apitypes.Responder

NewWeb3LogListener returns a new websocket block listener

func RecoveryInterceptor added in v1.8.1

func RecoveryInterceptor() grpc_recovery.Option

RecoveryInterceptor handles panic to a custom error

Types

type BroadcastOutbound

type BroadcastOutbound func(ctx context.Context, chainID uint32, msg proto.Message) error

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"`
}

Config is the api service config

type CoreService added in v1.7.1

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.Execution) (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)
	// 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)
	// 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, hash.Hash256, uint64, uint32, 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)
	// EstimateGasForNonExecution  estimates action gas except execution
	EstimateGasForNonExecution(action.Action) (uint64, error)
	// EstimateExecutionGasConsumption estimate gas consumption for execution action
	EstimateExecutionGasConsumption(ctx context.Context, sc *action.Execution, callerAddr address.Address) (uint64, 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)
	// 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.Execution) ([]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 *logger.Config) ([]byte, *action.Receipt, *logger.StructLogger, 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 *logger.Config) ([]byte, *action.Receipt, *logger.StructLogger, error)

	// Track tracks the api call
	Track(ctx context.Context, start time.Time, method string, size int64, success bool)
}

CoreService provides api interface for user to interact with blockchain data

type GRPCServer added in v1.6.3

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

GRPCServer contains grpc server

func NewGRPCServer added in v1.6.3

func NewGRPCServer(core CoreService, grpcPort int) *GRPCServer

NewGRPCServer creates a new grpc server

func (*GRPCServer) Start added in v1.6.3

func (grpc *GRPCServer) Start(_ context.Context) error

Start starts the GRPC server

func (*GRPCServer) Stop added in v1.6.3

func (grpc *GRPCServer) Stop(_ context.Context) error

Stop stops the GRPC server

type HTTPServer added in v1.8.0

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

HTTPServer crates a http server

func NewHTTPServer added in v1.8.0

func NewHTTPServer(route string, port int, handler http.Handler) *HTTPServer

NewHTTPServer creates a new http server

func (*HTTPServer) Start added in v1.8.0

func (hSvr *HTTPServer) Start(_ context.Context) error

Start starts the http server

func (*HTTPServer) Stop added in v1.8.0

func (hSvr *HTTPServer) Stop(ctx context.Context) error

Stop stops the http server

type Option

type Option func(cfg *coreService)

Option is the option to override the api config

func WithAPIStats added in v1.11.0

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

func WithNativeElection(committee committee.Committee) Option

WithNativeElection is the option to return native election data through API.

type ReadCache added in v1.5.0

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

ReadCache stores read results

func NewReadCache added in v1.5.0

func NewReadCache() *ReadCache

NewReadCache returns a new read cache

func (*ReadCache) Clear added in v1.5.0

func (rc *ReadCache) Clear()

Clear clears the cache

func (*ReadCache) Get added in v1.5.0

func (rc *ReadCache) Get(key hash.Hash160) ([]byte, bool)

Get reads according to key

func (*ReadCache) Put added in v1.5.0

func (rc *ReadCache) Put(key hash.Hash160, value []byte)

Put writes according to key

type ReadKey added in v1.5.0

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

func (*ReadKey) Hash added in v1.5.0

func (k *ReadKey) Hash() hash.Hash160

Hash returns the hash of key's json string

type ServerV2 added in v1.6.3

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

ServerV2 provides api for user to interact with blockchain data

func NewServerV2 added in v1.6.3

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,
	opts ...Option,
) (*ServerV2, error)

NewServerV2 creates a new server with coreService and GRPC Server

func (*ServerV2) CoreService added in v1.8.1

func (svr *ServerV2) CoreService() CoreService

CoreService returns the coreservice of the api

func (*ServerV2) ReceiveBlock added in v1.8.0

func (svr *ServerV2) ReceiveBlock(blk *block.Block) error

ReceiveBlock receives the new block

func (*ServerV2) Start added in v1.6.3

func (svr *ServerV2) Start(ctx context.Context) error

Start starts the CoreService and the GRPC server

func (*ServerV2) Stop added in v1.6.3

func (svr *ServerV2) Stop(ctx context.Context) error

Stop stops the GRPC server and the CoreService

type StreamBlocksServer added in v1.1.0

type StreamBlocksServer interface {
	Send(*iotexapi.StreamBlocksResponse) error
	grpc.ServerStream
}

StreamBlocksServer defines the interface of a rpc stream server

type Web3Handler added in v1.8.0

type Web3Handler interface {
	HandlePOSTReq(context.Context, io.Reader, apitypes.Web3ResponseWriter) error
}

Web3Handler handle JRPC request

func NewWeb3Handler added in v1.8.0

func NewWeb3Handler(core CoreService, cacheURL string, batchRequestLimit int) Web3Handler

NewWeb3Handler creates a handle to process web3 requests

type WebsocketHandler added in v1.8.2

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

WebsocketHandler handles requests from websocket protocol

func NewWebsocketHandler added in v1.8.2

func NewWebsocketHandler(web3Handler Web3Handler) *WebsocketHandler

NewWebsocketHandler creates a new websocket handler

func (*WebsocketHandler) ServeHTTP added in v1.8.2

func (wsSvr *WebsocketHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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