rpc

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: AGPL-3.0 Imports: 32 Imported by: 3

Documentation

Index

Constants

View Source
const (
	MetricsScopeGRPCAPI = "grpc_api"

	DefaultMaxBodyBytes           int64 = 4194304 // 4MB
	DefaultBatchItemLimit         int   = 1000
	DefaultBatchResponseSizeLimit int   = int(DefaultMaxBodyBytes)
)

Variables

This section is empty.

Functions

func InstrumentMetricsUnaryServerInterceptor

func InstrumentMetricsUnaryServerInterceptor(mtr metric.Meter, log *slog.Logger) grpc.UnaryServerInterceptor

func NewGRPCServer

func NewGRPCServer(node partitionNode, obs Observability, opts ...Option) (*grpcServer, error)

func NewHTTPServer

func NewHTTPServer(conf *ServerConfiguration, obs Observability, registrars ...Registrar) (*http.Server, error)

func NewRESTServer deprecated

func NewRESTServer(addr string, maxBodySize int64, obs Observability, registrars ...Registrar) *http.Server

Deprecated: Moving away from REST API to JSON-RPC API, use NewHTTPServer instead.

func WriteCBORError

func WriteCBORError(w http.ResponseWriter, e error, code int, log *slog.Logger)

WriteCBORError replies to the request with the specified error message and HTTP code. It does not otherwise end the request; the caller should ensure no further writes are done to w.

func WriteCBORResponse

func WriteCBORResponse(w http.ResponseWriter, response any, statusCode int, log *slog.Logger)

WriteCBORResponse replies to the request with the given response and HTTP code.

Types

type API

type API struct {
	Namespace string
	Service   interface{}
}

type AdminAPI added in v0.4.0

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

func NewAdminAPI added in v0.4.0

func NewAdminAPI(node AdminNode, name string, self *network.Peer, log *slog.Logger) *AdminAPI

func (*AdminAPI) GetNodeInfo added in v0.4.0

func (s *AdminAPI) GetNodeInfo() (*NodeInfoResponse, error)

GetNodeInfo returns status information about the node.

type AdminNode added in v0.4.0

type AdminNode interface {
	SystemIdentifier() types.SystemID
}

type NodeInfoResponse added in v0.4.0

type NodeInfoResponse struct {
	SystemID            types.SystemID `json:"systemId"` // hex encoded system identifier
	Name                string         `json:"name"`     // one of [money node | tokens node | evm node]
	Self                PeerInfo       `json:"self"`     // information about this peer
	BootstrapNodes      []PeerInfo     `json:"bootstrapNodes"`
	RootValidators      []PeerInfo     `json:"rootValidators"`
	PartitionValidators []PeerInfo     `json:"partitionValidators"`
	OpenConnections     []PeerInfo     `json:"openConnections"` // all libp2p connections to other peers in the network

}

type Observability

type Observability interface {
	Meter(name string, opts ...metric.MeterOption) metric.Meter
	PrometheusRegisterer() prometheus.Registerer
	Logger() *slog.Logger
}

type Option

type Option func(*Options)

func WithMaxGetBlocksBatchSize

func WithMaxGetBlocksBatchSize(maxGetBlocksBatchSize uint64) Option

type Options

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

type PeerInfo added in v0.4.0

type PeerInfo struct {
	Identifier string                `json:"identifier"`
	Addresses  []multiaddr.Multiaddr `json:"addresses"`
}

func (*PeerInfo) UnmarshalJSON added in v0.4.0

func (pi *PeerInfo) UnmarshalJSON(data []byte) error

type Registrar

type Registrar interface {
	Register(r *mux.Router)
}

Registrar registers new HTTP handlers for given router.

type RegistrarFunc

type RegistrarFunc func(r *mux.Router)

RegistrarFunc type is an adapter to allow the use of ordinary function as Registrar.

func MetricsEndpoints

func MetricsEndpoints(pr prometheus.Registerer) RegistrarFunc

func NodeEndpoints

func NodeEndpoints(node partitionNode, ownerIndexer partition.IndexReader, obs Observability) RegistrarFunc

func (RegistrarFunc) Register

func (f RegistrarFunc) Register(r *mux.Router)

type ServerConfiguration

type ServerConfiguration struct {
	// Address specifies the TCP address for the server to listen on, in the form "host:port".
	// REST server isn't initialised if Address is empty.
	Address string

	// ReadTimeout is the maximum duration for reading the entire request, including the body. A zero or negative
	// value means there will be no timeout.
	ReadTimeout time.Duration

	// ReadHeaderTimeout is the amount of time allowed to read request headers. If ReadHeaderTimeout is zero, the
	// value of ReadTimeout is used. If both are zero, there is no timeout.
	ReadHeaderTimeout time.Duration

	// WriteTimeout is the maximum duration before timing out writes of the response. A zero or negative value means
	// there will be no timeout.
	WriteTimeout time.Duration

	// IdleTimeout is the maximum amount of time to wait for the next request when keep-alives are enabled. If
	// IdleTimeout is zero, the value of ReadTimeout is used. If both are zero, there is no timeout.
	IdleTimeout time.Duration

	// MaxHeaderBytes controls the maximum number of bytes the server will read parsing the request header's keys
	// and values, including the request line. It does not limit the size of the request body. If zero,
	// http.DefaultMaxHeaderBytes is used.
	MaxHeaderBytes int

	// MaxHeaderBytes controls the maximum number of bytes the server will read parsing the request body. If zero,
	// MaxBodyBytes is used.
	MaxBodyBytes int64

	// BatchItemLimit is the maximum number of requests in a batch.
	BatchItemLimit int

	// BatchResponseSizeLimit is the maximum number of response bytes across all requests in a batch.
	BatchResponseSizeLimit int

	Router Registrar

	// APIs contains is an array of enabled RPC services.
	APIs []API
}

ServerConfiguration is a common configuration for RPC servers.

func (*ServerConfiguration) IsAddressEmpty

func (c *ServerConfiguration) IsAddressEmpty() bool

type StateAPI

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

func NewStateAPI

func NewStateAPI(node partitionNode, ownerIndex partition.IndexReader) *StateAPI

func (*StateAPI) GetBlock added in v0.4.0

func (s *StateAPI) GetBlock(ctx context.Context, blockNumber types.Uint64) (types.Bytes, error)

GetBlock returns block for the given block number.

func (*StateAPI) GetRoundNumber

func (s *StateAPI) GetRoundNumber(ctx context.Context) (types.Uint64, error)

GetRoundNumber returns the round number of the latest UC seen by node.

func (*StateAPI) GetTransactionProof

func (s *StateAPI) GetTransactionProof(ctx context.Context, txHash types.Bytes) (*TransactionRecordAndProof, error)

GetTransactionProof returns transaction record and proof for the given transaction hash.

func (*StateAPI) GetUnit

func (s *StateAPI) GetUnit(unitID types.UnitID, includeStateProof bool) (*Unit[any], error)

GetUnit returns unit data and optionally the state proof for the given unitID.

func (*StateAPI) GetUnitsByOwnerID

func (s *StateAPI) GetUnitsByOwnerID(ownerID types.Bytes) ([]types.UnitID, error)

GetUnitsByOwnerID returns list of unit identifiers that belong to the given owner.

func (*StateAPI) SendTransaction

func (s *StateAPI) SendTransaction(ctx context.Context, txBytes types.Bytes) (types.Bytes, error)

SendTransaction broadcasts the given transaction to the network, returns the submitted transaction hash.

type TransactionRecordAndProof added in v0.4.0

type TransactionRecordAndProof struct {
	TxRecord types.Bytes `json:"txRecord"`
	TxProof  types.Bytes `json:"txProof"`
}

type Unit added in v0.4.0

type Unit[T any] struct {
	UnitID         types.UnitID          `json:"unitId"`
	Data           T                     `json:"data"`
	OwnerPredicate types.Bytes           `json:"ownerPredicate,omitempty"`
	StateProof     *types.UnitStateProof `json:"stateProof,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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