public async Task browse_will_return_pending_claims() { var claims = GetPaymentClaims(); foreach (var claim in claims) { await repository.AddAsync(claim); } PagedResult <PaymentClaim> pendingClaims = await repository.BrowseAsync(new GetPaymentClaims { OnlyPending = true }); Assert.IsTrue(pendingClaims.Items.Count == 1); }
public async Task can_send_transaction_when_claim_status_unknown() { PaymentClaim claim = GenerateTestClaim(PaymentClaimStatus.Unknown, "can_send_transaction_when_claim_status_unknown"); var testTransaction = new NdmTransaction(new Transaction(), false, 5, Keccak.OfAnEmptyString, 0); await paymentClaimRepository.AddAsync(claim); blockchainBridge.GetTransactionAsync(claim.Transaction.Hash).Returns(Task.FromResult(testTransaction)); transactionVerifier.VerifyAsync(testTransaction).Returns(Task.FromResult(new TransactionVerifierResult(true, 5, 2))); WaitForPaymentClaimsProcessing(); var addedClaim = await paymentClaimRepository.GetAsync(claim.Id); Assert.IsTrue(addedClaim.Status == PaymentClaimStatus.Sent); }
public async Task <PaymentClaim?> ProcessAsync(DataDeliveryReceiptRequest receiptRequest, Signature signature) { Keccak depositId = receiptRequest.DepositId; Consumer?consumer = await _consumerRepository.GetAsync(depositId); if (consumer is null) { if (_logger.IsError) { _logger.Error($"Could not find any consumers for deposit {depositId} in the repository."); } return(null); } DataRequest dataRequest = consumer.DataRequest; UnitsRange range = receiptRequest.UnitsRange; uint claimedUnits = range.Units; BigInteger claimedValue = claimedUnits * (BigInteger)consumer.DataRequest.Value / consumer.DataRequest.Units; ulong timestamp = _timestamper.UnixTime.Seconds; Rlp unitsRangeRlp = _unitsRangeRlpDecoder.Encode(range); Keccak id = Keccak.Compute(Rlp.Encode(Rlp.Encode(depositId), Rlp.Encode(timestamp), unitsRangeRlp).Bytes); PaymentClaim paymentClaim = new PaymentClaim(id, consumer.DepositId, consumer.DataAsset.Id, consumer.DataAsset.Name, dataRequest.Units, claimedUnits, range, dataRequest.Value, (UInt256)claimedValue, dataRequest.ExpiryTime, dataRequest.Pepper, dataRequest.Provider, dataRequest.Consumer, signature, timestamp, Array.Empty <TransactionInfo>(), PaymentClaimStatus.Unknown); await _paymentClaimRepository.AddAsync(paymentClaim); if (_logger.IsInfo) { _logger.Info($"Claiming a payment (id: '{paymentClaim.Id}') for deposit: '{depositId}', range: [{range.From}, {range.To}], units: {claimedUnits}."); } UInt256 gasPrice = await _gasPriceService.GetCurrentPaymentClaimGasPriceAsync(); Keccak?transactionHash = null; if (_disableSendingPaymentClaimTransaction) { if (_logger.IsWarn) { _logger.Warn("*** NDM provider sending payment claim transaction is disabled ***"); } } else { transactionHash = await SendTransactionAsync(paymentClaim, gasPrice); if (transactionHash is null) { if (_logger.IsInfo) { _logger.Info($"Payment claim (id: {paymentClaim.Id}) for deposit: '{paymentClaim.DepositId}' did not receive a transaction hash."); } return(paymentClaim); } } if (_logger.IsInfo) { _logger.Info($"Payment claim (id: {paymentClaim.Id}) for deposit: '{paymentClaim.DepositId}' received a transaction hash: '{transactionHash}'."); } paymentClaim.AddTransaction(TransactionInfo.Default(transactionHash, 0, gasPrice, _paymentService.GasLimit, timestamp)); paymentClaim.SetStatus(PaymentClaimStatus.Sent); await _paymentClaimRepository.UpdateAsync(paymentClaim); string claimedEth = ((decimal)claimedValue / Eth).ToString("0.0000"); if (_logger.IsInfo) { _logger.Info($"Sent a payment claim (id: '{paymentClaim.Id}') for deposit: '{depositId}', range: [{range.From}, {range.To}], units: {claimedUnits}, units: {claimedUnits}, value: {claimedValue} wei ({claimedEth} ETH, transaction hash: '{transactionHash}'."); } return(paymentClaim); }