From 2bd8488f5f795d5ce5528448851c264e687ee418 Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Thu, 8 Feb 2018 10:03:39 -0500 Subject: [PATCH] Extending gem timeout --- lightninggem.js | 14 ++++++-------- public/index.html | 17 ++++++++++------- public/js/app.js | 1 + 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lightninggem.js b/lightninggem.js index d3aa05b..0e64d38 100644 --- a/lightninggem.js +++ b/lightninggem.js @@ -5,6 +5,7 @@ require('dotenv').config(); const LND_HOMEDIR = process.env.LND_HOMEDIR; const LN_GEM_PORT = process.env.LN_GEM_PORT; const DB_NAME = process.env.DB_NAME; +const LND_CONNECTION_STRING = process.env.LND_CONNECTION_STRING; const env = process.env.NODE_ENV; const grpc = require('grpc'); @@ -39,7 +40,7 @@ const lndCert = fs.readFileSync(LND_HOMEDIR + 'tls.cert'); const credentials = grpc.credentials.createSsl(lndCert); const lnrpcDescriptor = grpc.load("rpc.proto"); const lnrpc = lnrpcDescriptor.lnrpc; -const lightning = new lnrpc.Lightning('127.0.0.1:10009', credentials); +var lightning = new lnrpc.Lightning('127.0.0.1:10009', credentials); const adminMacaroon = fs.readFileSync(LND_HOMEDIR + 'admin.macaroon'); const meta = new grpc.Metadata(); @@ -90,7 +91,7 @@ var invoiceSubscription = subscribeInvoices(); //timer function to run every 2 minutes setInterval(async () => { //check for timeout - if (gem.owner && gem.date < (new Date().getTime() - 12 * 60 * 60 * 1000)) { + if (gem.owner && gem.date < (new Date().getTime() - 24 * 60 * 60 * 1000)) { try { gem = await createGem(null, gem, true); updateListeners(); //update all clients to indicate gem has expired @@ -99,10 +100,6 @@ setInterval(async () => { logger.error("error on gem reset: " + err); } } - - //if invoiceSubscription is undefined, try to resubscribe - if (!invoiceSubscription) - invoiceSubscription = subscribeInvoices(); }, 2 * 60 * 1000); // scheduled function to run once a day @@ -140,7 +137,8 @@ MongoClient.connect(dbUrl).then((connection) => { app.get('/status', (req, res) => { res.status(200).json({ recentGems: recentGems, - paidOutSum: paidOutSum + paidOutSum: paidOutSum, + lndConnectionString: LND_CONNECTION_STRING }); }); @@ -485,7 +483,7 @@ function subscribeInvoices() { logger.warn("subscribeInvoices ended"); invoiceSubscription = undefined; }).on('status', (status) => { - logger.info("subscribeInvoices status: " + JSON.stringify(status)); + logger.debug("subscribeInvoices status: " + JSON.stringify(status)); }).on('error', (error) => { logger.error("subscribeInvoices error: " + error); invoiceSubscription = undefined; diff --git a/public/index.html b/public/index.html index 02f8b07..b6d8e3e 100644 --- a/public/index.html +++ b/public/index.html @@ -49,7 +49,7 @@

How to Buy the Gem

You can be the next owner of the gem! The current price is . After your purchase, the gem's price will be bits.

You will stay the owner until the next person buys it. We then will send bits back to you. Yes, that's a 25% profit for you.

-

However, there's a 1 in 32 (3.125%) chance that the gem will reset each time it is purchased. It will also reset if there's no new buyer for 12 hours. Should your purchase result in a reset, you will lose your stake and the gem's price will start over at 1 bit.

+

However, there's a 1 in 32 (3.125%) chance that the gem will reset each time it is purchased. It will also reset if there's no new buyer for 24 hours. Should your purchase result in a reset, you will lose your stake and the gem's price will start over at 1 bit.

Currently, the Lightning Gem works on the Bitcoin Testnet only.

@@ -61,9 +61,9 @@

How to Buy the Gem

- To buy the gem, create a lightning payment request for bits with an expiry of at least 12 hours. Paste that below along with a name to display and, optionally, a website to link to. Click 'Submit' to create your unique invoice and pay it before someone else buys the gem! Keep your lightning node online and we'll pay you your profit if somebody buys the gem from you. + To buy the gem, create a lightning payment request for bits with an expiry of at least 24 hours. Paste that below along with a name to display and, optionally, a website to link to. Click 'Submit' to create your unique invoice and pay it before someone else buys the gem! Keep your lightning node online and we'll pay you your profit if somebody buys the gem from you.

-

lncli addinvoice --value --expiry 86400

+

lncli addinvoice --amt --expiry 86400

@@ -97,6 +97,9 @@

How to Buy the Gem

+
+

New! Now you can check on the status of the lnd node behind the lightning gem!

+
@@ -125,16 +128,16 @@
What is the lightning network?

The lightning network is a second layer payment network on top of bitcoin that enables microtransactions and instant settlement. This site uses lnd for lightning functionality.

Why should I buy the gem?

To advertise your name (or link) under it and show off that you own the gem. Not to mention you can make a handsome profit when a new buyer comes in!

-
How do I create an invoice with an expiry of at least 12 hours?
-

Using the command line interface with lnd, you can create a long-lived invoice by setting the expiry parameter to a value over 43200. For example, to create an invoice for 1.25 bits that's good for a day use lncli addinvoice --value 125 --expiry 86400.

+
How do I create an invoice with an expiry of at least 24h hours?
+

Using the command line interface with lnd, you can create a long-lived invoice by setting the expiry parameter to a value over 86400. For example, to create an invoice for 1.25 bits that's good for a day use lncli addinvoice --amt 125 --expiry 86400.

Why can't I complete my payment to buy the gem?
-

Your node may be unable to find a payment path to ours. You can open a channel with us directly at 023c1fc1ef2d9a555693cf0fdc39b66d934dfc07bc0b1ee050fd3f4aeb773b9438@35.185.13.214.

+

Your node may be unable to find a payment path to ours. You can open a channel with us directly at .

How does the price increase?

Every time the gem changes hands its worth increases by 30% rounded to the nearest satoshi.

How do random resets work?

We take the payment request you generated and append a secret string of characters as a nonce, then we hash that using SHA-256. We convert the first byte of the hash to a number from 0 to 255. If that number is less than 8 - which will happen 1 in 32 times - we reset the gem. We use a different secret every day based on UTC time, and every day we will publish the secret for the previous day here so you can check our work for yourself. A list of the SHA-256 hashes for all secrets we will use through 2018 is available as a gist here.

What happens if no one after me buys the gem?
-

If there's no new buyer for more than 12 hours, the gem will reset automatically to 1 bit and you'll lose your stake.

+

If there's no new buyer for more than 24 hours, the gem will reset automatically to 1 bit and you'll lose your stake.

What's a bit?

A bit, as specified in BIP176, is 1 millionth of a bitcoin - or 100 satoshis.

What happens if I send payment but someone buys the gem before me?
diff --git a/public/js/app.js b/public/js/app.js index eab04e9..8cd2ed9 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -48,6 +48,7 @@ function refresh() { $(".payout").text((Math.round(1.25 * price) / 100).toLocaleString()); $("#payout_sats").text(Math.round(1.25 * price)); $("#new_price").text((Math.round(price * 1.3) / 100).toLocaleString()); + $("#lnd_connection_string").text(status.lndConnectionString); gem_id = gem._id; var recentGemsHtml = "";