public static int Verify(Cash cash, Stream stream) { if (cash == null) return 0; if (stream == null) throw new ArgumentNullException(nameof(stream)); if (cash.CashAlgorithm == CashAlgorithm.Version1) { var minerUtils = new MinerUtils(); return minerUtils.Verify_1(cash.Key, Sha256.ComputeHash(stream)); } return 0; }
public Cash Create(Stream stream) { if (stream == null) throw new ArgumentNullException(nameof(stream)); if (this.Limit == 0 || this.ComputationTime <= TimeSpan.Zero) return null; if (this.CashAlgorithm == CashAlgorithm.Version1) { _isCanceled = false; var minerUtils = new MinerUtils(); try { var task = Task.Run(() => { var key = minerUtils.Create_1(Sha256.ComputeHash(stream), this.Limit, this.ComputationTime); return new Cash(CashAlgorithm.Version1, key); }); while (!task.IsCompleted) { if (_isCanceled) minerUtils.Cancel(); Thread.Sleep(1000); } return task.Result; } catch (AggregateException e) { throw e.InnerExceptions.FirstOrDefault(); } } return null; }