The signing context should not be passed to PSBT screen

This commit is contained in:
nicolas.dorier
2020-05-25 07:05:01 +09:00
parent 9e9b5945fe
commit cccf3ca617
6 changed files with 16 additions and 20 deletions

View File

@@ -128,10 +128,7 @@ namespace BTCPayServer.Tests
var ready = (await walletController.WalletPSBTReady(walletId, new WalletPSBTReadyViewModel() var ready = (await walletController.WalletPSBTReady(walletId, new WalletPSBTReadyViewModel()
{ {
SigningContext = new SigningContextModel() SigningContext = new SigningContextModel(signedPSBT)
{
PSBT = signedPSBT.ToBase64()
}
})).AssertViewModel<WalletPSBTReadyViewModel>(); })).AssertViewModel<WalletPSBTReadyViewModel>();
Assert.Equal(signedPSBT.ToBase64(), ready.SigningContext.PSBT); Assert.Equal(signedPSBT.ToBase64(), ready.SigningContext.PSBT);
psbt = AssertRedirectedPSBT(await walletController.WalletPSBTReady(walletId, ready, command: "analyze-psbt"), nameof(walletController.WalletPSBT)); psbt = AssertRedirectedPSBT(await walletController.WalletPSBTReady(walletId, ready, command: "analyze-psbt"), nameof(walletController.WalletPSBT));
@@ -146,7 +143,7 @@ namespace BTCPayServer.Tests
var postRedirectView = Assert.IsType<ViewResult>(view); var postRedirectView = Assert.IsType<ViewResult>(view);
var postRedirectViewModel = Assert.IsType<PostRedirectViewModel>(postRedirectView.Model); var postRedirectViewModel = Assert.IsType<PostRedirectViewModel>(postRedirectView.Model);
Assert.Equal(actionName, postRedirectViewModel.AspAction); Assert.Equal(actionName, postRedirectViewModel.AspAction);
var redirectedPSBT = postRedirectViewModel.Parameters.Single(p => p.Key == "psbt").Value; var redirectedPSBT = postRedirectViewModel.Parameters.Single(p => p.Key == "psbt" || p.Key == "SigningContext.PSBT").Value;
return redirectedPSBT; return redirectedPSBT;
} }
} }

View File

@@ -100,8 +100,7 @@ namespace BTCPayServer.Controllers
ModelState.AddModelError(nameof(vm.PSBT), "Invalid PSBT"); ModelState.AddModelError(nameof(vm.PSBT), "Invalid PSBT");
return View(vm); return View(vm);
} }
var res = await TryHandleSigningCommands(walletId, psbt, command, new SigningContextModel(psbt));
var res = await TryHandleSigningCommands(walletId, psbt, command, vm.SigningContext);
if (res != null) if (res != null)
{ {
return res; return res;
@@ -129,18 +128,14 @@ namespace BTCPayServer.Controllers
return RedirectToWalletPSBT(new WalletPSBTViewModel() return RedirectToWalletPSBT(new WalletPSBTViewModel()
{ {
PSBT = psbt.ToBase64(), PSBT = psbt.ToBase64(),
FileName = vm.FileName, FileName = vm.FileName
SigningContext = vm.SigningContext
}); });
case "broadcast": case "broadcast":
{ {
return RedirectToWalletPSBTReady(new WalletPSBTReadyViewModel() return RedirectToWalletPSBTReady(new WalletPSBTReadyViewModel()
{ {
SigningContext = new SigningContextModel() SigningContext = new SigningContextModel(psbt)
{
PSBT = psbt.ToBase64()
}
}); });
} }
case "combine": case "combine":
@@ -437,8 +432,7 @@ namespace BTCPayServer.Controllers
case "analyze-psbt": case "analyze-psbt":
return RedirectToWalletPSBT(new WalletPSBTViewModel() return RedirectToWalletPSBT(new WalletPSBTViewModel()
{ {
PSBT = psbt.ToBase64(), PSBT = psbt.ToBase64()
SigningContext = vm.SigningContext
}); });
default: default:
vm.GlobalError = "Unknown command"; vm.GlobalError = "Unknown command";

View File

@@ -677,8 +677,7 @@ namespace BTCPayServer.Controllers
return RedirectToWalletPSBT(new WalletPSBTViewModel() return RedirectToWalletPSBT(new WalletPSBTViewModel()
{ {
PSBT = psbt.PSBT.ToBase64(), PSBT = psbt.PSBT.ToBase64(),
FileName = name, FileName = name
SigningContext = signingContext
}); });
default: default:
return View(vm); return View(vm);
@@ -801,7 +800,6 @@ namespace BTCPayServer.Controllers
new KeyValuePair<string, string>("fileName", vm.FileName) new KeyValuePair<string, string>("fileName", vm.FileName)
} }
}; };
AddSigningContext(redirectVm, vm.SigningContext);
return View("PostRedirect", redirectVm); return View("PostRedirect", redirectVm);
} }

View File

@@ -2,11 +2,20 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using NBitcoin;
namespace BTCPayServer.Models.WalletViewModels namespace BTCPayServer.Models.WalletViewModels
{ {
public class SigningContextModel public class SigningContextModel
{ {
public SigningContextModel()
{
}
public SigningContextModel(PSBT psbt)
{
PSBT = psbt.ToBase64();
}
public string PSBT { get; set; } public string PSBT { get; set; }
public string OriginalPSBT { get; set; } public string OriginalPSBT { get; set; }
public string PayJoinEndpointUrl { get; set; } public string PayJoinEndpointUrl { get; set; }

View File

@@ -10,7 +10,6 @@ namespace BTCPayServer.Models.WalletViewModels
{ {
public class WalletPSBTViewModel public class WalletPSBTViewModel
{ {
public SigningContextModel SigningContext { get; set; } = new SigningContextModel();
public string CryptoCode { get; set; } public string CryptoCode { get; set; }
public string Decoded { get; set; } public string Decoded { get; set; }
string _FileName; string _FileName;

View File

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