api

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: MIT Imports: 26 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer

func NewServer(hostKey types.PublicKey, g Syncer, chain ChainManager, tp TPool, cm ContractManager, vm VolumeManager, m Metrics, ls LogStore, s Settings, w Wallet, log *zap.Logger) http.Handler

NewServer initializes the API

Types

type AddVolumeRequest

type AddVolumeRequest struct {
	LocalPath  string `json:"localPath"`
	MaxSectors uint64 `json:"maxSectors"`
}

AddVolumeRequest is the request body for the [POST] /volume endpoint.

type BuildState

type BuildState struct {
	Network   string    `json:"network"`
	Version   string    `json:"version"`
	Commit    string    `json:"commit"`
	OS        string    `json:"OS"`
	BuildTime time.Time `json:"buildTime"`
}

BuildState contains static information about the build.

type ChainManager

type ChainManager interface {
	Synced() bool
	TipState() consensus.State
}

A ChainManager retrieves the current blockchain state

type Client

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

A Client is a client for the hostd API.

func NewClient

func NewClient(baseURL, password string) *Client

NewClient creates a new hostd API client.

func (*Client) AddVolume

func (c *Client) AddVolume(localPath string, sectors uint64) (vol storage.Volume, err error)

AddVolume adds a new volume to the host

func (*Client) Announce

func (c *Client) Announce() error

Announce announces the host to the network. The announced address is determined by the host's current settings.

func (*Client) Consensus

func (c *Client) Consensus() (resp ConsensusState, err error)

Consensus returns the current consensus state.

func (*Client) Contract

func (c *Client) Contract(id types.FileContractID) (contract contracts.Contract, err error)

Contract returns the contract with the specified ID.

func (*Client) Contracts

func (c *Client) Contracts(filter contracts.ContractFilter) ([]contracts.Contract, int, error)

Contracts returns the contracts of the host matching the filter.

func (*Client) DeleteIntegrityCheck

func (c *Client) DeleteIntegrityCheck(id types.FileContractID) error

DeleteIntegrityCheck deletes the integrity check for the specified contract.

func (*Client) DeleteSector

func (c *Client) DeleteSector(root types.Hash256) error

DeleteSector deletes the sector with the specified root. This can cause contract failures if the sector is still in use.

func (*Client) DeleteVolume

func (c *Client) DeleteVolume(id int) error

DeleteVolume deletes the volume with the specified ID.

func (*Client) Host

func (c *Client) Host() (resp HostState, err error)

Host returns the current state of the host

func (*Client) IntegrityCheckProgress

func (c *Client) IntegrityCheckProgress(id types.FileContractID) (IntegrityCheckResult, error)

IntegrityCheckProgress returns the progress of the integrity check for the specified contract.

func (*Client) LocalDir

func (c *Client) LocalDir(path string) (resp SystemDirResponse, err error)

LocalDir returns the contents of the specified directory on the host.

func (*Client) LogEntries

func (c *Client) LogEntries(filter logging.Filter) (entries []logging.Entry, err error)

LogEntries returns log entries matching the filter.

func (*Client) LogPrune

func (c *Client) LogPrune(before time.Time) error

LogPrune deletes log entries before the specified time.

func (*Client) Metrics

func (c *Client) Metrics(at time.Time) (metrics metrics.Metrics, err error)

Metrics returns the metrics of the host at the specified time.

func (*Client) MkDir

func (c *Client) MkDir(path string) error

MkDir creates a new directory on the host.

func (*Client) PendingTransactions

func (c *Client) PendingTransactions() (transactions []wallet.Transaction, err error)

PendingTransactions returns transactions that are not yet confirmed.

func (*Client) PeriodMetrics

func (c *Client) PeriodMetrics(start time.Time, n int, interval metrics.Interval) (periods []metrics.Metrics, err error)

PeriodMetrics returns the metrics of the host for n periods starting at start.

func (*Client) ResizeVolume

func (c *Client) ResizeVolume(id int, sectors uint64) error

ResizeVolume resizes the volume with the specified ID to a new size.

func (*Client) SendSiacoins

func (c *Client) SendSiacoins(address types.Address, amount types.Currency) (id types.TransactionID, err error)

SendSiacoins sends siacoins to the specified address.

func (*Client) Settings

func (c *Client) Settings() (settings settings.Settings, err error)

Settings returns the current settings of the host.

func (*Client) StartIntegrityCheck

func (c *Client) StartIntegrityCheck(id types.FileContractID) error

StartIntegrityCheck scans the volume with the specified ID for consistency errors.

func (*Client) SyncerAddress

func (c *Client) SyncerAddress() (addr string, err error)

SyncerAddress returns the address of the syncer.

func (*Client) SyncerConnect

func (c *Client) SyncerConnect(address string) error

SyncerConnect connects to a peer.

func (*Client) SyncerDisconnect

func (c *Client) SyncerDisconnect(address string) error

SyncerDisconnect disconnects from a peer.

func (*Client) SyncerPeers

func (c *Client) SyncerPeers() (peers []Peer, err error)

SyncerPeers returns the currently connected peers of the syncer.

func (*Client) TestDynDNS

func (c *Client) TestDynDNS() error

TestDynDNS tests the dynamic DNS settings of the host.

func (*Client) Transactions

func (c *Client) Transactions(limit, offset int) (transactions []wallet.Transaction, err error)

Transactions returns the transactions of the host's wallet.

func (*Client) UpdateSettings

func (c *Client) UpdateSettings(patch UpdateSettingsRequest) (settings settings.Settings, err error)

UpdateSettings updates the host's settings.

func (*Client) UpdateVolume

func (c *Client) UpdateVolume(id int, req UpdateVolumeRequest) error

UpdateVolume updates the volume with the specified ID.

func (*Client) Volume

func (c *Client) Volume(id int) (volume VolumeMeta, err error)

Volume returns the volume with the specified ID.

func (*Client) Volumes

func (c *Client) Volumes() (volumes []VolumeMeta, err error)

Volumes returns the volumes of the host.

func (*Client) Wallet

func (c *Client) Wallet() (resp WalletResponse, err error)

Wallet returns the state of the host's wallet.

type ConsensusState

type ConsensusState struct {
	Synced     bool             `json:"synced"`
	ChainIndex types.ChainIndex `json:"chainIndex"`
}

ConsensusState is the response body for the [GET] /consensus endpoint.

type ContractIntegrityResponse

type ContractIntegrityResponse struct {
	BadSectors   []types.Hash256 `json:"badSectors"`
	TotalSectors uint64          `json:"totalSectors"`
}

ContractIntegrityResponse is the response body for the [POST] /contracts/:id/check endpoint.

type ContractManager

type ContractManager interface {
	Contracts(filter contracts.ContractFilter) ([]contracts.Contract, int, error)
	Contract(id types.FileContractID) (contracts.Contract, error)

	// CheckIntegrity checks the integrity of a contract's sector roots on
	// disk. The result of each sector checked is sent on the returned
	// channel. Read errors are logged.
	CheckIntegrity(ctx context.Context, contractID types.FileContractID) (<-chan contracts.IntegrityResult, uint64, error)
}

A ContractManager manages the host's contracts

type ContractsResponse

type ContractsResponse struct {
	Count     int                  `json:"count"`
	Contracts []contracts.Contract `json:"contracts"`
}

ContractsResponse is the response body for the [POST] /contracts endpoint.

type CreateDirRequest

type CreateDirRequest struct {
	Path string `json:"path"`
}

A CreateDirRequest is the request body for the [POST] /system/dir endpoint.

type HostState

type HostState struct {
	PublicKey     types.PublicKey `json:"publicKey"`
	WalletAddress types.Address   `json:"walletAddress"`
	BuildState
}

HostState is the response body for the [GET] /state/host endpoint.

type IntegrityCheckResult

type IntegrityCheckResult struct {
	Start time.Time `json:"start"`
	End   time.Time `json:"end"`

	CheckedSectors uint64                      `json:"checkedSectors"`
	TotalSectors   uint64                      `json:"totalSectors"`
	BadSectors     []contracts.IntegrityResult `json:"badSectors"`
}

IntegrityCheckResult tracks the result of an integrity check.

type JSONErrors

type JSONErrors []error

JSONErrors is a slice of errors that can be marshaled to and unmarshaled from JSON.

func (JSONErrors) MarshalJSON

func (je JSONErrors) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*JSONErrors) UnmarshalJSON

func (je *JSONErrors) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler

type LogResponse

type LogResponse struct {
	Count   int             `json:"count"`
	Entries []logging.Entry `json:"entries"`
}

LogResponse is the response body for the [GET] /log/entries endpoint.

type LogStore

type LogStore interface {
	LogEntries(logging.Filter) ([]logging.Entry, int, error)
	Prune(time.Time) error
}

A LogStore retrieves host logs

type Metrics

type Metrics interface {
	// PeriodMetrics returns metrics for n periods starting at start.
	PeriodMetrics(start time.Time, periods int, interval metrics.Interval) (period []metrics.Metrics, err error)
	// Metrics returns aggregated metrics for the host as of the timestamp.
	Metrics(time.Time) (m metrics.Metrics, err error)
}

Metrics retrieves metrics related to the host

type Peer

type Peer struct {
	Address string `json:"address"`
	Version string `json:"version"`
}

A Peer is a peer in the network.

type ResizeVolumeRequest

type ResizeVolumeRequest struct {
	MaxSectors uint64 `json:"maxSectors"`
}

ResizeVolumeRequest is the request body for the [PUT] /volume/:id/resize endpoint.

type Settings

type Settings interface {
	Announce() error

	UpdateSettings(s settings.Settings) error
	Settings() settings.Settings

	UpdateDynDNS(force bool) error
}

Settings updates and retrieves the host's settings

type Syncer

type Syncer interface {
	Address() modules.NetAddress
	Peers() []modules.Peer
	Connect(addr modules.NetAddress) error
	Disconnect(addr modules.NetAddress) error
}

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

type SyncerConnectRequest

type SyncerConnectRequest struct {
	Address string `json:"address"`
}

SyncerConnectRequest is the request body for the [PUT] /syncer/peers endpoint.

type SystemDirResponse

type SystemDirResponse struct {
	Path        string   `json:"path"`
	TotalBytes  uint64   `json:"totalBytes"`
	FreeBytes   uint64   `json:"freeBytes"`
	Directories []string `json:"directories"`
}

SystemDirResponse is the response body for the [GET] /system/dir endpoint.

type TPool

type TPool interface {
	RecommendedFee() (fee types.Currency)
	AcceptTransactionSet(txns []types.Transaction) error
}

A TPool manages the transaction pool

type UpdateSettingsRequest

type UpdateSettingsRequest map[string]any

UpdateSettingsRequest is the request body for the [PUT] /settings endpoint. It will be merged with the current settings.

func (UpdateSettingsRequest) WithAcceptingContracts

func (ur UpdateSettingsRequest) WithAcceptingContracts(value bool)

WithAcceptingContracts sets the AcceptingContracts field of the request

func (UpdateSettingsRequest) WithAccountExpiry

func (ur UpdateSettingsRequest) WithAccountExpiry(value time.Duration)

WithAccountExpiry sets the AccountExpiry field of the request

func (UpdateSettingsRequest) WithBaseRPCPrice

func (ur UpdateSettingsRequest) WithBaseRPCPrice(value types.Currency)

WithBaseRPCPrice sets the BaseRPCPrice field of the request

func (UpdateSettingsRequest) WithCollateral

func (ur UpdateSettingsRequest) WithCollateral(value types.Currency)

WithCollateral sets the Collateral field of the request

func (UpdateSettingsRequest) WithContractPrice

func (ur UpdateSettingsRequest) WithContractPrice(value types.Currency)

WithContractPrice sets the ContractPrice field of the request

func (UpdateSettingsRequest) WithEgressLimit

func (ur UpdateSettingsRequest) WithEgressLimit(value uint64)

WithEgressLimit sets the EgressLimit field of the request

func (UpdateSettingsRequest) WithIngressLimit

func (ur UpdateSettingsRequest) WithIngressLimit(value uint64)

WithIngressLimit sets the IngressLimit field of the request

func (UpdateSettingsRequest) WithMaxAccountBalance

func (ur UpdateSettingsRequest) WithMaxAccountBalance(value types.Currency)

WithMaxAccountBalance sets the MaxAccountBalance field of the request

func (UpdateSettingsRequest) WithMaxCollateral

func (ur UpdateSettingsRequest) WithMaxCollateral(value types.Currency)

WithMaxCollateral sets the MaxCollateral field of the request

func (UpdateSettingsRequest) WithMaxContractDuration

func (ur UpdateSettingsRequest) WithMaxContractDuration(value uint64)

WithMaxContractDuration sets the MaxContractDuration field of the request

func (UpdateSettingsRequest) WithMaxRegistryEntries

func (ur UpdateSettingsRequest) WithMaxRegistryEntries(value uint64)

WithMaxRegistryEntries sets the MaxRegistryEntries field of the request

func (UpdateSettingsRequest) WithMinEgressPrice

func (ur UpdateSettingsRequest) WithMinEgressPrice(value types.Currency)

WithMinEgressPrice sets the MinEgressPrice field of the request

func (UpdateSettingsRequest) WithMinIngressPrice

func (ur UpdateSettingsRequest) WithMinIngressPrice(value types.Currency)

WithMinIngressPrice sets the MinIngressPrice field of the request

func (UpdateSettingsRequest) WithMinStoragePrice

func (ur UpdateSettingsRequest) WithMinStoragePrice(value types.Currency)

WithMinStoragePrice sets the MinStoragePrice field of the request

func (UpdateSettingsRequest) WithNetAddress

func (ur UpdateSettingsRequest) WithNetAddress(value string)

WithNetAddress sets the NetAddress field of the request

func (UpdateSettingsRequest) WithPriceTableValidity

func (ur UpdateSettingsRequest) WithPriceTableValidity(value time.Duration)

WithPriceTableValidity sets the PriceTableValidity field of the request

func (UpdateSettingsRequest) WithSectorAccessPrice

func (ur UpdateSettingsRequest) WithSectorAccessPrice(value types.Currency)

WithSectorAccessPrice sets the SectorAccessPrice field of the request

type UpdateVolumeRequest

type UpdateVolumeRequest struct {
	ReadOnly bool `json:"readOnly"`
}

UpdateVolumeRequest is the request body for the [PUT] /volume/:id endpoint.

type VolumeManager

type VolumeManager interface {
	Usage() (usedSectors uint64, totalSectors uint64, err error)
	Volumes() ([]storage.VolumeMeta, error)
	Volume(id int) (storage.VolumeMeta, error)
	AddVolume(localPath string, maxSectors uint64) (storage.Volume, error)
	SetReadOnly(id int, readOnly bool) error
	RemoveVolume(id int, force bool) error
	ResizeVolume(id int, maxSectors uint64) error
	RemoveSector(root types.Hash256) error
}

A VolumeManager manages the host's storage volumes

type VolumeMeta

type VolumeMeta struct {
	storage.VolumeMeta
	Errors JSONErrors `json:"errors"`
}

VolumeMeta is a volume with its metadata. It overrides the marshalling of the storage.VolumeMeta type to handle error messages.

type Wallet

type Wallet interface {
	Address() types.Address
	ScanHeight() uint64
	Balance() (spendable, confirmed, unconfirmed types.Currency, err error)
	UnconfirmedTransactions() ([]wallet.Transaction, error)
	FundTransaction(txn *types.Transaction, amount types.Currency) (toSign []types.Hash256, release func(), err error)
	SignTransaction(cs consensus.State, txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error
	Transactions(limit, offset int) ([]wallet.Transaction, error)
}

A Wallet manages Siacoins and funds transactions

type WalletResponse

type WalletResponse struct {
	ScanHeight  uint64         `json:"scanHeight"`
	Address     types.Address  `json:"address"`
	Spendable   types.Currency `json:"spendable"`
	Confirmed   types.Currency `json:"confirmed"`
	Unconfirmed types.Currency `json:"unconfirmed"`
}

WalletResponse is the response body for the [GET] /wallet endpoint.

type WalletSendSiacoinsRequest

type WalletSendSiacoinsRequest struct {
	Address types.Address  `json:"address"`
	Amount  types.Currency `json:"amount"`
}

WalletSendSiacoinsRequest is the request body for the [POST] /wallet/send endpoint.

Jump to

Keyboard shortcuts

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