Skip to content

Commit

Permalink
Delete Config.SEGWIT_TRADE_PROTOCOL_ACTIVE
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarguindzberg committed Oct 22, 2020
1 parent 16c4b13 commit 1d79dfb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
2 changes: 0 additions & 2 deletions common/src/main/java/bisq/common/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
*/
public class Config {

public static final boolean SEGWIT_TRADE_PROTOCOL_ACTIVE = true;

// Option name constants
public static final String HELP = "help";
public static final String APP_NAME = "appName";
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/java/bisq/core/btc/wallet/BtcWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,19 +580,17 @@ public AddressEntry getOrCreateAddressEntry(String offerId, AddressEntry.Context
if (addressEntry.isPresent()) {
return addressEntry.get();
} else {
boolean segwit = Config.SEGWIT_TRADE_PROTOCOL_ACTIVE;
Script.ScriptType scriptTypeToUse = segwit ? Script.ScriptType.P2WPKH : Script.ScriptType.P2PKH;
// We try to use available and not yet used entries
Optional<AddressEntry> emptyAvailableAddressEntry = getAddressEntryListAsImmutableList().stream()
.filter(e -> AddressEntry.Context.AVAILABLE == e.getContext())
.filter(e -> isAddressUnused(e.getAddress()))
.filter(e -> scriptTypeToUse.equals(e.getAddress().getOutputScriptType()))
.filter(e -> Script.ScriptType.P2WPKH.equals(e.getAddress().getOutputScriptType()))
.findAny();
if (emptyAvailableAddressEntry.isPresent()) {
return addressEntryList.swapAvailableToAddressEntryWithOfferId(emptyAvailableAddressEntry.get(), context, offerId);
} else {
DeterministicKey key = (DeterministicKey) wallet.findKeyFromAddress(wallet.freshReceiveAddress(scriptTypeToUse));
AddressEntry entry = new AddressEntry(key, context, offerId, segwit);
DeterministicKey key = (DeterministicKey) wallet.findKeyFromAddress(wallet.freshReceiveAddress(Script.ScriptType.P2WPKH));
AddressEntry entry = new AddressEntry(key, context, offerId, true);
addressEntryList.addAddressEntry(entry);
return entry;
}
Expand Down
27 changes: 8 additions & 19 deletions core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,7 @@ private PreparedDepositTxAndMakerInputs makerCreatesDepositTx(boolean makerIsBuy


// Add MultiSig output
Script hashedMultiSigOutputScript = get2of2MultiSigOutputScript(buyerPubKey, sellerPubKey,
!Config.SEGWIT_TRADE_PROTOCOL_ACTIVE);
Script hashedMultiSigOutputScript = get2of2MultiSigOutputScript(buyerPubKey, sellerPubKey, false);

// Tx fee for deposit tx will be paid by buyer.
TransactionOutput hashedMultiSigOutput = new TransactionOutput(params, preparedDepositTx, msOutputAmount,
Expand Down Expand Up @@ -588,8 +587,7 @@ public Transaction takerSignsDepositTx(boolean takerIsSeller,
checkArgument(!sellerInputs.isEmpty());

// Check if maker's MultiSig script is identical to the takers
Script hashedMultiSigOutputScript = get2of2MultiSigOutputScript(buyerPubKey, sellerPubKey,
!Config.SEGWIT_TRADE_PROTOCOL_ACTIVE);
Script hashedMultiSigOutputScript = get2of2MultiSigOutputScript(buyerPubKey, sellerPubKey, false);
if (!makersDepositTx.getOutput(0).getScriptPubKey().equals(hashedMultiSigOutputScript)) {
throw new TransactionVerificationException("Maker's hashedMultiSigOutputScript does not match to takers hashedMultiSigOutputScript");
}
Expand Down Expand Up @@ -717,13 +715,9 @@ public byte[] signDelayedPayoutTx(Transaction delayedPayoutTx,

Script redeemScript = get2of2MultiSigRedeemScript(buyerPubKey, sellerPubKey);
Sha256Hash sigHash;
if (!Config.SEGWIT_TRADE_PROTOCOL_ACTIVE) {
sigHash = delayedPayoutTx.hashForSignature(0, redeemScript, Transaction.SigHash.ALL, false);
} else {
Coin delayedPayoutTxInputValue = preparedDepositTx.getOutput(0).getValue();
sigHash = delayedPayoutTx.hashForWitnessSignature(0, redeemScript,
delayedPayoutTxInputValue, Transaction.SigHash.ALL, false);
}
Coin delayedPayoutTxInputValue = preparedDepositTx.getOutput(0).getValue();
sigHash = delayedPayoutTx.hashForWitnessSignature(0, redeemScript,
delayedPayoutTxInputValue, Transaction.SigHash.ALL, false);
checkNotNull(myMultiSigKeyPair, "myMultiSigKeyPair must not be null");
if (myMultiSigKeyPair.isEncrypted()) {
checkNotNull(aesKey);
Expand All @@ -747,14 +741,9 @@ public Transaction finalizeDelayedPayoutTx(Transaction delayedPayoutTx,
TransactionSignature buyerTxSig = new TransactionSignature(buyerECDSASignature, Transaction.SigHash.ALL, false);
TransactionSignature sellerTxSig = new TransactionSignature(sellerECDSASignature, Transaction.SigHash.ALL, false);
TransactionInput input = delayedPayoutTx.getInput(0);
if (!Config.SEGWIT_TRADE_PROTOCOL_ACTIVE) {
Script inputScript = ScriptBuilder.createP2SHMultiSigInputScript(ImmutableList.of(sellerTxSig, buyerTxSig), redeemScript);
input.setScriptSig(inputScript);
} else {
input.setScriptSig(ScriptBuilder.createEmpty());
TransactionWitness witness = TransactionWitness.redeemP2WSH(redeemScript, sellerTxSig, buyerTxSig);
input.setWitness(witness);
}
input.setScriptSig(ScriptBuilder.createEmpty());
TransactionWitness witness = TransactionWitness.redeemP2WSH(redeemScript, sellerTxSig, buyerTxSig);
input.setWitness(witness);
WalletService.printTx("finalizeDelayedPayoutTx", delayedPayoutTx);
WalletService.verifyTransaction(delayedPayoutTx);
WalletService.checkWalletConsistency(wallet);
Expand Down

0 comments on commit 1d79dfb

Please sign in to comment.