public async Task <LightningNodeInformation> GetInfo(CancellationToken cancellation = default(CancellationToken)) { var resp = await _rpcClient.GetInfoAsync(cancellation); var nodeInfo = new LightningNodeInformation { BlockHeight = (int?)resp.Block_height ?? 0, NodeId = resp.Identity_pubkey }; var node = await _rpcClient.GetNodeInfoAsync(resp.Identity_pubkey, cancellation); if (node.Node.Addresses == null || node.Node.Addresses.Count == 0) { throw new Exception("Lnd External IP not set, make sure you use --externalip=$EXTERNALIP parameter on lnd"); } var firstNodeInfo = node.Node.Addresses.First(); var externalHostPort = firstNodeInfo.Addr.Split(':'); nodeInfo.Address = externalHostPort[0]; nodeInfo.P2PPort = ConvertInv.ToInt32(externalHostPort[1]); return(nodeInfo); }
internal static LightningInvoice ConvertLndInvoice(LnrpcInvoice resp) { var invoice = new LightningInvoice { // TODO: Verify id corresponds to R_hash Id = BitString(resp.R_hash), Amount = new LightMoney(ConvertInv.ToInt64(resp.Value), LightMoneyUnit.Satoshi), BOLT11 = resp.Payment_request, Status = "unpaid" }; if (resp.Settle_date != null) { invoice.PaidAt = DateTimeOffset.FromUnixTimeSeconds(ConvertInv.ToInt64(resp.Settle_date)); invoice.Status = "paid"; } else { var invoiceExpiry = ConvertInv.ToInt64(resp.Creation_date) + ConvertInv.ToInt64(resp.Expiry); if (DateTimeOffset.FromUnixTimeSeconds(invoiceExpiry) > DateTimeOffset.UtcNow) { invoice.Status = "expired"; } } return(invoice); }
public async Task <LightningInvoice> CreateInvoice(LightMoney amount, string description, TimeSpan expiry, CancellationToken cancellation = default(CancellationToken)) { var strAmount = ConvertInv.ToString(amount.ToUnit(LightMoneyUnit.Satoshi)); var strExpiry = ConvertInv.ToString(Math.Round(expiry.TotalSeconds, 0)); // lnd requires numbers sent as strings. don't ask var resp = await _rpcClient.AddInvoiceAsync(new LnrpcInvoice { Value = strAmount, Memo = description, Expiry = strExpiry }); var invoice = new LightningInvoice { Id = BitString(resp.R_hash), Amount = amount, BOLT11 = resp.Payment_request, Status = "unpaid" }; return(invoice); }