mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Can actually upload PSBT file in PSBT Combine and PSBT view.
Validate transaction before allowing any broadcast and show errors nicely.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NBitcoin;
|
||||
|
||||
namespace BTCPayServer.Models.WalletViewModels
|
||||
@@ -24,13 +26,38 @@ namespace BTCPayServer.Models.WalletViewModels
|
||||
public string PSBT { get; set; }
|
||||
public List<string> Errors { get; set; } = new List<string>();
|
||||
|
||||
internal PSBT GetPSBT(Network network)
|
||||
[Display(Name = "Upload PSBT from file...")]
|
||||
public IFormFile UploadedPSBTFile { get; set; }
|
||||
|
||||
public async Task<PSBT> GetPSBT(Network network)
|
||||
{
|
||||
try
|
||||
if (UploadedPSBTFile != null)
|
||||
{
|
||||
return NBitcoin.PSBT.Parse(PSBT, network);
|
||||
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))
|
||||
{
|
||||
try
|
||||
{
|
||||
return NBitcoin.PSBT.Parse(PSBT, network);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
catch { }
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user