Skip to content

Commit

Permalink
Merge pull request #131 from lbryio/claim_fix
Browse files Browse the repository at this point in the history
only try to claim reward for initial claims, not updates
  • Loading branch information
Jeremy Kauffman committed May 23, 2017
2 parents a3d9826 + d77fc88 commit 68b8feb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
3 changes: 0 additions & 3 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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});
}
Expand Down
55 changes: 53 additions & 2 deletions ui/js/rewards.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const hashes = require('jshashes');
import lbry from 'lbry';
import lbryio from 'lbryio';
import {
Expand All @@ -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",
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 68b8feb

Please sign in to comment.