|
30 | 30 | #include <node/types.h> |
31 | 31 | #include <outputtype.h> |
32 | 32 | #include <policy/feerate.h> |
| 33 | +#include <policy/truc_policy.h> |
33 | 34 | #include <primitives/block.h> |
34 | 35 | #include <primitives/transaction.h> |
35 | 36 | #include <psbt.h> |
@@ -1388,6 +1389,22 @@ void CWallet::transactionAddedToMempool(const CTransactionRef& tx) { |
1388 | 1389 | return wtx.mempool_conflicts.insert(txid).second ? TxUpdate::CHANGED : TxUpdate::UNCHANGED; |
1389 | 1390 | }); |
1390 | 1391 | } |
| 1392 | + |
| 1393 | + } |
| 1394 | + |
| 1395 | + if (tx->version == TRUC_VERSION) { |
| 1396 | + // Unconfirmed TRUC transactions are only allowed a 1-parent-1-child topology. |
| 1397 | + // For any unconfirmed v3 parents (there should be a maximum of 1 except in reorgs), |
| 1398 | + // record this child so the wallet doesn't try to spend any other outputs |
| 1399 | + for (const CTxIn& tx_in : tx->vin) { |
| 1400 | + auto parent_it = mapWallet.find(tx_in.prevout.hash); |
| 1401 | + if (parent_it != mapWallet.end()) { |
| 1402 | + CWalletTx& parent_wtx = parent_it->second; |
| 1403 | + if (parent_wtx.isUnconfirmed()) { |
| 1404 | + parent_wtx.truc_child_in_mempool = tx->GetHash(); |
| 1405 | + } |
| 1406 | + } |
| 1407 | + } |
1391 | 1408 | } |
1392 | 1409 | } |
1393 | 1410 |
|
@@ -1441,6 +1458,22 @@ void CWallet::transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRe |
1441 | 1458 | }); |
1442 | 1459 | } |
1443 | 1460 | } |
| 1461 | + |
| 1462 | + if (tx->version == TRUC_VERSION) { |
| 1463 | + // If this tx has a parent, unset its truc_child_in_mempool to make it possible |
| 1464 | + // to spend from the parent again. If this tx was replaced by another |
| 1465 | + // child of the same parent, transactionAddedToMempool |
| 1466 | + // will update truc_child_in_mempool |
| 1467 | + for (const CTxIn& tx_in : tx->vin) { |
| 1468 | + auto parent_it = mapWallet.find(tx_in.prevout.hash); |
| 1469 | + if (parent_it != mapWallet.end()) { |
| 1470 | + CWalletTx& parent_wtx = parent_it->second; |
| 1471 | + if (parent_wtx.truc_child_in_mempool == tx->GetHash()) { |
| 1472 | + parent_wtx.truc_child_in_mempool = std::nullopt; |
| 1473 | + } |
| 1474 | + } |
| 1475 | + } |
| 1476 | + } |
1444 | 1477 | } |
1445 | 1478 |
|
1446 | 1479 | void CWallet::blockConnected(ChainstateRole role, const interfaces::BlockInfo& block) |
|
0 commit comments