mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 06:54:19 +01:00
Can sign and export arbitrary PSBT
This commit is contained in:
@@ -233,25 +233,19 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
if (command == "ledger")
|
if (command == "ledger")
|
||||||
{
|
{
|
||||||
return View("WalletSendLedger", new WalletSendLedgerModel()
|
return ViewWalletSendLedger(psbt.PSBT, psbt.ChangeAddress);
|
||||||
{
|
|
||||||
PSBT = psbt.PSBT.ToBase64(),
|
|
||||||
HintChange = psbt.ChangeAddress?.ToString(),
|
|
||||||
WebsocketPath = this.Url.Action(nameof(LedgerConnection)),
|
|
||||||
SuccessPath = this.Url.Action(nameof(WalletSendLedgerSuccess))
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (command == "analyze-psbt")
|
if (command == "analyze-psbt")
|
||||||
return View(nameof(WalletPSBT), new WalletPSBTViewModel()
|
return View(nameof(WalletPSBT), new WalletPSBTViewModel()
|
||||||
{
|
{
|
||||||
Decoded = psbt.PSBT.ToString(),
|
Decoded = psbt.PSBT.ToString(),
|
||||||
PSBT = psbt.PSBT.ToBase64()
|
PSBT = psbt.PSBT.ToBase64()
|
||||||
});
|
});
|
||||||
return File(psbt.PSBT.ToBytes(), "application/octet-stream", $"Send-{vm.Amount.Value}-{network.CryptoCode}-to-{destination[0].ToString()}.psbt");
|
return FilePSBT(psbt.PSBT, $"Send-{vm.Amount.Value}-{network.CryptoCode}-to-{destination[0].ToString()}.psbt");
|
||||||
}
|
}
|
||||||
catch (NBXplorerException ex)
|
catch (NBXplorerException ex)
|
||||||
{
|
{
|
||||||
@@ -266,6 +260,22 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IActionResult FilePSBT(PSBT psbt, string fileName)
|
||||||
|
{
|
||||||
|
return File(psbt.ToBytes(), "application/octet-stream", fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ViewResult ViewWalletSendLedger(PSBT psbt, BitcoinAddress hintChange = null)
|
||||||
|
{
|
||||||
|
return View("WalletSendLedger", new WalletSendLedgerModel()
|
||||||
|
{
|
||||||
|
PSBT = psbt.ToBase64(),
|
||||||
|
HintChange = hintChange?.ToString(),
|
||||||
|
WebsocketPath = this.Url.Action(nameof(LedgerConnection)),
|
||||||
|
SuccessPath = this.Url.Action(nameof(WalletSendLedgerSuccess))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public async Task<CreatePSBTResponse> CreatePSBT(BTCPayNetwork network, DerivationSchemeSettings derivationSettings, WalletSendModel sendModel, CancellationToken cancellationToken)
|
public async Task<CreatePSBTResponse> CreatePSBT(BTCPayNetwork network, DerivationSchemeSettings derivationSettings, WalletSendModel sendModel, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
@@ -342,6 +352,26 @@ namespace BTCPayServer.Controllers
|
|||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Route("{walletId}/psbt/sign")]
|
||||||
|
public IActionResult WalletPSBTSign(
|
||||||
|
[ModelBinder(typeof(WalletIdModelBinder))]
|
||||||
|
WalletId walletId,
|
||||||
|
WalletPSBTViewModel vm,
|
||||||
|
string command = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var psbt = PSBT.Parse(vm.PSBT, NetworkProvider.GetNetwork(walletId.CryptoCode).NBitcoinNetwork);
|
||||||
|
if (command == "ledger")
|
||||||
|
{
|
||||||
|
return ViewWalletSendLedger(psbt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FilePSBT(psbt, "psbt-export.psbt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{walletId}/rescan")]
|
[Route("{walletId}/rescan")]
|
||||||
public async Task<IActionResult> WalletRescan(
|
public async Task<IActionResult> WalletRescan(
|
||||||
|
|||||||
@@ -10,6 +10,20 @@
|
|||||||
{
|
{
|
||||||
<h3>Decoded PSBT</h3>
|
<h3>Decoded PSBT</h3>
|
||||||
<pre><code class="json">@Model.Decoded</code></pre>
|
<pre><code class="json">@Model.Decoded</code></pre>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="dropdown" style="margin-top:16px;">
|
||||||
|
<button class="btn btn-primary dropdown-toggle" type="button" id="SendMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
Sign with...
|
||||||
|
</button>
|
||||||
|
<form method="post" asp-action="WalletPSBTSign">
|
||||||
|
<input type="hidden" asp-for="PSBT" />
|
||||||
|
<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 files</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
<h3>PSBT to decode</h3>
|
<h3>PSBT to decode</h3>
|
||||||
<form class="form-group" method="post" asp-action="WalletPSBT">
|
<form class="form-group" method="post" asp-action="WalletPSBT">
|
||||||
|
|||||||
Reference in New Issue
Block a user