Skip to content

Commit

Permalink
testutil: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Feb 13, 2024
1 parent 6d4798d commit bcb13c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 4 additions & 2 deletions testutil/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type (
}
)

func (et *ephemeralWalletUpdateTxn) WalletStateElements() (eles []types.StateElement, _ error) {
func (et *ephemeralWalletUpdateTxn) WalletStateElements() (elements []types.StateElement, _ error) {
for _, se := range et.store.utxos {
eles = append(eles, se.StateElement)
elements = append(elements, se.StateElement)
}
return
}
Expand Down Expand Up @@ -133,6 +133,7 @@ func (es *EphemeralWalletStore) Tip() (types.ChainIndex, error) {
return es.tip, nil
}

// ProcessChainApplyUpdate implements chain.Subscriber.
func (es *EphemeralWalletStore) ProcessChainApplyUpdate(cau *chain.ApplyUpdate, mayCommit bool) error {
es.mu.Lock()
defer es.mu.Unlock()
Expand All @@ -153,6 +154,7 @@ func (es *EphemeralWalletStore) ProcessChainApplyUpdate(cau *chain.ApplyUpdate,
return nil
}

// ProcessChainRevertUpdate implements chain.Subscriber.
func (es *EphemeralWalletStore) ProcessChainRevertUpdate(cru *chain.RevertUpdate) error {
es.mu.Lock()
defer es.mu.Unlock()
Expand Down
24 changes: 11 additions & 13 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (sw *SingleAddressWallet) TransactionCount() (uint64, error) {
// SpendableOutputs returns a list of spendable siacoin outputs, a spendable
// output is an unspent output that's not locked, not currently in the
// transaction pool and that has matured.
func (sw *SingleAddressWallet) SpendableOutputs() ([]types.SiacoinElement, error) {
func (sw *SingleAddressWallet) SpendableOutputs() ([]SiacoinElement, error) {
// fetch outputs from the store
utxos, err := sw.store.UnspentSiacoinElements()
if err != nil {
Expand Down Expand Up @@ -256,7 +256,7 @@ func (sw *SingleAddressWallet) FundTransaction(txn *types.Transaction, amount ty
return nil, nil
}

utxos, err := sw.store.UnspentSiacoinElements()
elements, err := sw.store.UnspentSiacoinElements()
if err != nil {
return nil, err
}
Expand All @@ -282,14 +282,13 @@ func (sw *SingleAddressWallet) FundTransaction(txn *types.Transaction, amount ty
defer sw.mu.Unlock()

// remove locked and spent outputs
filtered := utxos[:0]
for _, sce := range utxos {
utxos := make([]types.SiacoinElement, 0, len(elements))
for _, sce := range elements {
if time.Now().Before(sw.locked[sce.ID]) || tpoolSpent[sce.ID] {
continue
}
filtered = append(filtered, sce)
utxos = append(utxos, sce.SiacoinElement)
}
utxos = filtered

// sort by value, descending
sort.Slice(utxos, func(i, j int) bool {
Expand Down Expand Up @@ -319,7 +318,7 @@ func (sw *SingleAddressWallet) FundTransaction(txn *types.Transaction, amount ty
utxos = utxos[i:]
break
}
selected = append(selected, sce.SiacoinElement)
selected = append(selected, sce)
inputSum = inputSum.Add(sce.SiacoinOutput.Value)
}

Expand Down Expand Up @@ -355,7 +354,7 @@ func (sw *SingleAddressWallet) FundTransaction(txn *types.Transaction, amount ty
}

sce := defraggable[i]
selected = append(selected, sce.SiacoinElement)
selected = append(selected, sce)
inputSum = inputSum.Add(sce.SiacoinOutput.Value)
txnInputs++
}
Expand Down Expand Up @@ -459,7 +458,7 @@ func (sw *SingleAddressWallet) UnconfirmedTransactions() ([]Transaction, error)
// outputs. It also returns a list of output IDs that need to be signed.
func (sw *SingleAddressWallet) Redistribute(outputs int, amount, feePerByte types.Currency) (txns []types.Transaction, toSign []types.Hash256, err error) {
// fetch outputs from the store
utxos, err := sw.store.UnspentSiacoinElements()
elements, err := sw.store.UnspentSiacoinElements()
if err != nil {
return nil, nil, err
}
Expand All @@ -481,8 +480,8 @@ func (sw *SingleAddressWallet) Redistribute(outputs int, amount, feePerByte type

// adjust the number of desired outputs for any output we encounter that is
// unused, matured and has the same value
usable := utxos[:0]
for _, sce := range utxos {
utxos := make([]types.SiacoinElement, 0, len(elements))
for _, sce := range elements {
inUse := time.Now().After(sw.locked[sce.ID]) || inPool[sce.ID]
matured := bh >= sce.MaturityHeight
sameValue := sce.SiacoinOutput.Value.Equals(amount)
Expand All @@ -494,10 +493,9 @@ func (sw *SingleAddressWallet) Redistribute(outputs int, amount, feePerByte type

// collect usable outputs for defragging
if !inUse && matured && !sameValue {
usable = append(usable, sce)
utxos = append(utxos, sce.SiacoinElement)
}
}
utxos = usable

// return early if we don't have to defrag at all
if outputs <= 0 {
Expand Down

0 comments on commit bcb13c5

Please sign in to comment.