mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2024-11-20 18:22:12 +01:00
TransactionOutPoint: deprecate setters
This required a little tweak to a @VisibleForTesting method in Block.java to remove use of setHash().
This commit is contained in:
parent
20364cb7b2
commit
9c61d6b5fb
@ -993,16 +993,9 @@ public class Block extends Message {
|
|||||||
// The input does not really need to be a valid signature, as long as it has the right general form.
|
// The input does not really need to be a valid signature, as long as it has the right general form.
|
||||||
TransactionInput input;
|
TransactionInput input;
|
||||||
if (prevOut == null) {
|
if (prevOut == null) {
|
||||||
input = new TransactionInput(params, t, Script.createInputScript(EMPTY_BYTES, EMPTY_BYTES));
|
prevOut = new TransactionOutPoint(params, 0, nextTestOutPointHash());
|
||||||
// Importantly the outpoint hash cannot be zero as that's how we detect a coinbase transaction in isolation
|
|
||||||
// but it must be unique to avoid 'different' transactions looking the same.
|
|
||||||
byte[] counter = new byte[32];
|
|
||||||
counter[0] = (byte) txCounter;
|
|
||||||
counter[1] = (byte) (txCounter++ >> 8);
|
|
||||||
input.getOutpoint().setHash(Sha256Hash.wrap(counter));
|
|
||||||
} else {
|
|
||||||
input = new TransactionInput(params, t, Script.createInputScript(EMPTY_BYTES, EMPTY_BYTES), prevOut);
|
|
||||||
}
|
}
|
||||||
|
input = new TransactionInput(params, t, Script.createInputScript(EMPTY_BYTES, EMPTY_BYTES), prevOut);
|
||||||
t.addInput(input);
|
t.addInput(input);
|
||||||
b.addTransaction(t);
|
b.addTransaction(t);
|
||||||
}
|
}
|
||||||
@ -1025,6 +1018,15 @@ public class Block extends Message {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Importantly the outpoint hash cannot be zero as that's how we detect a coinbase transaction in isolation
|
||||||
|
// but it must be unique to avoid 'different' transactions looking the same.
|
||||||
|
private Sha256Hash nextTestOutPointHash() {
|
||||||
|
byte[] counter = new byte[32];
|
||||||
|
counter[0] = (byte) txCounter;
|
||||||
|
counter[1] = (byte) (txCounter++ >> 8);
|
||||||
|
return Sha256Hash.wrap(counter);
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public Block createNextBlock(@Nullable Address to, TransactionOutPoint prevOut) {
|
public Block createNextBlock(@Nullable Address to, TransactionOutPoint prevOut) {
|
||||||
return createNextBlock(to, BLOCK_VERSION_GENESIS, prevOut, getTimeSeconds() + 5, pubkeyForTesting, FIFTY_COINS, BLOCK_HEIGHT_UNKNOWN);
|
return createNextBlock(to, BLOCK_VERSION_GENESIS, prevOut, getTimeSeconds() + 5, pubkeyForTesting, FIFTY_COINS, BLOCK_HEIGHT_UNKNOWN);
|
||||||
|
@ -197,6 +197,11 @@ public class TransactionOutPoint extends ChildMessage {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param hash new hash
|
||||||
|
* @deprecated Don't mutate this class -- create a new instance instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
void setHash(Sha256Hash hash) {
|
void setHash(Sha256Hash hash) {
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
}
|
}
|
||||||
@ -205,6 +210,11 @@ public class TransactionOutPoint extends ChildMessage {
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param index new index
|
||||||
|
* @deprecated Don't mutate this class -- create a new instance instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public void setIndex(long index) {
|
public void setIndex(long index) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user