remove bpu TempData

This commit is contained in:
Kukks 2020-03-26 14:18:16 +01:00
parent ff9865c516
commit 10fcfab233
8 changed files with 28 additions and 17 deletions

View File

@ -71,6 +71,7 @@ namespace BTCPayServer.Controllers
vm.Decoded = psbt.ToString();
vm.PSBT = psbt.ToBase64();
}
return View(nameof(WalletPSBT), vm ?? new WalletPSBTViewModel() { CryptoCode = walletId.CryptoCode });
}
[HttpPost]
@ -101,7 +102,7 @@ namespace BTCPayServer.Controllers
vm.FileName = vm.UploadedPSBTFile?.FileName;
return View(vm);
case "vault":
return ViewVault(walletId, psbt);
return ViewVault(walletId, psbt, vm.PayJoinEndpointUrl);
case "ledger":
return ViewWalletSendLedger(walletId, psbt);
case "update":
@ -115,7 +116,7 @@ namespace BTCPayServer.Controllers
TempData[WellKnownTempData.SuccessMessage] = "PSBT updated!";
return RedirectToWalletPSBT(psbt, vm.FileName);
case "seed":
return SignWithSeed(walletId, psbt.ToBase64());
return SignWithSeed(walletId, psbt.ToBase64(), vm.PayJoinEndpointUrl);
case "nbx-seed":
if (await CanUseHotWallet())
{
@ -125,7 +126,7 @@ namespace BTCPayServer.Controllers
WellknownMetadataKeys.MasterHDKey);
return await SignWithSeed(walletId,
new SignWithSeedViewModel() {SeedOrKey = extKey, PSBT = psbt.ToBase64()});
new SignWithSeedViewModel() {SeedOrKey = extKey, PSBT = psbt.ToBase64(), PayJoinEndpointUrl = vm.PayJoinEndpointUrl});
}
return View(vm);
@ -158,12 +159,10 @@ namespace BTCPayServer.Controllers
private async Task<PSBT> TryGetBPProposedTX(PSBT psbt, DerivationSchemeSettings derivationSchemeSettings, BTCPayNetwork btcPayNetwork)
private async Task<PSBT> TryGetBPProposedTX(string bpu, PSBT psbt, DerivationSchemeSettings derivationSchemeSettings, BTCPayNetwork btcPayNetwork)
{
if (TempData.TryGetValue( "bpu", out var bpu) && !string.IsNullOrEmpty(bpu?.ToString()) && Uri.TryCreate(bpu.ToString(), UriKind.Absolute, out var endpoint))
if (!string.IsNullOrEmpty(bpu) && Uri.TryCreate(bpu, UriKind.Absolute, out var endpoint))
{
TempData.Remove("bpu");
var httpClient = _httpClientFactory.CreateClient("payjoin");
var cloned = psbt.Clone();
@ -173,7 +172,7 @@ namespace BTCPayServer.Controllers
return null;
}
var bpuresponse = await httpClient.PostAsync(bpu.ToString(), new StringContent(cloned.ToHex(), Encoding.UTF8, "text/plain"));
var bpuresponse = await httpClient.PostAsync(endpoint, new StringContent(cloned.ToHex(), Encoding.UTF8, "text/plain"));
if (bpuresponse.IsSuccessStatusCode)
{
var hex = await bpuresponse.Content.ReadAsStringAsync();

View File

@ -600,28 +600,28 @@ namespace BTCPayServer.Controllers
return View(vm);
}
derivationScheme.RebaseKeyPaths(psbt.PSBT);
TempData.AddOrReplace("bpu", vm.PayJoinEndpointUrl);
switch (command)
{
case "vault":
return ViewVault(walletId, psbt.PSBT);
return ViewVault(walletId, psbt.PSBT, vm.PayJoinEndpointUrl);
case "nbx-seed":
var extKey = await ExplorerClientProvider.GetExplorerClient(network)
.GetMetadataAsync<string>(derivationScheme.AccountDerivation, WellknownMetadataKeys.MasterHDKey, cancellation);
return await SignWithSeed(walletId, new SignWithSeedViewModel()
{
PayJoinEndpointUrl = vm.PayJoinEndpointUrl,
SeedOrKey = extKey,
PSBT = psbt.PSBT.ToBase64()
});
case "ledger":
return ViewWalletSendLedger(walletId, psbt.PSBT, psbt.ChangeAddress);
case "seed":
return SignWithSeed(walletId, psbt.PSBT.ToBase64());
return SignWithSeed(walletId, psbt.PSBT.ToBase64(), vm.PayJoinEndpointUrl);
case "analyze-psbt":
var name =
$"Send-{string.Join('_', vm.Outputs.Select(output => $"{output.Amount}->{output.DestinationAddress}{(output.SubtractFeesFromOutput ? "-Fees" : string.Empty)}"))}.psbt";
return RedirectToWalletPSBT(psbt.PSBT, name);
return RedirectToWalletPSBT(psbt.PSBT, name, vm.PayJoinEndpointUrl);
default:
return View(vm);
}
@ -671,10 +671,11 @@ namespace BTCPayServer.Controllers
ModelState.Clear();
}
private IActionResult ViewVault(WalletId walletId, PSBT psbt)
private IActionResult ViewVault(WalletId walletId, PSBT psbt, string payJoinEndpointUrl)
{
return View(nameof(WalletSendVault), new WalletSendVaultModel()
{
PayJoinEndpointUrl = payJoinEndpointUrl,
WalletId = walletId.ToString(),
PSBT = psbt.ToBase64(),
WebsocketPath = this.Url.Action(nameof(VaultController.VaultBridgeConnection), "Vault", new { walletId = walletId.ToString() })
@ -687,7 +688,8 @@ namespace BTCPayServer.Controllers
WalletId walletId, WalletSendVaultModel model)
{
var network = NetworkProvider.GetNetwork<BTCPayNetwork>(walletId.CryptoCode);
var newPSBT = await TryGetBPProposedTX(PSBT.Parse(model.PSBT, network.NBitcoinNetwork), GetDerivationSchemeSettings(walletId), network);
var newPSBT = await TryGetBPProposedTX(model.PayJoinEndpointUrl, PSBT.Parse(model.PSBT, network.NBitcoinNetwork), GetDerivationSchemeSettings(walletId), network);
model.PayJoinEndpointUrl = null;
if (newPSBT != null)
{
model.PSBT = newPSBT.ToBase64();
@ -712,7 +714,7 @@ namespace BTCPayServer.Controllers
return View("PostRedirect", vm);
}
private IActionResult RedirectToWalletPSBT(PSBT psbt, string fileName = null)
private IActionResult RedirectToWalletPSBT(PSBT psbt, string fileName = null, string payJoinEndpointUrl = null)
{
var vm = new PostRedirectViewModel()
{
@ -725,6 +727,8 @@ namespace BTCPayServer.Controllers
};
if (!string.IsNullOrEmpty(fileName))
vm.Parameters.Add(new KeyValuePair<string, string>("fileName", fileName));
if (!string.IsNullOrEmpty(payJoinEndpointUrl))
vm.Parameters.Add(new KeyValuePair<string, string>("payJoinEndpointUrl", payJoinEndpointUrl));
return View("PostRedirect", vm);
}
@ -771,10 +775,11 @@ namespace BTCPayServer.Controllers
[HttpGet("{walletId}/psbt/seed")]
public IActionResult SignWithSeed([ModelBinder(typeof(WalletIdModelBinder))]
WalletId walletId,string psbt)
WalletId walletId,string psbt, string payJoinEndpointUrl)
{
return View(nameof(SignWithSeed), new SignWithSeedViewModel()
{
PayJoinEndpointUrl = payJoinEndpointUrl,
PSBT = psbt
});
}
@ -842,7 +847,8 @@ namespace BTCPayServer.Controllers
return View(viewModel);
}
ModelState.Remove(nameof(viewModel.PSBT));
var newPSBT = await TryGetBPProposedTX(psbt, GetDerivationSchemeSettings(walletId), network);
var newPSBT = await TryGetBPProposedTX(viewModel.PayJoinEndpointUrl,psbt, GetDerivationSchemeSettings(walletId), network);
viewModel.PayJoinEndpointUrl = null;
if (newPSBT != null)
{
viewModel.PSBT = newPSBT.ToBase64();

View File

@ -7,6 +7,7 @@ namespace BTCPayServer.Models.WalletViewModels
{
public class SignWithSeedViewModel
{
public string PayJoinEndpointUrl { get; set; }
[Required]
public string PSBT { get; set; }
[Required][Display(Name = "BIP39 Seed (12/24 word mnemonic phrase) or HD private key (xprv...)")]

View File

@ -10,6 +10,7 @@ namespace BTCPayServer.Models.WalletViewModels
{
public class WalletPSBTViewModel
{
public string PayJoinEndpointUrl { get; set; }
public string CryptoCode { get; set; }
public string Decoded { get; set; }
string _FileName;

View File

@ -10,5 +10,6 @@ namespace BTCPayServer.Models.WalletViewModels
public string WalletId { get; set; }
public string PSBT { get; set; }
public string WebsocketPath { get; set; }
public string PayJoinEndpointUrl { get; set; }
}
}

View File

@ -28,6 +28,7 @@
<div asp-validation-summary="All" class="text-danger"></div>
<form method="post" asp-action="SignWithSeed" asp-route-walletId="@this.Context.GetRouteValue("walletId")">
<input type="hidden" asp-for="PSBT" />
<input type="hidden" asp-for="PayJoinEndpointUrl" />
<div class="form-group">
<label asp-for="SeedOrKey"></label>
<input asp-for="SeedOrKey" class="form-control" />

View File

@ -30,6 +30,7 @@
<div class="form-group">
<form method="post" asp-action="WalletPSBT" asp-route-walletId="@this.Context.GetRouteValue("walletId")">
<input type="hidden" asp-for="CryptoCode" />
<input type="hidden" asp-for="PayJoinEndpointUrl" />
<input type="hidden" asp-for="NBXSeedAvailable" />
<input type="hidden" asp-for="PSBT" />
<input type="hidden" asp-for="FileName" />

View File

@ -24,6 +24,7 @@
<input type="hidden" id="WalletId" asp-for="WalletId" />
<input type="hidden" id="PSBT" asp-for="PSBT" value="@Model.PSBT"/>
<input type="hidden" asp-for="WebsocketPath" />
<input type="hidden" asp-for="PayJoinEndpointUrl" />
</form>
<div id="vaultPlaceholder"></div>
<button id="vault-confirm" class="btn btn-primary" style="display:none;"></button>