@@ -102,7 +102,10 @@ static void WalletTxToJSON(interfaces::Chain& chain, interfaces::Chain::Lock& lo
102
102
{
103
103
entry.pushKV (" blockhash" , wtx.hashBlock .GetHex ());
104
104
entry.pushKV (" blockindex" , wtx.nIndex );
105
- entry.pushKV (" blocktime" , LookupBlockIndex (wtx.hashBlock )->GetBlockTime ());
105
+ int64_t block_time;
106
+ bool found_block = chain.findBlock (wtx.hashBlock , nullptr /* block */ , &block_time);
107
+ assert (found_block);
108
+ entry.pushKV (" blocktime" , block_time);
106
109
} else {
107
110
entry.pushKV (" trusted" , wtx.IsTrusted (locked_chain));
108
111
}
@@ -1573,24 +1576,18 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
1573
1576
auto locked_chain = pwallet->chain ().lock ();
1574
1577
LOCK (pwallet->cs_wallet );
1575
1578
1576
- const CBlockIndex* pindex = nullptr ; // Block index of the specified block or the common ancestor, if the block provided was in a deactivated chain.
1577
- const CBlockIndex* paltindex = nullptr ; // Block index of the specified block, even if it's in a deactivated chain.
1579
+ Optional< int > height ; // Height of the specified block or the common ancestor, if the block provided was in a deactivated chain.
1580
+ Optional< int > altheight ; // Height of the specified block, even if it's in a deactivated chain.
1578
1581
int target_confirms = 1 ;
1579
1582
isminefilter filter = ISMINE_SPENDABLE;
1580
1583
1584
+ uint256 blockId;
1581
1585
if (!request.params [0 ].isNull () && !request.params [0 ].get_str ().empty ()) {
1582
- uint256 blockId (ParseHashV (request.params [0 ], " blockhash" ));
1583
-
1584
- paltindex = pindex = LookupBlockIndex (blockId);
1585
- if (!pindex) {
1586
+ blockId = ParseHashV (request.params [0 ], " blockhash" );
1587
+ height = locked_chain->findFork (blockId, &altheight);
1588
+ if (!height) {
1586
1589
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found" );
1587
1590
}
1588
- if (chainActive[pindex->nHeight ] != pindex) {
1589
- // the block being asked for is a part of a deactivated chain;
1590
- // we don't want to depend on its perceived height in the block
1591
- // chain, we want to instead use the last common ancestor
1592
- pindex = chainActive.FindFork (pindex);
1593
- }
1594
1591
}
1595
1592
1596
1593
if (!request.params [1 ].isNull ()) {
@@ -1608,7 +1605,7 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
1608
1605
bool include_removed = (request.params [3 ].isNull () || request.params [3 ].get_bool ());
1609
1606
1610
1607
const Optional<int > tip_height = locked_chain->getHeight ();
1611
- int depth = tip_height && pindex ? (1 + *tip_height - pindex-> nHeight ) : -1 ;
1608
+ int depth = tip_height && height ? (1 + *tip_height - *height ) : -1 ;
1612
1609
1613
1610
UniValue transactions (UniValue::VARR);
1614
1611
@@ -1623,9 +1620,9 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
1623
1620
// when a reorg'd block is requested, we also list any relevant transactions
1624
1621
// in the blocks of the chain that was detached
1625
1622
UniValue removed (UniValue::VARR);
1626
- while (include_removed && paltindex && paltindex != pindex ) {
1623
+ while (include_removed && altheight && *altheight > *height ) {
1627
1624
CBlock block;
1628
- if (!ReadBlockFromDisk (block, paltindex, Params (). GetConsensus () )) {
1625
+ if (!pwallet-> chain (). findBlock (blockId, &block) || block. IsNull ( )) {
1629
1626
throw JSONRPCError (RPC_INTERNAL_ERROR, " Can't read block from disk" );
1630
1627
}
1631
1628
for (const CTransactionRef& tx : block.vtx ) {
@@ -1636,7 +1633,8 @@ static UniValue listsinceblock(const JSONRPCRequest& request)
1636
1633
ListTransactions (*locked_chain, pwallet, it->second , -100000000 , true , removed, filter, nullptr /* filter_label */ );
1637
1634
}
1638
1635
}
1639
- paltindex = paltindex->pprev ;
1636
+ blockId = block.hashPrevBlock ;
1637
+ --*altheight;
1640
1638
}
1641
1639
1642
1640
int last_height = tip_height ? *tip_height + 1 - target_confirms : -1 ;
0 commit comments