gitlab.com/SkynetLabs/skyd@v1.6.9/skymodules/renter/contractor/dependencies.go (about)

     1  package contractor
     2  
     3  import (
     4  	"gitlab.com/SkynetLabs/skyd/skymodules"
     5  	"go.sia.tech/siad/modules"
     6  	"go.sia.tech/siad/types"
     7  )
     8  
     9  // These interfaces define the HostDB's dependencies. Using the smallest
    10  // interface possible makes it easier to mock these dependencies in testing.
    11  type (
    12  	// In order to restrict the modules.TransactionBuilder interface, we must
    13  	// provide a shim to bridge the gap between modules.Wallet and
    14  	// transactionBuilder.
    15  	walletShim interface {
    16  		NextAddress() (types.UnlockConditions, error)
    17  		PrimarySeed() (modules.Seed, uint64, error)
    18  		StartTransaction() (modules.TransactionBuilder, error)
    19  		RegisterTransaction(types.Transaction, []types.Transaction) (modules.TransactionBuilder, error)
    20  		Unlocked() (bool, error)
    21  	}
    22  	transactionBuilder interface {
    23  		AddArbitraryData([]byte) uint64
    24  		AddFileContract(types.FileContract) uint64
    25  		AddFileContractRevision(types.FileContractRevision) uint64
    26  		AddMinerFee(types.Currency) uint64
    27  		AddParents([]types.Transaction)
    28  		AddSiacoinInput(types.SiacoinInput) uint64
    29  		AddSiacoinOutput(types.SiacoinOutput) uint64
    30  		ReplaceSiacoinOutput(uint64, types.SiacoinOutput) error
    31  		AddTransactionSignature(types.TransactionSignature) uint64
    32  		Copy() modules.TransactionBuilder
    33  		Drop()
    34  		FundSiacoins(types.Currency) error
    35  		MarkWalletInputs() bool
    36  		Sign(bool) ([]types.Transaction, error)
    37  		UnconfirmedParents() ([]types.Transaction, error)
    38  		View() (types.Transaction, []types.Transaction)
    39  		ViewAdded() (parents, coins, funds, signatures []int)
    40  	}
    41  	transactionPool interface {
    42  		AcceptTransactionSet([]types.Transaction) error
    43  		FeeEstimation() (min types.Currency, max types.Currency)
    44  	}
    45  
    46  	hostDB interface {
    47  		AllHosts() ([]skymodules.HostDBEntry, error)
    48  		ActiveHosts() ([]skymodules.HostDBEntry, error)
    49  		CheckForIPViolations([]types.SiaPublicKey) ([]types.SiaPublicKey, error)
    50  		Filter() (skymodules.FilterMode, map[string]types.SiaPublicKey, error)
    51  		SetFilterMode(fm skymodules.FilterMode, hosts []types.SiaPublicKey) error
    52  		Host(types.SiaPublicKey) (skymodules.HostDBEntry, bool, error)
    53  		IncrementSuccessfulInteractions(key types.SiaPublicKey) error
    54  		IncrementFailedInteractions(key types.SiaPublicKey) error
    55  		InitialScanComplete() (complete bool, err error)
    56  		RandomHosts(n int, blacklist, addressBlacklist []types.SiaPublicKey) ([]skymodules.HostDBEntry, error)
    57  		UpdateContracts([]skymodules.RenterContract) error
    58  		ScoreBreakdown(skymodules.HostDBEntry) (skymodules.HostScoreBreakdown, error)
    59  		SetAllowance(allowance skymodules.Allowance) error
    60  	}
    61  )
    62  
    63  // WalletBridge is a bridge for the wallet because wallet is not directly
    64  // compatible with modules.Wallet (wrong type signature for StartTransaction),
    65  // we must provide a bridge type.
    66  type WalletBridge struct {
    67  	W walletShim
    68  }
    69  
    70  // NextAddress computes and returns the next address of the wallet.
    71  func (ws *WalletBridge) NextAddress() (types.UnlockConditions, error) { return ws.W.NextAddress() }
    72  
    73  // PrimarySeed returns the primary wallet seed.
    74  func (ws *WalletBridge) PrimarySeed() (modules.Seed, uint64, error) { return ws.W.PrimarySeed() }
    75  
    76  // StartTransaction creates a new transactionBuilder that can be used to create
    77  // and sign a transaction.
    78  func (ws *WalletBridge) StartTransaction() (transactionBuilder, error) {
    79  	return ws.W.StartTransaction()
    80  }
    81  
    82  // RegisterTransaction creates a new transactionBuilder from a transaction and parent transactions.
    83  func (ws *WalletBridge) RegisterTransaction(t types.Transaction, parents []types.Transaction) (transactionBuilder, error) {
    84  	return ws.W.RegisterTransaction(t, parents)
    85  }
    86  
    87  // Unlocked reports whether the wallet bridge is unlocked.
    88  func (ws *WalletBridge) Unlocked() (bool, error) { return ws.W.Unlocked() }