mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-03 17:36:59 +01:00
Add utility tool to decode PSBT
This commit is contained in:
parent
79d26b5d95
commit
e853bddbc8
7 changed files with 80 additions and 1 deletions
|
@ -182,6 +182,9 @@
|
|||
<Content Update="Views\Wallets\ListWallets.cshtml">
|
||||
<Pack>$(IncludeRazorContentInPack)</Pack>
|
||||
</Content>
|
||||
<Content Update="Views\Wallets\WalletPSBT.cshtml">
|
||||
<Pack>$(IncludeRazorContentInPack)</Pack>
|
||||
</Content>
|
||||
<Content Update="Views\Wallets\WalletRescan.cshtml">
|
||||
<Pack>$(IncludeRazorContentInPack)</Pack>
|
||||
</Content>
|
||||
|
|
|
@ -247,6 +247,12 @@ namespace BTCPayServer.Controllers
|
|||
try
|
||||
{
|
||||
var psbt = await CreatePSBT(network, derivationScheme, sendModel, cancellation);
|
||||
if (command == "analyze-psbt")
|
||||
return View(nameof(WalletPSBT), new WalletPSBTViewModel()
|
||||
{
|
||||
Decoded = psbt.PSBT.ToString(),
|
||||
PSBT = psbt.PSBT.ToBase64()
|
||||
});
|
||||
return File(psbt.PSBT.ToBytes(), "application/octet-stream", $"Send-{vm.Amount.Value}-{network.CryptoCode}-to-{destination[0].ToString()}.psbt");
|
||||
}
|
||||
catch (NBXplorerException ex)
|
||||
|
@ -331,6 +337,31 @@ namespace BTCPayServer.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{walletId}/psbt")]
|
||||
public IActionResult WalletPSBT()
|
||||
{
|
||||
return View(new WalletPSBTViewModel());
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("{walletId}/psbt")]
|
||||
public IActionResult WalletPSBT(
|
||||
[ModelBinder(typeof(WalletIdModelBinder))]
|
||||
WalletId walletId,
|
||||
WalletPSBTViewModel vm)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(vm.PSBT))
|
||||
vm.Decoded = PSBT.Parse(vm.PSBT, NetworkProvider.GetNetwork(walletId.CryptoCode).NBitcoinNetwork).ToString();
|
||||
}
|
||||
catch (FormatException ex)
|
||||
{
|
||||
ModelState.AddModelError(nameof(vm.PSBT), ex.Message);
|
||||
}
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{walletId}/rescan")]
|
||||
public async Task<IActionResult> WalletRescan(
|
||||
|
|
13
BTCPayServer/Models/WalletViewModels/WalletPSBTViewModel.cs
Normal file
13
BTCPayServer/Models/WalletViewModels/WalletPSBTViewModel.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BTCPayServer.Models.WalletViewModels
|
||||
{
|
||||
public class WalletPSBTViewModel
|
||||
{
|
||||
public string Decoded { get; set; }
|
||||
public string PSBT { get; set; }
|
||||
}
|
||||
}
|
29
BTCPayServer/Views/Wallets/WalletPSBT.cshtml
Normal file
29
BTCPayServer/Views/Wallets/WalletPSBT.cshtml
Normal file
|
@ -0,0 +1,29 @@
|
|||
@model WalletPSBTViewModel
|
||||
@{
|
||||
Layout = "../Shared/_NavLayout.cshtml";
|
||||
ViewData["Title"] = "PSBT";
|
||||
ViewData.SetActivePageAndTitle(WalletsNavPages.PSBT);
|
||||
}
|
||||
<div class="row">
|
||||
<div class="col-md-10">
|
||||
@if (!string.IsNullOrEmpty(Model.Decoded))
|
||||
{
|
||||
<h3>Decoded PSBT</h3>
|
||||
<pre><code class="json">@Model.Decoded</code></pre>
|
||||
}
|
||||
<h3>PSBT to decode</h3>
|
||||
<form class="form-group" method="post" asp-action="WalletPSBT">
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" rows="5" asp-for="PSBT"></textarea>
|
||||
<span asp-validation-for="PSBT" class="text-danger"></span>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Decode</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<link rel="stylesheet" href="~/vendor/highlightjs/default.min.css">
|
||||
<script src="~/vendor/highlightjs/highlight.min.js"></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
}
|
|
@ -90,6 +90,7 @@
|
|||
<div class="dropdown-menu" aria-labelledby="SendMenu">
|
||||
<button name="command" type="submit" class="dropdown-item" value="ledger">... your Ledger Wallet device</button>
|
||||
<button name="command" type="submit" class="dropdown-item" value="save-psbt">... a wallet supporting PSBT</button>
|
||||
<button name="command" type="submit" class="dropdown-item" value="analyze-psbt">... analyze the PSBT</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace BTCPayServer.Views.Wallets
|
|||
{
|
||||
Send,
|
||||
Transactions,
|
||||
Rescan
|
||||
Rescan,
|
||||
PSBT
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,5 +4,6 @@
|
|||
<a class="nav-link @ViewData.IsActivePage(WalletsNavPages.Transactions)" asp-action="WalletTransactions">Transactions</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(WalletsNavPages.Send)" asp-action="WalletSend">Send</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(WalletsNavPages.Rescan)" asp-action="WalletRescan">Rescan</a>
|
||||
<a class="nav-link @ViewData.IsActivePage(WalletsNavPages.PSBT)" asp-action="WalletPSBT">PSBT</a>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue