diff --git a/build.gradle b/build.gradle index 86d4c95a..c1fcae99 100644 --- a/build.gradle +++ b/build.gradle @@ -189,8 +189,6 @@ application { "--add-opens=java.base/java.net=com.sparrowwallet.sparrow", "--add-opens=java.base/java.io=com.google.gson", "--add-opens=java.smartcardio/sun.security.smartcardio=com.sparrowwallet.sparrow", - "--add-opens=com.samourai.whirlpool.client/com.samourai.whirlpool.client.whirlpool=com.sparrowwallet.sparrow", - "--add-opens=com.samourai.soroban.client/com.samourai.soroban.client.rpc=com.sparrowwallet.sparrow", "--add-reads=kotlin.stdlib=kotlinx.coroutines.core"] if(os.macOsX) { @@ -240,8 +238,6 @@ jlink { "--add-opens=java.base/java.net=com.sparrowwallet.sparrow", "--add-opens=java.base/java.io=com.google.gson", "--add-opens=java.smartcardio/sun.security.smartcardio=com.sparrowwallet.sparrow", - "--add-opens=com.samourai.whirlpool.client/com.samourai.whirlpool.client.whirlpool=com.sparrowwallet.sparrow", - "--add-opens=com.samourai.soroban.client/com.samourai.soroban.client.rpc=com.sparrowwallet.sparrow", "--add-reads=com.sparrowwallet.merged.module=java.desktop", "--add-reads=com.sparrowwallet.merged.module=java.sql", "--add-reads=com.sparrowwallet.merged.module=com.sparrowwallet.sparrow", diff --git a/src/main/java/com/sparrowwallet/sparrow/soroban/CounterpartyController.java b/src/main/java/com/sparrowwallet/sparrow/soroban/CounterpartyController.java index 7ad8e841..7f6586e5 100644 --- a/src/main/java/com/sparrowwallet/sparrow/soroban/CounterpartyController.java +++ b/src/main/java/com/sparrowwallet/sparrow/soroban/CounterpartyController.java @@ -264,7 +264,7 @@ public class CounterpartyController extends SorobanController { .subscribe(responseMessage -> { requestUserAttention(); if(accepted) { - startCounterpartyCollaboration(sorobanWalletCounterparty, paymentCodeInitiator, cahootsType, soroban.getBip47Account()); + startCounterpartyCollaboration(sorobanWalletCounterparty, paymentCodeInitiator, cahootsType, cahootsWallet.getAccount()); followPaymentCode(paymentCodeInitiator); } }, error -> { diff --git a/src/main/java/com/sparrowwallet/sparrow/soroban/InitiatorController.java b/src/main/java/com/sparrowwallet/sparrow/soroban/InitiatorController.java index e28bd9df..87d9329c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/soroban/InitiatorController.java +++ b/src/main/java/com/sparrowwallet/sparrow/soroban/InitiatorController.java @@ -63,6 +63,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.*; +import java.util.concurrent.TimeoutException; import java.util.function.UnaryOperator; import static com.sparrowwallet.sparrow.AppServices.showErrorDialog; @@ -424,7 +425,7 @@ public class InitiatorController extends SorobanController { Payment payment = walletTransaction.getPayments().get(0); long feePerB = (long)walletTransaction.getFeeRate(); - CahootsContext cahootsContext = CahootsContext.newInitiator(cahootsWallet, cahootsType, soroban.getBip47Account(), feePerB, payment.getAmount(), payment.getAddress().getAddress(), paymentCodeCounterparty.toString()); + CahootsContext cahootsContext = CahootsContext.newInitiator(cahootsWallet, cahootsType, cahootsWallet.getAccount(), feePerB, payment.getAmount(), payment.getAddress().getAddress(), paymentCodeCounterparty.toString()); CahootsSorobanInitiatorListener listener = new CahootsSorobanInitiatorListener() { @Override @@ -684,9 +685,10 @@ public class InitiatorController extends SorobanController { } private static String getErrorMessage(Throwable error) { + String message = error.getMessage() == null ? (error instanceof TimeoutException ? "Timed out receiving meeting response" : "Error receiving meeting response") : error.getMessage(); String cutFrom = "Exception: "; - int index = error.getMessage().lastIndexOf(cutFrom); - String msg = index < 0 ? error.getMessage() : error.getMessage().substring(index + cutFrom.length()); + int index = message.lastIndexOf(cutFrom); + String msg = index < 0 ? message : message.substring(index + cutFrom.length()); msg = msg.replace("#Cahoots", "mix transaction"); msg = msg.endsWith(".") ? msg : msg + "."; return msg; diff --git a/src/main/java/com/sparrowwallet/sparrow/soroban/SparrowCahootsWallet.java b/src/main/java/com/sparrowwallet/sparrow/soroban/SparrowCahootsWallet.java index b7179a6e..d15cd9c0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/soroban/SparrowCahootsWallet.java +++ b/src/main/java/com/sparrowwallet/sparrow/soroban/SparrowCahootsWallet.java @@ -21,14 +21,17 @@ import com.sparrowwallet.drongo.wallet.WalletNode; import com.sparrowwallet.sparrow.whirlpool.Whirlpool; import org.bitcoinj.core.NetworkParameters; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; public class SparrowCahootsWallet extends AbstractCahootsWallet { private final Wallet wallet; private final HD_Wallet bip84w; private final int account; private final List utxos; + private final Map lastWalletNodes = new HashMap<>(); public SparrowCahootsWallet(ChainSupplier chainSupplier, Wallet wallet, HD_Wallet bip84w, int bip47Account) { super(chainSupplier, bip84w.getFingerprint(), new BIP47Wallet(bip84w).getAccount(bip47Account)); @@ -59,15 +62,15 @@ public class SparrowCahootsWallet extends AbstractCahootsWallet { protected String doFetchAddressReceive(int account, boolean increment, BipFormat bipFormat) throws Exception { if(account == StandardAccount.WHIRLPOOL_POSTMIX.getAccountNumber()) { // force change chain - return getAddress(account, KeyPurpose.CHANGE); + return getAddress(account, increment, KeyPurpose.CHANGE); } - return getAddress(account, KeyPurpose.RECEIVE); + return getAddress(account, increment, KeyPurpose.RECEIVE); } @Override protected String doFetchAddressChange(int account, boolean increment, BipFormat bipFormat) throws Exception { - return getAddress(account, KeyPurpose.CHANGE); + return getAddress(account, increment, KeyPurpose.CHANGE); } @Override @@ -75,8 +78,10 @@ public class SparrowCahootsWallet extends AbstractCahootsWallet { return utxos; } - private String getAddress(int account, KeyPurpose keyPurpose) { - return getWallet(account).getFreshNode(keyPurpose).getAddress().getAddress(); + private String getAddress(int account, boolean increment, KeyPurpose keyPurpose) { + WalletNode addressNode = getWallet(account).getFreshNode(keyPurpose, increment ? lastWalletNodes.get(keyPurpose) : null); + lastWalletNodes.put(keyPurpose, addressNode); + return addressNode.getAddress().getAddress(); } private Wallet getWallet(int account) {