mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-12 10:30:47 +01:00
* Refactoring to generalize wizard layout * Wallet: Add intermediate signing options view * Update BTCPayServer/Views/Wallets/WalletSigningOptions.cshtml Co-authored-by: britttttk <39231115+britttttk@users.noreply.github.com> * Skip signing options for hot wallets * Update signing options wordings, add PSBT doc link * Fix test * Remove form route params * Use decode command for PSBT Co-authored-by: britttttk <39231115+britttttk@users.noreply.github.com>
77 lines
2.3 KiB
C#
77 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Http;
|
|
using NBitcoin;
|
|
|
|
namespace BTCPayServer.Models.WalletViewModels
|
|
{
|
|
public class WalletPSBTViewModel
|
|
{
|
|
public string CryptoCode { get; set; }
|
|
public string Decoded { get; set; }
|
|
string _FileName;
|
|
public string PSBTHex { get; set; }
|
|
public bool NBXSeedAvailable { get; set; }
|
|
|
|
public string FileName
|
|
{
|
|
get
|
|
{
|
|
return string.IsNullOrEmpty(_FileName) ? "psbt-export.psbt" : _FileName;
|
|
}
|
|
set
|
|
{
|
|
_FileName = value;
|
|
}
|
|
}
|
|
[Display(Name = "PSBT content")]
|
|
public string PSBT { get; set; }
|
|
public List<string> Errors { get; set; } = new List<string>();
|
|
|
|
[Display(Name = "Upload PSBT from file...")]
|
|
public IFormFile UploadedPSBTFile { get; set; }
|
|
|
|
public SigningContextModel SigningContext { get; set; } = new SigningContextModel();
|
|
|
|
public async Task<PSBT> GetPSBT(Network network)
|
|
{
|
|
if (UploadedPSBTFile != null)
|
|
{
|
|
if (UploadedPSBTFile.Length > 500 * 1024)
|
|
return null;
|
|
|
|
try
|
|
{
|
|
byte[] bytes = new byte[UploadedPSBTFile.Length];
|
|
await using (var stream = UploadedPSBTFile.OpenReadStream())
|
|
{
|
|
await stream.ReadAsync(bytes, 0, (int)UploadedPSBTFile.Length);
|
|
}
|
|
return NBitcoin.PSBT.Load(bytes, network);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
using var stream = new StreamReader(UploadedPSBTFile.OpenReadStream());
|
|
PSBT = await stream.ReadToEndAsync();
|
|
}
|
|
}
|
|
if (SigningContext != null && !string.IsNullOrEmpty(SigningContext.PSBT))
|
|
{
|
|
PSBT = SigningContext.PSBT;
|
|
}
|
|
if (!string.IsNullOrEmpty(PSBT))
|
|
{
|
|
try
|
|
{
|
|
return NBitcoin.PSBT.Parse(PSBT, network);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|