This commit is contained in:
nicolas.dorier
2019-05-13 08:55:26 +09:00
parent a7edbfe5e9
commit d1556eb6cd
6 changed files with 44 additions and 27 deletions

View File

@@ -67,7 +67,7 @@ namespace BTCPayServer.Tests
var unsignedPSBT = PSBT.Parse(vmPSBT.PSBT, user.SupportedNetwork.NBitcoinNetwork); var unsignedPSBT = PSBT.Parse(vmPSBT.PSBT, user.SupportedNetwork.NBitcoinNetwork);
Assert.NotNull(vmPSBT.Decoded); Assert.NotNull(vmPSBT.Decoded);
var filePSBT = (FileContentResult)(await walletController.WalletSend(walletId, sendModel, command: "save-psbt")); var filePSBT = (FileContentResult)(await walletController.WalletPSBT(walletId, vmPSBT, "save-psbt"));
PSBT.Load(filePSBT.FileContents, user.SupportedNetwork.NBitcoinNetwork); PSBT.Load(filePSBT.FileContents, user.SupportedNetwork.NBitcoinNetwork);
await walletController.WalletPSBT(walletId, vmPSBT, "ledger").AssertViewModelAsync<WalletSendLedgerModel>(); await walletController.WalletPSBT(walletId, vmPSBT, "ledger").AssertViewModelAsync<WalletSendLedgerModel>();

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework> <TargetFramework>netcoreapp2.1</TargetFramework>
<Version>1.0.3.102</Version> <Version>1.0.3.103</Version>
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn> <NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

View File

@@ -64,6 +64,7 @@ namespace BTCPayServer.Controllers
if (command == null) if (command == null)
{ {
vm.Decoded = psbt.ToString(); vm.Decoded = psbt.ToString();
vm.FileName = string.Empty;
return View(vm); return View(vm);
} }
else if (command == "ledger") else if (command == "ledger")
@@ -96,11 +97,11 @@ namespace BTCPayServer.Controllers
ModelState.Remove(nameof(vm.PSBT)); ModelState.Remove(nameof(vm.PSBT));
return View(nameof(WalletPSBTCombine), new WalletPSBTCombineViewModel() { OtherPSBT = psbt.ToBase64() }); return View(nameof(WalletPSBTCombine), new WalletPSBTCombineViewModel() { OtherPSBT = psbt.ToBase64() });
} }
else else if (command == "save-psbt")
{ {
(await GetDerivationSchemeSettings(walletId)).RebaseKeyPaths(psbt); return FilePSBT(psbt, vm.FileName);
return FilePSBT(psbt, "psbt-export.psbt");
} }
return View(vm);
} }
[HttpGet] [HttpGet]
@@ -171,13 +172,18 @@ namespace BTCPayServer.Controllers
private IActionResult ViewPSBT<T>(PSBT psbt, IEnumerable<T> errors = null) private IActionResult ViewPSBT<T>(PSBT psbt, IEnumerable<T> errors = null)
{ {
return ViewPSBT(psbt, errors?.Select(e => e.ToString()).ToList()); return ViewPSBT(psbt, null, errors?.Select(e => e.ToString()).ToList());
} }
private IActionResult ViewPSBT(PSBT psbt, IEnumerable<string> errors = null) private IActionResult ViewPSBT(PSBT psbt, IEnumerable<string> errors = null)
{
return ViewPSBT(psbt, null, errors);
}
private IActionResult ViewPSBT(PSBT psbt, string fileName, IEnumerable<string> errors = null)
{ {
return View(nameof(WalletPSBT), new WalletPSBTViewModel() return View(nameof(WalletPSBT), new WalletPSBTViewModel()
{ {
Decoded = psbt.ToString(), Decoded = psbt.ToString(),
FileName = fileName ?? string.Empty,
PSBT = psbt.ToBase64(), PSBT = psbt.ToBase64(),
Errors = errors?.ToList() Errors = errors?.ToList()
}); });

View File

@@ -228,32 +228,32 @@ namespace BTCPayServer.Controllers
return View(vm); return View(vm);
DerivationSchemeSettings derivationScheme = await GetDerivationSchemeSettings(walletId); DerivationSchemeSettings derivationScheme = await GetDerivationSchemeSettings(walletId);
var psbt = await CreatePSBT(network, derivationScheme, vm, cancellation);
CreatePSBTResponse psbt = null;
try
{
psbt = await CreatePSBT(network, derivationScheme, vm, cancellation);
}
catch (NBXplorerException ex)
{
ModelState.AddModelError(nameof(vm.Amount), ex.Error.Message);
return View(vm);
}
catch (NotSupportedException)
{
ModelState.AddModelError(nameof(vm.Destination), "You need to update your version of NBXplorer");
return View(vm);
}
derivationScheme.RebaseKeyPaths(psbt.PSBT);
if (command == "ledger") if (command == "ledger")
{ {
return ViewWalletSendLedger(psbt.PSBT, psbt.ChangeAddress); return ViewWalletSendLedger(psbt.PSBT, psbt.ChangeAddress);
} }
else else if (command == "analyze-psbt")
{ {
try return ViewPSBT(psbt.PSBT, $"Send-{vm.Amount.Value}-{network.CryptoCode}-to-{destination[0].ToString()}.psbt");
{
if (command == "analyze-psbt")
return ViewPSBT(psbt.PSBT);
derivationScheme.RebaseKeyPaths(psbt.PSBT);
return FilePSBT(psbt.PSBT, $"Send-{vm.Amount.Value}-{network.CryptoCode}-to-{destination[0].ToString()}.psbt");
}
catch (NBXplorerException ex)
{
ModelState.AddModelError(nameof(vm.Amount), ex.Error.Message);
return View(vm);
}
catch (NotSupportedException)
{
ModelState.AddModelError(nameof(vm.Destination), "You need to update your version of NBXplorer");
return View(vm);
}
} }
return View(vm);
} }
private ViewResult ViewWalletSendLedger(PSBT psbt, BitcoinAddress hintChange = null) private ViewResult ViewWalletSendLedger(PSBT psbt, BitcoinAddress hintChange = null)

View File

@@ -9,6 +9,18 @@ namespace BTCPayServer.Models.WalletViewModels
public class WalletPSBTViewModel public class WalletPSBTViewModel
{ {
public string Decoded { get; set; } public string Decoded { get; set; }
string _FileName;
public string FileName
{
get
{
return string.IsNullOrEmpty(_FileName) ? "psbt-export.psbt" : _FileName;
}
set
{
_FileName = value;
}
}
public string PSBT { get; set; } public string PSBT { get; set; }
public List<string> Errors { get; set; } = new List<string>(); public List<string> Errors { get; set; } = new List<string>();

View File

@@ -89,9 +89,8 @@
</button> </button>
<div class="dropdown-menu" aria-labelledby="SendMenu"> <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="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">... a wallet supporting PSBT</button>
</div> </div>
<button name="command" type="submit" class="btn btn-secondary" value="analyze-psbt">... analyze the PSBT</button>
</div> </div>
</div> </div>
</form> </form>