mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 14:50:57 +01:00
Implement some missed Bloom filter application logic (does not impact existing apps).
This commit is contained in:
parent
387be0790c
commit
f5216b1d49
3 changed files with 18 additions and 3 deletions
|
@ -961,6 +961,7 @@ public class Block extends Message {
|
|||
static private int txCounter;
|
||||
|
||||
/** Adds a coinbase transaction to the block. This exists for unit tests. */
|
||||
@VisibleForTesting
|
||||
void addCoinbaseTransaction(byte[] pubKeyTo, Coin value) {
|
||||
unCacheTransactions();
|
||||
transactions = new ArrayList<Transaction>();
|
||||
|
@ -970,7 +971,8 @@ public class Block extends Message {
|
|||
//
|
||||
// Here we will do things a bit differently so a new address isn't needed every time. We'll put a simple
|
||||
// counter in the scriptSig so every transaction has a different hash.
|
||||
coinbase.addInput(new TransactionInput(params, coinbase, new byte[]{(byte) txCounter, (byte) (txCounter++ >> 8)}));
|
||||
coinbase.addInput(new TransactionInput(params, coinbase,
|
||||
new ScriptBuilder().data(new byte[]{(byte) txCounter, (byte) (txCounter++ >> 8)}).build().getProgram()));
|
||||
coinbase.addOutput(new TransactionOutput(params, coinbase, value,
|
||||
ScriptBuilder.createOutputScript(ECKey.fromPublicOnly(pubKeyTo)).getProgram()));
|
||||
transactions.add(coinbase);
|
||||
|
|
|
@ -339,7 +339,17 @@ public class BloomFilter extends Message {
|
|||
}
|
||||
}
|
||||
}
|
||||
return found;
|
||||
if (found) return true;
|
||||
for (TransactionInput input : tx.getInputs()) {
|
||||
if (contains(input.getOutpoint().bitcoinSerialize())) {
|
||||
return true;
|
||||
}
|
||||
for (ScriptChunk chunk : input.getScriptSig().getChunks()) {
|
||||
if (chunk.isPushData() && contains(chunk.data))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
package org.bitcoinj.testing;
|
||||
|
||||
import org.bitcoinj.core.*;
|
||||
import org.bitcoinj.crypto.TransactionSignature;
|
||||
import org.bitcoinj.script.ScriptBuilder;
|
||||
import org.bitcoinj.store.BlockStore;
|
||||
import org.bitcoinj.store.BlockStoreException;
|
||||
|
||||
|
@ -43,7 +45,8 @@ public class FakeTxBuilder {
|
|||
TransactionOutput prevOut = new TransactionOutput(params, prevTx, value, to);
|
||||
prevTx.addOutput(prevOut);
|
||||
// Connect it.
|
||||
t.addInput(prevOut);
|
||||
t.addInput(prevOut).setScriptSig(ScriptBuilder.createInputScript(TransactionSignature.dummy()));
|
||||
// Fake signature.
|
||||
// Serialize/deserialize to ensure internal state is stripped, as if it had been read from the wire.
|
||||
return roundTripTransaction(params, t);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue