Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dcrwallet to master branch (future version v4) #48

Closed
wants to merge 11 commits into from
14 changes: 7 additions & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Set up Go 1.19
uses: actions/setup-go@v1
- name: Set up Go 1.20
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: "1.20"
id: go

- name: Libraries for gio
Expand All @@ -20,13 +20,13 @@ jobs:
sudo apt install libwayland-dev libx11-dev libx11-xcb-dev libxkbcommon-x11-dev libgles2-mesa-dev libegl1-mesa-dev libffi-dev libxcursor-dev libvulkan-dev

- name: Cache (dependencies)
uses: actions/cache@v1
uses: actions/cache@v3
id: cache
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-v2
key: ${{ runner.os }}-go-v2-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
${{ runner.os }}-go-v2

- name: Install linter
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.53.3
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/crypto-power/cryptopower

go 1.19
go 1.20

require (
decred.org/dcrwallet/v3 v3.0.1
decred.org/dcrwallet/v4 v4.0.0-20230809150859-a87fa843495e
dmigwi marked this conversation as resolved.
Show resolved Hide resolved
gioui.org v0.1.0
github.com/JohannesKaufmann/html-to-markdown v1.2.1
github.com/PuerkitoBio/goquery v1.6.1
Expand Down Expand Up @@ -37,6 +37,8 @@ require (
github.com/decred/dcrdata/v8 v8.0.0-20230617164141-fa4d8e1b4e8e
github.com/decred/politeia v1.4.0
github.com/decred/slog v1.2.0
github.com/decred/vspd/client/v2 v2.0.0
github.com/decred/vspd/types/v2 v2.0.0
github.com/dgraph-io/badger v1.6.2
github.com/gen2brain/beeep v0.0.0-20220402123239-6a3042f4b71a
github.com/gomarkdown/markdown v0.0.0-20220817224203-2206187d3406
Expand Down Expand Up @@ -100,8 +102,6 @@ require (
github.com/decred/dcrd/txscript/v3 v3.0.0 // indirect
github.com/decred/dcrtime v0.0.0-20191018193024-8d8b4ef0458e // indirect
github.com/decred/go-socks v1.1.0 // indirect
github.com/decred/vspd/client/v2 v2.0.0 // indirect
github.com/decred/vspd/types/v2 v2.0.0 // indirect
github.com/dgraph-io/ristretto v0.0.2 // indirect
github.com/dustin/go-humanize v1.0.1-0.20210705192016-249ff6c91207 // indirect
github.com/fogleman/gg v1.3.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ decred.org/cspp/v2 v2.1.0 h1:HeHb9+BFqrBaAPc6CsPiUpPFmC1uyBM2mJZUAbUXkRw=
decred.org/cspp/v2 v2.1.0/go.mod h1:9nO3bfvCheOPIFZw5f6sRQ42CjBFB5RKSaJ9Iq6G4MA=
decred.org/dcrwallet v1.7.0 h1:U/ew00YBdUlx3rJAynt2OdKDgGzBKK4O89FijBq8iVg=
decred.org/dcrwallet v1.7.0/go.mod h1:hNOGyvH53gWdgFB601/ubGRzCPfPtWnEVAi9Grs90y4=
decred.org/dcrwallet/v3 v3.0.1 h1:+OLi+u/MvKc3Ubcnf19oyG/a5hJ/qp4OtezdiQZnLIs=
decred.org/dcrwallet/v3 v3.0.1/go.mod h1:a+R8BZIOKVpWVPat5VZoBWNh/cnIciwcRkPtrzfS/tw=
decred.org/dcrwallet/v4 v4.0.0-20230809150859-a87fa843495e h1:Y1f5xYRQi7qMzLYifvAOplMhgHiKxtWWzd1psXqsS6A=
decred.org/dcrwallet/v4 v4.0.0-20230809150859-a87fa843495e/go.mod h1:0+CchVf/baDYJ0tlDjtEzAFsvYcwWRm0eo1+Lf7Z1as=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d h1:ARo7NCVvN2NdhLlJE9xAbKweuI9L6UgfTbYb0YwPacY=
gioui.org v0.1.0 h1:fEDY5A4+epOdzjCBYSUC4BzvjWqsjfqf5D6mskbthOs=
Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/btc/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"time"

"decred.org/dcrwallet/v3/errors"
"decred.org/dcrwallet/v4/errors"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcwallet/waddrmgr"
Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/btc/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package btc
import (
"fmt"

"decred.org/dcrwallet/v3/errors"
"decred.org/dcrwallet/v4/errors"
"github.com/btcsuite/btcd/btcutil"
"github.com/crypto-power/cryptopower/libwallet/utils"
)
Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/btc/feerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"sync"

"decred.org/dcrwallet/v3/errors"
"decred.org/dcrwallet/v4/errors"
"github.com/btcsuite/btcd/btcutil"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/utils"
Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/btc/rescan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync/atomic"
"time"

"decred.org/dcrwallet/v3/errors"
"decred.org/dcrwallet/v4/errors"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcwallet/chain"
"github.com/btcsuite/btcwallet/waddrmgr"
Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/btc/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync/atomic"
"time"

"decred.org/dcrwallet/v3/errors"
"decred.org/dcrwallet/v4/errors"
"github.com/btcsuite/btcwallet/chain"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/utils"
Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/btc/txandblocknotifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"sync/atomic"

"decred.org/dcrwallet/v3/errors"
"decred.org/dcrwallet/v4/errors"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/utils"
)
Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/btc/txauthor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"sync"
"time"

"decred.org/dcrwallet/v3/errors"
"decred.org/dcrwallet/v4/errors"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/btc/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sync"
"time"

"decred.org/dcrwallet/v3/errors"
"decred.org/dcrwallet/v4/errors"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/gcs"
Expand Down
6 changes: 3 additions & 3 deletions libwallet/assets/dcr/account_mixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"errors"
"net"

"decred.org/dcrwallet/v3/ticketbuyer"
w "decred.org/dcrwallet/v3/wallet"
"decred.org/dcrwallet/v3/wallet/udb"
"decred.org/dcrwallet/v4/ticketbuyer"
w "decred.org/dcrwallet/v4/wallet"
"decred.org/dcrwallet/v4/wallet/udb"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/internal/certs"
"github.com/crypto-power/cryptopower/libwallet/utils"
Expand Down
4 changes: 2 additions & 2 deletions libwallet/assets/dcr/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"strconv"

"decred.org/dcrwallet/v3/errors"
w "decred.org/dcrwallet/v3/wallet"
"decred.org/dcrwallet/v4/errors"
w "decred.org/dcrwallet/v4/wallet"
"github.com/crypto-power/cryptopower/libwallet/addresshelper"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/utils"
Expand Down
4 changes: 2 additions & 2 deletions libwallet/assets/dcr/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package dcr
import (
"fmt"

"decred.org/dcrwallet/v3/errors"
w "decred.org/dcrwallet/v3/wallet"
"decred.org/dcrwallet/v4/errors"
w "decred.org/dcrwallet/v4/wallet"
"github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/decred/dcrd/txscript/v4/stdaddr"
)
Expand Down
36 changes: 16 additions & 20 deletions libwallet/assets/dcr/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"sort"
"strings"

"decred.org/dcrwallet/v3/errors"
w "decred.org/dcrwallet/v3/wallet"
"decred.org/dcrwallet/v4/errors"

"github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/decred/dcrd/chaincfg/chainhash"
Expand Down Expand Up @@ -111,24 +110,21 @@ func (asset *Asset) SetVoteChoice(agendaID, choiceID, hash, passphrase string) e
return err
}

currentChoice := w.AgendaChoice{
AgendaID: agendaID,
ChoiceID: "abstain", // default to abstain as current choice if not found in wallet
currentChoice, ok := choices[agendaID]
if ok && currentChoice == strings.ToLower(choiceID) {
// Do not set the same choice again
return nil
}
Comment on lines +114 to 117
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be necessary to continue even if it's the same value? Below, the specified ticket or all unvoted tickets are updated with the vsp to use this choice. I'm wondering if it's possible that a ticket in that list doesn't already have the correct vote choice set with the vsp.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of this is to prevent unnecessary API calls. It does this by preventing the existing choice being set again.
I don't think setting the same choice again is necessary.


for i := range choices {
if choices[i].AgendaID == agendaID {
currentChoice.ChoiceID = choices[i].ChoiceID
break
}
if !ok {
// Default to abstain if no previous choice existed
currentChoice = "abstain"
}

newChoice := w.AgendaChoice{
AgendaID: agendaID,
ChoiceID: strings.ToLower(choiceID),
}
currentChoiceMap := map[string]string{agendaID: currentChoice}
newChoiceMap := map[string]string{agendaID: strings.ToLower(choiceID)}

_, err = asset.Internal().DCR.SetAgendaChoices(ctx, ticketHash, newChoice)
_, err = asset.Internal().DCR.SetAgendaChoices(ctx, ticketHash, newChoiceMap)
if err != nil {
return err
}
Expand All @@ -138,7 +134,7 @@ func (asset *Asset) SetVoteChoice(agendaID, choiceID, hash, passphrase string) e
if !vspPreferenceUpdateSuccess {
// Updating the agenda voting preference with the vsp failed,
// revert the locally saved voting preference for the agenda.
_, revertError := asset.Internal().DCR.SetAgendaChoices(ctx, ticketHash, currentChoice)
_, revertError := asset.Internal().DCR.SetAgendaChoices(ctx, ticketHash, currentChoiceMap)
if revertError != nil {
log.Errorf("unable to revert locally saved voting preference: %v", revertError)
}
Expand Down Expand Up @@ -181,7 +177,7 @@ func (asset *Asset) SetVoteChoice(agendaID, choiceID, hash, passphrase string) e
firstErr = err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the new dcrwallet commits since v3.0.1 abolished the concept of firstErr and returns any error encountered immediately. We should adopt that. Can possibly create a separate issue but generally, when upgrading the dcrwallet dep, I often do a comparison of the code changes between the last version in our go.mod and the new version we're introducing. The comparison for this version bump is https://github.com/decred/dcrwallet/compare/v3.0.1..a87fa843495e (file changes) and decred/dcrwallet@v3.0.1...a87fa84 (commits).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done app wide so a separate issue can best address this.

continue // try next tHash
}
err = vspClient.SetVoteChoice(ctx, tHash, []w.AgendaChoice{newChoice}, nil, nil)
err = vspClient.SetVoteChoice(ctx, tHash, newChoiceMap, nil, nil)
if err != nil && firstErr == nil {
firstErr = err
continue // try next tHash
Expand Down Expand Up @@ -245,9 +241,9 @@ func (asset *Asset) AllVoteAgendas(hash string, newestFirst bool) ([]*Agenda, er
d := &deployments[i]

votingPreference := "abstain" // assume abstain, if we have the saved pref, it'll be updated below
for c := range choices {
if choices[c].AgendaID == d.Vote.Id {
votingPreference = choices[c].ChoiceID
for agendaID, choiceID := range choices {
if agendaID == d.Vote.Id {
votingPreference = choiceID
break
}
}
Comment on lines +244 to 249
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This look correct?
votingPreference = choices[d.Vote.Id]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is double query; during the map for loop, choices[d.Vote.Id] already exists as choiceID.

Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/dcr/decodetx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dcr
import (
"fmt"

w "decred.org/dcrwallet/v3/wallet"
w "decred.org/dcrwallet/v4/wallet"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/txhelper"
"github.com/decred/dcrd/blockchain/stake/v5"
Expand Down
4 changes: 2 additions & 2 deletions libwallet/assets/dcr/message.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dcr

import (
"decred.org/dcrwallet/v3/errors"
w "decred.org/dcrwallet/v3/wallet"
"decred.org/dcrwallet/v4/errors"
w "decred.org/dcrwallet/v4/wallet"
"github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/decred/dcrd/txscript/v4/stdaddr"
)
Expand Down
4 changes: 2 additions & 2 deletions libwallet/assets/dcr/rescan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"math"
"time"

"decred.org/dcrwallet/v3/errors"
w "decred.org/dcrwallet/v3/wallet"
"decred.org/dcrwallet/v4/errors"
w "decred.org/dcrwallet/v4/wallet"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/utils"
)
Expand Down
8 changes: 4 additions & 4 deletions libwallet/assets/dcr/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"strings"
"sync"

"decred.org/dcrwallet/v3/errors"
"decred.org/dcrwallet/v3/p2p"
"decred.org/dcrwallet/v3/spv"
w "decred.org/dcrwallet/v3/wallet"
"decred.org/dcrwallet/v4/errors"
"decred.org/dcrwallet/v4/p2p"
"decred.org/dcrwallet/v4/spv"
w "decred.org/dcrwallet/v4/wallet"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/decred/dcrd/addrmgr/v2"
Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/dcr/syncnotification.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math"
"time"

"decred.org/dcrwallet/v3/spv"
"decred.org/dcrwallet/v4/spv"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"golang.org/x/sync/errgroup"
)
Expand Down
Loading