Reuse same html and handling of commands for PSBT signing/ Wallet Send (#1587)

* Reuse same html and handling of commands for PSBT signing/ Wallet Send

* fix ledger
This commit is contained in:
Andrew Camilleri
2020-05-23 21:31:21 +02:00
committed by GitHub
parent cdf6886c39
commit 9d215ea27d
5 changed files with 77 additions and 74 deletions

View File

@@ -100,6 +100,12 @@ namespace BTCPayServer.Controllers
ModelState.AddModelError(nameof(vm.PSBT), "Invalid PSBT");
return View(vm);
}
var res = await TryHandleSigningCommands(walletId, psbt, command, vm.PayJoinEndpointUrl, null);
if (res != null)
{
return res;
}
switch (command)
{
case "decode":
@@ -110,10 +116,7 @@ namespace BTCPayServer.Controllers
vm.PSBT = psbt.ToBase64();
vm.FileName = vm.UploadedPSBTFile?.FileName;
return View(vm);
case "vault":
return ViewVault(walletId, psbt, vm.PayJoinEndpointUrl);
case "ledger":
return ViewWalletSendLedger(walletId, psbt);
case "update":
var derivationSchemeSettings = GetDerivationSchemeSettings(walletId);
psbt = await ExplorerClientProvider.UpdatePSBT(derivationSchemeSettings, psbt);
@@ -124,21 +127,7 @@ namespace BTCPayServer.Controllers
}
TempData[WellKnownTempData.SuccessMessage] = "PSBT updated!";
return RedirectToWalletPSBT(psbt, vm.FileName);
case "seed":
return SignWithSeed(walletId, psbt.ToBase64(), vm.PayJoinEndpointUrl);
case "nbx-seed":
if (await CanUseHotWallet())
{
var derivationScheme = GetDerivationSchemeSettings(walletId);
var extKey = await ExplorerClientProvider.GetExplorerClient(network)
.GetMetadataAsync<string>(derivationScheme.AccountDerivation,
WellknownMetadataKeys.MasterHDKey);
return SignWithSeed(walletId,
new SignWithSeedViewModel() {SeedOrKey = extKey, PSBT = psbt.ToBase64(), PayJoinEndpointUrl = vm.PayJoinEndpointUrl});
}
return View(vm);
case "broadcast":
{
return RedirectToWalletPSBTReady(psbt.ToBase64());
@@ -470,5 +459,38 @@ namespace BTCPayServer.Controllers
TempData[WellKnownTempData.SuccessMessage] = "PSBT Successfully combined!";
return RedirectToWalletPSBT(sourcePSBT);
}
private async Task<IActionResult> TryHandleSigningCommands(WalletId walletId, PSBT psbt, string command,
string payjoinEndpointUrl, BitcoinAddress changeAddress)
{
switch (command )
{
case "vault":
return ViewVault(walletId, psbt, payjoinEndpointUrl);
case "ledger":
return ViewWalletSendLedger(walletId, psbt, changeAddress);
case "seed":
return SignWithSeed(walletId, psbt.ToBase64(), payjoinEndpointUrl);
case "nbx-seed":
if (await CanUseHotWallet())
{
var derivationScheme = GetDerivationSchemeSettings(walletId);
var extKey = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode)
.GetMetadataAsync<string>(derivationScheme.AccountDerivation,
WellknownMetadataKeys.MasterHDKey);
return SignWithSeed(walletId,
new SignWithSeedViewModel() {SeedOrKey = extKey, PSBT = psbt.ToBase64(), PayJoinEndpointUrl = payjoinEndpointUrl});
}
TempData.SetStatusMessageModel(new StatusMessageModel()
{
Severity = StatusMessageModel.StatusSeverity.Error,
Message = "NBX seed functionality is not available"
});
break;
}
return null;
}
}
}

View File

@@ -653,24 +653,16 @@ namespace BTCPayServer.Controllers
return View(vm);
}
derivationScheme.RebaseKeyPaths(psbt.PSBT);
var res = await TryHandleSigningCommands(walletId, psbt.PSBT, command, vm.PayJoinEndpointUrl, psbt.ChangeAddress);
if (res != null)
{
return res;
}
switch (command)
{
case "vault":
return ViewVault(walletId, psbt.PSBT, vm.PayJoinEndpointUrl);
case "nbx-seed":
var extKey = await ExplorerClientProvider.GetExplorerClient(network)
.GetMetadataAsync<string>(derivationScheme.AccountDerivation, WellknownMetadataKeys.MasterHDKey, cancellation);
return 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(), vm.PayJoinEndpointUrl);
case "analyze-psbt":
var name =
$"Send-{string.Join('_', vm.Outputs.Select(output => $"{output.Amount}->{output.DestinationAddress}{(output.SubtractFeesFromOutput ? "-Fees" : string.Empty)}"))}.psbt";