From 961fd94dd603adc54a44647dcde393b4b0fe7b3c Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 29 Mar 2023 15:17:19 +0200 Subject: [PATCH] allow stowaway counterparty to spend postmix utxos but receive to master wallet --- build.gradle | 4 ++-- .../soroban/CounterpartyController.java | 16 +++------------ .../sparrow/soroban/SparrowCahootsWallet.java | 20 ++++++++++++++++--- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 4f707129..69108b3d 100644 --- a/build.gradle +++ b/build.gradle @@ -121,7 +121,7 @@ dependencies { implementation('org.slf4j:jul-to-slf4j:1.7.30') { exclude group: 'org.slf4j' } - implementation('com.sparrowwallet.nightjar:nightjar:0.2.35') + implementation('com.sparrowwallet.nightjar:nightjar:0.2.36') implementation('io.reactivex.rxjava2:rxjava:2.2.15') implementation('io.reactivex.rxjava2:rxjavafx:2.2.2') implementation('org.apache.commons:commons-lang3:3.7') @@ -508,7 +508,7 @@ extraJavaModuleInfo { exports('co.nstant.in.cbor.model') exports('co.nstant.in.cbor.builder') } - module('nightjar-0.2.35.jar', 'com.sparrowwallet.nightjar', '0.2.35') { + module('nightjar-0.2.36.jar', 'com.sparrowwallet.nightjar', '0.2.36') { requires('com.google.common') requires('net.sourceforge.streamsupport') requires('org.slf4j') diff --git a/src/main/java/com/sparrowwallet/sparrow/soroban/CounterpartyController.java b/src/main/java/com/sparrowwallet/sparrow/soroban/CounterpartyController.java index af3f1e26..f99dbdc9 100644 --- a/src/main/java/com/sparrowwallet/sparrow/soroban/CounterpartyController.java +++ b/src/main/java/com/sparrowwallet/sparrow/soroban/CounterpartyController.java @@ -294,20 +294,10 @@ public class CounterpartyController extends SorobanController { sorobanProgressLabel.setText("Creating mix transaction..."); Soroban soroban = AppServices.getSorobanServices().getSoroban(walletId); - Wallet counterpartyWallet; - if(counterpartyCahootsWallet.getAccount() == StandardAccount.WHIRLPOOL_POSTMIX.getAccountNumber() && cahootsType == CahootsType.STOWAWAY - && !counterpartyCahootsWallet.getWallet().isMasterWallet()) { - //Counterparty cannot participate in Stowaway using Postmix wallet, switch to master wallet - counterpartyWallet = counterpartyCahootsWallet.getWallet().getMasterWallet(); - counterpartyCahootsWallet = soroban.getCahootsWallet(counterpartyWallet, 1); - } else { - counterpartyWallet = wallet; - } - - Map walletUtxos = counterpartyWallet.getWalletUtxos(); + Map walletUtxos = wallet.getWalletUtxos(); for(Map.Entry entry : walletUtxos.entrySet()) { if(entry.getKey().getStatus() != Status.FROZEN) { - counterpartyCahootsWallet.addUtxo(entry.getValue(), counterpartyWallet.getWalletTransaction(entry.getKey().getHash()), (int)entry.getKey().getIndex()); + counterpartyCahootsWallet.addUtxo(entry.getValue(), wallet.getWalletTransaction(entry.getKey().getHash()), (int)entry.getKey().getIndex()); } } @@ -331,7 +321,7 @@ public class CounterpartyController extends SorobanController { Transaction transaction = getTransaction(cahoots); if(transaction != null) { transactionProperty.set(transaction); - updateTransactionDiagram(transactionDiagram, counterpartyWallet, null, transaction); + updateTransactionDiagram(transactionDiagram, wallet, null, transaction); next(); } } catch(PSBTParseException e) { diff --git a/src/main/java/com/sparrowwallet/sparrow/soroban/SparrowCahootsWallet.java b/src/main/java/com/sparrowwallet/sparrow/soroban/SparrowCahootsWallet.java index 367950c9..9f8750cb 100644 --- a/src/main/java/com/sparrowwallet/sparrow/soroban/SparrowCahootsWallet.java +++ b/src/main/java/com/sparrowwallet/sparrow/soroban/SparrowCahootsWallet.java @@ -34,6 +34,12 @@ public class SparrowCahootsWallet extends SimpleCahootsWallet { this.bip47Account = bip47Account; bip84w.getAccount(account).getReceive().setAddrIdx(wallet.getFreshNode(KeyPurpose.RECEIVE).getIndex()); bip84w.getAccount(account).getChange().setAddrIdx(wallet.getFreshNode(KeyPurpose.CHANGE).getIndex()); + + if(!wallet.isMasterWallet() && account != 0) { + Wallet masterWallet = wallet.getMasterWallet(); + bip84w.getAccount(0).getReceive().setAddrIdx(masterWallet.getFreshNode(KeyPurpose.RECEIVE).getIndex()); + bip84w.getAccount(0).getChange().setAddrIdx(masterWallet.getFreshNode(KeyPurpose.CHANGE).getIndex()); + } } public void addUtxo(WalletNode node, BlockTransaction blockTransaction, int index) { @@ -84,15 +90,23 @@ public class SparrowCahootsWallet extends SimpleCahootsWallet { public Pair fetchReceiveIndex(int account) throws Exception { if(account == StandardAccount.WHIRLPOOL_POSTMIX.getAccountNumber()) { // force change chain - return Pair.of(wallet.getFreshNode(KeyPurpose.CHANGE).getIndex(), 1); + return Pair.of(getWallet(account).getFreshNode(KeyPurpose.CHANGE).getIndex(), 1); } - return Pair.of(wallet.getFreshNode(KeyPurpose.RECEIVE).getIndex(), 0); + return Pair.of(getWallet(account).getFreshNode(KeyPurpose.RECEIVE).getIndex(), 0); } @Override public Pair fetchChangeIndex(int account) throws Exception { - return Pair.of(wallet.getFreshNode(KeyPurpose.CHANGE).getIndex(), 1); + return Pair.of(getWallet(account).getFreshNode(KeyPurpose.CHANGE).getIndex(), 1); + } + + private Wallet getWallet(int account) { + if(account != this.account && account == 0 && !wallet.isMasterWallet()) { + return wallet.getMasterWallet(); + } + + return wallet; } @Override