Backport 2618 to v0.13.0.x (#2619)

Add owner and voting addresses to rpc output, unify it across different methods.
Also fix keyid option in `masternode list` rpc.
This commit is contained in:
UdjinM6 2019-01-11 12:53:54 +03:00 committed by GitHub
parent a3b01dfbe5
commit 18e1edabff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 48 deletions

View File

@ -496,7 +496,7 @@ class DIP3Test(BitcoinTestFramework):
for node in self.nodes:
protx_info = node.protx('info', mn.protx_hash)
mn_list = node.masternode('list')
assert_equal(protx_info['state']['addr'], '127.0.0.2:%d' % mn.p2p_port)
assert_equal(protx_info['state']['service'], '127.0.0.2:%d' % mn.p2p_port)
assert_equal(mn_list['%s-%d' % (mn.collateral_txid, mn.collateral_vout)]['address'], '127.0.0.2:%d' % mn.p2p_port)
# undo

View File

@ -27,45 +27,43 @@ std::string CDeterministicMNState::ToString() const
{
CTxDestination dest;
std::string payoutAddress = "unknown";
std::string operatorRewardAddress = "none";
std::string operatorPayoutAddress = "none";
if (ExtractDestination(scriptPayout, dest)) {
payoutAddress = CBitcoinAddress(dest).ToString();
}
if (ExtractDestination(scriptOperatorPayout, dest)) {
operatorRewardAddress = CBitcoinAddress(dest).ToString();
operatorPayoutAddress = CBitcoinAddress(dest).ToString();
}
return strprintf("CDeterministicMNState(nRegisteredHeight=%d, nLastPaidHeight=%d, nPoSePenalty=%d, nPoSeRevivedHeight=%d, nPoSeBanHeight=%d, nRevocationReason=%d, "
"keyIDOwner=%s, pubKeyOperator=%s, keyIDVoting=%s, addr=%s, payoutAddress=%s, operatorRewardAddress=%s)",
"ownerAddress=%s, pubKeyOperator=%s, votingAddress=%s, addr=%s, payoutAddress=%s, operatorPayoutAddress=%s)",
nRegisteredHeight, nLastPaidHeight, nPoSePenalty, nPoSeRevivedHeight, nPoSeBanHeight, nRevocationReason,
keyIDOwner.ToString(), pubKeyOperator.ToString(), keyIDVoting.ToString(), addr.ToStringIPPort(false), payoutAddress, operatorRewardAddress);
CBitcoinAddress(keyIDOwner).ToString(), pubKeyOperator.ToString(), CBitcoinAddress(keyIDVoting).ToString(), addr.ToStringIPPort(false), payoutAddress, operatorPayoutAddress);
}
void CDeterministicMNState::ToJson(UniValue& obj) const
{
obj.clear();
obj.setObject();
obj.push_back(Pair("service", addr.ToStringIPPort(false)));
obj.push_back(Pair("registeredHeight", nRegisteredHeight));
obj.push_back(Pair("lastPaidHeight", nLastPaidHeight));
obj.push_back(Pair("PoSePenalty", nPoSePenalty));
obj.push_back(Pair("PoSeRevivedHeight", nPoSeRevivedHeight));
obj.push_back(Pair("PoSeBanHeight", nPoSeBanHeight));
obj.push_back(Pair("revocationReason", nRevocationReason));
obj.push_back(Pair("keyIDOwner", keyIDOwner.ToString()));
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
obj.push_back(Pair("keyIDVoting", keyIDVoting.ToString()));
obj.push_back(Pair("ownerKeyAddr", CBitcoinAddress(keyIDOwner).ToString()));
obj.push_back(Pair("votingKeyAddr", CBitcoinAddress(keyIDVoting).ToString()));
obj.push_back(Pair("addr", addr.ToStringIPPort(false)));
obj.push_back(Pair("ownerAddress", CBitcoinAddress(keyIDOwner).ToString()));
obj.push_back(Pair("votingAddress", CBitcoinAddress(keyIDVoting).ToString()));
CTxDestination dest;
if (ExtractDestination(scriptPayout, dest)) {
CBitcoinAddress bitcoinAddress(dest);
obj.push_back(Pair("payoutAddress", bitcoinAddress.ToString()));
CBitcoinAddress payoutAddress(dest);
obj.push_back(Pair("payoutAddress", payoutAddress.ToString()));
}
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
if (ExtractDestination(scriptOperatorPayout, dest)) {
CBitcoinAddress bitcoinAddress(dest);
obj.push_back(Pair("operatorRewardAddress", bitcoinAddress.ToString()));
CBitcoinAddress operatorPayoutAddress(dest);
obj.push_back(Pair("operatorPayoutAddress", operatorPayoutAddress.ToString()));
}
}

View File

@ -417,8 +417,8 @@ std::string CProRegTx::ToString() const
payee = CBitcoinAddress(dest).ToString();
}
return strprintf("CProRegTx(nVersion=%d, collateralOutpoint=%s, addr=%s, nOperatorReward=%f, keyIDOwner=%s, pubKeyOperator=%s, keyIDVoting=%s, scriptPayout=%s)",
nVersion, collateralOutpoint.ToStringShort(), addr.ToString(), (double)nOperatorReward / 100, keyIDOwner.ToString(), pubKeyOperator.ToString(), keyIDVoting.ToString(), payee);
return strprintf("CProRegTx(nVersion=%d, collateralOutpoint=%s, addr=%s, nOperatorReward=%f, ownerAddress=%s, pubKeyOperator=%s, votingAddress=%s, scriptPayout=%s)",
nVersion, collateralOutpoint.ToStringShort(), addr.ToString(), (double)nOperatorReward / 100, CBitcoinAddress(keyIDOwner).ToString(), pubKeyOperator.ToString(), CBitcoinAddress(keyIDVoting).ToString(), payee);
}
void CProRegTx::ToJson(UniValue& obj) const
@ -429,15 +429,15 @@ void CProRegTx::ToJson(UniValue& obj) const
obj.push_back(Pair("collateralHash", collateralOutpoint.hash.ToString()));
obj.push_back(Pair("collateralIndex", (int)collateralOutpoint.n));
obj.push_back(Pair("service", addr.ToString(false)));
obj.push_back(Pair("keyIDOwner", keyIDOwner.ToString()));
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
obj.push_back(Pair("keyIDVoting", keyIDVoting.ToString()));
obj.push_back(Pair("ownerAddress", CBitcoinAddress(keyIDOwner).ToString()));
obj.push_back(Pair("votingAddress", CBitcoinAddress(keyIDVoting).ToString()));
CTxDestination dest;
if (ExtractDestination(scriptPayout, dest)) {
CBitcoinAddress bitcoinAddress(dest);
obj.push_back(Pair("payoutAddress", bitcoinAddress.ToString()));
}
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
obj.push_back(Pair("operatorReward", (double)nOperatorReward / 100));
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
@ -478,8 +478,8 @@ std::string CProUpRegTx::ToString() const
payee = CBitcoinAddress(dest).ToString();
}
return strprintf("CProUpRegTx(nVersion=%d, proTxHash=%s, pubKeyOperator=%s, keyIDVoting=%s, payoutAddress=%s)",
nVersion, proTxHash.ToString(), pubKeyOperator.ToString(), keyIDVoting.ToString(), payee);
return strprintf("CProUpRegTx(nVersion=%d, proTxHash=%s, pubKeyOperator=%s, votingAddress=%s, payoutAddress=%s)",
nVersion, proTxHash.ToString(), pubKeyOperator.ToString(), CBitcoinAddress(keyIDVoting).ToString(), payee);
}
void CProUpRegTx::ToJson(UniValue& obj) const
@ -488,13 +488,13 @@ void CProUpRegTx::ToJson(UniValue& obj) const
obj.setObject();
obj.push_back(Pair("version", nVersion));
obj.push_back(Pair("proTxHash", proTxHash.ToString()));
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
obj.push_back(Pair("keyIDVoting", keyIDVoting.ToString()));
obj.push_back(Pair("votingAddress", CBitcoinAddress(keyIDVoting).ToString()));
CTxDestination dest;
if (ExtractDestination(scriptPayout, dest)) {
CBitcoinAddress bitcoinAddress(dest);
obj.push_back(Pair("payoutAddress", bitcoinAddress.ToString()));
}
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
obj.push_back(Pair("inputsHash", inputsHash.ToString()));
}

View File

@ -8,6 +8,7 @@
#include "simplifiedmns.h"
#include "specialtx.h"
#include "base58.h"
#include "chainparams.h"
#include "consensus/merkle.h"
#include "univalue.h"
@ -32,8 +33,8 @@ uint256 CSimplifiedMNListEntry::CalcHash() const
std::string CSimplifiedMNListEntry::ToString() const
{
return strprintf("CSimplifiedMNListEntry(proRegTxHash=%s, confirmedHash=%s, service=%s, pubKeyOperator=%s, keyIDVoting=%s, isValie=%d)",
proRegTxHash.ToString(), confirmedHash.ToString(), service.ToString(false), pubKeyOperator.ToString(), keyIDVoting.ToString(), isValid);
return strprintf("CSimplifiedMNListEntry(proRegTxHash=%s, confirmedHash=%s, service=%s, pubKeyOperator=%s, votingAddress=%s, isValie=%d)",
proRegTxHash.ToString(), confirmedHash.ToString(), service.ToString(false), pubKeyOperator.ToString(), CBitcoinAddress(keyIDVoting).ToString(), isValid);
}
void CSimplifiedMNListEntry::ToJson(UniValue& obj) const
@ -44,7 +45,7 @@ void CSimplifiedMNListEntry::ToJson(UniValue& obj) const
obj.push_back(Pair("confirmedHash", confirmedHash.ToString()));
obj.push_back(Pair("service", service.ToString(false)));
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.ToString()));
obj.push_back(Pair("keyIDVoting", keyIDVoting.ToString()));
obj.push_back(Pair("votingAddress", CBitcoinAddress(keyIDVoting).ToString()));
obj.push_back(Pair("isValid", isValid));
}

View File

@ -692,7 +692,7 @@ UniValue gobject_vote_alias(const JSONRPCRequest& request)
CKey votingKey;
if (!pwalletMain->GetKey(dmn->pdmnState->keyIDVoting, votingKey)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Voting ekey %s not known by wallet", CBitcoinAddress(dmn->pdmnState->keyIDVoting).ToString()));
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Private key for voting address %s not known by wallet", CBitcoinAddress(dmn->pdmnState->keyIDVoting).ToString()));
}
CBitcoinSecret secret(votingKey);

View File

@ -148,7 +148,8 @@ void masternode_list_help()
" lastpaidblock - Print the last block height a node was paid on the network\n"
" lastpaidtime - Print the last time a node was paid on the network\n"
" lastseen - Print timestamp of when a masternode was last seen on the network\n"
" payee - Print Dash address associated with a masternode (can be additionally filtered,\n"
" owneraddress - Print the masternode owner Dash address\n"
" payee - Print the masternode payout Dash address (can be additionally filtered,\n"
" partial match)\n"
" protocol - Print protocol of a masternode (can be additionally filtered, exact match)\n"
" keyid - Print the masternode (not collateral) key id\n"
@ -156,6 +157,7 @@ void masternode_list_help()
" sentinel - Print sentinel version of a masternode (can be additionally filtered, exact match)\n"
" status - Print masternode status: PRE_ENABLED / ENABLED / EXPIRED / SENTINEL_PING_EXPIRED / NEW_START_REQUIRED /\n"
" UPDATE_REQUIRED / POSE_BAN / OUTPOINT_SPENT (can be additionally filtered, partial match)\n"
" votingaddress - Print the masternode voting Dash address\n"
);
}
@ -855,6 +857,7 @@ UniValue masternodelist(const JSONRPCRequest& request)
if (request.fHelp || (
strMode != "activeseconds" && strMode != "addr" && strMode != "daemon" && strMode != "full" && strMode != "info" && strMode != "json" &&
strMode != "owneraddress" && strMode != "votingaddress" && strMode != "keyid" &&
strMode != "lastseen" && strMode != "lastpaidtime" && strMode != "lastpaidblock" &&
strMode != "protocol" && strMode != "payee" && strMode != "pubkey" &&
strMode != "rank" && strMode != "sentinel" && strMode != "status"))
@ -953,7 +956,7 @@ UniValue masternodelist(const JSONRPCRequest& request)
} else if (strMode == "json") {
std::ostringstream streamInfo;
streamInfo << mn.addr.ToString() << " " <<
CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString() << " " <<
payeeStr << " " <<
mn.GetStatus() << " " <<
mn.nProtocolVersion << " " <<
mn.lastPing.nDaemonVersion << " " <<
@ -968,7 +971,7 @@ UniValue masternodelist(const JSONRPCRequest& request)
strOutpoint.find(strFilter) == std::string::npos) continue;
UniValue objMN(UniValue::VOBJ);
objMN.push_back(Pair("address", mn.addr.ToString()));
objMN.push_back(Pair("payee", CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString()));
objMN.push_back(Pair("payee", payeeStr));
objMN.push_back(Pair("status", mn.GetStatus()));
objMN.push_back(Pair("protocol", mn.nProtocolVersion));
objMN.push_back(Pair("daemonversion", mn.lastPing.GetDaemonString()));
@ -978,7 +981,12 @@ UniValue masternodelist(const JSONRPCRequest& request)
objMN.push_back(Pair("activeseconds", (int64_t)(mn.lastPing.sigTime - mn.sigTime)));
objMN.push_back(Pair("lastpaidtime", mn.GetLastPaidTime()));
objMN.push_back(Pair("lastpaidblock", mn.GetLastPaidBlock()));
objMN.push_back(Pair("owneraddress", CBitcoinAddress(mn.keyIDOwner).ToString()));
objMN.push_back(Pair("votingaddress", CBitcoinAddress(mn.keyIDVoting).ToString()));
obj.push_back(Pair(strOutpoint, objMN));
} else if (strMode == "keyid") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, HexStr(mn.legacyKeyIDOperator)));
} else if (strMode == "lastpaidblock") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, mn.GetLastPaidBlock()));
@ -988,6 +996,9 @@ UniValue masternodelist(const JSONRPCRequest& request)
} else if (strMode == "lastseen") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, (int64_t)mn.lastPing.sigTime));
} else if (strMode == "owneraddress") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, CBitcoinAddress(mn.keyIDOwner).ToString()));
} else if (strMode == "payee") {
if (strFilter !="" && payeeStr.find(strFilter) == std::string::npos &&
strOutpoint.find(strFilter) == std::string::npos) continue;
@ -996,20 +1007,14 @@ UniValue masternodelist(const JSONRPCRequest& request)
if (strFilter !="" && strFilter != strprintf("%d", mn.nProtocolVersion) &&
strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, mn.nProtocolVersion));
} else if (strMode == "keyIDOwner") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, HexStr(mn.keyIDOwner)));
} else if (strMode == "keyIDOperator") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, HexStr(mn.legacyKeyIDOperator)));
} else if (strMode == "keyIDVoting") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, HexStr(mn.keyIDVoting)));
} else if (strMode == "status") {
std::string strStatus = mn.GetStatus();
if (strFilter !="" && strStatus.find(strFilter) == std::string::npos &&
strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, strStatus));
} else if (strMode == "votingaddress") {
if (strFilter !="" && strOutpoint.find(strFilter) == std::string::npos) continue;
obj.push_back(Pair(strOutpoint, CBitcoinAddress(mn.keyIDVoting).ToString()));
}
}
}

View File

@ -224,7 +224,7 @@ static std::string SignAndSendSpecialTx(const CMutableTransaction& tx)
void protx_register_fund_help()
{
throw std::runtime_error(
"protx register_fund \"collateralAddress\" \"ipAndPort\" \"ownerKeyAddr\" \"operatorPubKey\" \"votingKeyAddr\" operatorReward \"payoutAddress\" ( \"fundAddress\" )\n"
"protx register_fund \"collateralAddress\" \"ipAndPort\" \"ownerAddress\" \"operatorPubKey\" \"votingAddress\" operatorReward \"payoutAddress\" ( \"fundAddress\" )\n"
"\nCreates, funds and sends a ProTx to the network. The resulting transaction will move 1000 Dash\n"
"to the address specified by collateralAddress and will then function as the collateral of your\n"
"masternode.\n"
@ -235,12 +235,12 @@ void protx_register_fund_help()
" Must be a P2PKH address.\n"
"2. \"ipAndPort\" (string, required) IP and port in the form \"IP:PORT\".\n"
" Must be unique on the network. Can be set to 0, which will require a ProUpServTx afterwards.\n"
"3. \"ownerKeyAddr\" (string, required) The owner key used for payee updates and proposal voting.\n"
"3. \"ownerAddress\" (string, required) The owner key used for payee updates and proposal voting.\n"
" The private key belonging to this address must be known in your wallet. The address must\n"
" be unused and must differ from the collateralAddress\n"
"4. \"operatorPubKey\" (string, required) The operator BLS public key. The private key does not have to be known.\n"
" It has to match the private key which is later used when operating the masternode.\n"
"5. \"votingKeyAddr\" (string, required) The voting key address. The private key does not have to be known by your wallet.\n"
"5. \"votingAddress\" (string, required) The voting key address. The private key does not have to be known by your wallet.\n"
" It has to match the private key which is later used when voting on proposals.\n"
" If set to \"0\" or an empty string, ownerAddr will be used.\n"
"6. \"operatorReward\" (numeric, required) The fraction in % to share with the operator. The value must be\n"
@ -257,7 +257,7 @@ void protx_register_fund_help()
void protx_register_help()
{
throw std::runtime_error(
"protx register \"collateralHash\" collateralIndex \"ipAndPort\" \"ownerKeyAddr\" \"operatorPubKey\" \"votingKeyAddr\" operatorReward \"payoutAddress\" ( \"feeSourceAddress\" )\n"
"protx register \"collateralHash\" collateralIndex \"ipAndPort\" \"ownerAddress\" \"operatorPubKey\" \"votingAddress\" operatorReward \"payoutAddress\" ( \"feeSourceAddress\" )\n"
"\nSame as \"protx register_fund\", but with an externally referenced collateral.\n"
"The collateral is specified through \"collateralHash\" and \"collateralIndex\" and must be an unspent\n"
"transaction output. It must also not be used by any other masternode.\n"
@ -274,7 +274,7 @@ void protx_register_help()
void protx_register_prepare_help()
{
throw std::runtime_error(
"protx register_prepare \"collateralHash\" collateralIndex \"ipAndPort\" \"ownerKeyAddr\" \"operatorPubKey\" \"votingKeyAddr\" operatorReward \"payoutAddress\" ( \"feeSourceAddress\" )\n"
"protx register_prepare \"collateralHash\" collateralIndex \"ipAndPort\" \"ownerAddress\" \"operatorPubKey\" \"votingAddress\" operatorReward \"payoutAddress\" ( \"feeSourceAddress\" )\n"
"\nCreates an unsigned ProTx and returns it. The ProTx must be signed externally with the collateral\n"
"key and then passed to \"protx register_submit\". The prepared transaction will also contain inputs\n"
"and outputs to cover fees.\n"
@ -577,7 +577,7 @@ UniValue protx_update_service(const JSONRPCRequest& request)
void protx_update_registrar_help()
{
throw std::runtime_error(
"protx update_registrar \"proTxHash\" \"operatorKeyAddr\" \"votingKeyAddr\" \"payoutAddress\" ( \"feeSourceAddress\" )\n"
"protx update_registrar \"proTxHash\" \"operatorPubKey\" \"votingAddress\" \"payoutAddress\" ( \"feeSourceAddress\" )\n"
"\nCreates and sends a ProUpRegTx to the network. This will update the operator key, voting key and payout\n"
"address of the masternode specified by \"proTxHash\".\n"
"The owner key of the masternode must be known to your wallet.\n"
@ -586,7 +586,7 @@ void protx_update_registrar_help()
"2. \"operatorPubKey\" (string, required) The operator public key. The private key does not have to be known by you.\n"
" It has to match the private key which is later used when operating the masternode.\n"
" If set to \"0\" or an empty string, the last on-chain operator key of the masternode will be used.\n"
"3. \"votingKeyAddr\" (string, required) The voting key address. The private key does not have to be known by your wallet.\n"
"3. \"votingAddress\" (string, required) The voting key address. The private key does not have to be known by your wallet.\n"
" It has to match the private key which is later used when voting on proposals.\n"
" If set to \"0\" or an empty string, the last on-chain voting key of the masternode will be used.\n"
"4. \"payoutAddress\" (string, required) The dash address to use for masternode reward payments\n"
@ -632,7 +632,7 @@ UniValue protx_update_registrar(const JSONRPCRequest& request)
CKey keyOwner;
if (!pwalletMain->GetKey(dmn->pdmnState->keyIDOwner, keyOwner)) {
throw std::runtime_error(strprintf("owner key %s not found in your wallet", dmn->pdmnState->keyIDOwner.ToString()));
throw std::runtime_error(strprintf("Private key for owner address %s not found in your wallet", CBitcoinAddress(dmn->pdmnState->keyIDOwner).ToString()));
}
CMutableTransaction tx;