dont error on claims without value

This commit is contained in:
Alex Grintsvayg 2017-02-14 12:37:23 -05:00
parent 5ecaf39e7d
commit a4cf012974

View file

@ -130,6 +130,20 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
lbryCall('getclaimsforname', claim['name']), lbryCall('getclaimsforname', claim['name']),
]) ])
.then(function ([currentWinningClaim, claimsForName]) { .then(function ([currentWinningClaim, claimsForName]) {
let takeoverMessage = '';
if (!claim['is controlling'])
{
// the following is based on https://lbry.io/faq/claimtrie-implementation
const lastTakeoverHeight = claimsForName['nLastTakeoverHeight'],
maxDelay = 4032, // 7 days of blocks at 2.5min per block
activationDelay = Math.min(maxDelay, Math.floor((claimBlockHeight - lastTakeoverHeight) / 32)),
takeoverHeight = claimBlockHeight + activationDelay,
secondsPerBlock = 161, // in theory this should be 150, but in practice its closer to 161
takeoverTime = Date.now() + ((takeoverHeight - currentHeight) * secondsPerBlock * 1000);
takeoverMessage = 'Takes effect on approx. *' + moment(takeoverTime, 'x').format('MMMM Do [at] HH:mm [UTC]') + '* (block ' + takeoverHeight + ')';
}
let value; let value;
try try
{ {
@ -137,6 +151,8 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
} }
catch (e) catch (e)
{ {
slackPost('New claim for lbry://' + claim['name'] + ' ' + takeoverMessage, {icon_emoji: ':bellhop_bell:'});
return;
} }
// console.log(claim); // console.log(claim);
@ -170,18 +186,9 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
text.push(fees.join(', ')); text.push(fees.join(', '));
} }
const fields = []; if (takeoverMessage)
if (!claim['is controlling'])
{ {
// the following is based on https://lbry.io/faq/claimtrie-implementation text.push(takeoverMessage);
const lastTakeoverHeight = claimsForName['nLastTakeoverHeight'],
maxDelay = 4032, // 7 days of blocks at 2.5min per block
activationDelay = Math.min(maxDelay, Math.floor((claimBlockHeight - lastTakeoverHeight) / 32)),
takeoverHeight = claimBlockHeight + activationDelay,
secondsPerBlock = 161, // in theory this should be 150, but in practice its closer to 161
takeoverTime = Date.now() + ((takeoverHeight - currentHeight) * secondsPerBlock * 1000);
text.push('Takes effect on approx. *' + moment(takeoverTime, 'x').format('MMMM Do [at] HH:mm [UTC]') + '* (block ' + takeoverHeight + ')');
} }
@ -195,7 +202,7 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
"title": escapeSlackHtml(value['title']), "title": escapeSlackHtml(value['title']),
"title_link": "lbry://" + claim['name'], "title_link": "lbry://" + claim['name'],
"text": escapeSlackHtml(text.join("\n")), "text": escapeSlackHtml(text.join("\n")),
"fields": fields, // "fields": [],
// "image_url": value['nsfw'] ? null : value['thumbnail'], // "image_url": value['nsfw'] ? null : value['thumbnail'],
"thumb_url": value['nsfw'] ? null : value['thumbnail'], "thumb_url": value['nsfw'] ? null : value['thumbnail'],
"unfurl_links": false, "unfurl_links": false,
@ -207,7 +214,7 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
}; };
slackPost('', {icon_emoji: ':bellhop_bell:', attachments: [attachment]}); slackPost('', {icon_emoji: ':bellhop_bell:', attachments: [attachment]});
}) });
} }
function escapeSlackHtml(txt) { function escapeSlackHtml(txt) {