2019-05-11 00:29:29 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-05-19 23:27:18 +09:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2019-05-11 00:29:29 +09:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-05-19 23:27:18 +09:00
|
|
|
|
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
|
|
|
|
|
{
|
2019-11-11 14:22:04 +09:00
|
|
|
|
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; }
|
2019-05-12 00:05:30 +09:00
|
|
|
|
public List<string> Errors { get; set; } = new List<string>();
|
2019-05-12 13:13:52 +09:00
|
|
|
|
|
2019-05-19 23:27:18 +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
|
|
|
|
{
|
2019-05-19 23:27:18 +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
|
|
|
|
{
|
2019-05-19 23:27:18 +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
|
|
|
|
}
|
|
|
|
|
}
|