api

package
v0.0.0-...-9307437 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTransactionNotFound is returned by /transactions/:id when we are
	// unable to find the transaction with that `id`.
	ErrTransactionNotFound = errors.New("no transaction found")
	// ErrSiacoinOutputNotFound is returned by /outputs/siacoin/:id when we
	// are unable to find the siacoin output with that `id`.
	ErrSiacoinOutputNotFound = errors.New("no siacoin output found")
	// ErrSiafundOutputNotFound is returned by /outputs/siafund/:id when we
	// are unable to find the siafund output with that `id`.
	ErrSiafundOutputNotFound = errors.New("no siafund output found")
	// ErrHostNotFound is returned by /pubkey/:key/host when we are unable to
	// find the host with the pubkey `key`.
	ErrHostNotFound = errors.New("no host found")

	// ErrNoSearchResults is returned by /search/:id when we do not find any
	// elements with that ID.
	ErrNoSearchResults = errors.New("no search results found")

	// ErrTooManyIDs is returned by the batch transaction and contract
	// endpoints when more than maxIDs IDs are specified.
	ErrTooManyIDs = fmt.Errorf("too many IDs provided (provide less than %d)", maxIDs)
)

Functions

func NewServer

func NewServer(e Explorer, cm ChainManager, s Syncer) http.Handler

NewServer returns an HTTP handler that serves the explored API.

Types

type AddressBalanceResponse

type AddressBalanceResponse struct {
	UnspentSiacoins  types.Currency `json:"unspentSiacoins"`
	ImmatureSiacoins types.Currency `json:"immatureSiacoins"`
	UnspentSiafunds  uint64         `json:"unspentSiafunds"`
}

AddressBalanceResponse is the response for /addresses/:address/balance.

type ChainManager

type ChainManager interface {
	Tip() types.ChainIndex
	TipState() consensus.State
	AddBlocks([]types.Block) error
	RecommendedFee() types.Currency
	PoolTransactions() []types.Transaction
	V2PoolTransactions() []types.V2Transaction
	AddPoolTransactions(txns []types.Transaction) (bool, error)
	AddV2PoolTransactions(index types.ChainIndex, txns []types.V2Transaction) (bool, error)
	UnconfirmedParents(txn types.Transaction) []types.Transaction
}

A ChainManager manages blockchain and txpool state.

type Client

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

A Client provides methods for interacting with a explored API server.

func NewClient

func NewClient(addr, password string) *Client

NewClient returns a client that communicates with a explored server listening on the specified address.

func (*Client) AddressBalance

func (c *Client) AddressBalance(address types.Address) (resp AddressBalanceResponse, err error)

AddressBalance returns the specified address' balance.

func (*Client) AddressEvents

func (c *Client) AddressEvents(address types.Address, offset, limit uint64) (resp []explorer.Event, err error)

AddressEvents returns the specified address' events.

func (*Client) AddressSiacoinUTXOs

func (c *Client) AddressSiacoinUTXOs(address types.Address, offset, limit uint64) (resp []explorer.SiacoinOutput, err error)

AddressSiacoinUTXOs returns the specified address' unspent outputs.

func (*Client) AddressSiafundUTXOs

func (c *Client) AddressSiafundUTXOs(address types.Address, offset, limit uint64) (resp []explorer.SiafundOutput, err error)

AddressSiafundUTXOs returns the specified address' unspent outputs.

func (*Client) BestIndex

func (c *Client) BestIndex(height uint64) (resp types.ChainIndex, err error)

BestIndex returns the chain index at the specified height.

func (*Client) Block

func (c *Client) Block(id types.BlockID) (resp explorer.Block, err error)

Block returns the block with the specified ID.

func (*Client) BlockMetrics

func (c *Client) BlockMetrics() (resp explorer.Metrics, err error)

BlockMetrics returns the most recent metrics about the Sia blockchain.

func (*Client) BlockMetricsID

func (c *Client) BlockMetricsID(id types.BlockID) (resp explorer.Metrics, err error)

BlockMetricsID returns various metrics about Sia at the given block ID.

func (*Client) ConsensusNetwork

func (c *Client) ConsensusNetwork() (n *consensus.Network, err error)

ConsensusNetwork returns the network parameters of the consensus set.

func (*Client) ConsensusState

func (c *Client) ConsensusState() (state consensus.State, err error)

ConsensusState returns the current state of the consensus set.

func (*Client) ConsensusTip

func (c *Client) ConsensusTip() (resp types.ChainIndex, err error)

ConsensusTip returns the current tip of the chain manager.

func (*Client) Contract

func (c *Client) Contract(id types.FileContractID) (resp explorer.ExtendedFileContract, err error)

Contract returns the file contract with the specified ID.

func (*Client) ContractRevisions

func (c *Client) ContractRevisions(id types.FileContractID) (resp []explorer.ExtendedFileContract, err error)

ContractRevisions returns all the revisions of the contract with the specified ID.

func (*Client) Contracts

func (c *Client) Contracts(ids []types.FileContractID) (resp []explorer.ExtendedFileContract, err error)

Contracts returns the contracts with the specified IDs.

func (*Client) ContractsKey

func (c *Client) ContractsKey(key types.PublicKey) (resp []explorer.ExtendedFileContract, err error)

ContractsKey returns the contracts for a particular ed25519 key.

func (*Client) Host

func (c *Client) Host(key types.PublicKey) (resp explorer.Host, err error)

Host returns information about the host with a given ed25519 key.

func (*Client) HostMetrics

func (c *Client) HostMetrics() (resp explorer.HostMetrics, err error)

HostMetrics returns various metrics about currently available hosts.

func (*Client) OutputSiacoin

func (c *Client) OutputSiacoin(id types.SiacoinOutputID) (resp explorer.SiacoinOutput, err error)

OutputSiacoin returns the specified siacoin output.

func (*Client) OutputSiafund

func (c *Client) OutputSiafund(id types.SiafundOutputID) (resp explorer.SiafundOutput, err error)

OutputSiafund returns the specified siafund output.

func (*Client) Search

func (c *Client) Search(id types.Hash256) (resp explorer.SearchType, err error)

Search returns what type of object an ID is.

func (*Client) State

func (c *Client) State() (resp StateResponse, err error)

State returns information about the current state of the explored daemon.

func (*Client) SyncerBroadcastBlock

func (c *Client) SyncerBroadcastBlock(b types.Block) (err error)

SyncerBroadcastBlock broadcasts a block to all peers.

func (*Client) SyncerConnect

func (c *Client) SyncerConnect(addr string) (err error)

SyncerConnect adds the address as a peer of the syncer.

func (*Client) SyncerPeers

func (c *Client) SyncerPeers() (resp []string, err error)

SyncerPeers returns the peers of the syncer.

func (*Client) Tip

func (c *Client) Tip() (resp types.ChainIndex, err error)

Tip returns the current tip of the explorer.

func (*Client) Transaction

func (c *Client) Transaction(id types.TransactionID) (resp explorer.Transaction, err error)

Transaction returns the transaction with the specified ID.

func (*Client) TransactionChainIndices

func (c *Client) TransactionChainIndices(id types.TransactionID, offset, limit uint64) (resp []types.ChainIndex, err error)

TransactionChainIndices returns chain indices a transaction was included in.

func (*Client) Transactions

func (c *Client) Transactions(ids []types.TransactionID) (resp []explorer.Transaction, err error)

Transactions returns the transactions with the specified IDs.

func (*Client) TxpoolBroadcast

func (c *Client) TxpoolBroadcast(txns []types.Transaction, v2txns []types.V2Transaction) (err error)

TxpoolBroadcast broadcasts a set of transaction to the network.

func (*Client) TxpoolFee

func (c *Client) TxpoolFee() (resp types.Currency, err error)

TxpoolFee returns the recommended fee (per weight unit) to ensure a high probability of inclusion in the next block.

func (*Client) TxpoolTransactions

func (c *Client) TxpoolTransactions() (txns []types.Transaction, v2txns []types.V2Transaction, err error)

TxpoolTransactions returns all transactions in the transaction pool.

func (*Client) V2Contract

func (c *Client) V2Contract(id types.FileContractID) (resp explorer.V2FileContract, err error)

V2Contract returns the v2 file contract with the specified ID.

func (*Client) V2ContractRevisions

func (c *Client) V2ContractRevisions(id types.FileContractID) (resp []explorer.V2FileContract, err error)

V2ContractRevisions returns all the revisions of the contract with the specified ID.

func (*Client) V2Contracts

func (c *Client) V2Contracts(ids []types.FileContractID) (resp []explorer.V2FileContract, err error)

V2Contracts returns the v2 contracts with the specified IDs.

func (*Client) V2ContractsKey

func (c *Client) V2ContractsKey(key types.PublicKey) (resp []explorer.V2FileContract, err error)

V2ContractsKey returns the v2 contracts for a particular ed25519 key.

func (*Client) V2Transaction

func (c *Client) V2Transaction(id types.TransactionID) (resp explorer.V2Transaction, err error)

V2Transaction returns the v2 transaction with the specified ID.

func (*Client) V2TransactionChainIndices

func (c *Client) V2TransactionChainIndices(id types.TransactionID, offset, limit uint64) (resp []types.ChainIndex, err error)

V2TransactionChainIndices returns chain indices a v2 transaction was included in.

func (*Client) V2Transactions

func (c *Client) V2Transactions(ids []types.TransactionID) (resp []explorer.V2Transaction, err error)

V2Transactions returns the v2 transactions with the specified IDs.

type Explorer

type Explorer interface {
	Tip() (types.ChainIndex, error)
	Block(id types.BlockID) (explorer.Block, error)
	BestTip(height uint64) (types.ChainIndex, error)
	Metrics(id types.BlockID) (explorer.Metrics, error)
	HostMetrics() (explorer.HostMetrics, error)
	Transactions(ids []types.TransactionID) ([]explorer.Transaction, error)
	TransactionChainIndices(id types.TransactionID, offset, limit uint64) ([]types.ChainIndex, error)
	V2Transactions(ids []types.TransactionID) ([]explorer.V2Transaction, error)
	V2TransactionChainIndices(id types.TransactionID, offset, limit uint64) ([]types.ChainIndex, error)
	Balance(address types.Address) (sc types.Currency, immatureSC types.Currency, sf uint64, err error)
	SiacoinElements(ids []types.SiacoinOutputID) (result []explorer.SiacoinOutput, err error)
	SiafundElements(ids []types.SiafundOutputID) (result []explorer.SiafundOutput, err error)
	UnspentSiacoinOutputs(address types.Address, offset, limit uint64) ([]explorer.SiacoinOutput, error)
	UnspentSiafundOutputs(address types.Address, offset, limit uint64) ([]explorer.SiafundOutput, error)
	AddressEvents(address types.Address, offset, limit uint64) (events []explorer.Event, err error)
	Contracts(ids []types.FileContractID) (result []explorer.ExtendedFileContract, err error)
	ContractsKey(key types.PublicKey) (result []explorer.ExtendedFileContract, err error)
	ContractRevisions(id types.FileContractID) (result []explorer.ExtendedFileContract, err error)
	V2Contracts(ids []types.FileContractID) (result []explorer.V2FileContract, err error)
	V2ContractsKey(key types.PublicKey) (result []explorer.V2FileContract, err error)
	V2ContractRevisions(id types.FileContractID) (result []explorer.V2FileContract, err error)
	Search(id types.Hash256) (explorer.SearchType, error)

	Hosts(pks []types.PublicKey) ([]explorer.Host, error)
}

Explorer implements a Sia explorer.

type GatewayPeer

type GatewayPeer struct {
	Addr    string `json:"addr"`
	Inbound bool   `json:"inbound"`
	Version string `json:"version"`

	FirstSeen      time.Time     `json:"firstSeen"`
	ConnectedSince time.Time     `json:"connectedSince"`
	SyncedBlocks   uint64        `json:"syncedBlocks"`
	SyncDuration   time.Duration `json:"syncDuration"`
}

A GatewayPeer is a currently-connected peer.

type StateResponse

type StateResponse struct {
	Version   string    `json:"version"`
	Commit    string    `json:"commit"`
	OS        string    `json:"os"`
	BuildTime time.Time `json:"buildTime"`
	StartTime time.Time `json:"startTime"`
}

A StateResponse returns information about the current state of the explored daemon.

type Syncer

type Syncer interface {
	Addr() string
	Peers() []*syncer.Peer
	Connect(ctx context.Context, addr string) (*syncer.Peer, error)
	BroadcastHeader(bh types.BlockHeader)
	BroadcastTransactionSet(txns []types.Transaction)
	BroadcastV2TransactionSet(index types.ChainIndex, txns []types.V2Transaction)
	BroadcastV2BlockOutline(bo gateway.V2BlockOutline)
}

A Syncer can connect to other peers and synchronize the blockchain.

type TxpoolBroadcastRequest

type TxpoolBroadcastRequest struct {
	Transactions   []types.Transaction   `json:"transactions"`
	V2Transactions []types.V2Transaction `json:"v2transactions"`
}

TxpoolBroadcastRequest is the request type for /txpool/broadcast.

type TxpoolTransactionsResponse

type TxpoolTransactionsResponse struct {
	Transactions   []types.Transaction   `json:"transactions"`
	V2Transactions []types.V2Transaction `json:"v2transactions"`
}

TxpoolTransactionsResponse is the response type for /txpool/transactions.

Jump to

Keyboard shortcuts

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