client

package
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPeerExists indicates that two peers are already connected. The string
	// of this error needs to be updated if the string of errPeerExists in the
	// gateway package is changed.
	ErrPeerExists = errors.New("already connected to this peer")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Options
}

A Client makes requests to the satd HTTP API.

func New

func New(opts Options) *Client

New creates a new Client using the provided address. The password will be set using SATD_API_PASSWORD environment variable and the user agent will be set to "Sat-Agent". Both can be changed manually by the caller after the client is returned.

func (*Client) ConsensusBlocksHeightGet

func (c *Client) ConsensusBlocksHeightGet(height types.BlockHeight) (cbg api.ConsensusBlocksGet, err error)

ConsensusBlocksHeightGet requests the /consensus/blocks api resource.

func (*Client) ConsensusBlocksIDGet

func (c *Client) ConsensusBlocksIDGet(id types.BlockID) (cbg api.ConsensusBlocksGet, err error)

ConsensusBlocksIDGet requests the /consensus/blocks api resource.

func (*Client) ConsensusGet

func (c *Client) ConsensusGet() (cg api.ConsensusGET, err error)

ConsensusGet requests the /consensus api resource.

func (*Client) ConsensusSetSubscribe

func (c *Client) ConsensusSetSubscribe(subscriber modules.ConsensusSetSubscriber, ccid modules.ConsensusChangeID, cancel <-chan struct{}) (<-chan error, func())

ConsensusSetSubscribe polls the /consensus/subscribe endpoint, streaming consensus changes to the subscriber indefinitely. First, it will stream changes until the subscriber is fully caught up. It will send any error encountered down the returned channel, or nil. Consequently, the caller should always wait for the first error before proceeding with initialization. Subsequent errors may be handled asynchronously. It also returns a function that can be called to unsubscribe from further changes.

func (*Client) ConsensusSubscribeSingle

func (c *Client) ConsensusSubscribeSingle(subscriber modules.ConsensusSetSubscriber, ccid modules.ConsensusChangeID, cancel <-chan struct{}) (modules.ConsensusChangeID, error)

ConsensusSubscribeSingle streams consensus changes from the /consensus/subscribe endpoint to the provided subscriber. Multiple calls may be required before the subscriber is fully caught up. It returns the latest change ID; if no changes were sent, this will be the same as the input ID.

func (*Client) DaemonAlertsGet

func (c *Client) DaemonAlertsGet() (dag api.DaemonAlertsGet, err error)

DaemonAlertsGet requests the /daemon/alerts resource.

func (*Client) DaemonStopGet

func (c *Client) DaemonStopGet() (err error)

DaemonStopGet stops the daemon using the /daemon/stop endpoint.

func (*Client) DaemonVersionGet

func (c *Client) DaemonVersionGet() (dvg api.DaemonVersionGet, err error)

DaemonVersionGet requests the /daemon/version resource.

func (*Client) GatewayAppendBlocklistPost

func (c *Client) GatewayAppendBlocklistPost(addresses []string) (err error)

GatewayAppendBlocklistPost uses the /gateway/blocklist endpoint to append addresses to the Gateway's blocklist.

func (*Client) GatewayBandwidthGet

func (c *Client) GatewayBandwidthGet() (gbg api.GatewayBandwidthGET, err error)

GatewayBandwidthGet requests the /gateway/bandwidth api resource.

func (*Client) GatewayBlocklistGet

func (c *Client) GatewayBlocklistGet() (gbg api.GatewayBlocklistGET, err error)

GatewayBlocklistGet uses the /gateway/blocklist endpoint to request the Gateway's blocklist.

func (*Client) GatewayConnectPost

func (c *Client) GatewayConnectPost(address modules.NetAddress) (err error)

GatewayConnectPost uses the /gateway/connect/:address endpoint to connect to the gateway at address.

func (*Client) GatewayDisconnectPost

func (c *Client) GatewayDisconnectPost(address modules.NetAddress) (err error)

GatewayDisconnectPost uses the /gateway/disconnect/:address endpoint to disconnect the gateway from a peer.

func (*Client) GatewayGet

func (c *Client) GatewayGet() (gwg api.GatewayGET, err error)

GatewayGet requests the /gateway api resource.

func (*Client) GatewayRateLimitPost

func (c *Client) GatewayRateLimitPost(downloadSpeed, uploadSpeed int64) (err error)

GatewayRateLimitPost uses the /gateway endpoint to change the gateway's bandwidth rate limit. downloadSpeed and uploadSpeed are interpreted as bytes/second.

func (*Client) GatewayRemoveBlocklistPost

func (c *Client) GatewayRemoveBlocklistPost(addresses []string) (err error)

GatewayRemoveBlocklistPost uses the /gateway/blocklist endpoint to remove addresses from the Gateway's blocklist.

func (*Client) GatewaySetBlocklistPost

func (c *Client) GatewaySetBlocklistPost(addresses []string) (err error)

GatewaySetBlocklistPost uses the /gateway/blocklist endpoint to set the Gateway's blocklist.

func (*Client) HostDbActiveGet

func (c *Client) HostDbActiveGet() (hdag api.HostdbActiveGET, err error)

HostDbActiveGet requests the /hostdb/active endpoint's resources.

func (*Client) HostDbAllGet

func (c *Client) HostDbAllGet() (hdag api.HostdbAllGET, err error)

HostDbAllGet requests the /hostdb/all endpoint's resources.

func (*Client) HostDbFilterModeGet

func (c *Client) HostDbFilterModeGet() (hdfmg api.HostdbFilterModeGET, err error)

HostDbFilterModeGet requests the /hostdb/filtermode GET endpoint.

func (*Client) HostDbFilterModePost

func (c *Client) HostDbFilterModePost(fm modules.FilterMode, hosts []types.SiaPublicKey, netAddresses []string) (err error)

HostDbFilterModePost requests the /hostdb/filtermode POST endpoint.

func (*Client) HostDbGet

func (c *Client) HostDbGet() (hdg api.HostdbGet, err error)

HostDbGet requests the /hostdb endpoint's resources.

func (*Client) HostDbHostsGet

func (c *Client) HostDbHostsGet(pk types.SiaPublicKey) (hhg api.HostdbHostsGET, err error)

HostDbHostsGet request the /hostdb/hosts/:pubkey endpoint's resources.

func (*Client) NewRequest

func (c *Client) NewRequest(method, resource string, body io.Reader) (*http.Request, error)

NewRequest constructs a request to the satd HTTP API, setting the correct User-Agent and Basic Auth. The resource path must begin with /.

func (*Client) PortalCreditsGet

func (c *Client) PortalCreditsGet() (credits modules.CreditData, err error)

PortalCreditsGet requests the /portal/credits resource.

func (*Client) PortalCreditsPost

func (c *Client) PortalCreditsPost(credits modules.CreditData) (err error)

PortalCreditsPost requests the /portal/credits resource.

func (*Client) SatelliteBalanceGet

func (c *Client) SatelliteBalanceGet(key string) (ub modules.UserBalance, err error)

SatelliteBalanceGet requests the /satellite/balance resource.

func (*Client) SatelliteContractsGet

func (c *Client) SatelliteContractsGet(key string) (rc api.RenterContracts, err error)

SatelliteContractsGet requests the /satellite/contracts resource.

func (*Client) SatelliteRenterGet

func (c *Client) SatelliteRenterGet(key string) (r modules.Renter, err error)

SatelliteRenterGet requests the /satellite/renter resource.

func (*Client) SatelliteRentersGet

func (c *Client) SatelliteRentersGet() (rg api.RentersGET, err error)

SatelliteRentersGet requests the /satellite/renters resource.

func (*Client) TransactionPoolFeeGet

func (c *Client) TransactionPoolFeeGet() (tfg api.TpoolFeeGET, err error)

TransactionPoolFeeGet uses the /tpool/fee endpoint to get a fee estimation.

func (*Client) TransactionPoolRawPost

func (c *Client) TransactionPoolRawPost(txn types.Transaction, parents []types.Transaction) (err error)

TransactionPoolRawPost uses the /tpool/raw endpoint to send a raw transaction to the transaction pool.

func (*Client) TransactionPoolTransactionsGet

func (c *Client) TransactionPoolTransactionsGet() (tptg api.TpoolTxnsGET, err error)

TransactionPoolTransactionsGet uses the /tpool/transactions endpoint to get the transactions of the tpool.

func (*Client) WalletAddressGet

func (c *Client) WalletAddressGet() (wag api.WalletAddressGET, err error)

WalletAddressGet requests a new address from the /wallet/address endpoint.

func (*Client) WalletAddressesGet

func (c *Client) WalletAddressesGet() (wag api.WalletAddressesGET, err error)

WalletAddressesGet requests the wallets known addresses from the /wallet/addresses endpoint.

func (*Client) WalletChangePasswordPost

func (c *Client) WalletChangePasswordPost(currentPassword, newPassword string) (err error)

WalletChangePasswordPost uses the /wallet/changepassword endpoint to change the wallet's password.

func (*Client) WalletChangePasswordWithSeedPost

func (c *Client) WalletChangePasswordWithSeedPost(seed modules.Seed, newPassword string) (err error)

WalletChangePasswordWithSeedPost uses the /wallet/changepassword endpoint to change the password used to encrypt the wallet.

func (*Client) WalletGet

func (c *Client) WalletGet() (wg api.WalletGET, err error)

WalletGet requests the /wallet api resource.

func (*Client) WalletInitPost

func (c *Client) WalletInitPost(password string, force bool) (wip api.WalletInitPOST, err error)

WalletInitPost uses the /wallet/init endpoint to initialize and encrypt a wallet.

func (*Client) WalletInitSeedPost

func (c *Client) WalletInitSeedPost(seed, password string, force bool) (err error)

WalletInitSeedPost uses the /wallet/init/seed endpoint to initialize and encrypt a wallet using a given seed.

func (*Client) WalletLastAddressesGet

func (c *Client) WalletLastAddressesGet(count uint64) (wag api.WalletAddressesGET, err error)

WalletLastAddressesGet returns the count last addresses generated by the wallet in reverse order. That means the last generated address will be the first one in the slice.

func (*Client) WalletLockPost

func (c *Client) WalletLockPost() (err error)

WalletLockPost uses the /wallet/lock endpoint to lock the wallet.

func (*Client) WalletSeedPost

func (c *Client) WalletSeedPost(seed, password string) (err error)

WalletSeedPost uses the /wallet/seed endpoint to add a seed to the wallet's list of seeds.

func (*Client) WalletSeedsGet

func (c *Client) WalletSeedsGet() (wsg api.WalletSeedsGET, err error)

WalletSeedsGet uses the /wallet/seeds endpoint to return the wallet's current seeds.

func (*Client) WalletSiacoinsMultiPost

func (c *Client) WalletSiacoinsMultiPost(outputs []types.SiacoinOutput) (wsp api.WalletSiacoinsPOST, err error)

WalletSiacoinsMultiPost uses the /wallet/siacoin api endpoint to send money to multiple addresses at once.

func (*Client) WalletSiacoinsPost

func (c *Client) WalletSiacoinsPost(amount types.Currency, destination types.UnlockHash, feeIncluded bool) (wsp api.WalletSiacoinsPOST, err error)

WalletSiacoinsPost uses the /wallet/siacoins api endpoint to send money to a single address.

func (*Client) WalletSignPost

func (c *Client) WalletSignPost(txn types.Transaction, toSign []crypto.Hash) (wspr api.WalletSignPOSTResp, err error)

WalletSignPost uses the /wallet/sign api endpoint to sign a transaction.

func (*Client) WalletSweepPost

func (c *Client) WalletSweepPost(seed string) (wsp api.WalletSweepPOST, err error)

WalletSweepPost uses the /wallet/sweep/seed endpoint to sweep a seed into the current wallet.

func (*Client) WalletTransactionGet

func (c *Client) WalletTransactionGet(id types.TransactionID) (wtg api.WalletTransactionGETid, err error)

WalletTransactionGet requests the /wallet/transaction/:id api resource for a certain TransactionID.

func (*Client) WalletTransactionsGet

func (c *Client) WalletTransactionsGet(startHeight types.BlockHeight, endHeight types.BlockHeight) (wtg api.WalletTransactionsGET, err error)

WalletTransactionsGet requests the/wallet/transactions api resource for a certain startheight and endheight.

func (*Client) WalletUnlockConditionsGet

func (c *Client) WalletUnlockConditionsGet(addr types.UnlockHash) (wucg api.WalletUnlockConditionsGET, err error)

WalletUnlockConditionsGet requests the /wallet/unlockconditions endpoint and returns the UnlockConditions of addr.

func (*Client) WalletUnlockPost

func (c *Client) WalletUnlockPost(password string) (err error)

WalletUnlockPost uses the /wallet/unlock endpoint to unlock the wallet with a given encryption key. Per default this key is the seed.

func (*Client) WalletUnspentGet

func (c *Client) WalletUnspentGet() (wug api.WalletUnspentGET, err error)

WalletUnspentGet requests the /wallet/unspent endpoint and returns all of the unspent outputs related to the wallet.

func (*Client) WalletVerifyPasswordGet

func (c *Client) WalletVerifyPasswordGet(password string) (wvpg api.WalletVerifyPasswordGET, err error)

WalletVerifyPasswordGet uses the /wallet/verifypassword endpoint to check the wallet's password.

func (*Client) WalletVerifyPasswordSeedGet

func (c *Client) WalletVerifyPasswordSeedGet(seed modules.Seed) (wvpg api.WalletVerifyPasswordGET, err error)

WalletVerifyPasswordSeedGet takes a seed and generates a seed string to submit to the /wallet/verifypassword endpoint.

func (*Client) WalletWatchAddPost

func (c *Client) WalletWatchAddPost(addrs []types.UnlockHash, unused bool) error

WalletWatchAddPost uses the /wallet/watch endpoint to add a set of addresses to the watch set. The unused flag should be set to true if the addresses have never appeared in the blockchain.

func (*Client) WalletWatchGet

func (c *Client) WalletWatchGet() (wwg api.WalletWatchGET, err error)

WalletWatchGet requests the /wallet/watch endpoint and returns the set of currently watched addresses.

func (*Client) WalletWatchRemovePost

func (c *Client) WalletWatchRemovePost(addrs []types.UnlockHash, unused bool) error

WalletWatchRemovePost uses the /wallet/watch endpoint to remove a set of addresses from the watch set. The unused flag should be set to true if the addresses have never appeared in the blockchain.

type Options

type Options struct {
	// Address is the API address of the satd server.
	Address string

	// Password must match the password of the satd server.
	Password string

	// UserAgent must match the User-Agent required by the satd server. If not
	// set, it defaults to "Sat-Agent".
	UserAgent string

	// CheckRedirect is an optional handler to be called if the request
	// receives a redirect status code.
	// For more see https://golang.org/pkg/net/http/#Client
	CheckRedirect func(req *http.Request, via []*http.Request) error
}

Options defines the options that are available when creating a client.

func DefaultOptions

func DefaultOptions() (Options, error)

DefaultOptions returns the default options for a client. This includes setting the default satd user agent to "Sat-Agent" and setting the password using SATD_API_PASSWORD environment variable.

Jump to

Keyboard shortcuts

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