mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-25 09:36:44 +00:00
rename tx segwit version field to segwit flag
This commit is contained in:
parent
60511e2c83
commit
5013a0ef2f
4 changed files with 17 additions and 17 deletions
|
@ -22,7 +22,7 @@ public class Transaction extends ChildMessage {
|
|||
public static final long SATOSHIS_PER_BITCOIN = 100 * 1000 * 1000L;
|
||||
public static final long MAX_BLOCK_LOCKTIME = 500000000L;
|
||||
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
|
||||
//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 locktime;
|
||||
private boolean segwit;
|
||||
private int segwitVersion;
|
||||
private int segwitFlag;
|
||||
|
||||
private Sha256Hash cachedTxId;
|
||||
private Sha256Hash cachedWTxId;
|
||||
|
@ -134,17 +134,17 @@ public class Transaction extends ChildMessage {
|
|||
return segwit;
|
||||
}
|
||||
|
||||
public int getSegwitVersion() {
|
||||
return segwitVersion;
|
||||
public int getSegwitFlag() {
|
||||
return segwitFlag;
|
||||
}
|
||||
|
||||
public void setSegwitVersion(int segwitVersion) {
|
||||
public void setSegwitFlag(int segwitFlag) {
|
||||
if(!segwit) {
|
||||
adjustLength(2);
|
||||
this.segwit = true;
|
||||
}
|
||||
|
||||
this.segwitVersion = segwitVersion;
|
||||
this.segwitFlag = segwitFlag;
|
||||
}
|
||||
|
||||
public void clearSegwit() {
|
||||
|
@ -208,7 +208,7 @@ public class Transaction extends ChildMessage {
|
|||
// marker, flag
|
||||
if(useWitnessFormat) {
|
||||
stream.write(0);
|
||||
stream.write(segwitVersion);
|
||||
stream.write(segwitFlag);
|
||||
}
|
||||
|
||||
// txin_count, txins
|
||||
|
@ -253,7 +253,7 @@ public class Transaction extends ChildMessage {
|
|||
// marker, flag
|
||||
if (segwit) {
|
||||
byte[] segwitHeader = readBytes(2);
|
||||
segwitVersion = segwitHeader[1];
|
||||
segwitFlag = segwitHeader[1];
|
||||
}
|
||||
// txin_count, txins
|
||||
parseInputs();
|
||||
|
@ -352,7 +352,7 @@ public class Transaction extends ChildMessage {
|
|||
|
||||
public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script, TransactionWitness witness) {
|
||||
if(!isSegwit()) {
|
||||
setSegwitVersion(DEFAULT_SEGWIT_VERSION);
|
||||
setSegwitFlag(DEFAULT_SEGWIT_FLAG);
|
||||
}
|
||||
|
||||
return addInput(new TransactionInput(this, new TransactionOutPoint(spendTxHash, outputIndex), script.getProgram(), witness));
|
||||
|
|
|
@ -542,7 +542,7 @@ public class PSBT {
|
|||
Transaction finalTransaction = new Transaction(transaction.bitcoinSerialize());
|
||||
|
||||
if(hasWitness && !finalTransaction.isSegwit()) {
|
||||
finalTransaction.setSegwitVersion(1);
|
||||
finalTransaction.setSegwitFlag(Transaction.DEFAULT_SEGWIT_FLAG);
|
||||
}
|
||||
|
||||
for(int i = 0; i < finalTransaction.getInputs().size(); i++) {
|
||||
|
|
|
@ -443,7 +443,7 @@ public class Wallet extends Persistable {
|
|||
public int getNoInputsWeightUnits(List<Payment> payments) {
|
||||
Transaction transaction = new Transaction();
|
||||
if(Arrays.asList(ScriptType.WITNESS_TYPES).contains(getScriptType())) {
|
||||
transaction.setSegwitVersion(1);
|
||||
transaction.setSegwitFlag(Transaction.DEFAULT_SEGWIT_FLAG);
|
||||
}
|
||||
for(Payment payment : payments) {
|
||||
transaction.addOutput(payment.getAmount(), payment.getAddress());
|
||||
|
|
|
@ -162,7 +162,7 @@ public class TransactionTest {
|
|||
|
||||
Transaction transaction = new Transaction();
|
||||
transaction.setVersion(parsedTransaction.getVersion());
|
||||
transaction.setSegwitVersion(parsedTransaction.getSegwitVersion());
|
||||
transaction.setSegwitFlag(parsedTransaction.getSegwitFlag());
|
||||
for(TransactionInput txInput : parsedTransaction.getInputs()) {
|
||||
transaction.addInput(txInput.getOutpoint().getHash(), txInput.getOutpoint().getIndex(), txInput.getScriptSig(), txInput.getWitness());
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ public class TransactionTest {
|
|||
|
||||
Transaction transaction = new Transaction();
|
||||
transaction.setVersion(parsedTransaction.getVersion());
|
||||
transaction.setSegwitVersion(parsedTransaction.getSegwitVersion());
|
||||
transaction.setSegwitFlag(parsedTransaction.getSegwitFlag());
|
||||
transaction.setLocktime(parsedTransaction.getLocktime());
|
||||
for(TransactionInput txInput : parsedTransaction.getInputs()) {
|
||||
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));
|
||||
|
||||
Transaction transaction = new Transaction();
|
||||
transaction.setSegwitVersion(1);
|
||||
transaction.setSegwitFlag(1);
|
||||
TransactionInput input = ScriptType.P2SH_P2WPKH.addSpendingInput(transaction, spent0Output, pubKey0, signature0);
|
||||
input.setSequenceNumber(TransactionInput.SEQUENCE_RBF_ENABLED);
|
||||
|
||||
|
@ -388,7 +388,7 @@ public class TransactionTest {
|
|||
pubKeySignatures.put(key2, null);
|
||||
|
||||
Transaction transaction = new Transaction();
|
||||
transaction.setSegwitVersion(1);
|
||||
transaction.setSegwitFlag(1);
|
||||
TransactionInput input = ScriptType.P2SH_P2WSH.addMultisigSpendingInput(transaction, spent0Output, 2, pubKeySignatures);
|
||||
|
||||
transaction.addOutput(59287429, Address.fromString("3PBjKH4FRuEKy4sD3NfL7tqfZTG5K42owu"));
|
||||
|
@ -422,7 +422,7 @@ public class TransactionTest {
|
|||
|
||||
Transaction transaction = new Transaction();
|
||||
transaction.setVersion(2);
|
||||
transaction.setSegwitVersion(1);
|
||||
transaction.setSegwitFlag(1);
|
||||
spent0ScriptType.addSpendingInput(transaction, spent0Output, key0, signature0);
|
||||
|
||||
transaction.addOutput(211584990, Address.fromString("bc1q9k6aan6ncahvlslw8w54jzv897k55zh077un6s"));
|
||||
|
@ -464,7 +464,7 @@ public class TransactionTest {
|
|||
pubKeySignatures.put(key2, null);
|
||||
|
||||
Transaction transaction = new Transaction();
|
||||
transaction.setSegwitVersion(1);
|
||||
transaction.setSegwitFlag(1);
|
||||
spent0ScriptType.addMultisigSpendingInput(transaction, spent0Output, 2, pubKeySignatures);
|
||||
|
||||
transaction.addOutput(10900000, Address.fromString("3Dt17mpd8FDXBjP56rCD7a4Sx7wpL91uhn"));
|
||||
|
|
Loading…
Reference in a new issue