api

package
v0.1.10-docs-prerelease Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: MIT Imports: 25 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 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 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     *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

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

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

type Syncer

type Syncer interface {
	IsSynced() bool
}

Syncer is the API to get sync status

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

Directories

Path Synopsis
Package config provides configuration for GRPC and HTTP api servers
Package config provides configuration for GRPC and HTTP api servers

Jump to

Keyboard shortcuts

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