-
Notifications
You must be signed in to change notification settings - Fork 39
Upgrade dcrwallet to master branch (future version v4) #48
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
Changes from all commits
b87f8d5
5e1eee9
5f2fb01
860029e
b980746
c92100a
000de69
ccb3b21
e812b40
60d8e04
e431d1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| 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 | ||
| } | ||
|
|
@@ -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) | ||
| } | ||
|
|
@@ -181,7 +177,7 @@ func (asset *Asset) SetVoteChoice(agendaID, choiceID, hash, passphrase string) e | |
| firstErr = err | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the new dcrwallet commits since
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This look correct?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is double query; during the map for loop, |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.