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

View file

@ -121,7 +121,7 @@ dependencies {
implementation('org.slf4j:jul-to-slf4j:1.7.30') { implementation('org.slf4j:jul-to-slf4j:1.7.30') {
exclude group: 'org.slf4j' 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:rxjava:2.2.15')
implementation('io.reactivex.rxjava2:rxjavafx:2.2.2') implementation('io.reactivex.rxjava2:rxjavafx:2.2.2')
implementation('org.apache.commons:commons-lang3:3.7') implementation('org.apache.commons:commons-lang3:3.7')
@ -508,7 +508,7 @@ extraJavaModuleInfo {
exports('co.nstant.in.cbor.model') exports('co.nstant.in.cbor.model')
exports('co.nstant.in.cbor.builder') 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('com.google.common')
requires('net.sourceforge.streamsupport') requires('net.sourceforge.streamsupport')
requires('org.slf4j') requires('org.slf4j')

View file

@ -294,20 +294,10 @@ public class CounterpartyController extends SorobanController {
sorobanProgressLabel.setText("Creating mix transaction..."); sorobanProgressLabel.setText("Creating mix transaction...");
Soroban soroban = AppServices.getSorobanServices().getSoroban(walletId); Soroban soroban = AppServices.getSorobanServices().getSoroban(walletId);
Wallet counterpartyWallet; Map<BlockTransactionHashIndex, WalletNode> walletUtxos = wallet.getWalletUtxos();
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();
for(Map.Entry<BlockTransactionHashIndex, WalletNode> entry : walletUtxos.entrySet()) { for(Map.Entry<BlockTransactionHashIndex, WalletNode> entry : walletUtxos.entrySet()) {
if(entry.getKey().getStatus() != Status.FROZEN) { 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); Transaction transaction = getTransaction(cahoots);
if(transaction != null) { if(transaction != null) {
transactionProperty.set(transaction); transactionProperty.set(transaction);
updateTransactionDiagram(transactionDiagram, counterpartyWallet, null, transaction); updateTransactionDiagram(transactionDiagram, wallet, null, transaction);
next(); next();
} }
} catch(PSBTParseException e) { } catch(PSBTParseException e) {

View file

@ -34,6 +34,12 @@ public class SparrowCahootsWallet extends SimpleCahootsWallet {
this.bip47Account = bip47Account; this.bip47Account = bip47Account;
bip84w.getAccount(account).getReceive().setAddrIdx(wallet.getFreshNode(KeyPurpose.RECEIVE).getIndex()); bip84w.getAccount(account).getReceive().setAddrIdx(wallet.getFreshNode(KeyPurpose.RECEIVE).getIndex());
bip84w.getAccount(account).getChange().setAddrIdx(wallet.getFreshNode(KeyPurpose.CHANGE).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) { 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 { public Pair<Integer, Integer> fetchReceiveIndex(int account) throws Exception {
if(account == StandardAccount.WHIRLPOOL_POSTMIX.getAccountNumber()) { if(account == StandardAccount.WHIRLPOOL_POSTMIX.getAccountNumber()) {
// force change chain // 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 @Override
public Pair<Integer, Integer> fetchChangeIndex(int account) throws Exception { 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 @Override