-
Notifications
You must be signed in to change notification settings - Fork 156
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
add generatevote #647
Conversation
stakemgrNs := tx.ReadWriteBucket(wstakemgrNamespaceKey) | ||
addrmgrNs := tx.ReadBucket(waddrmgrNamespaceKey) | ||
|
||
shit, err := w.StakeMgr.GenerateVoteTx(stakemgrNs, addrmgrNs, blockHash, height, sstxHash, voteBits) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*msgtx = *shit
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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.