Can sign and export arbitrary PSBT

This commit is contained in:
nicolas.dorier
2019-05-11 20:26:31 +09:00
parent 541c748ecb
commit 5f1aa619cd
2 changed files with 53 additions and 9 deletions

View File

@@ -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(