コード例 #1
0
        public async Task <(PaymentReceivedType, LNMoney)> PaymentReceived(Primitives.PaymentHash paymentHash, LNMoney amount, uint256?secret = null)
        {
            var tx = await _engine.OpenTransaction();

            using var invoiceRow = await tx.GetTable(DBKeys.HashToInvoice).Get(paymentHash.ToBytes(false));

            if (invoiceRow != null)
            {
                var res = PaymentRequest.Parse(await invoiceRow.ReadValueString());
                if (res.IsError)
                {
                    throw new NRustLightningException($"Failed to read payment request for {res.ErrorValue}");
                }
                var req = res.ResultValue;
                if (req.AmountValue is null)
                {
                    return(PaymentReceivedType.Ok, amount);
                }

                var intendedAmount = req.AmountValue.Value;
                if (amount.MilliSatoshi < intendedAmount.MilliSatoshi)
                {
                    return(PaymentReceivedType.AmountTooLow, intendedAmount);
                }

                if (intendedAmount.MilliSatoshi * 2 < amount.MilliSatoshi)
                {
                    return(PaymentReceivedType.AmountTooHigh, intendedAmount);
                }

                return(PaymentReceivedType.Ok, intendedAmount);
            }
            return(PaymentReceivedType.UnknownPaymentHash, amount);
        }
コード例 #2
0
        public async Task <(PaymentReceivedType, LNMoney)> PaymentReceived(Primitives.PaymentHash paymentHash, LNMoney amount, uint256?secret = null)
        {
            var invoice = await _repository.GetInvoice(paymentHash);

            if (invoice != null)
            {
                if (invoice.AmountValue is null)
                {
                    return(PaymentReceivedType.Ok, amount);
                }

                var intendedAmount = invoice.AmountValue.Value;
                if (amount.MilliSatoshi < intendedAmount.MilliSatoshi)
                {
                    return(PaymentReceivedType.AmountTooLow, intendedAmount);
                }

                if (intendedAmount.MilliSatoshi * 2 < amount.MilliSatoshi)
                {
                    return(PaymentReceivedType.AmountTooHigh, intendedAmount);
                }

                return(PaymentReceivedType.Ok, intendedAmount);
            }
            return(PaymentReceivedType.UnknownPaymentHash, amount);
        }
コード例 #3
0
        public async Task <Primitives.PaymentPreimage> GetPreimage(Primitives.PaymentHash hash)
        {
            var tx = await _engine.OpenTransaction();

            using var preimageRow = await tx.GetTable(DBKeys.HashToPreimage).Get(hash.ToBytes(false));

            return(Primitives.PaymentPreimage.Create((await preimageRow.ReadValue()).ToArray()));
        }
コード例 #4
0
        public async Task <Primitives.PaymentPreimage?> GetPreimage(Primitives.PaymentHash hash, CancellationToken ct = default)
        {
            if (hash == null)
            {
                throw new ArgumentNullException(nameof(hash));
            }
            using var tx = await _engine.OpenTransaction(ct);

            using var preimageRow = await tx.GetTable(DBKeys.HashToPreimage).Get(hash.ToBytes(false));

            return(preimageRow is null ? null : Primitives.PaymentPreimage.Create((await preimageRow.ReadValue()).ToArray()));
        }
コード例 #5
0
        public async Task <PaymentRequest?> GetInvoice(Primitives.PaymentHash hash, CancellationToken ct = default)
        {
            if (hash == null)
            {
                throw new ArgumentNullException(nameof(hash));
            }
            using var tx = await _engine.OpenTransaction(ct);

            using var row = await tx.GetTable(DBKeys.HashToInvoice).Get(hash.Value.ToString());

            if (row is null)
            {
                return(null);
            }
            var r = PaymentRequest.Parse((await row.ReadValueString()));

            if (r.IsError)
            {
                _logger.LogError($"Failed to get invoice for hash {hash}. {r.ErrorValue}");
                return(null);
            }

            return(r.ResultValue);
        }
コード例 #6
0
 public Task <PaymentRequest?> GetInvoice(Primitives.PaymentHash hash, CancellationToken ct = default)
 {
     _hashToInvoice.TryGetValue(hash, out var invoice);
     return(Task.FromResult(invoice));
 }
コード例 #7
0
 public Task <Primitives.PaymentPreimage?> GetPreimage(Primitives.PaymentHash hash, CancellationToken ct = default)
 {
     _hashToPreimage.TryGetValue(hash, out var preimage);
     return(Task.FromResult(preimage));
 }