rhp

package
v1.1.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFailedToCreatePayment is returned when the client failed to pay using a contract.
	ErrFailedToCreatePayment = errors.New("failed to create contract payment")

	// errDialTransport is returned when the worker could not dial the host.
	ErrDialTransport = errors.New("could not dial transport")

	// errBalanceInsufficient occurs when a withdrawal failed because the
	// account balance was insufficient.
	ErrBalanceInsufficient = errors.New("ephemeral account balance was insufficient")

	// ErrMaxRevisionReached occurs when trying to revise a contract that has
	// already reached the highest possible revision number. Usually happens
	// when trying to use a renewed contract.
	ErrMaxRevisionReached = errors.New("contract has reached the maximum number of revisions")

	// ErrSectorNotFound is returned by a host when it can't find the requested
	// sector.
	ErrSectorNotFound = errors.New("sector not found")
)

Functions

func IsBalanceInsufficient

func IsBalanceInsufficient(err error) bool

func IsBalanceMaxExceeded

func IsBalanceMaxExceeded(err error) bool

func IsClosedStream

func IsClosedStream(err error) bool

func IsErrHost

func IsErrHost(err error) bool

IsErrHost indicates whether an error was returned by a host as part of an RPC.

func IsInsufficientFunds

func IsInsufficientFunds(err error) bool

func IsPriceTableExpired

func IsPriceTableExpired(err error) bool

func IsPriceTableGouging

func IsPriceTableGouging(err error) bool

func IsPriceTableNotFound

func IsPriceTableNotFound(err error) bool

func IsSectorNotFound

func IsSectorNotFound(err error) bool

func IsWithdrawalExpired

func IsWithdrawalExpired(err error) bool

func IsWithdrawalsInactive

func IsWithdrawalsInactive(err error) bool

Types

type Client

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

func New

func New(dialer Dialer, logger *zap.Logger) *Client

func (*Client) AppendSector

func (c *Client) AppendSector(ctx context.Context, sectorRoot types.Hash256, sector *[rhpv2.SectorSize]byte, rev *types.FileContractRevision, hk types.PublicKey, siamuxAddr string, accID rhpv3.Account, pt rhpv3.HostPriceTable, rk types.PrivateKey) (types.Currency, error)

func (*Client) FundAccount

func (c *Client) FundAccount(ctx context.Context, rev *types.FileContractRevision, hk types.PublicKey, siamuxAddr string, amount types.Currency, accID rhpv3.Account, pt rhpv3.HostPriceTable, renterKey types.PrivateKey) error

func (*Client) PriceTable

func (c *Client) PriceTable(ctx context.Context, hk types.PublicKey, siamuxAddr string, paymentFn PriceTablePaymentFunc) (pt api.HostPriceTable, err error)

func (*Client) PriceTableUnpaid

func (c *Client) PriceTableUnpaid(ctx context.Context, hk types.PublicKey, siamuxAddr string) (pt api.HostPriceTable, err error)

func (*Client) ReadSector

func (c *Client) ReadSector(ctx context.Context, offset, length uint32, root types.Hash256, w io.Writer, hk types.PublicKey, siamuxAddr string, accID rhpv3.Account, accKey types.PrivateKey, pt rhpv3.HostPriceTable) (types.Currency, error)

func (*Client) Renew

func (c *Client) Renew(ctx context.Context, rrr api.RHPRenewRequest, gougingChecker gouging.Checker, renewer PrepareRenewFunc, signer SignFunc, rev types.FileContractRevision, renterKey types.PrivateKey) (newRev rhpv2.ContractRevision, txnSet []types.Transaction, contractPrice, fundAmount types.Currency, err error)

func (*Client) Revision

func (c *Client) Revision(ctx context.Context, fcid types.FileContractID, hk types.PublicKey, siamuxAddr string) (rev types.FileContractRevision, err error)

func (*Client) SyncAccount

func (c *Client) SyncAccount(ctx context.Context, rev *types.FileContractRevision, hk types.PublicKey, siamuxAddr string, accID rhpv3.Account, pt rhpv3.SettingsID, rk types.PrivateKey) (balance types.Currency, _ error)

type Dialer

type Dialer interface {
	Dial(ctx context.Context, hk types.PublicKey, address string) (net.Conn, error)
}

type PrepareRenewFunc

type PrepareRenewFunc func(ctx context.Context, revision types.FileContractRevision, hostAddress, renterAddress types.Address, renterKey types.PrivateKey, renterFunds, minNewCollateral, maxFundAmount types.Currency, pt rhpv3.HostPriceTable, endHeight, windowSize, expectedStorage uint64) (resp api.WalletPrepareRenewResponse, discard func(context.Context, types.Transaction, *error), err error)

type PriceTablePaymentFunc

type PriceTablePaymentFunc func(pt rhpv3.HostPriceTable) (rhpv3.PaymentMethod, error)

PriceTablePaymentFunc is a function that can be passed in to RPCPriceTable. It is called after the price table is received from the host and supposed to create a payment for that table and return it. It can also be used to perform gouging checks before paying for the table.

func PreparePriceTableAccountPayment

func PreparePriceTableAccountPayment(accKey types.PrivateKey) PriceTablePaymentFunc

PreparePriceTableAccountPayment prepare a payment function to pay for a price table from the given host using the provided revision.

NOTE: This is the preferred way of paying for a price table since it is faster and doesn't require locking a contract.

func PreparePriceTableContractPayment

func PreparePriceTableContractPayment(rev *types.FileContractRevision, refundAccID rhpv3.Account, renterKey types.PrivateKey) PriceTablePaymentFunc

PreparePriceTableContractPayment prepare a payment function to pay for a price table from the given host using the provided revision.

NOTE: This way of paying for a price table should only be used if payment by EA is not possible or if we already need a contract revision anyway. e.g. funding an EA.

type SignFunc

type SignFunc func(ctx context.Context, txn *types.Transaction, toSign []types.Hash256, cf types.CoveredFields) error

Jump to

Keyboard shortcuts

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