only try to claim reward for initial claims, not updates
This commit is contained in:
parent
9183717354
commit
d77fc883d1
3 changed files with 54 additions and 5 deletions
|
@ -73,7 +73,6 @@ function checkForNewVersion(callback) {
|
|||
result += data;
|
||||
});
|
||||
res.on('end', () => {
|
||||
console.log('Local version:', localVersion);
|
||||
const tagName = JSON.parse(result).tag_name;
|
||||
const [_, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/);
|
||||
if (!remoteVersion) {
|
||||
|
@ -82,9 +81,7 @@ function checkForNewVersion(callback) {
|
|||
win.webContents.send('version-info-received', null);
|
||||
}
|
||||
} else {
|
||||
console.log('Remote version:', remoteVersion);
|
||||
const upgradeAvailable = semver.gt(formatRc(remoteVersion), formatRc(localVersion));
|
||||
console.log(upgradeAvailable ? 'Upgrade available' : 'No upgrade available');
|
||||
if (win) {
|
||||
win.webContents.send('version-info-received', {remoteVersion, localVersion, upgradeAvailable});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const hashes = require('jshashes');
|
||||
import lbry from 'lbry';
|
||||
import lbryio from 'lbryio';
|
||||
import {
|
||||
|
@ -16,6 +17,56 @@ function rewardMessage(type, amount) {
|
|||
}[type];
|
||||
}
|
||||
|
||||
function toHex(s) {
|
||||
let h = ''
|
||||
for (var i = 0; i < s.length; i++)
|
||||
{
|
||||
let c = s.charCodeAt(i).toString(16);
|
||||
if (c.length < 2)
|
||||
{
|
||||
c = "0".concat(c);
|
||||
}
|
||||
h += c;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
function fromHex(h) {
|
||||
let s = ''
|
||||
for (let i = 0; i < h.length; i += 2)
|
||||
{
|
||||
s += String.fromCharCode(parseInt(h.substr(i, 2), 16))
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function reverseString(s) {
|
||||
let o = '';
|
||||
for (let i = s.length - 1; i >= 0; i--)
|
||||
{
|
||||
o += s[i];
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
function pack(num) {
|
||||
return "" +
|
||||
String.fromCharCode((num ) & 0xFF) +
|
||||
String.fromCharCode((num >> 8) & 0xFF) +
|
||||
String.fromCharCode((num >> 16) & 0xFF) +
|
||||
String.fromCharCode((num >> 24) & 0xFF);
|
||||
}
|
||||
|
||||
// Returns true if claim is an initial claim, false if it's an update to an existing claim
|
||||
function isInitialClaim(claim) {
|
||||
const reversed = reverseString(fromHex(claim.txid))
|
||||
const concat = reversed.concat(pack(claim.nout))
|
||||
const sha256 = (new hashes.SHA256({utf8: false})).raw(concat)
|
||||
const ripemd160 = (new hashes.RMD160({utf8: false})).raw(sha256)
|
||||
const hash = toHex(reverseString(ripemd160));
|
||||
return hash == claim.claim_id;
|
||||
}
|
||||
|
||||
const rewards = {};
|
||||
|
||||
rewards.TYPE_NEW_DEVELOPER = "new_developer",
|
||||
|
@ -68,7 +119,7 @@ rewards.claimReward = function (type) {
|
|||
case rewards.TYPE_FIRST_CHANNEL:
|
||||
lbry.claim_list_mine().then(function(claims) {
|
||||
let claim = claims.find(function(claim) {
|
||||
return claim.name.length && claim.name[0] == '@' && claim.txid.length
|
||||
return claim.name.length && claim.name[0] == '@' && claim.txid.length && isInitialClaim(claim)
|
||||
})
|
||||
if (claim) {
|
||||
params.transaction_id = claim.txid;
|
||||
|
@ -82,7 +133,7 @@ rewards.claimReward = function (type) {
|
|||
case rewards.TYPE_FIRST_PUBLISH:
|
||||
lbry.claim_list_mine().then((claims) => {
|
||||
let claim = claims.find(function(claim) {
|
||||
return claim.name.length && claim.name[0] != '@' && claim.txid.length
|
||||
return claim.name.length && claim.name[0] != '@' && claim.txid.length && isInitialClaim(claim)
|
||||
})
|
||||
if (claim) {
|
||||
params.transaction_id = claim.txid
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
"babel-cli": "^6.11.4",
|
||||
"babel-preset-es2015": "^6.13.2",
|
||||
"babel-preset-react": "^6.11.1",
|
||||
"jshashes": "^1.0.6",
|
||||
"node-sass": "^3.8.0",
|
||||
"plyr": "^2.0.12",
|
||||
"rc-progress": "^2.0.6",
|
||||
|
|
Loading…
Reference in a new issue