gitlab.com/jokerrs1/Sia@v1.3.2/modules/renter/proto/proto.go (about)

     1  package proto
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/NebulousLabs/Sia/crypto"
     7  	"github.com/NebulousLabs/Sia/modules"
     8  	"github.com/NebulousLabs/Sia/types"
     9  )
    10  
    11  // Dependencies.
    12  type (
    13  	transactionBuilder interface {
    14  		AddFileContract(types.FileContract) uint64
    15  		AddMinerFee(types.Currency) uint64
    16  		AddParents([]types.Transaction)
    17  		AddSiacoinInput(types.SiacoinInput) uint64
    18  		AddSiacoinOutput(types.SiacoinOutput) uint64
    19  		AddTransactionSignature(types.TransactionSignature) uint64
    20  		FundSiacoins(types.Currency) error
    21  		Sign(bool) ([]types.Transaction, error)
    22  		View() (types.Transaction, []types.Transaction)
    23  		ViewAdded() (parents, coins, funds, signatures []int)
    24  	}
    25  
    26  	transactionPool interface {
    27  		AcceptTransactionSet([]types.Transaction) error
    28  		FeeEstimation() (min types.Currency, max types.Currency)
    29  	}
    30  
    31  	hostDB interface {
    32  		IncrementSuccessfulInteractions(key types.SiaPublicKey)
    33  		IncrementFailedInteractions(key types.SiaPublicKey)
    34  	}
    35  )
    36  
    37  // ContractParams are supplied as an argument to FormContract.
    38  type ContractParams struct {
    39  	Host          modules.HostDBEntry
    40  	Funding       types.Currency
    41  	StartHeight   types.BlockHeight
    42  	EndHeight     types.BlockHeight
    43  	RefundAddress types.UnlockHash
    44  	// TODO: add optional keypair
    45  }
    46  
    47  // A revisionSaver is called just before we send our revision signature to the host; this
    48  // allows the revision and Merkle roots to be reloaded later if we desync from the host.
    49  type revisionSaver func(types.FileContractRevision, []crypto.Hash) error
    50  
    51  // A recentRevisionError occurs if the host reports a different revision
    52  // number than expected.
    53  type recentRevisionError struct {
    54  	ours, theirs uint64
    55  }
    56  
    57  func (e *recentRevisionError) Error() string {
    58  	return fmt.Sprintf("our revision number (%v) does not match the host's (%v)", e.ours, e.theirs)
    59  }
    60  
    61  // IsRevisionMismatch returns true if err was caused by the host reporting a
    62  // different revision number than expected.
    63  func IsRevisionMismatch(err error) bool {
    64  	_, ok := err.(*recentRevisionError)
    65  	return ok
    66  }