Skip to content

Commit

Permalink
deps: Update wallet to v4.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed Jun 17, 2024
1 parent 0d1e873 commit 720df64
Show file tree
Hide file tree
Showing 19 changed files with 407 additions and 381 deletions.
2 changes: 1 addition & 1 deletion client/asset/dcr/coin_selection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

dexdcr "decred.org/dcrdex/dex/networks/dcr"
walletjson "decred.org/dcrwallet/v3/rpc/jsonrpc/types"
walletjson "decred.org/dcrwallet/v4/rpc/jsonrpc/types"
)

func Test_leastOverFund(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
"decred.org/dcrdex/dex/config"
"decred.org/dcrdex/dex/dexnet"
dexdcr "decred.org/dcrdex/dex/networks/dcr"
walletjson "decred.org/dcrwallet/v3/rpc/jsonrpc/types"
"decred.org/dcrwallet/v3/wallet"
_ "decred.org/dcrwallet/v3/wallet/drivers/bdb"
walletjson "decred.org/dcrwallet/v4/rpc/jsonrpc/types"
"decred.org/dcrwallet/v4/wallet"
_ "decred.org/dcrwallet/v4/wallet/drivers/bdb"
"github.com/decred/dcrd/blockchain/stake/v5"
blockchain "github.com/decred/dcrd/blockchain/standalone/v2"
"github.com/decred/dcrd/chaincfg/chainhash"
Expand All @@ -50,7 +50,7 @@ import (
"github.com/decred/dcrd/txscript/v4/stdaddr"
"github.com/decred/dcrd/txscript/v4/stdscript"
"github.com/decred/dcrd/wire"
vspdjson "github.com/decred/vspd/types"
vspdjson "github.com/decred/vspd/types/v2"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions client/asset/dcr/dcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"decred.org/dcrdex/dex/config"
"decred.org/dcrdex/dex/encode"
dexdcr "decred.org/dcrdex/dex/networks/dcr"
"decred.org/dcrwallet/v3/rpc/client/dcrwallet"
walletjson "decred.org/dcrwallet/v3/rpc/jsonrpc/types"
"decred.org/dcrwallet/v4/rpc/client/dcrwallet"
walletjson "decred.org/dcrwallet/v4/rpc/jsonrpc/types"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrec"
Expand Down
8 changes: 4 additions & 4 deletions client/asset/dcr/native_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

"decred.org/dcrdex/client/asset"
"decred.org/dcrdex/dex"
walletjson "decred.org/dcrwallet/v3/rpc/jsonrpc/types"
"decred.org/dcrwallet/v3/wallet"
"decred.org/dcrwallet/v4/p2p"
walletjson "decred.org/dcrwallet/v4/rpc/jsonrpc/types"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/dcrutil/v4"
)
Expand All @@ -40,7 +40,7 @@ type mixingConfigFile struct {
type mixingConfig struct {
server string
cert []byte
dialer wallet.DialFunc
dialer p2p.DialFunc
enabled bool
}

Expand Down Expand Up @@ -155,7 +155,7 @@ func initNativeWallet(ew *ExchangeWallet) (*NativeWallet, error) {
return w, nil
}

func makeCSPPDialer(serverAddress string, certB []byte) (wallet.DialFunc, error) {
func makeCSPPDialer(serverAddress string, certB []byte) (p2p.DialFunc, error) {
serverName, _, err := net.SplitHostPort(serverAddress)
if err != nil {
return nil, fmt.Errorf("cannot parse CoinShuffle++ server name %q: %v", serverAddress, err)
Expand Down
18 changes: 5 additions & 13 deletions client/asset/dcr/rpcwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (

"decred.org/dcrdex/client/asset"
"decred.org/dcrdex/dex"
"decred.org/dcrwallet/v3/rpc/client/dcrwallet"
walletjson "decred.org/dcrwallet/v3/rpc/jsonrpc/types"
"decred.org/dcrwallet/v3/wallet"
"decred.org/dcrwallet/v4/rpc/client/dcrwallet"
walletjson "decred.org/dcrwallet/v4/rpc/jsonrpc/types"
"decred.org/dcrwallet/v4/wallet"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
Expand Down Expand Up @@ -1256,16 +1256,8 @@ func isAccountLockedErr(err error) bool {
strings.Contains(rpcErr.Message, "account is already locked")
}

// newWalletInfo is walletinfo with a new field found in version 9.2.0+.
//
// TODO: Just use *walletjson.WalletInfoResult after we update to dcrwallet/v4.
type newWalletInfo struct {
*walletjson.WalletInfoResult
VSP string `json:"vsp"`
}

func (w *rpcWallet) walletInfo(ctx context.Context) (*newWalletInfo, error) {
var walletInfo newWalletInfo
func (w *rpcWallet) walletInfo(ctx context.Context) (*walletjson.WalletInfoResult, error) {
var walletInfo walletjson.WalletInfoResult
err := w.rpcClientRawRequest(ctx, methodWalletInfo, nil, &walletInfo)
return &walletInfo, translateRPCCancelErr(err)
}
Expand Down
91 changes: 49 additions & 42 deletions client/asset/dcr/spv.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (
"decred.org/dcrdex/client/asset"
"decred.org/dcrdex/dex"
"decred.org/dcrdex/dex/utils"
"decred.org/dcrwallet/v3/chain"
walleterrors "decred.org/dcrwallet/v3/errors"
"decred.org/dcrwallet/v3/p2p"
walletjson "decred.org/dcrwallet/v3/rpc/jsonrpc/types"
"decred.org/dcrwallet/v3/spv"
"decred.org/dcrwallet/v3/wallet"
"decred.org/dcrwallet/v3/wallet/udb"
"decred.org/dcrwallet/v4/chain"
walleterrors "decred.org/dcrwallet/v4/errors"
"decred.org/dcrwallet/v4/p2p"
walletjson "decred.org/dcrwallet/v4/rpc/jsonrpc/types"
"decred.org/dcrwallet/v4/spv"
vspclient "decred.org/dcrwallet/v4/vsp"
"decred.org/dcrwallet/v4/wallet"
"decred.org/dcrwallet/v4/wallet/udb"
"github.com/decred/dcrd/addrmgr/v2"
"github.com/decred/dcrd/blockchain/stake/v5"
"github.com/decred/dcrd/chaincfg/chainhash"
Expand All @@ -42,7 +43,6 @@ import (
"github.com/decred/dcrd/txscript/v4/stdaddr"
"github.com/decred/dcrd/wire"
"github.com/decred/slog"
vspclient "github.com/decred/vspd/client/v2"
"github.com/jrick/logrotate/rotator"
)

Expand Down Expand Up @@ -71,9 +71,8 @@ type dcrWallet interface {
ListUnspent(ctx context.Context, minconf, maxconf int32, addresses map[string]struct{}, accountName string) ([]*walletjson.ListUnspentResult, error)
LockOutpoint(txHash *chainhash.Hash, index uint32)
ListTransactionDetails(ctx context.Context, txHash *chainhash.Hash) ([]walletjson.ListTransactionsResult, error)
MixAccount(ctx context.Context, dialTLS wallet.DialFunc, csppserver string, changeAccount, mixAccount, mixBranch uint32) error
MixAccount(context.Context, uint32, uint32, uint32) error
MainChainTip(ctx context.Context) (hash chainhash.Hash, height int32)
MainTipChangedNotifications() (chan *wallet.MainTipChangedNotification, func())
NewExternalAddress(ctx context.Context, account uint32, callOpts ...wallet.NextAddressCallOption) (stdaddr.Address, error)
NewInternalAddress(ctx context.Context, account uint32, callOpts ...wallet.NextAddressCallOption) (stdaddr.Address, error)
PublishTransaction(ctx context.Context, tx *wire.MsgTx, n wallet.NetworkBackend) (*chainhash.Hash, error)
Expand All @@ -95,20 +94,25 @@ type dcrWallet interface {
GetAllTSpends(ctx context.Context) []*wire.MsgTx
TSpendPolicy(tspendHash, ticketHash *chainhash.Hash) stake.TreasuryVoteT
VSPHostForTicket(ctx context.Context, ticketHash *chainhash.Hash) (string, error)
SetAgendaChoices(ctx context.Context, ticketHash *chainhash.Hash, choices ...wallet.AgendaChoice) (voteBits uint16, err error)
SetAgendaChoices(ctx context.Context, ticketHash *chainhash.Hash, choices map[string]string) (voteBits uint16, err error)
SetTSpendPolicy(ctx context.Context, tspendHash *chainhash.Hash, policy stake.TreasuryVoteT, ticketHash *chainhash.Hash) error
SetTreasuryKeyPolicy(ctx context.Context, pikey []byte, policy stake.TreasuryVoteT, ticketHash *chainhash.Hash) error
SetRelayFee(relayFee dcrutil.Amount)
GetTicketInfo(ctx context.Context, hash *chainhash.Hash) (*wallet.TicketSummary, *wire.BlockHeader, error)
GetTransactions(ctx context.Context, f func(*wallet.Block) (bool, error), startBlock, endBlock *wallet.BlockIdentifier) error
vspclient.Wallet
ListSinceBlock(ctx context.Context, start, end, syncHeight int32) ([]walletjson.ListTransactionsResult, error)
UnlockOutpoint(txHash *chainhash.Hash, index uint32)
SignTransaction(ctx context.Context, tx *wire.MsgTx, hashType txscript.SigHashType, additionalPrevScripts map[wire.OutPoint][]byte,
additionalKeysByAddress map[string]*dcrutil.WIF, p2shRedeemScriptsByAddress map[string][]byte) ([]wallet.SignatureError, error)
AgendaChoices(ctx context.Context, ticketHash *chainhash.Hash) (choices map[string]string, voteBits uint16, err error)
NewVSPTicket(ctx context.Context, hash *chainhash.Hash) (*wallet.VSPTicket, error)
// TODO: Rescan and DiscoverActiveAddresses can be used for a Rescanner.
}

// Interface for *spv.Syncer so that we can test with a stub.
type spvSyncer interface {
wallet.NetworkBackend
Synced() bool
Synced(context.Context) (bool, int32)
GetRemotePeers() map[string]*p2p.RemotePeer
}

Expand Down Expand Up @@ -146,7 +150,7 @@ func (w *extendedWallet) MainTipChangedNotifications() (chan *wallet.MainTipChan
// spvWallet is a Wallet built on dcrwallet's *wallet.Wallet running in SPV
// mode.
type spvWallet struct {
dcrWallet // *wallet.Wallet
dcrWallet // *extendedWallet
db wallet.DB
dir string
chainParams *chaincfg.Params
Expand Down Expand Up @@ -972,7 +976,8 @@ func (w *spvWallet) SyncStatus(ctx context.Context) (bool, float32, error) {
targetHeight = height
}

synced, progress := w.spv.Synced(), float32(height)/float32(targetHeight)
synced, _ := w.spv.Synced(ctx)
progress := float32(height) / float32(targetHeight)
if progress > 0.999 && !synced {
progress = 0.999
}
Expand Down Expand Up @@ -1011,32 +1016,33 @@ func (w *spvWallet) StakeInfo(ctx context.Context) (*wallet.StakeInfoData, error
return w.dcrWallet.StakeInfo(ctx)
}

func newVSPClient(w vspclient.Wallet, vspHost, vspPubKey string, log dex.Logger) (*vspclient.AutoClient, error) {
func (w *spvWallet) newVSPClient(vspHost, vspPubKey string, log dex.Logger) (*vspclient.Client, error) {
return vspclient.New(vspclient.Config{
URL: vspHost,
PubKey: vspPubKey,
Dialer: new(net.Dialer).DialContext,
Wallet: w,
Wallet: w.dcrWallet.(*extendedWallet).Wallet,
Policy: &vspclient.Policy{
MaxFee: 0.2e8,
FeeAcct: 0,
ChangeAcct: 0,
},
Params: w.chainParams,
}, log)
}

// PurchaseTickets purchases n tickets, tells the provided vspd to monitor the
// ticket, and pays the vsp fee.
func (w *spvWallet) PurchaseTickets(ctx context.Context, n int, vspHost, vspPubKey string, mixCfg *mixingConfig) ([]*asset.Ticket, error) {
vspClient, err := newVSPClient(w.dcrWallet, vspHost, vspPubKey, w.log.SubLogger("VSP"))
vspClient, err := w.newVSPClient(vspHost, vspPubKey, w.log.SubLogger("VSP"))
if err != nil {
return nil, err
}

req := &wallet.PurchaseTicketsRequest{
Count: n,
VSPFeePaymentProcess: vspClient.Process,
VSPFeeProcess: vspClient.FeePercentage,
VSPFeePercent: vspClient.FeePercentage,
}

if mixCfg.enabled {
Expand All @@ -1049,8 +1055,6 @@ func (w *spvWallet) PurchaseTickets(ctx context.Context, n int, vspHost, vspPubK
// For simnet, we just change the source account. Others we need to
// mix tickets through the cspp server.
if w.chainParams.Net != wire.SimNet {
req.CSPPServer = mixCfg.server
req.DialCSPPServer = mixCfg.dialer
req.MixedAccount = mixedAccountNum
req.MixedAccountBranch = mixedAccountBranch
req.MixedSplitAccount = req.MixedAccount
Expand Down Expand Up @@ -1169,18 +1173,25 @@ func (w *spvWallet) VotingPreferences(ctx context.Context) ([]*walletjson.VoteCh

voteChoices := make([]*walletjson.VoteChoice, len(choices))

for i := range choices {
i := 0
for agendaID, choiceID := range choices {
voteChoices[i] = &walletjson.VoteChoice{
AgendaID: choices[i].AgendaID,
AgendaDescription: agendas[i].Vote.Description,
ChoiceID: choices[i].ChoiceID,
AgendaID: agendaID,
ChoiceID: choiceID,
}
for j := range agendas[i].Vote.Choices {
if choices[i].ChoiceID == agendas[i].Vote.Choices[j].Id {
voteChoices[i].ChoiceDescription = agendas[i].Vote.Choices[j].Description
break
for _, agenda := range agendas {
if agenda.Vote.Id != agendaID {
continue
}
voteChoices[i].AgendaDescription = agenda.Vote.Description
for _, choice := range agenda.Vote.Choices {
if choiceID == choice.Id {
voteChoices[i].ChoiceDescription = choice.Description
break
}
}
}
i++
}
policyToStr := func(p stake.TreasuryVoteT) string {
var policy string
Expand Down Expand Up @@ -1230,16 +1241,8 @@ func (w *spvWallet) VotingPreferences(ctx context.Context) ([]*walletjson.VoteCh
func (w *spvWallet) SetVotingPreferences(ctx context.Context, choices, tspendPolicy,
treasuryPolicy map[string]string) error {
// Set the consensus vote choices for the wallet.
agendaChoices := make([]wallet.AgendaChoice, 0, len(choices))
for k, v := range choices {
choice := wallet.AgendaChoice{
AgendaID: k,
ChoiceID: v,
}
agendaChoices = append(agendaChoices, choice)
}
if len(agendaChoices) > 0 {
_, err := w.SetAgendaChoices(ctx, nil, agendaChoices...)
if len(choices) > 0 {
_, err := w.SetAgendaChoices(ctx, nil, choices)
if err != nil {
return err
}
Expand Down Expand Up @@ -1295,7 +1298,7 @@ func (w *spvWallet) SetVotingPreferences(ctx context.Context, choices, tspendPol
return err
}
}
clientCache := make(map[string]*vspclient.AutoClient)
clientCache := make(map[string]*vspclient.Client)
// Set voting preferences for VSPs. Continuing for all errors.
// NOTE: Doing this in an unmetered loop like this is a privacy breaker.
return w.dcrWallet.ForUnspentUnexpiredTickets(ctx, func(hash *chainhash.Hash) error {
Expand All @@ -1316,15 +1319,19 @@ func (w *spvWallet) SetVotingPreferences(ctx context.Context, choices, tspendPol
return nil
}
vspPubKey := base64.StdEncoding.EncodeToString(info.PubKey)
vspClient, err = newVSPClient(w.dcrWallet, vspHost, vspPubKey, w.log.SubLogger("VSP"))
vspClient, err = w.newVSPClient(vspHost, vspPubKey, w.log.SubLogger("VSP"))
if err != nil {
w.log.Warnf("unable to load vsp at %s for ticket %s: %v", vspHost, hash, err)
return nil
}
}
// Never return errors here, so all tickets are tried.
// The first error will be returned to the user.
err = vspClient.SetVoteChoice(ctx, hash, choices, tspendPolicy, treasuryPolicy)
vspTicket, err := w.NewVSPTicket(ctx, hash)
if err != nil {
w.log.Warnf("unable to create vsp ticket for vsp at %s for ticket %s: %v", vspHost, hash, err)
}
err = vspClient.SetVoteChoice(ctx, vspTicket, choices, tspendPolicy, treasuryPolicy)
if err != nil {
w.log.Warnf("unable to set vote for vsp at %s for ticket %s: %v", vspHost, hash, err)
}
Expand Down
7 changes: 4 additions & 3 deletions client/asset/dcr/spv_mixing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dcr
import (
"context"

"decred.org/dcrwallet/v3/wallet/udb"
"decred.org/dcrwallet/v4/wallet/udb"
)

const (
Expand All @@ -27,12 +27,13 @@ func (w *spvWallet) mix(ctx context.Context, cfg *mixingConfig) {

// Don't perform any actions while transactions are not synced
// through the tip block.
if !w.spv.Synced() {
synced, _ := w.spv.Synced(ctx)
if !synced {
w.log.Tracef("Skipping account mixing: transactions are not synced")
return
}

if err = w.MixAccount(ctx, cfg.dialer, cfg.server, unmixedAccount, mixedAccount, mixedAccountBranch); err != nil {
if err = w.MixAccount(ctx, unmixedAccount, mixedAccount, mixedAccountBranch); err != nil {
w.log.Errorf("Error mixing account: %v", err)
}
}
Loading

0 comments on commit 720df64

Please sign in to comment.