Skip to content

Commit

Permalink
Extending gem timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
sangaman committed Feb 8, 2018
1 parent eea2287 commit 2bd8488
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
14 changes: 6 additions & 8 deletions lightninggem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
});
});

Expand Down Expand Up @@ -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;
Expand Down
17 changes: 10 additions & 7 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h3 class="twelve columns">How to Buy the Gem</h3>
<div class="six columns">
<p>You can be the next owner of the gem! The current price is <span class="price"></span>. After your purchase, the gem's price will be <span id="new_price"></span> bits.</p>
<p>You will stay the owner until the next person buys it. We then will send <span class="payout"></span> bits back to you. <b>Yes, that's a 25% profit for you.</b></p>
<p>However, there's a <strong>1 in 32</strong> (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.</p>
<p>However, there's a <strong>1 in 32</strong> (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.</p>
<p>Currently, the Lightning Gem works on the Bitcoin Testnet only.</p>
</div>
<!-- Own the gem End -->
Expand All @@ -61,9 +61,9 @@ <h3 class="twelve columns">How to Buy the Gem</h3>
<!-- Step One Start -->
<div id="step_one">
<p>
To buy the gem, create a lightning payment request for <strong class="payout"></strong> 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 <strong class="payout"></strong> 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.
</p>
<p><code>lncli addinvoice --value <span id="payout_sats"></span> --expiry 86400</code></p>
<p><code>lncli addinvoice --amt <span id="payout_sats"></span> --expiry 86400</code></p>
<div id="not_valid" class="alert-box alert" style="display: none;"><span id="not_valid_msg"></span><br />Please try again!<a href="" class="close">&times;</a></div>
<form>
<span class="fail" id="invoice_err"></span>
Expand Down Expand Up @@ -97,6 +97,9 @@ <h3 class="twelve columns">How to Buy the Gem</h3>
</div>
</section>
<!-- How to buy End -->
<section class="row">
<p><strong>New!</strong> Now you can check on the status of the <a href="https://info.lightninggem.com">lnd node behind the lightning gem</a>!</p>
</section>
<section class="row">
<div class="twelve columns">
<div class="title">
Expand Down Expand Up @@ -125,16 +128,16 @@ <h5>What is the lightning network?</h5>
<p>The <a href="https://lightning.network/">lightning network</a> is a second layer payment network on top of bitcoin that enables microtransactions and instant settlement. This site uses <a href="https://github.com/lightningnetwork/lnd">lnd</a> for lightning functionality.</p>
<h5>Why should I buy the gem?</h5>
<p>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!</p>
<h5>How do I create an invoice with an expiry of at least 12 hours?</h5>
<p>Using the command line interface with lnd, you can create a long-lived invoice by setting the <code>expiry</code> parameter to a value over 43200. For example, to create an invoice for 1.25 bits that's good for a day use <code>lncli addinvoice --value 125 --expiry 86400</code>.</p>
<h5>How do I create an invoice with an expiry of at least 24h hours?</h5>
<p>Using the command line interface with lnd, you can create a long-lived invoice by setting the <code>expiry</code> parameter to a value over 86400. For example, to create an invoice for 1.25 bits that's good for a day use <code>lncli addinvoice --amt 125 --expiry 86400</code>.</p>
<h5>Why can't I complete my payment to buy the gem?</h5>
<p>Your node may be unable to find a payment path to ours. You can open a channel with us directly at <code>023c1fc1ef2d9a555693cf0fdc39b66d934dfc07bc0b1ee050fd3f4aeb773b9438@35.185.13.214</code>.</p>
<p>Your node may be unable to find a payment path to ours. You can open a channel with us directly at <code id="lnd_connection_string"></code>.</p>
<h5>How does the price increase?</h5>
<p>Every time the gem changes hands its worth increases by 30% rounded to the nearest satoshi.</p>
<h5>How do random resets work?</h5>
<p>We take the payment request you generated and append a secret string of characters as a <a href="https://en.wikipedia.org/wiki/Cryptographic_nonce">nonce</a>, 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 <a href="secrets.txt">here</a> 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 <a href="https://gist.github.com/sangaman/00ec664d22548c7f2517a79d3fd31bf4">here</a>.</p>
<h5>What happens if no one after me buys the gem?</h5>
<p>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.</p>
<p>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.</p>
<h5>What's a bit?</h5>
<p>A bit, as specified in <a href="https://github.com/bitcoin/bips/blob/master/bip-0176.mediawiki">BIP176</a>, is 1 millionth of a bitcoin - or 100 satoshis.</p>
<h5>What happens if I send payment but someone buys the gem before me?</h5>
Expand Down
1 change: 1 addition & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down

0 comments on commit 2bd8488

Please sign in to comment.