1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
crate::ix!();
/**
| CoinsView that brings transactions
| from a mempool into view.
|
| It does not check for spendings by memory
| pool transactions.
|
| Instead, it provides access to all Coins
| which are either unspent in the base
| CCoinsView, are outputs from any mempool
| transaction, or are tracked temporarily
| to allow transaction dependencies
| in package validation.
|
| This allows transaction replacement
| to work as expected, as you want to have
| all inputs "available" to check signatures,
| and any cycles in the dependency graph
| are checked directly in AcceptToMemoryPool.
|
| It also allows you to sign a double-spend
| directly in signrawtransactionwithkey
| and signrawtransactionwithwallet,
| as long as the conflicting transaction
| is not yet confirmed.
|
*/
pub struct CoinsViewMemPool {
base: CoinsViewBacked,
/**
| Coins made available by transactions
| being validated. Tracking these allows
| for package validation, since we can
| access transaction outputs without
| submitting them to mempool.
|
*/
temp_added: HashMap<OutPoint,Coin,SaltedOutpointHasher>,
mempool: Arc<TxMemPool>,
}
impl CoinsViewMemPool {
pub fn new(
base_in: *mut Box<dyn CoinsView>,
mempool_in: &TxMemPool) -> Self {
todo!();
/*
: coins_view_backed(baseIn),
: mempool(mempoolIn),
*/
}
pub fn get_coin(&self,
outpoint: &OutPoint,
coin: &mut Coin) -> bool {
todo!();
/*
// Check to see if the inputs are made available by another tx in the package.
// These Coins would not be available in the underlying CoinsView.
if (auto it = m_temp_added.find(outpoint); it != m_temp_added.end()) {
coin = it->second;
return true;
}
// If an entry in the mempool exists, always return that one, as it's guaranteed to never
// conflict with the underlying cache, and it cannot have pruned entries (as it contains full)
// transactions. First checking the underlying cache risks returning a pruned entry instead.
CTransactionRef ptx = mempool.get(outpoint.hash);
if (ptx) {
if (outpoint.n < ptx->vout.size()) {
coin = Coin(ptx->vout[outpoint.n], MEMPOOL_HEIGHT, false);
return true;
} else {
return false;
}
}
return base->GetCoin(outpoint, coin);
*/
}
/**
| Add the coins created by this transaction.
| These coins are only temporarily stored
| in m_temp_added and cannot be flushed
| to the back end. Only used for package
| validation.
|
*/
pub fn package_add_transaction(&mut self, tx: &TransactionRef) {
todo!();
/*
for (unsigned int n = 0; n < tx->vout.size(); ++n) {
m_temp_added.emplace(OutPoint(tx->GetHash(), n), Coin(tx->vout[n], MEMPOOL_HEIGHT, false));
}
*/
}
}