mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-30 23:02:15 +00:00
Fix a bug where pending transactions with spent outputs would be considered unspent, triggering consistency assertions.
Resolves issue 313.
This commit is contained in:
parent
d310c289ab
commit
d4cfad59cf
@ -933,8 +933,9 @@ public class Wallet implements Serializable, BlockChainListener {
|
||||
// A transaction we created appeared in a block. Probably this is a spend we broadcast that has been
|
||||
// accepted by the network.
|
||||
if (bestChain) {
|
||||
if (valueSentToMe.equals(BigInteger.ZERO)) {
|
||||
// There were no change transactions so this tx is fully spent.
|
||||
// Was confirmed.
|
||||
if (tx.isEveryOwnedOutputSpent(this)) {
|
||||
// There were no change transactions so this tx is fully spent
|
||||
log.info(" ->spent");
|
||||
addWalletTransaction(Pool.SPENT, tx);
|
||||
} else {
|
||||
@ -1091,7 +1092,7 @@ public class Wallet implements Serializable, BlockChainListener {
|
||||
|
||||
updateForSpends(tx, true);
|
||||
|
||||
if (!tx.getValueSentToMe(this).equals(BigInteger.ZERO)) {
|
||||
if (!tx.isEveryOwnedOutputSpent(this)) {
|
||||
// It's sending us coins.
|
||||
log.info(" new tx {} ->unspent", tx.getHashAsString());
|
||||
addWalletTransaction(Pool.UNSPENT, tx);
|
||||
|
@ -142,6 +142,14 @@ public class WalletTest {
|
||||
assertEquals(v3, wallet.getBalance());
|
||||
Transaction t3 = wallet.createSend(new ECKey().toAddress(params), v3);
|
||||
assertNotNull(t3);
|
||||
wallet.commitTx(t3);
|
||||
assertTrue(wallet.isConsistent());
|
||||
// t2 and t3 gets confirmed in the same block.
|
||||
BlockPair bp = createFakeBlock(blockStore, t2, t3);
|
||||
wallet.receiveFromBlock(t2, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||
wallet.receiveFromBlock(t3, bp.storedBlock, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||
wallet.notifyNewBestBlock(bp.block);
|
||||
assertTrue(wallet.isConsistent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -848,7 +856,7 @@ public class WalletTest {
|
||||
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
|
||||
assertEquals(2, wallet.getPoolSize(WalletTransaction.Pool.ALL));
|
||||
|
||||
// Now try the spend the output
|
||||
// Now try to the spend the output.
|
||||
ECKey k3 = new ECKey();
|
||||
BigInteger v3 = toNanoCoins(0, 25);
|
||||
Transaction t3 = new Transaction(params);
|
||||
|
Loading…
Reference in New Issue
Block a user