-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70f479b
commit 6e7d6d8
Showing
19 changed files
with
135 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"use strict"; | ||
var _dataSource = _interopRequireDefault(require("../lib/dataSource.js")); | ||
var _nod3Connect = _interopRequireDefault(require("../lib/nod3Connect")); | ||
var _rskContractParser = _interopRequireDefault(require("rsk-contract-parser")); | ||
var _rskUtils = require("rsk-utils");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} | ||
|
||
const parser = new _rskContractParser.default({ nod3: _nod3Connect.default }); | ||
|
||
patch().then(() => { | ||
console.log('DONE!'); | ||
}).catch(err => { | ||
console.log('ERROR'); | ||
console.log(err); | ||
process.exit(9); | ||
}); | ||
|
||
async function patch() { | ||
try { | ||
let { db } = await (0, _dataSource.default)({ skipCheck: true }); | ||
let collection = db.collection('tokensAddresses'); | ||
let cursor = collection.find(); | ||
await cursor.forEach(async account => { | ||
try { | ||
let { balance, contract, address, _id } = account; | ||
let name = `${contract}--${address}`; | ||
if (balance !== null) { | ||
console.log(`Getting balance for ${name}`); | ||
let newBalance = await getBalance(account); | ||
newBalance = (0, _rskUtils.add0x)(newBalance.toString(16)); | ||
if (balance !== newBalance) { | ||
console.log(`Updating balance for ${name}`); | ||
await collection.updateOne({ _id }, { $set: { balance: newBalance } }); | ||
} else { | ||
console.log(`${name} .... OK`); | ||
} | ||
} else { | ||
console.log(`${name} has null balance, skipped`); | ||
} | ||
} catch (err) { | ||
console.log(err, account); | ||
return Promise.reject(err); | ||
} | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
process.exit(9); | ||
} | ||
} | ||
|
||
async function getBalance({ address, contract }, { abi } = {}) { | ||
try { | ||
let Contract = parser.makeContract(contract, abi); | ||
let balance = await Contract.call('balanceOf', [address]); | ||
return balance; | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ class Tx extends _BcThing.BcThing { | |
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
|
||
} | ||
|
||
async getTx() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.updateTokenAccountBalances = updateTokenAccountBalances; | ||
var _rskUtils = require("rsk-utils"); | ||
var _rskContractParser = _interopRequireDefault(require("rsk-contract-parser"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} | ||
|
||
async function updateTokenAccountBalances(block, { nod3, collections, log }) { | ||
const parser = new _rskContractParser.default({ nod3 }); | ||
let { number } = block; | ||
number = parseInt(number) - 1; | ||
if (number < 1) return; | ||
log.trace(`Checking token account balances for block ${number}`); | ||
try { | ||
let collection = collections.TokensAddrs; | ||
let query = { 'block.number': number }; | ||
let cursor = collection.find(query); | ||
await cursor.forEach(async account => { | ||
try { | ||
let { balance, _id, address, contract } = account; | ||
let newBalance = await getBalance(account, { parser }); | ||
if (balance !== newBalance) { | ||
log.info(`Updating token account balance ${contract}--${address}`); | ||
await collection.updateOne({ _id }, { $set: { balance: newBalance } }); | ||
} | ||
} catch (err) { | ||
log.error(err); | ||
return Promise.reject(err); | ||
} | ||
}); | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} | ||
|
||
async function getBalance({ address, contract }, { parser, abi } = {}) { | ||
try { | ||
let Contract = parser.makeContract(contract, abi); | ||
let balance = await Contract.call('balanceOf', [address]); | ||
if (balance) balance = (0, _rskUtils.add0x)(balance.toString(16)); | ||
return balance; | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters