mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +00:00
Fix bloom filter sizing with watched scripts
This commit is contained in:
parent
606f199e73
commit
751434ba7c
@ -2956,7 +2956,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi
|
|||||||
for (Transaction tx : getTransactions(false)) {
|
for (Transaction tx : getTransactions(false)) {
|
||||||
for (TransactionOutput out : tx.getOutputs()) {
|
for (TransactionOutput out : tx.getOutputs()) {
|
||||||
try {
|
try {
|
||||||
if (out.isMine(this) && out.getScriptPubKey().isSentToRawPubKey())
|
if (isTxOutputBloomFilterable(out))
|
||||||
size++;
|
size++;
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
throw new RuntimeException(e); // If it is ours, we parsed the script correctly, so this shouldn't happen
|
throw new RuntimeException(e); // If it is ours, we parsed the script correctly, so this shouldn't happen
|
||||||
@ -3026,8 +3026,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi
|
|||||||
for (int i = 0; i < tx.getOutputs().size(); i++) {
|
for (int i = 0; i < tx.getOutputs().size(); i++) {
|
||||||
TransactionOutput out = tx.getOutputs().get(i);
|
TransactionOutput out = tx.getOutputs().get(i);
|
||||||
try {
|
try {
|
||||||
if ((out.isMine(this) && out.getScriptPubKey().isSentToRawPubKey()) ||
|
if (isTxOutputBloomFilterable(out)) {
|
||||||
out.isWatched(this)) {
|
|
||||||
TransactionOutPoint outPoint = new TransactionOutPoint(params, i, tx);
|
TransactionOutPoint outPoint = new TransactionOutPoint(params, i, tx);
|
||||||
filter.insert(outPoint.bitcoinSerialize());
|
filter.insert(outPoint.bitcoinSerialize());
|
||||||
}
|
}
|
||||||
@ -3040,6 +3039,11 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi
|
|||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTxOutputBloomFilterable(TransactionOutput out) {
|
||||||
|
return (out.isMine(this) && out.getScriptPubKey().isSentToRawPubKey()) ||
|
||||||
|
out.isWatched(this);
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the {@link CoinSelector} object which controls which outputs can be spent by this wallet. */
|
/** Returns the {@link CoinSelector} object which controls which outputs can be spent by this wallet. */
|
||||||
public CoinSelector getCoinSelector() {
|
public CoinSelector getCoinSelector() {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
@ -993,10 +993,14 @@ public class WalletTest extends TestWithWallet {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void watchingScriptsSentFrom() throws Exception {
|
public void watchingScriptsSentFrom() throws Exception {
|
||||||
|
assertEquals(2, wallet.getBloomFilterElementCount());
|
||||||
|
|
||||||
ECKey key = new ECKey();
|
ECKey key = new ECKey();
|
||||||
ECKey notMyAddr = new ECKey();
|
ECKey notMyAddr = new ECKey();
|
||||||
Address watchedAddress = key.toAddress(params);
|
Address watchedAddress = key.toAddress(params);
|
||||||
wallet.addWatchedAddress(watchedAddress);
|
wallet.addWatchedAddress(watchedAddress);
|
||||||
|
assertEquals(3, wallet.getBloomFilterElementCount());
|
||||||
|
|
||||||
Transaction t1 = createFakeTx(params, CENT, watchedAddress);
|
Transaction t1 = createFakeTx(params, CENT, watchedAddress);
|
||||||
Transaction t2 = createFakeTx(params, COIN, notMyAddr);
|
Transaction t2 = createFakeTx(params, COIN, notMyAddr);
|
||||||
StoredBlock b1 = createFakeBlock(blockStore, t1).storedBlock;
|
StoredBlock b1 = createFakeBlock(blockStore, t1).storedBlock;
|
||||||
@ -1006,7 +1010,9 @@ public class WalletTest extends TestWithWallet {
|
|||||||
st2.addInput(t1.getOutput(0));
|
st2.addInput(t1.getOutput(0));
|
||||||
st2.addInput(t2.getOutput(0));
|
st2.addInput(t2.getOutput(0));
|
||||||
wallet.receiveFromBlock(t1, b1, BlockChain.NewBlockType.BEST_CHAIN, 0);
|
wallet.receiveFromBlock(t1, b1, BlockChain.NewBlockType.BEST_CHAIN, 0);
|
||||||
|
assertEquals(4, wallet.getBloomFilterElementCount());
|
||||||
wallet.receiveFromBlock(st2, b1, BlockChain.NewBlockType.BEST_CHAIN, 0);
|
wallet.receiveFromBlock(st2, b1, BlockChain.NewBlockType.BEST_CHAIN, 0);
|
||||||
|
assertEquals(4, wallet.getBloomFilterElementCount());
|
||||||
assertEquals(CENT, st2.getValueSentFromMe(wallet));
|
assertEquals(CENT, st2.getValueSentFromMe(wallet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user