mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-13 19:37:37 +01:00
Fix NRE and do nto activate onchain if node unavailable even when lazy payments (#4291)
fixes #4289
This commit is contained in:
parent
2d23819944
commit
1d7dee8314
1 changed files with 29 additions and 24 deletions
|
@ -79,12 +79,6 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||
model.InvoiceBitcoinUrl = (cryptoInfo.PaymentUrls?.BIP21 ?? "") + lightningFallback;
|
||||
model.InvoiceBitcoinUrlQR = (cryptoInfo.PaymentUrls?.BIP21 ?? "") + lightningFallback
|
||||
.Replace("LIGHTNING=", "lightning=", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
else
|
||||
{
|
||||
model.InvoiceBitcoinUrl = "";
|
||||
model.InvoiceBitcoinUrlQR = "";
|
||||
}
|
||||
|
||||
// Most wallets still don't support BITCOIN: schema, so we're leaving this for better days
|
||||
// Ref: https://github.com/btcpayserver/btcpayserver/pull/2060#issuecomment-723828348
|
||||
|
@ -100,6 +94,14 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
model.InvoiceBitcoinUrl = "";
|
||||
model.InvoiceBitcoinUrlQR = "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override string GetCryptoImage(PaymentMethodId paymentMethodId)
|
||||
{
|
||||
|
@ -155,6 +157,19 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||
DerivationSchemeSettings supportedPaymentMethod, PaymentMethod paymentMethod, StoreData store,
|
||||
BTCPayNetwork network, object preparePaymentObject, IEnumerable<PaymentMethodId> invoicePaymentMethods)
|
||||
{
|
||||
|
||||
if (!_ExplorerProvider.IsAvailable(network))
|
||||
throw new PaymentMethodUnavailableException($"Full node not available");
|
||||
if (paymentMethod.ParentEntity.Type != InvoiceType.TopUp)
|
||||
{
|
||||
var txOut = network.NBitcoinNetwork.Consensus.ConsensusFactory.CreateTxOut();
|
||||
txOut.ScriptPubKey =
|
||||
new Key().GetScriptPubKey(supportedPaymentMethod.AccountDerivation.ScriptPubKeyType());
|
||||
var dust = txOut.GetDustThreshold();
|
||||
var amount = paymentMethod.Calculate().Due;
|
||||
if (amount < dust)
|
||||
throw new PaymentMethodUnavailableException("Amount below the dust threshold. For amounts of this size, it is recommended to enable an off-chain (Lightning) payment method");
|
||||
}
|
||||
if (preparePaymentObject is null)
|
||||
{
|
||||
return new BitcoinLikeOnChainPaymentMethod()
|
||||
|
@ -162,8 +177,6 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||
Activated = false
|
||||
};
|
||||
}
|
||||
if (!_ExplorerProvider.IsAvailable(network))
|
||||
throw new PaymentMethodUnavailableException($"Full node not available");
|
||||
var prepare = (Prepare)preparePaymentObject;
|
||||
var onchainMethod = new BitcoinLikeOnChainPaymentMethod();
|
||||
var blob = store.GetStoreBlob();
|
||||
|
@ -190,15 +203,7 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||
}
|
||||
|
||||
var reserved = await prepare.ReserveAddress;
|
||||
if (paymentMethod.ParentEntity.Type != InvoiceType.TopUp)
|
||||
{
|
||||
var txOut = network.NBitcoinNetwork.Consensus.ConsensusFactory.CreateTxOut();
|
||||
txOut.ScriptPubKey = reserved.Address.ScriptPubKey;
|
||||
var dust = txOut.GetDustThreshold();
|
||||
var amount = paymentMethod.Calculate().Due;
|
||||
if (amount < dust)
|
||||
throw new PaymentMethodUnavailableException("Amount below the dust threshold. For amounts of this size, it is recommended to enable an off-chain (Lightning) payment method");
|
||||
}
|
||||
|
||||
onchainMethod.DepositAddress = reserved.Address.ToString();
|
||||
onchainMethod.KeyPath = reserved.KeyPath;
|
||||
onchainMethod.PayjoinEnabled = blob.PayJoinEnabled &&
|
||||
|
|
Loading…
Add table
Reference in a new issue