btcpayserver/BTCPayServer/Models/WalletViewModels/WalletPSBTViewModel.cs

66 lines
1.8 KiB
C#
Raw Normal View History

2019-05-11 00:29:29 +09:00
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
2019-05-11 00:29:29 +09:00
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
2019-05-12 13:13:52 +09:00
using NBitcoin;
2019-05-11 00:29:29 +09:00
namespace BTCPayServer.Models.WalletViewModels
{
public class WalletPSBTViewModel
{
public string CryptoCode { get; set; }
2019-05-11 00:29:29 +09:00
public string Decoded { get; set; }
2019-05-13 08:55:26 +09:00
string _FileName;
public string FileName
{
get
{
return string.IsNullOrEmpty(_FileName) ? "psbt-export.psbt" : _FileName;
}
set
{
_FileName = value;
}
}
2019-05-11 00:29:29 +09:00
public string PSBT { get; set; }
public List<string> Errors { get; set; } = new List<string>();
2019-05-12 13:13:52 +09:00
[Display(Name = "Upload PSBT from file...")]
public IFormFile UploadedPSBTFile { get; set; }
public async Task<PSBT> GetPSBT(Network network)
2019-05-12 13:13:52 +09:00
{
if (UploadedPSBTFile != null)
{
if (UploadedPSBTFile.Length > 500 * 1024)
return null;
byte[] bytes = new byte[UploadedPSBTFile.Length];
using (var stream = UploadedPSBTFile.OpenReadStream())
{
await stream.ReadAsync(bytes, 0, (int)UploadedPSBTFile.Length);
}
try
{
return NBitcoin.PSBT.Load(bytes, network);
}
catch
{
return null;
}
}
if (!string.IsNullOrEmpty(PSBT))
2019-05-12 13:13:52 +09:00
{
try
{
return NBitcoin.PSBT.Parse(PSBT, network);
}
catch
{ }
2019-05-12 13:13:52 +09:00
}
return null;
}
2019-05-11 00:29:29 +09:00
}
}