Пример #1
0
 public async Task <PSBT> GetPSBT(Network network)
 {
     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))
     {
         try
         {
             return(NBitcoin.PSBT.Parse(PSBT, network));
         }
         catch
         { }
     }
     return(null);
 }
        async Task <PSBT> GetPSBTCore(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();

                    InvalidPSBT = true;
                }
            }
            if (SigningContext != null && !string.IsNullOrEmpty(SigningContext.PSBT))
            {
                PSBT = SigningContext.PSBT;
            }
            if (!string.IsNullOrEmpty(PSBT))
            {
                try
                {
                    InvalidPSBT = false;
                    return(NBitcoin.PSBT.Parse(PSBT, network));
                }
                catch
                { InvalidPSBT = true; }
            }
            return(null);
        }