Documentation ¶
Index ¶
- Constants
- Variables
- func RPCAccountBalance(ctx context.Context, t TransportClient, account rhp4.Account) (types.Currency, error)
- func RPCLatestRevision(ctx context.Context, t TransportClient, contractID types.FileContractID) (resp rhp4.RPCLatestRevisionResponse, err error)
- func RPCSettings(ctx context.Context, t TransportClient) (rhp4.HostSettings, error)
- type AccountBalance
- type ChainManager
- type ContractRevision
- type ContractSigner
- type Contractor
- type FormContractSigner
- type RPCAppendSectorsResult
- type RPCFormContractResult
- type RPCFreeSectorsResult
- type RPCFundAccountResult
- type RPCReadSectorResult
- type RPCRefreshContractResult
- type RPCRenewContractResult
- type RPCSectorRootsResult
- type RPCVerifySectorResult
- type RPCWriteSectorResult
- type ReaderLen
- type RevisionState
- type Sectors
- type Server
- type ServerOption
- type Settings
- type Syncer
- type TransactionFunder
- type TransactionInputSigner
- type TransactionSet
- type TransportClient
- type TransportMux
- type TxPool
- type Wallet
Constants ¶
const (
ProtocolTCPSiaMux chain.Protocol = "siamux"
)
A Protocol is a string identifying a network protocol that a host may be reached on.
Variables ¶
var ( // ErrInvalidRoot is returned when RPCWrite returns a sector root that does // not match the expected value. ErrInvalidRoot = errors.New("invalid root") // ErrInvalidProof is returned when an RPC returns an invalid Merkle proof. ErrInvalidProof = errors.New("invalid proof") )
Functions ¶
func RPCAccountBalance ¶
func RPCAccountBalance(ctx context.Context, t TransportClient, account rhp4.Account) (types.Currency, error)
RPCAccountBalance returns the balance of an account.
func RPCLatestRevision ¶
func RPCLatestRevision(ctx context.Context, t TransportClient, contractID types.FileContractID) (resp rhp4.RPCLatestRevisionResponse, err error)
RPCLatestRevision returns the latest revision of a contract.
func RPCSettings ¶
func RPCSettings(ctx context.Context, t TransportClient) (rhp4.HostSettings, error)
RPCSettings returns the current settings of the host.
Types ¶
type AccountBalance ¶
type AccountBalance struct { Account rhp4.Account `json:"account"` Balance types.Currency `json:"balance"` }
An AccountBalance pairs an account with its current balance.
type ChainManager ¶
type ChainManager interface { Tip() types.ChainIndex TipState() consensus.State // V2TransactionSet returns the full transaction set and basis necessary for // broadcasting a transaction. If the provided basis does not match the current // tip, the transaction will be updated. The transaction set includes the parents // and the transaction itself in an order valid for broadcasting. V2TransactionSet(basis types.ChainIndex, txn types.V2Transaction) (types.ChainIndex, []types.V2Transaction, error) // AddV2PoolTransactions validates a transaction set and adds it to the // transaction pool. AddV2PoolTransactions(types.ChainIndex, []types.V2Transaction) (known bool, err error) // RecommendedFee returns the recommended fee per weight RecommendedFee() types.Currency // UpdateV2TransactionSet updates the basis of a transaction set from "from" to "to". // If from and to are equal, the transaction set is returned as-is. // Any transactions that were confirmed are removed from the set. // Any ephemeral state elements that were created by an update are updated. // // If it is undesirable to modify the transaction set, deep-copy it // before calling this method. UpdateV2TransactionSet(txns []types.V2Transaction, from, to types.ChainIndex) ([]types.V2Transaction, error) }
ChainManager defines the interface required by the contract manager to interact with the consensus set.
type ContractRevision ¶
type ContractRevision struct { ID types.FileContractID `json:"id"` Revision types.V2FileContract `json:"revision"` }
ContractRevision pairs a contract ID with a revision.
type ContractSigner ¶
A ContractSigner is a minimal interface for contract signing.
type Contractor ¶
type Contractor interface { // LockV2Contract locks a contract and returns its current state. // The returned function must be called to release the lock. LockV2Contract(types.FileContractID) (RevisionState, func(), error) // AddV2Contract adds a new contract to the host. AddV2Contract(TransactionSet, rhp4.Usage) error // RenewV2Contract finalizes an existing contract and adds its renewal. RenewV2Contract(TransactionSet, rhp4.Usage) error // ReviseV2Contract atomically revises a contract and updates its sector // roots and usage. ReviseV2Contract(contractID types.FileContractID, revision types.V2FileContract, roots []types.Hash256, usage rhp4.Usage) error // V2FileContractElement returns the contract state element for the given // contract ID. V2FileContractElement(types.FileContractID) (types.ChainIndex, types.V2FileContractElement, error) // AccountBalance returns the balance of an account. AccountBalance(rhp4.Account) (types.Currency, error) // CreditAccountsWithContract atomically revises a contract and credits the account. CreditAccountsWithContract([]rhp4.AccountDeposit, types.FileContractID, types.V2FileContract, rhp4.Usage) ([]types.Currency, error) // DebitAccount debits an account. DebitAccount(rhp4.Account, rhp4.Usage) error }
Contractor is an interface for managing a host's contracts.
type FormContractSigner ¶
type FormContractSigner interface { ContractSigner TransactionInputSigner TransactionFunder }
FormContractSigner is the minimal interface required to fund and sign a contract formation transaction.
type RPCAppendSectorsResult ¶ added in v0.6.0
type RPCAppendSectorsResult struct { Revision types.V2FileContract `json:"revision"` Usage rhp4.Usage `json:"usage"` Sectors []types.Hash256 `json:"sectors"` }
RPCAppendSectorsResult contains the result of executing the append sectors RPC.
func RPCAppendSectors ¶ added in v0.6.0
func RPCAppendSectors(ctx context.Context, t TransportClient, cs consensus.State, prices rhp4.HostPrices, sk types.PrivateKey, contract ContractRevision, roots []types.Hash256) (RPCAppendSectorsResult, error)
RPCAppendSectors appends sectors a host is storing to a contract.
type RPCFormContractResult ¶
type RPCFormContractResult struct { Contract ContractRevision `json:"contract"` FormationSet TransactionSet `json:"formationSet"` Cost types.Currency `json:"cost"` Usage rhp4.Usage `json:"usage"` }
RPCFormContractResult contains the result of executing the form contract RPC.
func RPCFormContract ¶
func RPCFormContract(ctx context.Context, t TransportClient, tp TxPool, signer FormContractSigner, cs consensus.State, p rhp4.HostPrices, hostKey types.PublicKey, hostAddress types.Address, params rhp4.RPCFormContractParams) (RPCFormContractResult, error)
RPCFormContract forms a contract with a host
type RPCFreeSectorsResult ¶ added in v0.6.0
type RPCFreeSectorsResult struct { Revision types.V2FileContract `json:"revision"` Usage rhp4.Usage `json:"usage"` }
RPCFreeSectorsResult contains the result of executing the remove sectors RPC.
func RPCFreeSectors ¶ added in v0.6.0
func RPCFreeSectors(ctx context.Context, t TransportClient, cs consensus.State, prices rhp4.HostPrices, sk types.PrivateKey, contract ContractRevision, indices []uint64) (RPCFreeSectorsResult, error)
RPCFreeSectors removes sectors from a contract.
type RPCFundAccountResult ¶
type RPCFundAccountResult struct { Revision types.V2FileContract `json:"revision"` Balances []AccountBalance `json:"balances"` Usage rhp4.Usage `json:"usage"` }
RPCFundAccountResult contains the result of executing the fund accounts RPC.
func RPCFundAccounts ¶
func RPCFundAccounts(ctx context.Context, t TransportClient, cs consensus.State, signer ContractSigner, contract ContractRevision, deposits []rhp4.AccountDeposit) (RPCFundAccountResult, error)
RPCFundAccounts funds accounts on the host.
type RPCReadSectorResult ¶
RPCReadSectorResult contains the result of executing the read sector RPC.
func RPCReadSector ¶
func RPCReadSector(ctx context.Context, t TransportClient, prices rhp4.HostPrices, token rhp4.AccountToken, w io.Writer, root types.Hash256, offset, length uint64) (RPCReadSectorResult, error)
RPCReadSector reads a sector from the host.
type RPCRefreshContractResult ¶ added in v0.6.0
type RPCRefreshContractResult struct { Contract ContractRevision `json:"contract"` RenewalSet TransactionSet `json:"renewalSet"` Cost types.Currency `json:"cost"` Usage rhp4.Usage `json:"usage"` }
RPCRefreshContractResult contains the result of executing the refresh contract RPC.
func RPCRefreshContract ¶ added in v0.6.0
func RPCRefreshContract(ctx context.Context, t TransportClient, tp TxPool, signer FormContractSigner, cs consensus.State, p rhp4.HostPrices, existing types.V2FileContract, params rhp4.RPCRefreshContractParams) (RPCRefreshContractResult, error)
RPCRefreshContract refreshes a contract with a host.
type RPCRenewContractResult ¶
type RPCRenewContractResult struct { Contract ContractRevision `json:"contract"` RenewalSet TransactionSet `json:"renewalSet"` Cost types.Currency `json:"cost"` Usage rhp4.Usage `json:"usage"` }
RPCRenewContractResult contains the result of executing the renew contract RPC.
func RPCRenewContract ¶
func RPCRenewContract(ctx context.Context, t TransportClient, tp TxPool, signer FormContractSigner, cs consensus.State, p rhp4.HostPrices, existing types.V2FileContract, params rhp4.RPCRenewContractParams) (RPCRenewContractResult, error)
RPCRenewContract renews a contract with a host.
type RPCSectorRootsResult ¶
type RPCSectorRootsResult struct { Revision types.V2FileContract `json:"revision"` Roots []types.Hash256 `json:"roots"` Usage rhp4.Usage `json:"usage"` }
RPCSectorRootsResult contains the result of executing the sector roots RPC.
func RPCSectorRoots ¶
func RPCSectorRoots(ctx context.Context, t TransportClient, cs consensus.State, prices rhp4.HostPrices, signer ContractSigner, contract ContractRevision, offset, length uint64) (RPCSectorRootsResult, error)
RPCSectorRoots returns the sector roots for a contract.
type RPCVerifySectorResult ¶
RPCVerifySectorResult contains the result of executing the verify sector RPC.
func RPCVerifySector ¶
func RPCVerifySector(ctx context.Context, t TransportClient, prices rhp4.HostPrices, token rhp4.AccountToken, root types.Hash256) (RPCVerifySectorResult, error)
RPCVerifySector verifies that the host is properly storing a sector
type RPCWriteSectorResult ¶
type RPCWriteSectorResult struct { Root types.Hash256 `json:"root"` Usage rhp4.Usage `json:"usage"` }
RPCWriteSectorResult contains the result of executing the write sector RPC.
func RPCWriteSector ¶
func RPCWriteSector(ctx context.Context, t TransportClient, prices rhp4.HostPrices, token rhp4.AccountToken, data io.Reader, length uint64) (RPCWriteSectorResult, error)
RPCWriteSector writes a sector to the host.
type RevisionState ¶
type RevisionState struct { Revision types.V2FileContract Renewed bool Revisable bool Roots []types.Hash256 }
A RevisionState pairs a contract revision with its sector roots.
type Sectors ¶
type Sectors interface { // HasSector returns true if the sector is stored. HasSector(root types.Hash256) (bool, error) // ReadSector retrieves a sector by its root ReadSector(root types.Hash256) (*[rhp4.SectorSize]byte, error) // StoreSector writes a sector to disk StoreSector(root types.Hash256, data *[rhp4.SectorSize]byte, expiration uint64) error }
A Sectors is an interface for reading and writing sectors.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
A Server handles incoming RHP4 RPC.
func NewServer ¶
func NewServer(pk types.PrivateKey, cm ChainManager, syncer Syncer, contracts Contractor, wallet Wallet, settings Settings, sectors Sectors, opts ...ServerOption) *Server
NewServer creates a new RHP4 server
func (*Server) HostKey ¶
func (s *Server) HostKey() types.PrivateKey
HostKey returns the host's private key
type ServerOption ¶
type ServerOption func(*Server)
An ServerOption sets an option on a Server.
func WithPriceTableValidity ¶
func WithPriceTableValidity(validity time.Duration) ServerOption
WithPriceTableValidity sets the duration for which a price table is valid.
type Settings ¶
type Settings interface {
RHP4Settings() rhp4.HostSettings
}
Settings reports the host's current settings.
type Syncer ¶
type Syncer interface { // BroadcastV2TransactionSet broadcasts a transaction set to the network. BroadcastV2TransactionSet(types.ChainIndex, []types.V2Transaction) }
A Syncer broadcasts transactions to its peers.
type TransactionFunder ¶
type TransactionFunder interface { FundV2Transaction(txn *types.V2Transaction, amount types.Currency) (types.ChainIndex, []int, error) ReleaseInputs([]types.V2Transaction) }
A TransactionFunder is an interface for funding v2 transactions.
type TransactionInputSigner ¶
type TransactionInputSigner interface {
SignV2Inputs(*types.V2Transaction, []int)
}
A TransactionInputSigner is an interface for signing v2 transactions using a single private key.
type TransactionSet ¶
type TransactionSet struct { Basis types.ChainIndex `json:"basis"` Transactions []types.V2Transaction `json:"transactions"` }
A TransactionSet is a set of transactions that are valid as of the provided chain index.
type TransportClient ¶
type TransportClient interface { DialStream(context.Context) net.Conn FrameSize() int PeerKey() types.PublicKey Close() error }
A TransportClient is a generic multiplexer for outgoing streams.
func DialSiaMux ¶
DialSiaMux creates a new TransportClient using the SiaMux multiplexer.
func UpgradeConn ¶ added in v0.6.0
func UpgradeConn(ctx context.Context, conn net.Conn, peerKey types.PublicKey) (TransportClient, error)
UpgradeConn upgrades an existing connection to use the SiaMux multiplexer.
type TransportMux ¶
A TransportMux is a generic multiplexer for incoming streams.
type TxPool ¶
type TxPool interface { // V2TransactionSet returns the full transaction set and basis necessary // for broadcasting a transaction. The transaction will be updated if // the provided basis does not match the current tip. The transaction set // includes the parents and the transaction itself in an order valid // for broadcasting. V2TransactionSet(basis types.ChainIndex, txn types.V2Transaction) (types.ChainIndex, []types.V2Transaction, error) // RecommendedFee returns the recommended fee per byte for a transaction. RecommendedFee() types.Currency }
A TxPool manages the transaction pool.
type Wallet ¶
type Wallet interface { // Address returns the host's address Address() types.Address // FundV2Transaction funds a transaction with the specified amount of // Siacoins. If useUnconfirmed is true, the transaction may spend // unconfirmed outputs. The outputs spent by the transaction are locked // until they are released by ReleaseInputs. FundV2Transaction(txn *types.V2Transaction, amount types.Currency, useUnconfirmed bool) (types.ChainIndex, []int, error) // SignV2Inputs signs the inputs of a transaction. SignV2Inputs(txn *types.V2Transaction, toSign []int) // ReleaseInputs releases the inputs of a transaction. It should only // be used if the transaction is not going to be broadcast ReleaseInputs(txns []types.Transaction, v2txns []types.V2Transaction) }
A Wallet manages Siacoins and funds transactions.