rhp

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const (
	ErrorCodeTransport = iota + 1
	ErrorCodeHostError
	ErrorCodeBadRequest
	ErrorCodeDecoding
	ErrorCodePayment
)

Error codes.

View Source
const (
	// LeafSize is the size of one leaf in bytes.
	LeafSize = rhp2.LeafSize

	// LeavesPerSector is the number of leaves in one sector.
	LeavesPerSector = rhp2.LeavesPerSector
)
View Source
const (
	// ProofWindow is the number of blocks a host has to submit a proof after
	// the contract expires.
	ProofWindow = 144 // 24 hours

	// TempSectorDuration is the number of blocks that temp sectors are expected to be stored
	// before being removed
	TempSectorDuration = 144 * 3

	// MaxSectorBatchSize is the number of sector operations that can be batched into a single RPC.
	// For example, the number of sectors appended to a contract within a single RPC append call or the
	// number of sectors removed in a single RPC free call.
	MaxSectorBatchSize = (1 << 40) / (SectorSize)

	// SectorSize is the size of one sector in bytes.
	SectorSize = 1 << 22 // 4 MiB
)

Variables

View Source
var (
	// ErrTokenExpired is returned when an account token has expired.
	ErrTokenExpired = NewRPCError(ErrorCodeBadRequest, "account token expired")
	// ErrPricesExpired is returned when the host's prices have expired.
	ErrPricesExpired = NewRPCError(ErrorCodeBadRequest, "prices expired")
	// ErrInvalidSignature is returned when a signature is invalid.
	ErrInvalidSignature = NewRPCError(ErrorCodeBadRequest, "invalid signature")
	// ErrNotEnoughFunds is returned when a client has insufficient funds to
	// pay for an RPC.
	ErrNotEnoughFunds = NewRPCError(ErrorCodePayment, "not enough funds")
	// ErrHostFundError is returned when the host encounters an error while
	// funding a formation or renewal transaction.
	ErrHostFundError = NewRPCError(ErrorCodeHostError, "host funding error")
	// ErrSectorNotFound is returned when the host is not storing a sector.
	ErrSectorNotFound = NewRPCError(ErrorCodeHostError, "sector not found")
	// ErrNotEnoughStorage is returned when the host does not have enough
	// storage to store a sector.
	ErrNotEnoughStorage = NewRPCError(ErrorCodeHostError, "not enough storage")

	// ErrHostInternalError is a catch-all for any error that occurs on the host
	// side and is not the client's fault.
	ErrHostInternalError = NewRPCError(ErrorCodeHostError, "internal error")
)
View Source
var (
	RPCAccountBalanceID  = types.NewSpecifier("AccountBalance")
	RPCFormContractID    = types.NewSpecifier("FormContract")
	RPCFundAccountsID    = types.NewSpecifier("FundAccounts")
	RPCLatestRevisionID  = types.NewSpecifier("LatestRevision")
	RPCAppendSectorsID   = types.NewSpecifier("AppendSectors")
	RPCFreeSectorsID     = types.NewSpecifier("FreeSectors")
	RPCReadSectorID      = types.NewSpecifier("ReadSector")
	RPCRenewContractID   = types.NewSpecifier("RenewContract")
	RPCRefreshContractID = types.NewSpecifier("RefreshContract")
	RPCSectorRootsID     = types.NewSpecifier("SectorRoots")
	RPCSettingsID        = types.NewSpecifier("Settings")
	RPCWriteSectorID     = types.NewSpecifier("WriteSector")
	RPCVerifySectorID    = types.NewSpecifier("VerifySector")
)

RPC identifiers.

Functions

func BuildAppendProof

func BuildAppendProof(sectorRoots, appended []types.Hash256) ([]types.Hash256, types.Hash256)

BuildAppendProof builds a Merkle proof for appending a set of sectors to a contract.

func BuildFreeSectorsProof

func BuildFreeSectorsProof(sectorRoots []types.Hash256, freed []uint64) (treeHashes, leafHashes []types.Hash256)

BuildFreeSectorsProof builds a Merkle proof for freeing a set of sectors.

func BuildSectorProof

func BuildSectorProof(sector *[SectorSize]byte, start, end uint64) []types.Hash256

BuildSectorProof builds a Merkle proof for a given range within a sector.

func BuildSectorRootsProof

func BuildSectorRootsProof(sectorRoots []types.Hash256, start, end uint64) []types.Hash256

BuildSectorRootsProof builds a Merkle proof for a range of sectors within a contract.

func ContractCost

func ContractCost(cs consensus.State, p HostPrices, fc types.V2FileContract, minerFee types.Currency) (renter, host types.Currency)

ContractCost calculates the cost to the host and renter for forming a contract.

func ErrorCode

func ErrorCode(err error) uint8

ErrorCode returns the code of err. If err is not an RPCError, ErrorCode returns ErrorCodeTransport.

func MetaRoot

func MetaRoot(roots []types.Hash256) types.Hash256

MetaRoot calculates the root of a set of existing Merkle roots.

func MinRenterAllowance

func MinRenterAllowance(hp HostPrices, duration uint64, collateral types.Currency) types.Currency

MinRenterAllowance returns the minimum allowance required to justify the given host collateral.

func NewRPCError

func NewRPCError(code uint8, desc string) error

NewRPCError returns a new RPCError with the given code and description.

func PayWithContract

func PayWithContract(fc *types.V2FileContract, usage Usage) error

PayWithContract modifies a contract to transfer the amount from the renter and deduct collateral from the host. It returns an RPC error if the contract does not have sufficient funds.

func ReadID

func ReadID(r io.Reader) (id types.Specifier, err error)

ReadID reads an RPC ID from the stream.

func ReadRequest

func ReadRequest(r io.Reader, o Object) error

ReadRequest reads a request from the stream.

func ReadResponse

func ReadResponse(r io.Reader, o Object) error

ReadResponse reads a response from the stream into r.

func ReadSector

func ReadSector(r io.Reader) (types.Hash256, *[SectorSize]byte, error)

ReadSector reads a single sector from r and calculates its root.

func ReaderRoot

func ReaderRoot(r io.Reader) (types.Hash256, error)

ReaderRoot returns the Merkle root of the supplied stream, which must contain an integer multiple of leaves.

func RefreshCost

func RefreshCost(cs consensus.State, p HostPrices, r types.V2FileContractRenewal, minerFee types.Currency) (renter, host types.Currency)

RefreshCost calculates the cost to the host and renter for refreshing a contract.

func RenewalCost

func RenewalCost(cs consensus.State, p HostPrices, r types.V2FileContractRenewal, minerFee types.Currency) (renter, host types.Currency)

RenewalCost calculates the cost to the host and renter for renewing a contract.

func SectorRoot

func SectorRoot(sector *[SectorSize]byte) types.Hash256

SectorRoot computes the Merkle root of a sector.

func VerifyAppendSectorsProof

func VerifyAppendSectorsProof(numSectors uint64, subtreeRoots []types.Hash256, appended []types.Hash256, oldRoot, newRoot types.Hash256) bool

VerifyAppendSectorsProof verifies a Merkle proof produced by BuildAppendProof.

func VerifyFreeSectorsProof

func VerifyFreeSectorsProof(treeHashes, leafHashes []types.Hash256, freed []uint64, numSectors uint64, oldRoot types.Hash256, newRoot types.Hash256) bool

VerifyFreeSectorsProof verifies a Merkle proof produced by BuildFreeSectorsProof.

func VerifyLeafProof

func VerifyLeafProof(proof []types.Hash256, leaf [64]byte, leafIndex uint64, root types.Hash256) bool

VerifyLeafProof verifies the Merkle proof for a given leaf within a sector.

func VerifySectorRootsProof

func VerifySectorRootsProof(proof, sectorRoots []types.Hash256, numSectors, start, end uint64, root types.Hash256) bool

VerifySectorRootsProof verifies a Merkle proof produced by BuildSectorRootsProof.

func WriteRequest

func WriteRequest(w io.Writer, id types.Specifier, o Object) error

WriteRequest writes a request to the stream.

func WriteResponse

func WriteResponse(w io.Writer, o Object) error

WriteResponse writes a response to the stream. Note that RPCError implements Object, and may be used as a response to any RPC.

Types

type Account

type Account types.PublicKey

An Account represents an ephemeral balance that can be funded via contract revision and spent to pay for RPCs.

func GenerateAccount

func GenerateAccount() (types.PrivateKey, Account)

GenerateAccount generates a pair of private key and Account from a secure entropy source.

func (*Account) DecodeFrom

func (a *Account) DecodeFrom(d *types.Decoder)

DecodeFrom implements types.DecoderFrom.

func (Account) EncodeTo

func (a Account) EncodeTo(e *types.Encoder)

EncodeTo implements types.EncoderTo.

func (Account) MarshalText

func (a Account) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Account) String

func (a Account) String() string

String implements fmt.Stringer.

func (*Account) Token added in v0.9.0

func (a *Account) Token(renterKey types.PrivateKey, hostKey types.PublicKey) AccountToken

Token returns a signed account token authorizing spending from the account on the host.

func (*Account) UnmarshalText

func (a *Account) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type AccountDeposit

type AccountDeposit struct {
	Account Account        `json:"account"`
	Amount  types.Currency `json:"amount"`
}

An AccountDeposit represents a transfer into an account.

func (*AccountDeposit) DecodeFrom

func (ad *AccountDeposit) DecodeFrom(d *types.Decoder)

DecodeFrom implements types.DecoderFrom.

func (AccountDeposit) EncodeTo

func (ad AccountDeposit) EncodeTo(e *types.Encoder)

EncodeTo implements types.EncoderTo.

type AccountToken

type AccountToken struct {
	HostKey    types.PublicKey `json:"hostKey"`
	Account    Account         `json:"account"`
	ValidUntil time.Time       `json:"validUntil"`
	Signature  types.Signature `json:"signature"`
}

An AccountToken authorizes an account action.

func (*AccountToken) SigHash

func (at *AccountToken) SigHash() types.Hash256

SigHash returns the hash of the account token used for signing.

func (AccountToken) Validate

func (at AccountToken) Validate(hostKey types.PublicKey) error

Validate verifies the account token is valid for use. It returns an error if the token has expired or the signature is invalid.

type HostPrices

type HostPrices struct {
	ContractPrice   types.Currency `json:"contractPrice"`
	Collateral      types.Currency `json:"collateral"`
	StoragePrice    types.Currency `json:"storagePrice"`
	IngressPrice    types.Currency `json:"ingressPrice"`
	EgressPrice     types.Currency `json:"egressPrice"`
	FreeSectorPrice types.Currency `json:"freeSectorPrice"`
	TipHeight       uint64         `json:"tipHeight"`
	ValidUntil      time.Time      `json:"validUntil"`

	// covers above fields
	Signature types.Signature `json:"signature"`
}

HostPrices specify a time-bound set of parameters used to calculate the cost of various RPCs.

func (*HostPrices) DecodeFrom

func (hp *HostPrices) DecodeFrom(d *types.Decoder)

DecodeFrom implements types.DecoderFrom.

func (HostPrices) EncodeTo

func (hp HostPrices) EncodeTo(e *types.Encoder)

EncodeTo implements types.EncoderTo.

func (HostPrices) RPCAppendSectorsCost

func (hp HostPrices) RPCAppendSectorsCost(sectors, duration uint64) Usage

RPCAppendSectorsCost returns the cost of appending sectors to a contract. The duration parameter is the number of blocks until the contract's expiration height.

func (HostPrices) RPCFreeSectorsCost

func (hp HostPrices) RPCFreeSectorsCost(sectors int) Usage

RPCFreeSectorsCost returns the cost of removing sectors from a contract.

func (HostPrices) RPCReadSectorCost

func (hp HostPrices) RPCReadSectorCost(length uint64) Usage

RPCReadSectorCost returns the cost of reading a sector of the given length.

func (HostPrices) RPCSectorRootsCost

func (hp HostPrices) RPCSectorRootsCost(length uint64) Usage

RPCSectorRootsCost returns the cost of fetching sector roots for the given length.

func (HostPrices) RPCVerifySectorCost

func (hp HostPrices) RPCVerifySectorCost() Usage

RPCVerifySectorCost returns the cost of building a proof for the specified sector.

func (HostPrices) RPCWriteSectorCost

func (hp HostPrices) RPCWriteSectorCost(sectorLength uint64) Usage

RPCWriteSectorCost returns the cost of executing the WriteSector RPC with the given sector length.

func (HostPrices) SigHash

func (hp HostPrices) SigHash() types.Hash256

SigHash returns the hash of the host settings used for signing.

func (*HostPrices) Validate

func (hp *HostPrices) Validate(pk types.PublicKey) error

Validate checks the host prices for validity. It returns an error if the prices have expired or the signature is invalid.

type HostSettings

type HostSettings struct {
	ProtocolVersion     [3]uint8       `json:"protocolVersion"`
	Release             string         `json:"release"`
	WalletAddress       types.Address  `json:"walletAddress"`
	AcceptingContracts  bool           `json:"acceptingContracts"`
	MaxCollateral       types.Currency `json:"maxCollateral"`
	MaxContractDuration uint64         `json:"maxContractDuration"`
	RemainingStorage    uint64         `json:"remainingStorage"`
	TotalStorage        uint64         `json:"totalStorage"`
	Prices              HostPrices     `json:"prices"`
}

HostSettings specify the settings of a host.

func (*HostSettings) DecodeFrom

func (hs *HostSettings) DecodeFrom(d *types.Decoder)

DecodeFrom implements types.DecoderFrom.

func (HostSettings) EncodeTo

func (hs HostSettings) EncodeTo(e *types.Encoder)

EncodeTo implements types.EncoderTo.

type Object

type Object interface {
	// contains filtered or unexported methods
}

An Object can be sent or received via a Transport.

type RPCAccountBalanceRequest

type RPCAccountBalanceRequest struct {
	Account Account `json:"account"`
}

RPCAccountBalanceRequest implements Object.

type RPCAccountBalanceResponse

type RPCAccountBalanceResponse struct {
	Balance types.Currency `json:"balance"`
}

RPCAccountBalanceResponse implements Object.

type RPCAppendSectorsRequest

type RPCAppendSectorsRequest struct {
	Prices             HostPrices           `json:"prices"`
	Sectors            []types.Hash256      `json:"sectors"`
	ContractID         types.FileContractID `json:"contractID"`
	ChallengeSignature types.Signature      `json:"challengeSignature"`
}

RPCAppendSectorsRequest implements Object.

func (*RPCAppendSectorsRequest) ChallengeSigHash

func (r *RPCAppendSectorsRequest) ChallengeSigHash(revisionNumber uint64) types.Hash256

ChallengeSigHash returns the hash of the challenge signature used for signing.

func (*RPCAppendSectorsRequest) ValidChallengeSignature

func (r *RPCAppendSectorsRequest) ValidChallengeSignature(fc types.V2FileContract) bool

ValidChallengeSignature checks the challenge signature for validity.

func (*RPCAppendSectorsRequest) Validate

func (req *RPCAppendSectorsRequest) Validate(pk types.PublicKey) error

Validate checks that the request is valid

type RPCAppendSectorsResponse

type RPCAppendSectorsResponse struct {
	Accepted      []bool          `json:"accepted"`
	SubtreeRoots  []types.Hash256 `json:"subtreeRoots"`
	NewMerkleRoot types.Hash256   `json:"newMerkleRoot"`
}

RPCAppendSectorsResponse implements Object.

type RPCAppendSectorsSecondResponse

type RPCAppendSectorsSecondResponse struct {
	RenterSignature types.Signature `json:"renterSignature"`
}

RPCAppendSectorsSecondResponse implements Object.

type RPCAppendSectorsThirdResponse

type RPCAppendSectorsThirdResponse struct {
	HostSignature types.Signature `json:"hostSignature"`
}

RPCAppendSectorsThirdResponse implements Object.

type RPCError

type RPCError struct {
	Code        uint8
	Description string
}

An RPCError pairs a human-readable error description with a status code.

func (RPCError) Error

func (e RPCError) Error() string

Error implements error.

type RPCFormContractParams

type RPCFormContractParams struct {
	RenterPublicKey types.PublicKey `json:"renterPublicKey"`
	RenterAddress   types.Address   `json:"renterAddress"`
	Allowance       types.Currency  `json:"allowance"`
	Collateral      types.Currency  `json:"collateral"`
	ProofHeight     uint64          `json:"proofHeight"`
}

RPCFormContractParams includes the contract details required to construct a contract.

type RPCFormContractRequest

type RPCFormContractRequest struct {
	Prices        HostPrices             `json:"prices"`
	Contract      RPCFormContractParams  `json:"contract"`
	MinerFee      types.Currency         `json:"minerFee"`
	Basis         types.ChainIndex       `json:"basis"`
	RenterInputs  []types.SiacoinElement `json:"renterInputs"`
	RenterParents []types.V2Transaction  `json:"renterParents"`
}

RPCFormContractRequest implements Object.

func (*RPCFormContractRequest) Validate

func (req *RPCFormContractRequest) Validate(pk types.PublicKey, tip types.ChainIndex, maxCollateral types.Currency, maxDuration uint64) error

Validate validates a form contract request. Prices are not validated

type RPCFormContractResponse

type RPCFormContractResponse struct {
	HostInputs []types.V2SiacoinInput `json:"hostInputs"`
}

RPCFormContractResponse implements Object.

type RPCFormContractSecondResponse

type RPCFormContractSecondResponse struct {
	RenterContractSignature types.Signature         `json:"renterContractSignature"`
	RenterSatisfiedPolicies []types.SatisfiedPolicy `json:"renterSatisfiedPolicies"`
}

RPCFormContractSecondResponse implements Object.

type RPCFormContractThirdResponse

type RPCFormContractThirdResponse struct {
	Basis          types.ChainIndex      `json:"basis"`
	TransactionSet []types.V2Transaction `json:"transactionSet"`
}

RPCFormContractThirdResponse implements Object.

type RPCFreeSectorsRequest

type RPCFreeSectorsRequest struct {
	ContractID types.FileContractID `json:"contractID"`
	Prices     HostPrices           `json:"prices"`
	Indices    []uint64             `json:"indices"`
	// A ChallengeSignature proves the renter can modify the contract.
	ChallengeSignature types.Signature `json:"challengeSignature"`
}

RPCFreeSectorsRequest implements Object.

func (*RPCFreeSectorsRequest) ChallengeSigHash

func (r *RPCFreeSectorsRequest) ChallengeSigHash(revisionNumber uint64) types.Hash256

ChallengeSigHash returns the hash of the challenge signature used for signing.

func (*RPCFreeSectorsRequest) ValidChallengeSignature

func (r *RPCFreeSectorsRequest) ValidChallengeSignature(fc types.V2FileContract) bool

ValidChallengeSignature checks the challenge signature for validity.

func (*RPCFreeSectorsRequest) Validate

Validate validates a modify sectors request. Signatures are not validated.

type RPCFreeSectorsResponse

type RPCFreeSectorsResponse struct {
	OldSubtreeHashes []types.Hash256 `json:"oldSubtreeHashes"`
	OldLeafHashes    []types.Hash256 `json:"oldLeafHashes"`
	NewMerkleRoot    types.Hash256   `json:"newMerkleRoot"`
}

RPCFreeSectorsResponse implements Object.

type RPCFreeSectorsSecondResponse

type RPCFreeSectorsSecondResponse struct {
	RenterSignature types.Signature `json:"renterSignature"`
}

RPCFreeSectorsSecondResponse implements Object.

type RPCFreeSectorsThirdResponse

type RPCFreeSectorsThirdResponse struct {
	HostSignature types.Signature `json:"hostSignature"`
}

RPCFreeSectorsThirdResponse implements Object.

type RPCFundAccountsRequest

type RPCFundAccountsRequest struct {
	ContractID      types.FileContractID `json:"contractID"`
	Deposits        []AccountDeposit     `json:"deposits"`
	RenterSignature types.Signature      `json:"renterSignature"`
}

RPCFundAccountsRequest implements Object.

type RPCFundAccountsResponse

type RPCFundAccountsResponse struct {
	Balances      []types.Currency `json:"balances"`
	HostSignature types.Signature  `json:"hostSignature"`
}

RPCFundAccountsResponse implements Object.

type RPCLatestRevisionRequest

type RPCLatestRevisionRequest struct {
	ContractID types.FileContractID `json:"contractID"`
}

RPCLatestRevisionRequest implements Object.

type RPCLatestRevisionResponse

type RPCLatestRevisionResponse struct {
	Contract  types.V2FileContract `json:"contract"`
	Revisable bool                 `json:"revisable"`
	Renewed   bool                 `json:"renewed"`
}

RPCLatestRevisionResponse implements Object.

The `Revisable` field indicates whether the host will accept further revisions to the contract. A host will not accept revisions too close to the proof window or revisions on contracts that have already been resolved. The `Renewed` field indicates whether the contract was renewed. If the contract was renewed, the renter can use `FileContractID.V2RenewalID` to get the ID of the new contract.

type RPCReadSectorRequest

type RPCReadSectorRequest struct {
	Prices HostPrices    `json:"prices"`
	Token  AccountToken  `json:"token"`
	Root   types.Hash256 `json:"root"`
	Offset uint64        `json:"offset"`
	Length uint64        `json:"length"`
}

RPCReadSectorRequest implements Object.

func (*RPCReadSectorRequest) Validate

func (req *RPCReadSectorRequest) Validate(hostKey types.PublicKey) error

Validate validates a read sector request.

type RPCReadSectorResponse

type RPCReadSectorResponse struct {
	Proof      []types.Hash256 `json:"proof"`
	DataLength uint64          `json:"dataLength"`
}

RPCReadSectorResponse implements Object.

type RPCRefreshContractParams

type RPCRefreshContractParams struct {
	ContractID types.FileContractID `json:"contractID"`
	Allowance  types.Currency       `json:"allowance"`
	Collateral types.Currency       `json:"collateral"`
}

RPCRefreshContractParams includes the contract details required to refresh a contract.

type RPCRefreshContractRequest

type RPCRefreshContractRequest struct {
	Prices             HostPrices               `json:"prices"`
	Refresh            RPCRefreshContractParams `json:"refresh"`
	MinerFee           types.Currency           `json:"minerFee"`
	Basis              types.ChainIndex         `json:"basis"`
	RenterInputs       []types.SiacoinElement   `json:"renterInputs"`
	RenterParents      []types.V2Transaction    `json:"renterParents"`
	ChallengeSignature types.Signature          `json:"challengeSignature"`
}

RPCRefreshContractRequest implements Object.

func (*RPCRefreshContractRequest) ChallengeSigHash

func (r *RPCRefreshContractRequest) ChallengeSigHash(lastRevisionNumber uint64) types.Hash256

ChallengeSigHash returns the challenge sighash used for proving ownership of a contract for the renew RPC.

func (*RPCRefreshContractRequest) ValidChallengeSignature

func (r *RPCRefreshContractRequest) ValidChallengeSignature(existing types.V2FileContract) bool

ValidChallengeSignature checks the challenge signature for validity.

func (*RPCRefreshContractRequest) Validate

func (req *RPCRefreshContractRequest) Validate(pk types.PublicKey, existingTotalCollateral types.Currency, expirationHeight uint64, maxCollateral types.Currency) error

Validate validates a refresh contract request. Prices are not validated

type RPCRefreshContractResponse

type RPCRefreshContractResponse struct {
	HostInputs []types.V2SiacoinInput `json:"hostInputs"`
}

RPCRefreshContractResponse implements Object.

type RPCRefreshContractSecondResponse

type RPCRefreshContractSecondResponse struct {
	RenterRenewalSignature  types.Signature         `json:"renterRenewalSignature"`
	RenterContractSignature types.Signature         `json:"renterContractSignature"`
	RenterSatisfiedPolicies []types.SatisfiedPolicy `json:"renterSatisfiedPolicies"`
}

RPCRefreshContractSecondResponse implements Object.

type RPCRefreshContractThirdResponse

type RPCRefreshContractThirdResponse struct {
	Basis          types.ChainIndex      `json:"basis"`
	TransactionSet []types.V2Transaction `json:"transactionSet"`
}

RPCRefreshContractThirdResponse implements Object.

type RPCRenewContractParams

type RPCRenewContractParams struct {
	ContractID  types.FileContractID `json:"contractID"`
	Allowance   types.Currency       `json:"allowance"`
	Collateral  types.Currency       `json:"collateral"`
	ProofHeight uint64               `json:"proofHeight"`
}

RPCRenewContractParams includes the contract details required to create a renewal.

type RPCRenewContractRequest

type RPCRenewContractRequest struct {
	Prices             HostPrices             `json:"prices"`
	Renewal            RPCRenewContractParams `json:"renewal"`
	MinerFee           types.Currency         `json:"minerFee"`
	Basis              types.ChainIndex       `json:"basis"`
	RenterInputs       []types.SiacoinElement `json:"renterInputs"`
	RenterParents      []types.V2Transaction  `json:"renterParents"`
	ChallengeSignature types.Signature        `json:"challengeSignature"`
}

RPCRenewContractRequest implements Object.

func (*RPCRenewContractRequest) ChallengeSigHash

func (r *RPCRenewContractRequest) ChallengeSigHash(lastRevisionNumber uint64) types.Hash256

ChallengeSigHash returns the challenge sighash used for proving ownership of a contract for the renew RPC.

func (*RPCRenewContractRequest) ValidChallengeSignature

func (r *RPCRenewContractRequest) ValidChallengeSignature(existing types.V2FileContract) bool

ValidChallengeSignature checks the challenge signature for validity.

func (*RPCRenewContractRequest) Validate

func (req *RPCRenewContractRequest) Validate(pk types.PublicKey, tip types.ChainIndex, existingSize uint64, existingProofHeight uint64, maxCollateral types.Currency, maxDuration uint64) error

Validate validates a renew contract request. Prices are not validated

type RPCRenewContractResponse

type RPCRenewContractResponse struct {
	HostInputs []types.V2SiacoinInput `json:"hostInputs"`
}

RPCRenewContractResponse implements Object.

type RPCRenewContractSecondResponse

type RPCRenewContractSecondResponse struct {
	RenterRenewalSignature  types.Signature         `json:"renterRenewalSignature"`
	RenterContractSignature types.Signature         `json:"renterContractSignature"`
	RenterSatisfiedPolicies []types.SatisfiedPolicy `json:"renterSatisfiedPolicies"`
}

RPCRenewContractSecondResponse implements Object.

type RPCRenewContractThirdResponse

type RPCRenewContractThirdResponse struct {
	Basis          types.ChainIndex      `json:"basis"`
	TransactionSet []types.V2Transaction `json:"transactionSet"`
}

RPCRenewContractThirdResponse implements Object.

type RPCSectorRootsRequest

type RPCSectorRootsRequest struct {
	Prices          HostPrices           `json:"prices"`
	ContractID      types.FileContractID `json:"contractID"`
	RenterSignature types.Signature      `json:"renterSignature"`
	Offset          uint64               `json:"offset"`
	Length          uint64               `json:"length"`
}

RPCSectorRootsRequest implements Object.

func (*RPCSectorRootsRequest) Validate

Validate validates a sector roots request. Signatures are not validated.

type RPCSectorRootsResponse

type RPCSectorRootsResponse struct {
	Proof         []types.Hash256 `json:"proof"`
	Roots         []types.Hash256 `json:"roots"`
	HostSignature types.Signature `json:"hostSignature"`
}

RPCSectorRootsResponse implements Object.

type RPCSettingsRequest

type RPCSettingsRequest struct{}

RPCSettingsRequest implements Object.

type RPCSettingsResponse

type RPCSettingsResponse struct {
	Settings HostSettings `json:"settings"`
}

RPCSettingsResponse implements Object.

type RPCVerifySectorRequest

type RPCVerifySectorRequest struct {
	Prices    HostPrices    `json:"prices"`
	Token     AccountToken  `json:"token"`
	Root      types.Hash256 `json:"root"`
	LeafIndex uint64        `json:"leafIndex"`
}

RPCVerifySectorRequest implements Object.

func (*RPCVerifySectorRequest) Validate

func (req *RPCVerifySectorRequest) Validate(hostKey types.PublicKey) error

Validate checks that the request is valid

type RPCVerifySectorResponse

type RPCVerifySectorResponse struct {
	Proof []types.Hash256 `json:"proof"`
	Leaf  [64]byte        `json:"leaf"`
}

RPCVerifySectorResponse implements Object.

type RPCWriteSectorRequest

type RPCWriteSectorRequest struct {
	Prices     HostPrices   `json:"prices"`
	Token      AccountToken `json:"token"`
	DataLength uint64       `json:"dataLength"` // extended to SectorSize by host
}

RPCWriteSectorRequest implements Object.

func (*RPCWriteSectorRequest) Validate

func (req *RPCWriteSectorRequest) Validate(hostKey types.PublicKey) error

Validate validates a write sector request.

type RPCWriteSectorResponse

type RPCWriteSectorResponse struct {
	Root types.Hash256 `json:"root"`
}

RPCWriteSectorResponse implements Object.

type RangeProofVerifier

type RangeProofVerifier = rhp2.RangeProofVerifier

A RangeProofVerifier allows range proofs to be verified in streaming fashion.

func NewRangeProofVerifier

func NewRangeProofVerifier(start, end uint64) *RangeProofVerifier

NewRangeProofVerifier returns a RangeProofVerifier for the sector range [start, end).

type Usage

type Usage struct {
	RPC              types.Currency `json:"rpc"`
	Storage          types.Currency `json:"storage"`
	Egress           types.Currency `json:"egress"`
	Ingress          types.Currency `json:"ingress"`
	AccountFunding   types.Currency `json:"accountFunding"`
	RiskedCollateral types.Currency `json:"collateral"`
}

Usage contains the cost breakdown and collateral of executing an RPC.

func NewContract

func NewContract(p HostPrices, cp RPCFormContractParams, hostKey types.PublicKey, hostAddress types.Address) (types.V2FileContract, Usage)

NewContract creates a new file contract with the given settings.

func RefreshContract

RefreshContract creates a contract renewal for the refresh RPC.

func RenewContract

RenewContract creates a contract renewal for the renew RPC

func ReviseForAppendSectors

func ReviseForAppendSectors(fc types.V2FileContract, prices HostPrices, root types.Hash256, appended uint64) (types.V2FileContract, Usage, error)

ReviseForAppendSectors creates a contract revision for the append sectors RPC

func ReviseForFreeSectors

func ReviseForFreeSectors(fc types.V2FileContract, prices HostPrices, newRoot types.Hash256, deletions int) (types.V2FileContract, Usage, error)

ReviseForFreeSectors creates a contract revision for the free sectors RPC

func ReviseForFundAccounts

func ReviseForFundAccounts(fc types.V2FileContract, amount types.Currency) (types.V2FileContract, Usage, error)

ReviseForFundAccounts creates a contract revision for the fund accounts RPC

func ReviseForSectorRoots

func ReviseForSectorRoots(fc types.V2FileContract, prices HostPrices, numRoots uint64) (types.V2FileContract, Usage, error)

ReviseForSectorRoots creates a contract revision for the sector roots RPC

func (Usage) Add

func (u Usage) Add(b Usage) Usage

Add returns the sum of two Usages.

func (Usage) HostRiskedCollateral

func (u Usage) HostRiskedCollateral() types.Currency

HostRiskedCollateral returns the amount of collateral the host must risk

func (Usage) RenterCost

func (u Usage) RenterCost() types.Currency

RenterCost returns the total cost of executing the RPC.

Jump to

Keyboard shortcuts

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