github.com/fozzysec/SiaPrime@v0.0.0-20190612043147-66c8e8d11fe3/modules/renter/proto/proto.go (about)

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