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

add generatevote #647

Merged
merged 3 commits into from
Apr 7, 2017
Merged

add generatevote #647

merged 3 commits into from
Apr 7, 2017

Conversation

jolan
Copy link
Contributor

@jolan jolan commented Apr 7, 2017

I'm using this for stakepoold to vote w/proper votebits rather than depending on dcrwallet to do so. This is my first RPC so I definitely might have missed something. It does work fine in my testing. Also not sure if it should be modified to allow processing multiple votes at a time or not. In practice a stake pool voting more than once per block shouldn't happen very often.

Needs:

decred/dcrd#652
decred/dcrrpcclient#57

Closes #646.

@jolan jolan merged commit a2543c2 into decred:master Apr 7, 2017
@jolan jolan deleted the jolan_generatevote branch April 7, 2017 18:31
stakemgrNs := tx.ReadWriteBucket(wstakemgrNamespaceKey)
addrmgrNs := tx.ReadBucket(waddrmgrNamespaceKey)

shit, err := w.StakeMgr.GenerateVoteTx(stakemgrNs, addrmgrNs, blockHash, height, sstxHash, voteBits)
Copy link
Member

Choose a reason for hiding this comment

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

shit? Surely this is not shit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The one time I happen to do that and I forget to take it out 😊

if err != nil {
return err
}
msgtx = shit
Copy link

Choose a reason for hiding this comment

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

Mutating outer variable doesn't look right to me. But I guess this can only be fixed with changing walletdb.Update API.

Copy link
Member

Choose a reason for hiding this comment

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

*msgtx = *shit?

Copy link
Member

Choose a reason for hiding this comment

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

In any case, the closure captures by reference so you can modify the msgtx variable directly.
https://play.golang.org/p/_1gs8wly1W

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this isn't a bug. I added the View/Update apis and would have made it a lot nicer when trying to return data out of the functions, but this is sadly not possible to do in a type safe way without generics.

For example, if we could specify a generic type parameter T, the update func signature could be:

func Update(db DB, func(tx ReadWriteTx) T) T

and then it would not be required to close over value just to use it as what is effectively the update's return value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants