rename tx segwit version field to segwit flag

This commit is contained in:
Craig Raw 2021-07-08 11:45:39 +02:00
parent 60511e2c83
commit 5013a0ef2f
4 changed files with 17 additions and 17 deletions

View file

@ -22,7 +22,7 @@ public class Transaction extends ChildMessage {
public static final long SATOSHIS_PER_BITCOIN = 100 * 1000 * 1000L; public static final long SATOSHIS_PER_BITCOIN = 100 * 1000 * 1000L;
public static final long MAX_BLOCK_LOCKTIME = 500000000L; public static final long MAX_BLOCK_LOCKTIME = 500000000L;
public static final int WITNESS_SCALE_FACTOR = 4; public static final int WITNESS_SCALE_FACTOR = 4;
public static final int DEFAULT_SEGWIT_VERSION = 1; public static final int DEFAULT_SEGWIT_FLAG = 1;
//Min feerate for defining dust, defined in sats/vByte //Min feerate for defining dust, defined in sats/vByte
//From: https://github.com/bitcoin/bitcoin/blob/0.19/src/policy/policy.h#L50 //From: https://github.com/bitcoin/bitcoin/blob/0.19/src/policy/policy.h#L50
@ -34,7 +34,7 @@ public class Transaction extends ChildMessage {
private long version; private long version;
private long locktime; private long locktime;
private boolean segwit; private boolean segwit;
private int segwitVersion; private int segwitFlag;
private Sha256Hash cachedTxId; private Sha256Hash cachedTxId;
private Sha256Hash cachedWTxId; private Sha256Hash cachedWTxId;
@ -134,17 +134,17 @@ public class Transaction extends ChildMessage {
return segwit; return segwit;
} }
public int getSegwitVersion() { public int getSegwitFlag() {
return segwitVersion; return segwitFlag;
} }
public void setSegwitVersion(int segwitVersion) { public void setSegwitFlag(int segwitFlag) {
if(!segwit) { if(!segwit) {
adjustLength(2); adjustLength(2);
this.segwit = true; this.segwit = true;
} }
this.segwitVersion = segwitVersion; this.segwitFlag = segwitFlag;
} }
public void clearSegwit() { public void clearSegwit() {
@ -208,7 +208,7 @@ public class Transaction extends ChildMessage {
// marker, flag // marker, flag
if(useWitnessFormat) { if(useWitnessFormat) {
stream.write(0); stream.write(0);
stream.write(segwitVersion); stream.write(segwitFlag);
} }
// txin_count, txins // txin_count, txins
@ -253,7 +253,7 @@ public class Transaction extends ChildMessage {
// marker, flag // marker, flag
if (segwit) { if (segwit) {
byte[] segwitHeader = readBytes(2); byte[] segwitHeader = readBytes(2);
segwitVersion = segwitHeader[1]; segwitFlag = segwitHeader[1];
} }
// txin_count, txins // txin_count, txins
parseInputs(); parseInputs();
@ -352,7 +352,7 @@ public class Transaction extends ChildMessage {
public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script, TransactionWitness witness) { public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script, TransactionWitness witness) {
if(!isSegwit()) { if(!isSegwit()) {
setSegwitVersion(DEFAULT_SEGWIT_VERSION); setSegwitFlag(DEFAULT_SEGWIT_FLAG);
} }
return addInput(new TransactionInput(this, new TransactionOutPoint(spendTxHash, outputIndex), script.getProgram(), witness)); return addInput(new TransactionInput(this, new TransactionOutPoint(spendTxHash, outputIndex), script.getProgram(), witness));

View file

@ -542,7 +542,7 @@ public class PSBT {
Transaction finalTransaction = new Transaction(transaction.bitcoinSerialize()); Transaction finalTransaction = new Transaction(transaction.bitcoinSerialize());
if(hasWitness && !finalTransaction.isSegwit()) { if(hasWitness && !finalTransaction.isSegwit()) {
finalTransaction.setSegwitVersion(1); finalTransaction.setSegwitFlag(Transaction.DEFAULT_SEGWIT_FLAG);
} }
for(int i = 0; i < finalTransaction.getInputs().size(); i++) { for(int i = 0; i < finalTransaction.getInputs().size(); i++) {

View file

@ -443,7 +443,7 @@ public class Wallet extends Persistable {
public int getNoInputsWeightUnits(List<Payment> payments) { public int getNoInputsWeightUnits(List<Payment> payments) {
Transaction transaction = new Transaction(); Transaction transaction = new Transaction();
if(Arrays.asList(ScriptType.WITNESS_TYPES).contains(getScriptType())) { if(Arrays.asList(ScriptType.WITNESS_TYPES).contains(getScriptType())) {
transaction.setSegwitVersion(1); transaction.setSegwitFlag(Transaction.DEFAULT_SEGWIT_FLAG);
} }
for(Payment payment : payments) { for(Payment payment : payments) {
transaction.addOutput(payment.getAmount(), payment.getAddress()); transaction.addOutput(payment.getAmount(), payment.getAddress());

View file

@ -162,7 +162,7 @@ public class TransactionTest {
Transaction transaction = new Transaction(); Transaction transaction = new Transaction();
transaction.setVersion(parsedTransaction.getVersion()); transaction.setVersion(parsedTransaction.getVersion());
transaction.setSegwitVersion(parsedTransaction.getSegwitVersion()); transaction.setSegwitFlag(parsedTransaction.getSegwitFlag());
for(TransactionInput txInput : parsedTransaction.getInputs()) { for(TransactionInput txInput : parsedTransaction.getInputs()) {
transaction.addInput(txInput.getOutpoint().getHash(), txInput.getOutpoint().getIndex(), txInput.getScriptSig(), txInput.getWitness()); transaction.addInput(txInput.getOutpoint().getHash(), txInput.getOutpoint().getIndex(), txInput.getScriptSig(), txInput.getWitness());
} }
@ -188,7 +188,7 @@ public class TransactionTest {
Transaction transaction = new Transaction(); Transaction transaction = new Transaction();
transaction.setVersion(parsedTransaction.getVersion()); transaction.setVersion(parsedTransaction.getVersion());
transaction.setSegwitVersion(parsedTransaction.getSegwitVersion()); transaction.setSegwitFlag(parsedTransaction.getSegwitFlag());
transaction.setLocktime(parsedTransaction.getLocktime()); transaction.setLocktime(parsedTransaction.getLocktime());
for(TransactionInput txInput : parsedTransaction.getInputs()) { for(TransactionInput txInput : parsedTransaction.getInputs()) {
TransactionInput newInput = transaction.addInput(txInput.getOutpoint().getHash(), txInput.getOutpoint().getIndex(), txInput.getScriptSig(), txInput.getWitness()); TransactionInput newInput = transaction.addInput(txInput.getOutpoint().getHash(), txInput.getOutpoint().getIndex(), txInput.getScriptSig(), txInput.getWitness());
@ -344,7 +344,7 @@ public class TransactionTest {
ECKey pubKey0 = ECKey.fromPublicOnly(witness0.getPushes().get(1)); ECKey pubKey0 = ECKey.fromPublicOnly(witness0.getPushes().get(1));
Transaction transaction = new Transaction(); Transaction transaction = new Transaction();
transaction.setSegwitVersion(1); transaction.setSegwitFlag(1);
TransactionInput input = ScriptType.P2SH_P2WPKH.addSpendingInput(transaction, spent0Output, pubKey0, signature0); TransactionInput input = ScriptType.P2SH_P2WPKH.addSpendingInput(transaction, spent0Output, pubKey0, signature0);
input.setSequenceNumber(TransactionInput.SEQUENCE_RBF_ENABLED); input.setSequenceNumber(TransactionInput.SEQUENCE_RBF_ENABLED);
@ -388,7 +388,7 @@ public class TransactionTest {
pubKeySignatures.put(key2, null); pubKeySignatures.put(key2, null);
Transaction transaction = new Transaction(); Transaction transaction = new Transaction();
transaction.setSegwitVersion(1); transaction.setSegwitFlag(1);
TransactionInput input = ScriptType.P2SH_P2WSH.addMultisigSpendingInput(transaction, spent0Output, 2, pubKeySignatures); TransactionInput input = ScriptType.P2SH_P2WSH.addMultisigSpendingInput(transaction, spent0Output, 2, pubKeySignatures);
transaction.addOutput(59287429, Address.fromString("3PBjKH4FRuEKy4sD3NfL7tqfZTG5K42owu")); transaction.addOutput(59287429, Address.fromString("3PBjKH4FRuEKy4sD3NfL7tqfZTG5K42owu"));
@ -422,7 +422,7 @@ public class TransactionTest {
Transaction transaction = new Transaction(); Transaction transaction = new Transaction();
transaction.setVersion(2); transaction.setVersion(2);
transaction.setSegwitVersion(1); transaction.setSegwitFlag(1);
spent0ScriptType.addSpendingInput(transaction, spent0Output, key0, signature0); spent0ScriptType.addSpendingInput(transaction, spent0Output, key0, signature0);
transaction.addOutput(211584990, Address.fromString("bc1q9k6aan6ncahvlslw8w54jzv897k55zh077un6s")); transaction.addOutput(211584990, Address.fromString("bc1q9k6aan6ncahvlslw8w54jzv897k55zh077un6s"));
@ -464,7 +464,7 @@ public class TransactionTest {
pubKeySignatures.put(key2, null); pubKeySignatures.put(key2, null);
Transaction transaction = new Transaction(); Transaction transaction = new Transaction();
transaction.setSegwitVersion(1); transaction.setSegwitFlag(1);
spent0ScriptType.addMultisigSpendingInput(transaction, spent0Output, 2, pubKeySignatures); spent0ScriptType.addMultisigSpendingInput(transaction, spent0Output, 2, pubKeySignatures);
transaction.addOutput(10900000, Address.fromString("3Dt17mpd8FDXBjP56rCD7a4Sx7wpL91uhn")); transaction.addOutput(10900000, Address.fromString("3Dt17mpd8FDXBjP56rCD7a4Sx7wpL91uhn"));