fix(rpc): masternode outputs should work correctly with multiple outputs created via a single tx (#4967)

* fix(rpc): `masternode outputs` should produce an array

or it would ignore all but 1 outputs produced by the same tx

* rpc: improve `masternode outputs` help

* tests: check that `masternode outputs` show all outputs produced in the same tx
This commit is contained in:
UdjinM6 2022-08-31 13:32:35 +03:00 committed by GitHub
parent 175323836a
commit b30005d246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -181,7 +181,11 @@ static void masternode_outputs_help(const JSONRPCRequest& request)
RPCHelpMan{"masternode outputs",
"Print masternode compatible outputs\n",
{},
RPCResults{},
RPCResult {
RPCResult::Type::ARR, "", "A list of outpoints that can be/are used as masternode collaterals",
{
{RPCResult::Type::STR, "", "A (potential) masternode collateral"},
}},
RPCExamples{""}
}.Check(request);
}
@ -202,12 +206,12 @@ static UniValue masternode_outputs(const JSONRPCRequest& request)
LOCK(pwallet->cs_wallet);
pwallet->AvailableCoins(vPossibleCoins, true, &coin_control);
}
UniValue obj(UniValue::VOBJ);
UniValue outputsArr(UniValue::VARR);
for (const auto& out : vPossibleCoins) {
obj.pushKV(out.tx->GetHash().ToString(), strprintf("%d", out.i));
outputsArr.push_back(out.GetInputCoin().outpoint.ToStringShort());
}
return obj;
return outputsArr;
}
#endif // ENABLE_WALLET

View File

@ -66,6 +66,13 @@ class RPCMasternodeTest(DashTestFramework):
assert_equal(gbt_masternode[i]["script"], payments_masternode["payees"][i]["script"])
assert_equal(gbt_masternode[i]["amount"], payments_masternode["payees"][i]["amount"])
self.log.info("test that `masternode outputs` show correct list")
addr1 = self.nodes[0].getnewaddress()
addr2 = self.nodes[0].getnewaddress()
self.nodes[0].sendmany('', {addr1: 1000, addr2: 1000})
self.nodes[0].generate(1)
# we have 3 masternodes that are running already and 2 new outputs we just created
assert_equal(len(self.nodes[0].masternode("outputs")), 5)
if __name__ == '__main__':
RPCMasternodeTest().main()