Allow Payjoin for wallet receive addresses (#2425)

* Allow Payjoin for wallet receive addresses

* wip

* show bip21 and additional work

* style better

* add to docs

* pr changes

* remove from state when unreserved
This commit is contained in:
Andrew Camilleri
2021-04-13 05:26:36 +02:00
committed by GitHub
parent b12c4c5fa0
commit 8fd4a816a6
12 changed files with 164 additions and 63 deletions

View File

@@ -11,6 +11,7 @@ using BTCPayServer.Client.Models;
using BTCPayServer.Data;
using BTCPayServer.HostedServices;
using BTCPayServer.Models.WalletViewModels;
using BTCPayServer.Payments.PayJoin;
using BTCPayServer.Payments.PayJoin.Sender;
using BTCPayServer.Services;
using BTCPayServer.Services.Wallets;
@@ -122,9 +123,18 @@ namespace BTCPayServer.Controllers.GreenField
{
return BadRequest();
}
var bip21 = network.GenerateBIP21(kpi.Address.ToString(), null);
var allowedPayjoin = derivationScheme.IsHotWallet && Store.GetStoreBlob().PayJoinEnabled;
if (allowedPayjoin)
{
bip21 +=
$"?{PayjoinClient.BIP21EndpointKey}={Request.GetAbsoluteUri(Url.Action(nameof(PayJoinEndpointController.Submit), "PayJoinEndpoint", new {cryptoCode}))}";
}
return Ok(new OnChainWalletAddressData()
{
Address = kpi.Address.ToString(),
PaymentLink = bip21,
KeyPath = kpi.KeyPath
});
}
@@ -323,7 +333,7 @@ namespace BTCPayServer.Controllers.GreenField
request.AddModelError(transactionRequest => transactionRequest.Destinations[index],
"Amount must be specified or destination must be a BIP21 payment link, and greater than 0", this);
}
if (request.ProceedWithPayjoin && bip21?.UnknowParameters?.ContainsKey("pj") is true)
if (request.ProceedWithPayjoin && bip21?.UnknowParameters?.ContainsKey(PayjoinClient.BIP21EndpointKey) is true)
{
payjoinOutputIndex = index;
}