Skip to content

Commit

Permalink
Use rand.ShuffleSlice
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Jun 14, 2024
1 parent f0152a4 commit eccbb0d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/decred/dcrd/chaincfg/v3 v3.2.1
github.com/decred/dcrd/connmgr/v3 v3.1.2
github.com/decred/dcrd/crypto/blake256 v1.0.1
github.com/decred/dcrd/crypto/rand v0.0.0-20240613225426-c320f9914994
github.com/decred/dcrd/crypto/rand v0.0.0-20240614031620-f7dd7c89f0a6
github.com/decred/dcrd/crypto/ripemd160 v1.0.2
github.com/decred/dcrd/dcrec v1.0.1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ github.com/decred/dcrd/connmgr/v3 v3.1.2 h1:+xNopie2L3YYwwkz51k0h/pASATOBzHtl2O8
github.com/decred/dcrd/connmgr/v3 v3.1.2/go.mod h1:tdbErFiNOuy/sHrX2mwaOk+r1HLs3EBz2EGxsocMPe4=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/crypto/rand v0.0.0-20240613225426-c320f9914994 h1:+SVSe5nF5ZHOMrFU/CV2QY1FMeYp6k5bYXwk5dYA64Q=
github.com/decred/dcrd/crypto/rand v0.0.0-20240613225426-c320f9914994/go.mod h1:coa7BbxSTiKH6esi257plGfMFYuGL4MTbQlLYnOdzpE=
github.com/decred/dcrd/crypto/rand v0.0.0-20240614031620-f7dd7c89f0a6 h1:n70K8plsbppuliD8X/oVjjfdRYK9tlCcJNo7G4IUz+M=
github.com/decred/dcrd/crypto/rand v0.0.0-20240614031620-f7dd7c89f0a6/go.mod h1:coa7BbxSTiKH6esi257plGfMFYuGL4MTbQlLYnOdzpE=
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
github.com/decred/dcrd/database/v3 v3.0.2 h1:rgP7XNZemTs8ZC7bnTKO8JO79Woj5nq+yQYmB9ry7yM=
Expand Down
8 changes: 2 additions & 6 deletions internal/rpc/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -4304,12 +4304,8 @@ func (s *Server) spendOutputs(ctx context.Context, icmd any) (any, error) {
txOut.Version = scriptVersion
outputs = append(outputs, txOut)
}
rand.Shuffle(len(inputs), func(i, j int) {
inputs[i], inputs[j] = inputs[j], inputs[i]
})
rand.Shuffle(len(outputs), func(i, j int) {
outputs[i], outputs[j] = outputs[j], outputs[i]
})
rand.ShuffleSlice(inputs)
rand.ShuffleSlice(outputs)

inputSource, err := spendOutputsInputSource(ctx, w, cmd.Account,
inputs)
Expand Down
4 changes: 1 addition & 3 deletions wallet/createtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2163,9 +2163,7 @@ func (w *Wallet) findEligibleOutputsAmount(dbtx walletdb.ReadTx, account uint32,
if err != nil {
return nil, err
}
rand.Shuffle(len(unspent), func(i, j int) {
unspent[i], unspent[j] = unspent[j], unspent[i]
})
rand.ShuffleSlice(unspent)

for i := range unspent {
output := unspent[i]
Expand Down
4 changes: 1 addition & 3 deletions wallet/udb/txmined.go
Original file line number Diff line number Diff line change
Expand Up @@ -3221,9 +3221,7 @@ func (s *Store) MakeInputSource(dbtx walletdb.ReadTx, account uint32, minConf,
return nil, err
}
}
rand.Shuffle(len(remainingKeys), func(i, j int) {
remainingKeys[i], remainingKeys[j] = remainingKeys[j], remainingKeys[i]
})
rand.ShuffleSlice(remainingKeys)
}

var unmined bool
Expand Down

0 comments on commit eccbb0d

Please sign in to comment.