mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 06:54:19 +01:00
This commit is contained in:
@@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using NBitcoin;
|
||||
|
||||
namespace BTCPayServer.Models.WalletViewModels
|
||||
@@ -35,9 +36,9 @@ namespace BTCPayServer.Models.WalletViewModels
|
||||
public IFormFile UploadedPSBTFile { get; set; }
|
||||
|
||||
|
||||
public async Task<PSBT> GetPSBT(Network network)
|
||||
public async Task<PSBT> GetPSBT(Network network, ModelStateDictionary modelState)
|
||||
{
|
||||
var psbt = await GetPSBTCore(network);
|
||||
var psbt = await GetPSBTCore(network, modelState);
|
||||
if (psbt != null)
|
||||
{
|
||||
Decoded = psbt.ToString();
|
||||
@@ -52,7 +53,7 @@ namespace BTCPayServer.Models.WalletViewModels
|
||||
}
|
||||
public bool InvalidPSBT { get; set; }
|
||||
|
||||
async Task<PSBT> GetPSBTCore(Network network)
|
||||
async Task<PSBT> GetPSBTCore(Network network, ModelStateDictionary modelState)
|
||||
{
|
||||
if (UploadedPSBTFile != null)
|
||||
{
|
||||
@@ -68,16 +69,20 @@ namespace BTCPayServer.Models.WalletViewModels
|
||||
}
|
||||
return NBitcoin.PSBT.Load(bytes, network);
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
using var stream = new StreamReader(UploadedPSBTFile.OpenReadStream());
|
||||
PSBT = await stream.ReadToEndAsync();
|
||||
modelState.Remove(nameof(PSBT));
|
||||
modelState.AddModelError(nameof(PSBT), ex.Message);
|
||||
InvalidPSBT = true;
|
||||
}
|
||||
}
|
||||
if (SigningContext != null && !string.IsNullOrEmpty(SigningContext.PSBT))
|
||||
{
|
||||
PSBT = SigningContext.PSBT;
|
||||
modelState.Remove(nameof(PSBT));
|
||||
InvalidPSBT = false;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(PSBT))
|
||||
{
|
||||
@@ -86,8 +91,11 @@ namespace BTCPayServer.Models.WalletViewModels
|
||||
InvalidPSBT = false;
|
||||
return NBitcoin.PSBT.Parse(PSBT, network);
|
||||
}
|
||||
catch
|
||||
{ InvalidPSBT = true; }
|
||||
catch (Exception ex) when (!InvalidPSBT)
|
||||
{
|
||||
modelState.AddModelError(nameof(PSBT), ex.Message);
|
||||
InvalidPSBT = true;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user