-
Notifications
You must be signed in to change notification settings - Fork 118
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 custom reward address to createmasternode
RPC
#1941
Changes from 9 commits
8cce184
43599c4
28699d1
0cfd26d
61458c3
a8f2b4b
a441aad
049f229
d19caa1
b25730c
2a6bf21
9046b53
bc6a47f
88fd8ab
c7b2194
e1803b9
6bbcde6
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 |
---|---|---|
|
@@ -109,6 +109,7 @@ UniValue createmasternode(const JSONRPCRequest& request) | |
"specify either FIVEYEARTIMELOCK or TENYEARTIMELOCK to create a masternode that cannot be resigned for\n" | ||
"five or ten years and will have 1.5x or 2.0 the staking power respectively. Be aware that this means\n" | ||
"that you cannot spend the collateral used to create a masternode for whatever period is specified."}, | ||
{"rewardAddress", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Masternode`s reward address"}, | ||
}, | ||
RPCResult{ | ||
"\"hash\" (string) The hex-encoded hash of broadcasted transaction\n" | ||
|
@@ -133,15 +134,23 @@ UniValue createmasternode(const JSONRPCRequest& request) | |
|
||
std::string ownerAddress = request.params[0].getValStr(); | ||
std::string operatorAddress = request.params.size() > 1 && !request.params[1].getValStr().empty() ? request.params[1].getValStr() : ownerAddress; | ||
std::string rewardAddress = !request.params[4].getValStr().empty() ? request.params[4].getValStr() : ownerAddress; | ||
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. Leave empty if no reward is set, so just get an empty string here, dest will be 0 which is the toggle as to whether to use the reward address or not. |
||
CTxDestination ownerDest = DecodeDestination(ownerAddress); // type will be checked on apply/create | ||
CTxDestination operatorDest = DecodeDestination(operatorAddress); | ||
CTxDestination rewardDest = DecodeDestination(rewardAddress); | ||
|
||
bool eunosPaya; | ||
{ | ||
LOCK(cs_main); | ||
eunosPaya = ::ChainActive().Tip()->nHeight >= Params().GetConsensus().EunosPayaHeight; | ||
} | ||
|
||
bool nextNetworkUpdate; | ||
{ | ||
LOCK(cs_main); | ||
nextNetworkUpdate = ::ChainActive().Tip()->nHeight >= Params().GetConsensus().NextNetworkUpgradeHeight; | ||
} | ||
|
||
// Get timelock if any | ||
uint16_t timelock{0}; | ||
if (!request.params[3].isNull()) { | ||
|
@@ -165,7 +174,12 @@ UniValue createmasternode(const JSONRPCRequest& request) | |
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Address (%s) is not owned by the wallet", EncodeDestination(ownerDest))); | ||
} | ||
|
||
if (rewardDest.index() != 1 && rewardDest.index() != 4) { | ||
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. Remove this check and let it happen on the consensus side. Reward will include type 2 as well on the next hard fork due to PR 1664. |
||
throw JSONRPCError(RPC_INVALID_PARAMETER, "rewardAddress (" + rewardAddress + ") does not refer to a P2PKH or P2WPKH address"); | ||
} | ||
|
||
CKeyID const operatorAuthKey = operatorDest.index() == 1 ? CKeyID(std::get<PKHash>(operatorDest)) : CKeyID(std::get<WitnessV0KeyHash>(operatorDest)); | ||
CKeyID const rewardAuthKey = rewardDest.index() == 1 ? CKeyID(std::get<PKHash>(rewardDest)) : CKeyID(std::get<WitnessV0KeyHash>(rewardDest)); | ||
|
||
CDataStream metadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION); | ||
metadata << static_cast<unsigned char>(CustomTxType::CreateMasternode) | ||
|
@@ -175,6 +189,10 @@ UniValue createmasternode(const JSONRPCRequest& request) | |
metadata << timelock; | ||
} | ||
|
||
if (nextNetworkUpdate) { | ||
metadata << static_cast<char>(rewardDest.index()) << rewardAuthKey; | ||
} | ||
|
||
CScript scriptMeta; | ||
scriptMeta << OP_RETURN << ToByteVector(metadata); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python3 | ||
"""Test the masternodes create RPC. | ||
|
||
- verify MN creation with custom reward address and resign | ||
""" | ||
|
||
from test_framework.test_framework import DefiTestFramework | ||
|
||
from test_framework.authproxy import JSONRPCException | ||
from test_framework.util import ( | ||
assert_equal, | ||
assert_raises_rpc_error, | ||
) | ||
|
||
|
||
class MasternodesRpcCreateRewardTest(DefiTestFramework): | ||
def set_test_params(self): | ||
self.num_nodes = 2 | ||
self.setup_clean_chain = True | ||
self.extra_args = [ | ||
['-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=50', '-dakotaheight=120', | ||
'-eunosheight=120', '-eunospayaheight=120', '-fortcanningheight=120', '-fortcanninghillheight=122', | ||
'-grandcentralheight=189', "-nextnetworkupgradeheight=120"], | ||
['-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=50', '-dakotaheight=120', | ||
'-eunosheight=120', '-eunospayaheight=120', '-fortcanningheight=120', '-fortcanninghillheight=122', | ||
'-grandcentralheight=189', '-txindex=1', "-nextnetworkupgradeheight=120"]] | ||
|
||
def run_test(self): | ||
assert_equal(len(self.nodes[0].listmasternodes()), 8) | ||
self.nodes[0].generate(100) | ||
self.sync_blocks() | ||
|
||
collateral0 = self.nodes[0].getnewaddress("", "legacy") | ||
|
||
# Fail to create: Insufficient funds (not matured coins) | ||
try: | ||
idnode0 = self.nodes[0].createmasternode( | ||
collateral0 | ||
) | ||
except JSONRPCException as e: | ||
errorString = e.error['message'] | ||
assert ("Insufficient funds" in errorString) | ||
|
||
# Create node0 | ||
self.nodes[0].generate(20) | ||
collateral1 = self.nodes[1].getnewaddress("", "legacy") | ||
reward = self.nodes[1].getnewaddress("reward", "legacy") | ||
assert_raises_rpc_error(-8, "Address ({}) is not owned by the wallet".format(collateral1), | ||
self.nodes[0].createmasternode, collateral1) | ||
|
||
# Fail to create: Wrong reward address | ||
try: | ||
self.nodes[0].createmasternode(collateral0, '', [], 'TENYEARTIMELOCK', "test") | ||
except JSONRPCException as e: | ||
errorString = e.error['message'] | ||
assert ("does not refer to a P2PKH or P2WPKH address" in errorString) | ||
|
||
idnode0 = self.nodes[0].createmasternode(collateral0, '', [], 'TENYEARTIMELOCK', reward) | ||
self.nodes[0].generate(1) | ||
assert_equal(self.nodes[0].listmasternodes()[idnode0]['rewardAddress'], reward) | ||
|
||
|
||
if __name__ == '__main__': | ||
MasternodesRpcCreateRewardTest().main() |
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 CMasternodesView::CreateMasternode add checks that the type is either NoDestType, PKHashType, ScriptHashType or WitV0KeyHashType, so 0, 1, 2 or 4.