@@ -1270,25 +1270,39 @@ static bool CheckWalletOwnsScript(CWallet* pwallet, const CScript& script) {
1270
1270
}
1271
1271
#endif
1272
1272
1273
- static UniValue BuildDMNListEntry (CWallet* pwallet, const CDeterministicMN& dmn, bool detailed)
1273
+ static UniValue BuildDMNListEntry (CWallet* pwallet, const CDeterministicMN& dmn, bool detailed, const ChainstateManager& chainman, const CBlockIndex* pindex = nullptr )
1274
1274
{
1275
1275
if (!detailed) {
1276
1276
return dmn.proTxHash .ToString ();
1277
1277
}
1278
1278
1279
1279
UniValue o = dmn.ToJson ();
1280
1280
1281
+ CTransactionRef collateralTx{nullptr };
1281
1282
int confirmations = GetUTXOConfirmations (dmn.collateralOutpoint );
1283
+
1284
+ if (pindex != nullptr ) {
1285
+ if (confirmations > -1 ) {
1286
+ confirmations -= WITH_LOCK (cs_main, return chainman.ActiveChain ().Height ()) - pindex->nHeight ;
1287
+ } else {
1288
+ uint256 minedBlockHash;
1289
+ collateralTx = GetTransaction (/* pindex */ nullptr , /* mempool */ nullptr , dmn.collateralOutpoint .hash , Params ().GetConsensus (), minedBlockHash);
1290
+ const CBlockIndex* const pindexMined = WITH_LOCK (cs_main, return chainman.m_blockman .LookupBlockIndex (minedBlockHash));
1291
+ CHECK_NONFATAL (pindexMined != nullptr );
1292
+ CHECK_NONFATAL (pindex->GetAncestor (pindexMined->nHeight ) == pindexMined);
1293
+ confirmations = pindex->nHeight - pindexMined->nHeight + 1 ;
1294
+ }
1295
+ }
1282
1296
o.pushKV (" confirmations" , confirmations);
1283
1297
1284
1298
#ifdef ENABLE_WALLET
1285
1299
bool hasOwnerKey = CheckWalletOwnsKey (pwallet, dmn.pdmnState ->keyIDOwner );
1286
1300
bool hasVotingKey = CheckWalletOwnsKey (pwallet, dmn.pdmnState ->keyIDVoting );
1287
1301
1288
1302
bool ownsCollateral = false ;
1289
- uint256 tmpHashBlock;
1290
- CTransactionRef collateralTx = GetTransaction ( /* block_index */ nullptr , /* mempool */ nullptr , dmn. collateralOutpoint . hash , Params (). GetConsensus (), tmpHashBlock );
1291
- if (collateralTx) {
1303
+ if (Coin coin; GetUTXOCoin (dmn. collateralOutpoint , coin)) {
1304
+ ownsCollateral = CheckWalletOwnsScript (pwallet, coin. out . scriptPubKey );
1305
+ } else if (collateralTx != nullptr ) {
1292
1306
ownsCollateral = CheckWalletOwnsScript (pwallet, collateralTx->vout [dmn.collateralOutpoint .n ].scriptPubKey );
1293
1307
}
1294
1308
@@ -1366,7 +1380,7 @@ static UniValue protx_list(const JSONRPCRequest& request, const ChainstateManage
1366
1380
CheckWalletOwnsKey (wallet.get (), dmn.pdmnState ->keyIDVoting ) ||
1367
1381
CheckWalletOwnsScript (wallet.get (), dmn.pdmnState ->scriptPayout ) ||
1368
1382
CheckWalletOwnsScript (wallet.get (), dmn.pdmnState ->scriptOperatorPayout )) {
1369
- ret.push_back (BuildDMNListEntry (wallet.get (), dmn, detailed));
1383
+ ret.push_back (BuildDMNListEntry (wallet.get (), dmn, detailed, chainman ));
1370
1384
}
1371
1385
});
1372
1386
#endif
@@ -1389,7 +1403,7 @@ static UniValue protx_list(const JSONRPCRequest& request, const ChainstateManage
1389
1403
bool onlyEvoNodes = type == " evo" ;
1390
1404
mnList.ForEachMN (onlyValid, [&](const auto & dmn) {
1391
1405
if (onlyEvoNodes && dmn.nType != MnType::Evo) return ;
1392
- ret.push_back (BuildDMNListEntry (wallet.get (), dmn, detailed));
1406
+ ret.push_back (BuildDMNListEntry (wallet.get (), dmn, detailed, chainman ));
1393
1407
});
1394
1408
} else {
1395
1409
throw JSONRPCError (RPC_INVALID_PARAMETER, " invalid type specified" );
@@ -1404,6 +1418,7 @@ static void protx_info_help(const JSONRPCRequest& request)
1404
1418
" \n Returns detailed information about a deterministic masternode.\n " ,
1405
1419
{
1406
1420
GetRpcArg (" proTxHash" ),
1421
+ {" blockHash" , RPCArg::Type::STR_HEX, /* default*/ " (chain tip)" , " The hash of the block to get deterministic masternode state at" },
1407
1422
},
1408
1423
RPCResult{
1409
1424
RPCResult::Type::OBJ, " " , " Details about a specific deterministic masternode" ,
@@ -1417,7 +1432,7 @@ static void protx_info_help(const JSONRPCRequest& request)
1417
1432
}.Check (request);
1418
1433
}
1419
1434
1420
- static UniValue protx_info (const JSONRPCRequest& request)
1435
+ static UniValue protx_info (const JSONRPCRequest& request, const ChainstateManager& chainman )
1421
1436
{
1422
1437
protx_info_help (request);
1423
1438
@@ -1433,13 +1448,28 @@ static UniValue protx_info(const JSONRPCRequest& request)
1433
1448
g_txindex->BlockUntilSyncedToCurrentChain ();
1434
1449
}
1435
1450
1451
+ CBlockIndex* pindex{nullptr };
1452
+
1436
1453
uint256 proTxHash (ParseHashV (request.params [0 ], " proTxHash" ));
1437
- auto mnList = deterministicMNManager->GetListAtChainTip ();
1454
+
1455
+ if (request.params [1 ].isNull ()) {
1456
+ LOCK (cs_main);
1457
+ pindex = chainman.ActiveChain ().Tip ();
1458
+ } else {
1459
+ LOCK (cs_main);
1460
+ uint256 blockHash (ParseHashV (request.params [1 ], " blockHash" ));
1461
+ pindex = chainman.m_blockman .LookupBlockIndex (blockHash);
1462
+ if (pindex == nullptr ) {
1463
+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found" );
1464
+ }
1465
+ }
1466
+
1467
+ auto mnList = deterministicMNManager->GetListForBlock (pindex);
1438
1468
auto dmn = mnList.GetMN (proTxHash);
1439
1469
if (!dmn) {
1440
1470
throw JSONRPCError (RPC_INVALID_PARAMETER, strprintf (" %s not found" , proTxHash.ToString ()));
1441
1471
}
1442
- return BuildDMNListEntry (wallet.get (), *dmn, true );
1472
+ return BuildDMNListEntry (wallet.get (), *dmn, true , chainman, pindex );
1443
1473
}
1444
1474
1445
1475
static void protx_diff_help (const JSONRPCRequest& request)
@@ -1644,7 +1674,7 @@ static UniValue protx(const JSONRPCRequest& request)
1644
1674
if (command == " protxlist" ) {
1645
1675
return protx_list (new_request, chainman);
1646
1676
} else if (command == " protxinfo" ) {
1647
- return protx_info (new_request);
1677
+ return protx_info (new_request, chainman );
1648
1678
} else if (command == " protxdiff" ) {
1649
1679
return protx_diff (new_request, chainman);
1650
1680
} else if (command == " protxlistdiff" ) {
0 commit comments