mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Can sign and export arbitrary PSBT
This commit is contained in:
@@ -233,25 +233,19 @@ namespace BTCPayServer.Controllers
|
||||
|
||||
if (command == "ledger")
|
||||
{
|
||||
return View("WalletSendLedger", new WalletSendLedgerModel()
|
||||
{
|
||||
PSBT = psbt.PSBT.ToBase64(),
|
||||
HintChange = psbt.ChangeAddress?.ToString(),
|
||||
WebsocketPath = this.Url.Action(nameof(LedgerConnection)),
|
||||
SuccessPath = this.Url.Action(nameof(WalletSendLedgerSuccess))
|
||||
});
|
||||
return ViewWalletSendLedger(psbt.PSBT, psbt.ChangeAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
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");
|
||||
return FilePSBT(psbt.PSBT, $"Send-{vm.Amount.Value}-{network.CryptoCode}-to-{destination[0].ToString()}.psbt");
|
||||
}
|
||||
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]
|
||||
public async Task<CreatePSBTResponse> CreatePSBT(BTCPayNetwork network, DerivationSchemeSettings derivationSettings, WalletSendModel sendModel, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -342,6 +352,26 @@ namespace BTCPayServer.Controllers
|
||||
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]
|
||||
[Route("{walletId}/rescan")]
|
||||
public async Task<IActionResult> WalletRescan(
|
||||
|
||||
Reference in New Issue
Block a user