allow stowaway counterparty to spend postmix utxos but receive to master wallet

This commit is contained in:
Craig Raw
2023-03-29 15:17:19 +02:00
parent 7915bbfa47
commit 961fd94dd6
3 changed files with 22 additions and 18 deletions
@@ -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<BlockTransactionHashIndex, WalletNode> walletUtxos = counterpartyWallet.getWalletUtxos();
Map<BlockTransactionHashIndex, WalletNode> walletUtxos = wallet.getWalletUtxos();
for(Map.Entry<BlockTransactionHashIndex, WalletNode> 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) {
@@ -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<Integer, Integer> 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<Integer, Integer> 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