-
Notifications
You must be signed in to change notification settings - Fork 122
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
rpc: votegov: Add support for owner and operator address #1717
rpc: votegov: Add support for owner and operator address #1717
Conversation
src/masternodes/rpc_proposals.cpp
Outdated
@@ -449,7 +449,8 @@ UniValue votegov(const JSONRPCRequest &request) { | |||
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR, UniValue::VSTR, UniValue::VARR}, true); | |||
|
|||
auto propId = ParseHashV(request.params[0].get_str(), "proposalId"); | |||
auto mnId = ParseHashV(request.params[1].get_str(), "masternodeId"); | |||
std::string id = request.params[1].get_str(); | |||
uint256 mnId = uint256(); |
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.
Note that you only need as uint256 will default initialise itself as the class has a default constructor.
uint256 mnId;
src/masternodes/rpc_proposals.cpp
Outdated
auto node = view.GetMasternode(mnId); | ||
if (!node) { | ||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("The masternode %s does not exist", mnId.ToString())); | ||
if (id.length() == 34) { |
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.
Address can be 26-35 chars long for P2PKH and 42 for P2WPKH. I'd work on getting the correct mnId before calling GetMasternode.
src/masternodes/rpc_proposals.cpp
Outdated
auto node = view.GetMasternode(mnId); | ||
if (!node) { | ||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("The masternode %s does not exist", mnId.ToString())); | ||
if (id.length() == 34) { | ||
CTxDestination dest = DecodeDestination(id); |
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.
You need to call IsValidDestination on dest to make sure it is valid. You can do this in the else statement.
if (id.length() == 64) {
mnId = ParseHashV(id, "masternodeId");
} else {
CTxDestination dest = DecodeDestination(id);
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_PARAMETER,
strprintf("The masternode id or address is not valid: %s", id));
}
// Call GetMasternodeIdByOwner and GetMasternodeIdByOperator here.
}
src/masternodes/rpc_proposals.cpp
Outdated
const CKeyID ckeyId = dest.index() == PKHashType ? CKeyID(std::get<PKHash>(dest)) : CKeyID(std::get<WitnessV0KeyHash>(dest)); | ||
auto masterNodeIdByOwner = view.GetMasternodeIdByOwner(ckeyId); | ||
if (!masterNodeIdByOwner) { | ||
auto masterNodeIdByOperator = view.GetMasternodeIdByOperator(ckeyId); |
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.
Check that masterNodeIdByOperator
is valid or you will get a std::bad_optional_access
thrown on masterNodeIdByOperator.value()
. I'd structure it like the following:
if (auto masterNodeIdByOwner = view.GetMasternodeIdByOwner(ckeyId)) {
mnId = masterNodeIdByOwner.value();
} else if (auto masterNodeIdByOperator = view.GetMasternodeIdByOperator(ckeyId)) {
mnId = masterNodeIdByOperator.value();
}
src/masternodes/rpc_proposals.cpp
Outdated
throw JSONRPCError(RPC_INVALID_PARAMETER, | ||
strprintf("The masternode id or address is not valid: %s", id)); | ||
} | ||
const CKeyID ckeyId = dest.index() == PKHashType ? CKeyID(std::get<PKHash>(dest)) : CKeyID(std::get<WitnessV0KeyHash>(dest)); |
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.
We need to make sure that the provided address is either P2PKH or a P2WPKH, otherwise if someone passes a different variant then std::get
will throw a std::bad_variant_access
.
const CKeyID ckeyId = dest.index() == PKHashType ? CKeyID(std::get<PKHash>(dest))
: dest.index() == WitV0KeyHashType ? CKeyID(std::get<WitnessV0KeyHash>(dest))
: CKeyID();
src/masternodes/rpc_proposals.cpp
Outdated
throw JSONRPCError(RPC_INVALID_PARAMETER, | ||
strprintf("The masternode id or address is not valid: %s", id)); | ||
} | ||
const CKeyID ckeyId = dest.index() == PKHashType ? |
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.
A bit too hard to read IMO, better to break it down into if
s.
Summary
Enables support for address support on
votegov
to vote with an address in addition to the currently accepted masternode ID.How
Limitations