Documentation ¶
Overview ¶
Package api provides the local go-spacemesh API endpoints. e.g. json-http and grpc-http2
Index ¶
- func ApproveAPIGossipMessages(ctx context.Context, s Service)
- type GenesisTimeAPI
- type JSONHTTPServer
- type LoggingAPI
- type MiningAPI
- type NetworkAPI
- type OracleAPI
- type PeerCounter
- type PostAPI
- type Service
- type SpacemeshGrpcService
- func (s SpacemeshGrpcService) Broadcast(ctx context.Context, in *pb.BroadcastMessage) (*pb.SimpleMessage, error)
- func (s SpacemeshGrpcService) BroadcastPoet(ctx context.Context, in *pb.BinaryMessage) (*pb.SimpleMessage, error)
- func (s SpacemeshGrpcService) Close() error
- func (s SpacemeshGrpcService) Echo(ctx context.Context, in *pb.SimpleMessage) (*pb.SimpleMessage, error)
- func (s SpacemeshGrpcService) GetAccountRewards(ctx context.Context, account *pb.AccountId) (*pb.AccountRewards, error)
- func (s SpacemeshGrpcService) GetAccountTxs(ctx context.Context, txsSinceLayer *pb.GetTxsSinceLayer) (*pb.AccountTxs, error)
- func (s SpacemeshGrpcService) GetBalance(ctx context.Context, in *pb.AccountId) (*pb.SimpleMessage, error)
- func (s SpacemeshGrpcService) GetGenesisTime(ctx context.Context, empty *empty.Empty) (*pb.SimpleMessage, error)
- func (s SpacemeshGrpcService) GetMiningStats(ctx context.Context, empty *empty.Empty) (*pb.MiningStats, error)
- func (s SpacemeshGrpcService) GetNodeStatus(context.Context, *empty.Empty) (*pb.NodeStatus, error)
- func (s SpacemeshGrpcService) GetNonce(ctx context.Context, in *pb.AccountId) (*pb.SimpleMessage, error)
- func (s SpacemeshGrpcService) GetStateRoot(ctx context.Context, empty *empty.Empty) (*pb.SimpleMessage, error)
- func (s SpacemeshGrpcService) GetTransaction(ctx context.Context, txID *pb.TransactionId) (*pb.Transaction, error)
- func (s SpacemeshGrpcService) GetUpcomingAwards(ctx context.Context, empty *empty.Empty) (*pb.EligibleLayers, error)
- func (s SpacemeshGrpcService) ResetPost(ctx context.Context, empty *empty.Empty) (*pb.SimpleMessage, error)
- func (s SpacemeshGrpcService) SetAwardsAddress(ctx context.Context, id *pb.AccountId) (*pb.SimpleMessage, error)
- func (s SpacemeshGrpcService) SetLoggerLevel(ctx context.Context, msg *pb.SetLogLevel) (*pb.SimpleMessage, error)
- func (s SpacemeshGrpcService) StartMining(ctx context.Context, message *pb.InitPost) (*pb.SimpleMessage, error)
- func (s SpacemeshGrpcService) StartService()
- func (s SpacemeshGrpcService) SubmitTransaction(ctx context.Context, in *pb.SignedTransaction) (*pb.TxConfirmation, error)
- type StateAPI
- type Syncer
- type TxAPI
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApproveAPIGossipMessages ¶
ApproveAPIGossipMessages registers the gossip api test protocol and approves every message as valid
Types ¶
type GenesisTimeAPI ¶
GenesisTimeAPI is an API to get genesis time and current layer of the system
type JSONHTTPServer ¶
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 ¶
LoggingAPI is an API to system loggers
type MiningAPI ¶
type MiningAPI interface { StartPost(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) }
MiningAPI is an API for controlling Post, setting coinbase account and getting mining stats
type NetworkAPI ¶
type NetworkAPI interface { Broadcast(channel string, data []byte) error SubscribePeerEvents() (conn, disc chan p2pcrypto.PublicKey) }
NetworkAPI is an API to nodes gossip network
type PeerCounter ¶
type PeerCounter interface {
PeerCount() uint64
}
PeerCounter is an api to get amount of connected peers
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 *miner.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 *miner.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 ¶
func (s SpacemeshGrpcService) Broadcast(ctx context.Context, in *pb.BroadcastMessage) (*pb.SimpleMessage, error)
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 ¶
func (s SpacemeshGrpcService) Echo(ctx context.Context, in *pb.SimpleMessage) (*pb.SimpleMessage, error)
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 ¶
func (s SpacemeshGrpcService) GetBalance(ctx context.Context, in *pb.AccountId) (*pb.SimpleMessage, error)
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(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 ¶
func (s SpacemeshGrpcService) GetNonce(ctx context.Context, in *pb.AccountId) (*pb.SimpleMessage, error)
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
type TxAPI ¶
type TxAPI interface { AddressExists(addr types.Address) bool ValidateNonceAndBalance(transaction *types.Transaction) error GetRewards(account types.Address) (rewards []types.Reward, err error) GetTransactionsByDestination(l types.LayerID, account types.Address) (txs []types.TransactionID) GetTransactionsByOrigin(l types.LayerID, account types.Address) (txs []types.TransactionID) LatestLayer() types.LayerID GetLayerApplied(txID types.TransactionID) *types.LayerID GetTransaction(id types.TransactionID) (*types.Transaction, error) GetProjection(addr types.Address, prevNonce, prevBalance uint64) (nonce, balance uint64, err error) LatestLayerInState() types.LayerID GetStateRoot() types.Hash32 }
TxAPI is an api for getting transaction transaction status