mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +00:00
Change how wallet callbacks are run in the case of a tx that both sends and receives coins from the wallet (common case).
This commit is contained in:
parent
c8e76a8f9b
commit
1df679cd17
@ -510,10 +510,15 @@ public class Wallet implements Serializable {
|
|||||||
boolean wasPending = wtx != null;
|
boolean wasPending = wtx != null;
|
||||||
if (!reorg && bestChain && !wasPending) {
|
if (!reorg && bestChain && !wasPending) {
|
||||||
BigInteger newBalance = getBalance();
|
BigInteger newBalance = getBalance();
|
||||||
if (valueSentToMe.compareTo(BigInteger.ZERO) > 0) {
|
int diff = valueDifference.compareTo(BigInteger.ZERO);
|
||||||
|
// We pick one callback based on the value difference, though a tx can of course both send and receive
|
||||||
|
// coins from the wallet.
|
||||||
|
if (diff > 0) {
|
||||||
invokeOnCoinsReceived(tx, prevBalance, newBalance);
|
invokeOnCoinsReceived(tx, prevBalance, newBalance);
|
||||||
}
|
} else if (diff == 0) {
|
||||||
if (valueSentFromMe.compareTo(BigInteger.ZERO) > 0) {
|
// Hack. Invoke onCoinsSent in order to let the client save the wallet. This needs to go away.
|
||||||
|
invokeOnCoinsSent(tx, prevBalance, newBalance);
|
||||||
|
} else {
|
||||||
invokeOnCoinsSent(tx, prevBalance, newBalance);
|
invokeOnCoinsSent(tx, prevBalance, newBalance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,9 +223,11 @@ public class WalletTest {
|
|||||||
// Pretend it makes it into the block chain, our wallet state is cleared but we still have the keys, and we
|
// Pretend it makes it into the block chain, our wallet state is cleared but we still have the keys, and we
|
||||||
// want to get back to our previous state. We can do this by just not confirming the transaction as
|
// want to get back to our previous state. We can do this by just not confirming the transaction as
|
||||||
// createSend is stateless.
|
// createSend is stateless.
|
||||||
|
txn[0] = txn[1] = null;
|
||||||
StoredBlock b2 = createFakeBlock(params, blockStore, send1).storedBlock;
|
StoredBlock b2 = createFakeBlock(params, blockStore, send1).storedBlock;
|
||||||
wallet.receiveFromBlock(send1, b2, BlockChain.NewBlockType.BEST_CHAIN);
|
wallet.receiveFromBlock(send1, b2, BlockChain.NewBlockType.BEST_CHAIN);
|
||||||
assertEquals(bitcoinValueToFriendlyString(wallet.getBalance()), "0.90");
|
assertEquals(bitcoinValueToFriendlyString(wallet.getBalance()), "0.90");
|
||||||
|
assertEquals(null, txn[0]);
|
||||||
assertEquals(txn[1].getHash(), send1.getHash());
|
assertEquals(txn[1].getHash(), send1.getHash());
|
||||||
assertEquals(bitcoinValueToFriendlyString(bigints[2]), "1.00");
|
assertEquals(bitcoinValueToFriendlyString(bigints[2]), "1.00");
|
||||||
assertEquals(bitcoinValueToFriendlyString(bigints[3]), "0.90");
|
assertEquals(bitcoinValueToFriendlyString(bigints[3]), "0.90");
|
||||||
|
Loading…
Reference in New Issue
Block a user