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 custom reward address to createmasternode RPC #1941

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,8 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor {
node.creationHeight = height;
node.operatorType = obj.operatorType;
node.operatorAuthAddress = obj.operatorAuthAddress;
node.rewardAddressType = obj.rewardType;
Bushstar marked this conversation as resolved.
Show resolved Hide resolved
node.rewardAddress = obj.rewardAddress;

// Set masternode version2 after FC for new serialisation
if (height >= static_cast<uint32_t>(consensus.FortCanningHeight))
Expand Down
4 changes: 4 additions & 0 deletions src/masternodes/mn_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ struct CCreateMasterNodeMessage {
char operatorType;
CKeyID operatorAuthAddress;
uint16_t timelock{0};
char rewardType;
CKeyID rewardAddress;

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
Expand All @@ -249,6 +251,8 @@ struct CCreateMasterNodeMessage {
if (!s.eof()) {
READWRITE(timelock);
}
READWRITE(rewardType);
Bushstar marked this conversation as resolved.
Show resolved Hide resolved
READWRITE(rewardAddress);
}
};

Expand Down
10 changes: 10 additions & 0 deletions src/masternodes/rpc_masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -133,8 +134,10 @@ 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;
Copy link
Member

Choose a reason for hiding this comment

The 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;
{
Expand Down Expand Up @@ -165,7 +168,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) {
Copy link
Member

Choose a reason for hiding this comment

The 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)
Expand All @@ -175,6 +183,8 @@ UniValue createmasternode(const JSONRPCRequest& request)
metadata << timelock;
}

metadata << static_cast<char>(rewardDest.index()) << rewardAuthKey;

CScript scriptMeta;
scriptMeta << OP_RETURN << ToByteVector(metadata);

Expand Down