api

package
v0.1.45 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package api provides the local go-spacemesh API endpoints. e.g. json-http and grpc-http2

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApproveAPIGossipMessages

func ApproveAPIGossipMessages(ctx context.Context, s Service)

ApproveAPIGossipMessages registers the gossip api test protocol and approves every message as valid

Types

type GenesisTimeAPI

type GenesisTimeAPI interface {
	GetGenesisTime() time.Time
	GetCurrentLayer() types.LayerID
}

GenesisTimeAPI is an API to get genesis time and current layer of the system

type JSONHTTPServer

type JSONHTTPServer struct {
	Port     uint
	GrpcPort uint
	// contains filtered or unexported fields
}

JSONHTTPServer is a JSON http server providing the Spacemesh API. It is implemented using a grpc-gateway. See https://github.com/grpc-ecosystem/grpc-gateway .

func NewJSONHTTPServer

func NewJSONHTTPServer(port int, grpcPort int) *JSONHTTPServer

NewJSONHTTPServer creates a new json http server.

func (*JSONHTTPServer) Close added in v0.1.6

func (s *JSONHTTPServer) Close() error

Close stops the server.

func (*JSONHTTPServer) StartService

func (s *JSONHTTPServer) StartService()

StartService starts the json api server and listens for status (started, stopped).

type LoggingAPI

type LoggingAPI interface {
	SetLogLevel(loggerName, severity string) error
}

LoggingAPI is an API to system loggers

type MempoolAPI added in v0.1.16

type MempoolAPI interface {
	Get(types.TransactionID) (*types.Transaction, error)
	GetTxIdsByAddress(types.Address) []types.TransactionID
	GetProjection(types.Address, uint64, uint64) (uint64, uint64)
}

MempoolAPI is an API for reading mempool data that's useful for API services

type MiningAPI

type MiningAPI interface {
	StartPost(ctx context.Context, address types.Address, datadir string, space uint64) error
	SetCoinbaseAccount(rewardAddress types.Address)
	// MiningStats returns state of post init, coinbase reward account and data directory path for post commitment
	MiningStats() (postStatus int, remainingBytes uint64, coinbaseAccount string, postDatadir string)
	GetSmesherID() types.NodeID
	Stop()
}

MiningAPI is an API for controlling Post, setting coinbase account and getting mining stats

type NetworkAPI

type NetworkAPI interface {
	Broadcast(ctx context.Context, channel string, data []byte) error
	SubscribePeerEvents() (conn, disc chan p2pcrypto.PublicKey)
}

NetworkAPI is an API to nodes gossip network

type OracleAPI

type OracleAPI interface {
	GetEligibleLayers() []types.LayerID
}

OracleAPI gets eligible layers from oracle

type PeerCounter

type PeerCounter interface {
	PeerCount() uint64
}

PeerCounter is an api to get amount of connected peers

type PostAPI

type PostAPI interface {
	Reset() error
}

PostAPI is an API for post init module

type Service

type Service interface {
	RegisterGossipProtocol(string, priorityq.Priority) chan service.GossipMessage
}

Service is an interface for receiving messages via gossip

type SpacemeshGrpcService

type SpacemeshGrpcService struct {
	Server        *grpc.Server
	Port          uint
	StateAPI      StateAPI         // State DB
	Network       NetworkAPI       // P2P Swarm
	Tx            TxAPI            // Mesh
	TxMempool     *state.TxMempool // TX Mempool
	Mining        MiningAPI        // ATX Builder
	Oracle        OracleAPI
	GenTime       GenesisTimeAPI
	Post          PostAPI
	LayerDuration time.Duration
	PeerCounter   PeerCounter
	Syncer        Syncer
	Config        *config.Config
	Logging       LoggingAPI
}

SpacemeshGrpcService is a grpc server providing the Spacemesh api

func NewGrpcService

func NewGrpcService(port int, net NetworkAPI, state StateAPI, tx TxAPI, txMempool *state.TxMempool, mining MiningAPI, oracle OracleAPI, genTime GenesisTimeAPI, post PostAPI, layerDurationSec int, syncer Syncer, cfg *config.Config, logging LoggingAPI) *SpacemeshGrpcService

NewGrpcService create a new grpc service using config data.

func (SpacemeshGrpcService) Broadcast

Broadcast broadcasts message to gossip network

func (SpacemeshGrpcService) BroadcastPoet

func (s SpacemeshGrpcService) BroadcastPoet(ctx context.Context, in *pb.BinaryMessage) (*pb.SimpleMessage, error)

BroadcastPoet is a specialized API to broadcast poet messages

func (SpacemeshGrpcService) Close added in v0.1.6

func (s SpacemeshGrpcService) Close() error

Close stops the grpc service.

func (SpacemeshGrpcService) Echo

Echo returns the response for an echo api request

func (SpacemeshGrpcService) GetAccountRewards

func (s SpacemeshGrpcService) GetAccountRewards(ctx context.Context, account *pb.AccountId) (*pb.AccountRewards, error)

GetAccountRewards returns the rewards for the provided account

func (SpacemeshGrpcService) GetAccountTxs

func (s SpacemeshGrpcService) GetAccountTxs(ctx context.Context, txsSinceLayer *pb.GetTxsSinceLayer) (*pb.AccountTxs, error)

GetAccountTxs returns transactions that were applied and pending by this account

func (SpacemeshGrpcService) GetBalance

GetBalance returns the current account balance for the provided account ID. The balance is based on the global state and all known transactions in unapplied blocks and the mempool that originate from the given account. Unapplied transactions coming INTO the given account (from mempool or unapplied blocks) are NOT counted.

func (SpacemeshGrpcService) GetGenesisTime

func (s SpacemeshGrpcService) GetGenesisTime(ctx context.Context, empty *empty.Empty) (*pb.SimpleMessage, error)

GetGenesisTime returns the time at which this blockmesh has started

func (SpacemeshGrpcService) GetMiningStats

func (s SpacemeshGrpcService) GetMiningStats(ctx context.Context, empty *empty.Empty) (*pb.MiningStats, error)

GetMiningStats returns post creation status, coinbase address and post data directory

func (SpacemeshGrpcService) GetNodeStatus

func (s SpacemeshGrpcService) GetNodeStatus(ctx context.Context, _ *empty.Empty) (*pb.NodeStatus, error)

GetNodeStatus returns a status object providing information about the connected peers, sync status, current and verified layer

func (SpacemeshGrpcService) GetNonce

GetNonce returns the current account nonce for the provided account ID. The nonce is based on the global state and all known transactions in unapplied blocks and the mempool.

func (SpacemeshGrpcService) GetStateRoot

func (s SpacemeshGrpcService) GetStateRoot(ctx context.Context, empty *empty.Empty) (*pb.SimpleMessage, error)

GetStateRoot returns current state root

func (SpacemeshGrpcService) GetTransaction

func (s SpacemeshGrpcService) GetTransaction(ctx context.Context, txID *pb.TransactionId) (*pb.Transaction, error)

GetTransaction gets transaction details by id

func (SpacemeshGrpcService) GetUpcomingAwards

func (s SpacemeshGrpcService) GetUpcomingAwards(ctx context.Context, empty *empty.Empty) (*pb.EligibleLayers, error)

GetUpcomingAwards returns the id of layers at which this miner will receive rewards

func (SpacemeshGrpcService) ResetPost

func (s SpacemeshGrpcService) ResetPost(ctx context.Context, empty *empty.Empty) (*pb.SimpleMessage, error)

ResetPost removed post commitment for this miner

func (SpacemeshGrpcService) SetAwardsAddress

func (s SpacemeshGrpcService) SetAwardsAddress(ctx context.Context, id *pb.AccountId) (*pb.SimpleMessage, error)

SetAwardsAddress sets the award address for which this miner will receive awards

func (SpacemeshGrpcService) SetLoggerLevel

func (s SpacemeshGrpcService) SetLoggerLevel(ctx context.Context, msg *pb.SetLogLevel) (*pb.SimpleMessage, error)

SetLoggerLevel sets logger level for specific logger

func (SpacemeshGrpcService) StartMining

func (s SpacemeshGrpcService) StartMining(ctx context.Context, message *pb.InitPost) (*pb.SimpleMessage, error)

StartMining start post init followed by publication of atxs and blocks

func (SpacemeshGrpcService) StartService

func (s SpacemeshGrpcService) StartService()

StartService starts the grpc service.

func (SpacemeshGrpcService) SubmitTransaction

func (s SpacemeshGrpcService) SubmitTransaction(ctx context.Context, in *pb.SignedTransaction) (*pb.TxConfirmation, error)

SubmitTransaction transmits transaction via gossip metwork

type StateAPI

type StateAPI interface {
	GetBalance(address types.Address) uint64
	GetNonce(address types.Address) uint64
	Exist(address types.Address) bool
}

StateAPI is an API to global state TODO: Remove me once the old API is removed. These are not used by the new API implementation as this interface has been completely folded into the TxAPI. see https://github.com/spacemeshos/go-spacemesh/issues/2077

type Syncer

type Syncer interface {
	IsSynced(context.Context) bool
	Start(context.Context)
}

Syncer is the API to get sync status and to start sync

type TxAPI

type TxAPI interface {
	AddressExists(types.Address) bool
	ValidateNonceAndBalance(*types.Transaction) error
	GetATXs(context.Context, []types.ATXID) (map[types.ATXID]*types.ActivationTx, []types.ATXID)
	GetLayer(types.LayerID) (*types.Layer, error)
	GetRewards(types.Address) ([]types.Reward, error)
	GetTransactions([]types.TransactionID) ([]*types.Transaction, map[types.TransactionID]struct{})
	GetTransactionsByDestination(types.LayerID, types.Address) []types.TransactionID
	GetTransactionsByOrigin(types.LayerID, types.Address) []types.TransactionID
	LatestLayer() types.LayerID
	GetLayerApplied(types.TransactionID) *types.LayerID
	GetTransaction(types.TransactionID) (*types.Transaction, error)
	GetProjection(types.Address, uint64, uint64) (uint64, uint64, error)
	LatestLayerInState() types.LayerID
	ProcessedLayer() types.LayerID
	GetStateRoot() types.Hash32
	GetLayerStateRoot(types.LayerID) (types.Hash32, error)
	GetBalance(types.Address) uint64
	GetNonce(types.Address) uint64
	GetAllAccounts() (*types.MultipleAccountsState, error)
	//TODO: fix the discrepancy between SmesherID and NodeID (see https://github.com/spacemeshos/go-spacemesh/issues/2269)
	GetRewardsBySmesherID(types.NodeID) ([]types.Reward, error)
}

TxAPI is an api for getting transaction status

Directories

Path Synopsis
Package config provides configuration for GRPC and HTTP api servers
Package config provides configuration for GRPC and HTTP api servers
Package pb is a reverse proxy.
Package pb is a reverse proxy.

Jump to

Keyboard shortcuts

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