api

package
v1.8.1-rc2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: Apache-2.0 Imports: 74 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

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 {
	// contains filtered or unexported fields
}

Config represents the config to setup api

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(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)
	// ActionsByBlock returns all actions in a block
	ActionsByBlock(blkHash string, start uint64, count uint64) ([]*iotexapi.ActionInfo, error)
	// ActionsInBlockByHash returns all actions in a block
	ActionsInBlockByHash(string) ([]action.SealedEnvelope, []*action.Receipt, error)
	// ActPoolActions returns the all Transaction Identifiers in the mempool
	ActPoolActions(actHashes []string) ([]*iotextypes.Action, 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)
	// BlockMetas returns blockmetas response within the height range
	BlockMetas(start uint64, count uint64) ([]*iotextypes.BlockMeta, error)
	// BlockMetaByHash returns blockmeta response by block hash
	BlockMetaByHash(blkHash string) (*iotextypes.BlockMeta, 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)
}

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 and the pointer to api coreservice

func NewGRPCServer added in v1.6.3

func NewGRPCServer(core CoreService, grpcPort int) *GRPCServer

NewGRPCServer creates a new grpc server

func (*GRPCServer) EstimateActionGasConsumption added in v1.6.3

EstimateActionGasConsumption estimate gas consume for action without signature

func (*GRPCServer) EstimateGasForAction added in v1.6.3

EstimateGasForAction estimates gas for action

func (*GRPCServer) GetAccount added in v1.6.3

GetAccount returns the metadata of an account

func (*GRPCServer) GetActPoolActions added in v1.6.3

GetActPoolActions returns the all Transaction Identifiers in the mempool

func (*GRPCServer) GetActions added in v1.6.3

GetActions returns actions

func (*GRPCServer) GetBlockMetas added in v1.6.3

GetBlockMetas returns block metadata

func (*GRPCServer) GetChainMeta added in v1.6.3

GetChainMeta returns blockchain metadata

func (*GRPCServer) GetElectionBuckets added in v1.6.3

GetElectionBuckets returns the native election buckets.

func (*GRPCServer) GetEpochMeta added in v1.6.3

GetEpochMeta gets epoch metadata

func (*GRPCServer) GetEvmTransfersByActionHash added in v1.6.3

GetEvmTransfersByActionHash returns evm transfers by action hash

func (*GRPCServer) GetEvmTransfersByBlockHeight added in v1.6.3

GetEvmTransfersByBlockHeight returns evm transfers by block height

func (*GRPCServer) GetLogs added in v1.6.3

GetLogs get logs filtered by contract address and topics TODO: simplify loop logic

func (*GRPCServer) GetRawBlocks added in v1.6.3

GetRawBlocks gets raw block data

func (*GRPCServer) GetReceiptByAction added in v1.6.3

GetReceiptByAction gets receipt with corresponding action hash

func (*GRPCServer) GetServerMeta added in v1.6.3

GetServerMeta gets the server metadata

func (*GRPCServer) GetTransactionLogByActionHash added in v1.6.3

GetTransactionLogByActionHash returns transaction log by action hash

func (*GRPCServer) GetTransactionLogByBlockHeight added in v1.6.3

GetTransactionLogByBlockHeight returns transaction log by block height

func (*GRPCServer) ReadContract added in v1.6.3

ReadContract reads the state in a contract address specified by the slot

func (*GRPCServer) ReadContractStorage added in v1.6.3

ReadContractStorage reads contract's storage

func (*GRPCServer) ReadState added in v1.6.3

ReadState reads state on blockchain

func (*GRPCServer) SendAction added in v1.6.3

SendAction is the API to send an action to blockchain.

func (*GRPCServer) Start added in v1.6.3

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

Start starts the GRPC server

func (*GRPCServer) Stop added in v1.6.3

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

Stop stops the GRPC server

func (*GRPCServer) StreamBlocks added in v1.6.3

StreamBlocks streams blocks

func (*GRPCServer) StreamLogs added in v1.6.3

StreamLogs streams logs that match the filter condition

func (*GRPCServer) SuggestGasPrice added in v1.6.3

SuggestGasPrice suggests gas price

func (*GRPCServer) TraceTransactionStructLogs added in v1.6.3

TraceTransactionStructLogs get trace transaction struct logs

type HTTPServer added in v1.8.0

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

HTTPServer handles requests from http protocol

func NewHTTPServer added in v1.8.0

func NewHTTPServer(route string, port int, handler Web3Handler) *HTTPServer

NewHTTPServer creates a new http server TODO: move timeout into config

func (*HTTPServer) ServeHTTP added in v1.8.0

func (hSvr *HTTPServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

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 *Config) error

Option is the option to override the api config

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 {
	GrpcServer *GRPCServer
	// 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.API,
	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(io.Reader, apitypes.Web3ResponseWriter) error
}

Web3Handler handle JRPC request

func NewWeb3Handler added in v1.8.0

func NewWeb3Handler(core CoreService, cacheURL string) Web3Handler

NewWeb3Handler creates a handle to process web3 requests

type WebsocketServer added in v1.8.0

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

WebsocketServer handles requests from websocket protocol

func NewWebSocketServer added in v1.8.0

func NewWebSocketServer(route string, port int, handler Web3Handler) *WebsocketServer

NewWebSocketServer creates a new websocket server

func (*WebsocketServer) ServeHTTP added in v1.8.0

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

func (*WebsocketServer) Start added in v1.8.0

func (wsSvr *WebsocketServer) Start(_ context.Context) error

Start starts the websocket server

func (*WebsocketServer) Stop added in v1.8.0

func (wsSvr *WebsocketServer) Stop(ctx context.Context) error

Stop stops the websocket server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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