only try to claim reward for initial claims, not updates #131

Merged
lyoshenka merged 1 commit from claim_fix into master 2017-05-23 21:54:12 +02:00
3 changed files with 54 additions and 5 deletions
Showing only changes of commit d77fc883d1 - Show all commits

View file

@ -73,7 +73,6 @@ function checkForNewVersion(callback) {
result += data; result += data;
}); });
res.on('end', () => { res.on('end', () => {
console.log('Local version:', localVersion);
const tagName = JSON.parse(result).tag_name; const tagName = JSON.parse(result).tag_name;
const [_, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/); const [_, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/);
if (!remoteVersion) { if (!remoteVersion) {
@ -82,9 +81,7 @@ function checkForNewVersion(callback) {
win.webContents.send('version-info-received', null); win.webContents.send('version-info-received', null);
} }
} else { } else {
console.log('Remote version:', remoteVersion);
const upgradeAvailable = semver.gt(formatRc(remoteVersion), formatRc(localVersion)); const upgradeAvailable = semver.gt(formatRc(remoteVersion), formatRc(localVersion));
console.log(upgradeAvailable ? 'Upgrade available' : 'No upgrade available');
if (win) { if (win) {
win.webContents.send('version-info-received', {remoteVersion, localVersion, upgradeAvailable}); win.webContents.send('version-info-received', {remoteVersion, localVersion, upgradeAvailable});
} }

View file

@ -1,3 +1,4 @@
const hashes = require('jshashes');
import lbry from 'lbry'; import lbry from 'lbry';
import lbryio from 'lbryio'; import lbryio from 'lbryio';
import { import {
@ -16,6 +17,56 @@ function rewardMessage(type, amount) {
}[type]; }[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 = {}; const rewards = {};
rewards.TYPE_NEW_DEVELOPER = "new_developer", rewards.TYPE_NEW_DEVELOPER = "new_developer",
@ -68,7 +119,7 @@ rewards.claimReward = function (type) {
case rewards.TYPE_FIRST_CHANNEL: case rewards.TYPE_FIRST_CHANNEL:
lbry.claim_list_mine().then(function(claims) { lbry.claim_list_mine().then(function(claims) {
let claim = claims.find(function(claim) { 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) { if (claim) {
params.transaction_id = claim.txid; params.transaction_id = claim.txid;
@ -82,7 +133,7 @@ rewards.claimReward = function (type) {
case rewards.TYPE_FIRST_PUBLISH: case rewards.TYPE_FIRST_PUBLISH:
lbry.claim_list_mine().then((claims) => { lbry.claim_list_mine().then((claims) => {
let claim = claims.find(function(claim) { 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) { if (claim) {
params.transaction_id = claim.txid params.transaction_id = claim.txid

View file

@ -22,6 +22,7 @@
"babel-cli": "^6.11.4", "babel-cli": "^6.11.4",
"babel-preset-es2015": "^6.13.2", "babel-preset-es2015": "^6.13.2",
"babel-preset-react": "^6.11.1", "babel-preset-react": "^6.11.1",
"jshashes": "^1.0.6",
"node-sass": "^3.8.0", "node-sass": "^3.8.0",
"plyr": "^2.0.12", "plyr": "^2.0.12",
"rc-progress": "^2.0.6", "rc-progress": "^2.0.6",