only allow sending to paynyms where a notification transaction has previously been sent

This commit is contained in:
Craig Raw 2022-07-19 10:34:31 +02:00
parent 60aa20ac55
commit 22303a2efc
2 changed files with 26 additions and 3 deletions

View file

@ -321,7 +321,9 @@ public class PayNymController {
public boolean isLinked(PayNym payNym) {
PaymentCode externalPaymentCode = payNym.paymentCode();
return getMasterWallet().getChildWallet(externalPaymentCode, payNym.segwit() ? ScriptType.P2WPKH : ScriptType.P2PKH) != null;
//As per BIP47 a notification transaction must have been sent from this wallet to enable the recipient to restore funds from seed
return getMasterWallet().getChildWallet(externalPaymentCode, payNym.segwit() ? ScriptType.P2WPKH : ScriptType.P2PKH) != null
&& !getNotificationTransaction(externalPaymentCode).isEmpty();
}
public void updateFollowing() {
@ -356,7 +358,7 @@ public class PayNymController {
for(PayNym payNym : following) {
if(!isLinked(payNym)) {
PaymentCode externalPaymentCode = payNym.paymentCode();
Map<BlockTransaction, WalletNode> unlinkedNotification = getMasterWallet().getNotificationTransaction(externalPaymentCode);
Map<BlockTransaction, WalletNode> unlinkedNotification = getNotificationTransaction(externalPaymentCode);
if(!unlinkedNotification.isEmpty() && !INVALID_PAYMENT_CODE_LABEL.equals(unlinkedNotification.keySet().iterator().next().getLabel())) {
unlinkedNotifications.putAll(unlinkedNotification);
unlinkedPayNyms.put(unlinkedNotification.keySet().iterator().next(), payNym);
@ -607,6 +609,22 @@ public class PayNymController {
return wallet.createWalletTransaction(utxoSelectors, utxoFilters, payments, opReturns, Collections.emptySet(), feeRate, minimumFeeRate, null, AppServices.getCurrentBlockHeight(), groupByAddress, includeMempoolOutputs, false);
}
private Map<BlockTransaction, WalletNode> getNotificationTransaction(PaymentCode externalPaymentCode) {
Map<BlockTransaction, WalletNode> notificationTransaction = getMasterWallet().getNotificationTransaction(externalPaymentCode);
if(notificationTransaction.isEmpty()) {
for(Wallet childWallet : getMasterWallet().getChildWallets()) {
if(!childWallet.isNested()) {
notificationTransaction = childWallet.getNotificationTransaction(externalPaymentCode);
if(!notificationTransaction.isEmpty()) {
return notificationTransaction;
}
}
}
}
return notificationTransaction;
}
public Wallet getMasterWallet() {
Wallet wallet = AppServices.get().getWallet(walletId);
return wallet.isMasterWallet() ? wallet : wallet.getMasterWallet();

View file

@ -90,7 +90,12 @@ public class WalletController extends WalletFormController implements Initializa
try {
if(!existing) {
FXMLLoader functionLoader = new FXMLLoader(AppServices.class.getResource("wallet/" + function.toString().toLowerCase() + ".fxml"));
URL url = AppServices.class.getResource("wallet/" + function.toString().toLowerCase() + ".fxml");
if(url == null) {
throw new IllegalStateException("Cannot find wallet/" + function.toString().toLowerCase() + ".fxml");
}
FXMLLoader functionLoader = new FXMLLoader(url);
Node walletFunction = functionLoader.load();
walletFunction.setUserData(function);
WalletFormController controller = functionLoader.getController();