api

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 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

View Source
const APIGossipProtocol = "api_test_gossip"

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
}

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
}

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)
}

type NetworkAPI

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

type OracleAPI

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

type PeerCounter

type PeerCounter interface {
	PeerCount() uint64
}

type PostAPI

type PostAPI interface {
	Reset() error
}

type Service

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

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 (SpacemeshGrpcService) BroadcastPoet

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

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)

func (SpacemeshGrpcService) GetAccountTxs

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

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)

func (SpacemeshGrpcService) GetMiningStats

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

func (SpacemeshGrpcService) GetNodeStatus

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)

func (SpacemeshGrpcService) GetTransaction

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

func (SpacemeshGrpcService) GetUpcomingAwards

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

func (SpacemeshGrpcService) ResetPost

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

func (SpacemeshGrpcService) SetAwardsAddress

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

func (SpacemeshGrpcService) SetLoggerLevel

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

func (SpacemeshGrpcService) StartMining

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

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)

type StateAPI

type StateAPI interface {
	GetBalance(address types.Address) uint64

	GetNonce(address types.Address) uint64

	Exist(address types.Address) bool
}

type Syncer

type Syncer interface {
	IsSynced() bool
}

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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