public void SendEarlyRefundTicket(EarlyRefundTicket ticket, RefundReason reason)
 {
     if (Logger.IsTrace)
     {
         Logger.Trace($"{Session.RemoteNodeId} NDM sending: earlyrefundticket");
     }
     Send(new EarlyRefundTicketMessage(ticket, reason));
 }
Ejemplo n.º 2
0
        public void can_set_early_refund_ticket()
        {
            var earlyRefundTicket = new EarlyRefundTicket(Keccak.Zero,
                                                          claimableAfter: 10,
                                                          new Signature(1, 2, 37));

            _depositDetails.SetEarlyRefundTicket(earlyRefundTicket);
            Assert.AreEqual(earlyRefundTicket, _depositDetails.EarlyRefundTicket);
        }
Ejemplo n.º 3
0
        public async Task set_early_refund_ticket_should_fail_if_deposit_does_not_exits()
        {
            const RefundReason reason = RefundReason.DataDiscontinued;
            var ticket        = new EarlyRefundTicket(TestItem.KeccakA, 0, null);
            var refundService = new RefundService(_ndmBridge, _abiEncoder, _depositRepository, _contractAddress, LimboLogs.Instance);
            await refundService.SetEarlyRefundTicketAsync(ticket, reason);

            await _depositRepository.Received().GetAsync(ticket.DepositId);

            await _depositRepository.DidNotReceiveWithAnyArgs().UpdateAsync(null);
        }
Ejemplo n.º 4
0
        public void will_not_set_can_claim_early_refund_when_current_timestamp_is_lower_than_deposit_timestamp()
        {
            var earlyRefundTicket = new EarlyRefundTicket(Keccak.Zero,
                                                          claimableAfter: 10,
                                                          new Signature(1, 2, 37));

            _depositDetails.SetEarlyRefundTicket(earlyRefundTicket);
            _depositDetails.SetConfirmationTimestamp(10);

            bool canClaimEarlyRefund = _depositDetails.CanClaimEarlyRefund(currentBlockTimestamp: 10, depositTimestamp: 50);

            Assert.IsFalse(canClaimEarlyRefund);
        }
Ejemplo n.º 5
0
        public void can_claim_early_refund_returns_correctly_true()
        {
            var earlyRefundTicket = new EarlyRefundTicket(Keccak.Zero,
                                                          claimableAfter: 10,
                                                          new Signature(1, 2, 37));

            _depositDetails.SetEarlyRefundTicket(earlyRefundTicket);
            _depositDetails.SetConfirmationTimestamp(10);

            bool canClaimEarlyRefund = _depositDetails.CanClaimEarlyRefund(currentBlockTimestamp: 20, depositTimestamp: 5);

            Assert.IsTrue(canClaimEarlyRefund);
        }
Ejemplo n.º 6
0
        public async Task set_early_refund_ticket_should_succeed_if_deposit_exists()
        {
            const RefundReason reason = RefundReason.DataDiscontinued;
            var deposit        = new Deposit(TestItem.KeccakA, 1, 1, 1);
            var depositDetails = new DepositDetails(deposit, null, null, null, 0, null, 0);
            var ticket         = new EarlyRefundTicket(deposit.Id, 0, null);
            var refundService  = new RefundService(_ndmBridge, _abiEncoder, _depositRepository, _contractAddress, LimboLogs.Instance);

            _depositRepository.GetAsync(ticket.DepositId).Returns(depositDetails);
            await refundService.SetEarlyRefundTicketAsync(ticket, reason);

            depositDetails.EarlyRefundTicket.Should().Be(ticket);
            await _depositRepository.Received().GetAsync(ticket.DepositId);

            await _depositRepository.Received().UpdateAsync(depositDetails);
        }
Ejemplo n.º 7
0
        public async Task SetEarlyRefundTicketAsync(EarlyRefundTicket ticket, RefundReason reason)
        {
            var depositDetails = await _depositRepository.GetAsync(ticket.DepositId);

            if (depositDetails is null)
            {
                return;
            }

            depositDetails.SetEarlyRefundTicket(ticket);
            await _depositRepository.UpdateAsync(depositDetails);

            if (_logger.IsInfo)
            {
                _logger.Info($"Early refund claim for deposit: '{ticket.DepositId}', reason: '{reason}'.");
            }
        }
Ejemplo n.º 8
0
 public DepositDetails(Deposit deposit, DataAsset dataAsset, Address consumer, byte[] pepper, uint timestamp,
                       TransactionInfo transaction, uint confirmationTimestamp = 0, bool rejected           = false,
                       EarlyRefundTicket earlyRefundTicket = null, TransactionInfo claimedRefundTransaction = null,
                       bool refundClaimed = false, string kyc = null, uint confirmations = 0, uint requiredConfirmations = 0)
 {
     Id                       = deposit.Id;
     Deposit                  = deposit;
     DataAsset                = dataAsset;
     Consumer                 = consumer;
     Pepper                   = pepper;
     Timestamp                = timestamp;
     Transaction              = transaction;
     ConfirmationTimestamp    = confirmationTimestamp;
     Rejected                 = rejected;
     EarlyRefundTicket        = earlyRefundTicket;
     ClaimedRefundTransaction = claimedRefundTransaction;
     RefundClaimed            = refundClaimed;
     Kyc                      = kyc;
     Confirmations            = confirmations;
     RequiredConfirmations    = requiredConfirmations;
 }
Ejemplo n.º 9
0
 public DepositDetails(Deposit deposit, DataAsset dataAsset, Address consumer, byte[] pepper, uint timestamp,
                       Keccak transactionHash, uint confirmationTimestamp = 0, bool rejected           = false,
                       EarlyRefundTicket earlyRefundTicket = null, Keccak claimedRefundTransactionHash = null,
                       bool refundClaimed = false, string kyc = null, uint confirmations = 0, uint requiredConfirmations = 0)
 {
     Id              = deposit.Id;
     Deposit         = deposit;
     DataAsset       = dataAsset;
     Consumer        = consumer;
     Pepper          = pepper;
     Timestamp       = timestamp;
     TransactionHash = transactionHash;
     SetConfirmationTimestamp(confirmationTimestamp);
     Rejected          = rejected;
     EarlyRefundTicket = earlyRefundTicket;
     SetClaimedRefundTransactionHash(claimedRefundTransactionHash);
     RefundClaimed         = refundClaimed;
     Kyc                   = kyc;
     Confirmations         = confirmations;
     RequiredConfirmations = requiredConfirmations;
 }
Ejemplo n.º 10
0
        public DepositDetails Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
        {
            rlpStream.ReadSequenceLength();
            Deposit           deposit                   = Serialization.Rlp.Rlp.Decode <Deposit>(rlpStream);
            DataAsset         dataAsset                 = Serialization.Rlp.Rlp.Decode <DataAsset>(rlpStream);
            Address           consumer                  = rlpStream.DecodeAddress();
            var               pepper                    = rlpStream.DecodeByteArray();
            uint              timestamp                 = rlpStream.DecodeUInt();
            var               transactions              = Serialization.Rlp.Rlp.DecodeArray <TransactionInfo>(rlpStream);
            uint              confirmationTimestamp     = rlpStream.DecodeUInt();
            bool              rejected                  = rlpStream.DecodeBool();
            bool              cancelled                 = rlpStream.DecodeBool();
            EarlyRefundTicket earlyRefundTicket         = Serialization.Rlp.Rlp.Decode <EarlyRefundTicket>(rlpStream);
            var               claimedRefundTransactions = Serialization.Rlp.Rlp.DecodeArray <TransactionInfo>(rlpStream);
            bool              refundClaimed             = rlpStream.DecodeBool();
            bool              refundCancelled           = rlpStream.DecodeBool();
            string            kyc                   = rlpStream.DecodeString();
            uint              confirmations         = rlpStream.DecodeUInt();
            uint              requiredConfirmations = rlpStream.DecodeUInt();

            return(new DepositDetails(deposit, dataAsset, consumer, pepper, timestamp, transactions,
                                      confirmationTimestamp, rejected, cancelled, earlyRefundTicket, claimedRefundTransactions,
                                      refundClaimed, refundCancelled, kyc, confirmations, requiredConfirmations));
        }
Ejemplo n.º 11
0
 public Task SetEarlyRefundTicketAsync(EarlyRefundTicket ticket, RefundReason reason)
 => _refundService.SetEarlyRefundTicketAsync(ticket, reason);
Ejemplo n.º 12
0
 public void SetEarlyRefundTicket(EarlyRefundTicket earlyRefundTicket)
 {
     EarlyRefundTicket = earlyRefundTicket;
 }
Ejemplo n.º 13
0
        public async Task <RefundClaimStatus> TryClaimEarlyRefundAsync(DepositDetails deposit, Address refundTo)
        {
            ulong now = _timestamper.EpochSeconds;

            if (!deposit.CanClaimEarlyRefund(now))
            {
                return(RefundClaimStatus.Empty);
            }

            Block?latestBlock = await _blockchainBridge.GetLatestBlockAsync();

            if (latestBlock == null)
            {
                return(RefundClaimStatus.Empty);
            }

            now = (ulong)latestBlock.Timestamp;
            if (!deposit.CanClaimEarlyRefund(now))
            {
                return(RefundClaimStatus.Empty);
            }

            Keccak depositId       = deposit.Deposit.Id;
            Keccak?transactionHash = deposit.ClaimedRefundTransaction?.Hash;

            if (transactionHash is null)
            {
                Address provider = deposit.DataAsset.Provider.Address;
                if (deposit.EarlyRefundTicket == null)
                {
                    throw new InvalidDataException($"Early refund ticket is null on a claimable deposit {depositId}");
                }

                EarlyRefundTicket ticket           = deposit.EarlyRefundTicket;
                EarlyRefundClaim  earlyRefundClaim = new EarlyRefundClaim(ticket.DepositId, deposit.DataAsset.Id,
                                                                          deposit.Deposit.Units, deposit.Deposit.Value, deposit.Deposit.ExpiryTime, deposit.Pepper, provider,
                                                                          ticket.ClaimableAfter, ticket.Signature, refundTo);
                UInt256 gasPrice = await _gasPriceService.GetCurrentAsync();

                transactionHash = await _refundService.ClaimEarlyRefundAsync(refundTo, earlyRefundClaim, gasPrice);

                if (transactionHash is null)
                {
                    if (_logger.IsError)
                    {
                        _logger.Error("There was an error when trying to claim early refund (no transaction hash returned).");
                    }
                    return(RefundClaimStatus.Empty);
                }

                deposit.AddClaimedRefundTransaction(TransactionInfo.Default(transactionHash, 0, gasPrice,
                                                                            _refundService.GasLimit, _timestamper.EpochSeconds));
                await _depositRepository.UpdateAsync(deposit);

                if (_logger.IsInfo)
                {
                    _logger.Info($"Claimed an early refund for deposit: '{depositId}', gas price: {gasPrice} wei, transaction hash: '{transactionHash}' (awaits a confirmation).");
                }
            }

            bool confirmed = await TryConfirmClaimAsync(deposit, "early ");

            return(confirmed
                ? RefundClaimStatus.Confirmed(transactionHash)
                : RefundClaimStatus.Unconfirmed(transactionHash));
        }
 public EarlyRefundTicketMessage(EarlyRefundTicket ticket, RefundReason reason)
 {
     Ticket = ticket;
     Reason = reason;
 }