-
Notifications
You must be signed in to change notification settings - Fork 405
Updating production wallet #407
Changes from 1 commit
fcfa74f
23aacfe
52d9685
a73dfdc
bcf1e17
522b63b
78dba9e
f5dda54
54f6989
d192c0d
c50ae83
d056bf3
663000d
cb31978
400ff5d
3c0bb8a
aaa83b5
283e52d
62abeab
eb917fa
cf317e1
0f1141a
f04fd18
1050bb3
4f4e98a
16e6425
5180dd7
90572dc
e889b50
4cb9dc0
42d5aba
3e64b51
23a5dfc
80f952a
c35592f
fb85462
fb4dec6
99daa14
16f1ee4
49a7010
98c2605
309eec5
1cd03b2
905b540
1910914
54cca96
9b8fec3
81a7c7d
3430dc2
a3bc1a1
d20a1d2
e24b3b3
8448f85
665c9d8
91a1c31
7646263
67589b9
e932df0
f04ab9f
a0fdde0
ede224d
b5e6fef
6c6552a
c70d1ab
de7cdd3
6410351
964c423
f4c6634
7b91854
707a022
fe79f2e
d83feec
d747bf5
1ccf8c0
fe478b4
66ec29c
84c0373
731953f
a6fc78e
3841407
380623f
853bf07
6a614ac
a874395
8c1a446
28a1dc2
06d5f08
b3921a2
ff3c552
5092cc2
5e107db
c4819c5
70753c0
0b9f4be
114c061
393b984
2975915
f33b38b
87a5011
ab0641b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
* add ens support * make regex case insensitive * fix dbissue * update files * do not pull etherscan or show currencies if on testnet * fix block watch * parenthesis
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,49 +19,64 @@ Update wallet balances | |
@method updateBalances | ||
*/ | ||
updateBalances = function() { | ||
// UPDATE TOKEN BALANCES | ||
var allWatchedAccounts = EthAccounts.find().fetch().concat(Wallets.find().fetch().concat(CustomContracts.find().fetch())); | ||
|
||
var walletsAndContracts = Wallets.find().fetch().concat(CustomContracts.find().fetch()); | ||
// go through all existing accounts, for each token | ||
_.each(allWatchedAccounts, function(account){ | ||
|
||
// UPDATE WALLETS ACCOUNTS balance | ||
_.each(walletsAndContracts, function(wallet){ | ||
if(wallet.address) { | ||
web3.eth.getBalance(wallet.address, function(err, res){ | ||
if(account.address) { | ||
web3.eth.getBalance(account.address, function(err, res){ | ||
if(!err) { | ||
// is of type wallet | ||
if(wallet.creationBlock) { | ||
Wallets.update(wallet._id, {$set: { | ||
if(account.creationBlock) { | ||
Wallets.update(account._id, {$set: { | ||
balance: res.toString(10) | ||
}}); | ||
} else { | ||
CustomContracts.update(wallet._id, {$set: { | ||
EthAccounts.update(account._id, {$set: { | ||
balance: res.toString(10) | ||
}}); | ||
CustomContracts.update(account._id, {$set: { | ||
balance: res.toString(10) | ||
}}); | ||
} | ||
} | ||
}); | ||
|
||
// update dailylimit spent, etc, if wallet type | ||
if(wallet.creationBlock) { | ||
if(account.creationBlock) { | ||
Meteor.setTimeout(function() { | ||
updateContractData(wallet); | ||
updateContractData(account); | ||
}, 1000); | ||
} | ||
} | ||
}); | ||
|
||
|
||
|
||
// UPDATE TOKEN BALANCES | ||
var walletsContractsAndAccounts = EthAccounts.find().fetch().concat(walletsAndContracts); | ||
// Only check ENS names every N minutes | ||
if (!account.ensCheck || (account.ensCheck && Date.now() - account.ensCheck > 10*60*1000)) { | ||
Helpers.getENSName(account.address, function(err, name, returnedAddr) { | ||
if (!err && account.address.toLowerCase() == returnedAddr){ | ||
EthAccounts.update({address: account.address}, {$set:{ name: name, ens: true, ensCheck: Date.now()}}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess its more performer to get the date once, safe it in a variable and then use it in all the below places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. |
||
CustomContracts.update({address: account.address}, {$set:{ name: name, ens: true, ensCheck: Date.now()}}); | ||
Wallets.update({address: account.address}, {$set:{ name: name, ens: true, ensCheck: Date.now()}}); | ||
} else { | ||
EthAccounts.update({address: account.address}, {$set:{ens: false, ensCheck: Date.now()}}); | ||
CustomContracts.update({address: account.address}, {$set:{ens: false, ensCheck: Date.now()}}); | ||
Wallets.update({address: account.address}, {$set:{ens: false, ensCheck: Date.now()}}); | ||
|
||
} | ||
}); | ||
} | ||
|
||
|
||
_.each(Tokens.find().fetch(), function(token){ | ||
if(!token.address) | ||
return; | ||
|
||
var tokenInstance = TokenContract.at(token.address); | ||
_.each(Tokens.find().fetch(), function(token){ | ||
if(!token.address) | ||
return; | ||
|
||
var tokenInstance = TokenContract.at(token.address); | ||
|
||
// go through all existing accounts, for each token | ||
_.each(walletsContractsAndAccounts, function(account){ | ||
tokenInstance.balanceOf(account.address, function(e, balance){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only checking on accounts addresses, will not show tokens on wallet contracts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, we are now running it all inside a allWatchedAccounts each loop, so it should check all of that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the changes above, i will also revert that, so we save on the custom contract address. Those don't need to be checked if they have tokens and would only create unnecessary queries. |
||
var currentBalance = (token && token.balances) ? token.balances[account._id] : 0; | ||
|
||
|
@@ -74,7 +89,7 @@ updateBalances = function() { | |
set['balances.'+ account._id] = ''; | ||
Tokens.update(token._id, {$unset: set}); | ||
} | ||
|
||
} | ||
}); | ||
}); | ||
|
@@ -88,11 +103,20 @@ Observe the latest blocks | |
@method observeLatestBlocks | ||
*/ | ||
observeLatestBlocks = function(){ | ||
// update balances on start | ||
console.log('observeLatestBlocks'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove this. |
||
|
||
// update balances on start | ||
updateBalances(); | ||
|
||
// If watching blocks is not working.. | ||
var interval = setInterval(updateBalances, 15000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now obsolete, after the fix in the isolatedPreloader |
||
|
||
// GET the latest blockchain information | ||
web3.eth.filter('latest').watch(function(e, res){ | ||
console.log('NEW BLOCK', e, res); | ||
|
||
clearInterval(interval); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with this. |
||
|
||
if(!e) { | ||
// console.log('Block arrived ', res); | ||
updateBalances(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,8 +272,10 @@ observeTransactions = function(){ | |
|
||
// check for confirmations | ||
if(!tx.confirmed && tx.transactionHash) { | ||
var filter = web3.eth.filter('latest'); | ||
filter.watch(function(e, blockHash){ | ||
|
||
var updateTransactions = function(e, blockHash){ | ||
console.log('updateTransactions', e, blockHash); | ||
|
||
if(!e) { | ||
var confirmations = (tx.blockNumber && EthBlocks.latest.number) ? (EthBlocks.latest.number + 1) - tx.blockNumber : 0; | ||
confCount++; | ||
|
@@ -370,6 +372,16 @@ observeTransactions = function(){ | |
}); | ||
} | ||
} | ||
}; | ||
|
||
// remove this if the filter works again | ||
var interval = setInterval(function(e, blockHash) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
updateTransactions(e, blockHash) | ||
}, 15000); | ||
|
||
var filter = web3.eth.filter('latest').watch(function(e, blockHash) { | ||
updateTransactions(e, blockHash); | ||
clearInterval(interval); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this. |
||
}); | ||
} | ||
}; | ||
|
@@ -408,8 +420,9 @@ observeTransactions = function(){ | |
checkTransactionConfirmations(newDocument); | ||
} | ||
|
||
// add price data | ||
if(newDocument.timestamp && | ||
// If on main net, add price data | ||
if( Session.get('network') == 'main' && | ||
newDocument.timestamp && | ||
(!newDocument.exchangeRates || | ||
!newDocument.exchangeRates.btc || | ||
!newDocument.exchangeRates.usd || | ||
|
@@ -426,7 +439,7 @@ observeTransactions = function(){ | |
if(!e && res && res.statusCode === 200) { | ||
var content = JSON.parse(res.content); | ||
|
||
if(content){ | ||
if(content && content.Response !== "Error"){ | ||
_.each(content, function(price, key){ | ||
if(price && _.isFinite(price)) { | ||
var name = key.toLowerCase(); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,14 +18,14 @@ Get the default contract example | |
@method getDefaultContractExample | ||
**/ | ||
Helpers.getDefaultContractExample = function(withoutPragma) { | ||
const source = 'contract MyContract {\n /* Constructor */\n function MyContract() {\n\n }\n}'; | ||
var source = 'contract MyContract {\n /* Constructor */\n function MyContract() {\n\n }\n}'; | ||
|
||
if (withoutPragma) { | ||
return source; | ||
} else { | ||
var solcVersion; | ||
|
||
// Keep this for now as the Mist-API object will only be availabe from Mist version >= 0.8.9 | ||
// Keep this for now as the Mist-API object will only be availabe from Mist version >= 0.8.9 | ||
// so that older versions that will query code from wallet.ethereum.org won't use broken example code. | ||
if (typeof mist !== 'undefined' && mist.solidity && mist.solidity.version) { | ||
solcVersion = mist.solidity.version; | ||
|
@@ -182,7 +182,7 @@ Helpers.showNotification = function(i18nText, values, callback) { | |
// icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png', | ||
body: TAPi18n.__(i18nText +'.text', values), | ||
}); | ||
|
||
if(_.isFunction(callback)) | ||
notification.onclick = callback; | ||
} | ||
|
@@ -227,8 +227,8 @@ Gets the docuement matching the given addess from the EthAccounts or Wallets col | |
Helpers.getAccountNameByAddress = function(address) { | ||
if (typeof address != 'undefined') | ||
var doc = Helpers.getAccountByAddress(address.toLowerCase()); | ||
return doc ? doc.name : address; | ||
|
||
return doc ? doc.name : address; | ||
}; | ||
|
||
/** | ||
|
@@ -262,7 +262,7 @@ Formats a timestamp to any format given. | |
@return {String} The formated time | ||
**/ | ||
Helpers.formatTime = function(time, format) { //parameters | ||
|
||
// make sure not existing values are not Spacebars.kw | ||
if(format instanceof Spacebars.kw) | ||
format = null; | ||
|
@@ -312,9 +312,9 @@ Helpers.formatTransactionBalance = function(value, exchangeRates, unit) { | |
|
||
if(unit === 'btc') | ||
format += '[000000]'; | ||
else | ||
else | ||
format += '[0]'; | ||
|
||
var price = new BigNumber(String(web3.fromWei(value, 'ether')), 10).times(exchangeRates[unit].price); | ||
return EthTools.formatNumber(price, format) + ' '+ unit.toUpperCase(); | ||
} else { | ||
|
@@ -324,8 +324,8 @@ Helpers.formatTransactionBalance = function(value, exchangeRates, unit) { | |
|
||
|
||
/** | ||
Formats an input and prepares it to be a template | ||
Formats an input and prepares it to be a template | ||
|
||
Helpers.createTemplateDataFromInput(abiFunctionInput); | ||
|
||
@method createTemplateDataFromInput | ||
|
@@ -342,7 +342,7 @@ Helpers.createTemplateDataFromInput = function (input, key){ | |
input.displayName = input.name | ||
.replace(/([A-Z])/g, ' $1') | ||
.replace(/([\-\_])/g, ' <span class="punctuation">$1</span> '); | ||
|
||
if(input.type.indexOf('[') === -1 && | ||
(input.typeShort === 'string' || | ||
input.typeShort === 'uint' || | ||
|
@@ -356,12 +356,12 @@ Helpers.createTemplateDataFromInput = function (input, key){ | |
input.template = 'elements_input_json'; | ||
} | ||
|
||
return input; | ||
return input; | ||
}; | ||
|
||
/** | ||
Adds the input value from a form field to the inputs array | ||
|
||
@method addInputValue | ||
@param {object} inputs The current inputs | ||
@param {object} currentInput The current input | ||
|
@@ -373,7 +373,7 @@ Helpers.addInputValue = function (inputs, currentInput, formField){ | |
var value = _.isUndefined(input.value) ? '' : input.value; | ||
|
||
if(currentInput.name === input.name && | ||
currentInput.type === input.type && | ||
currentInput.type === input.type && | ||
currentInput.index === input.index ) { | ||
|
||
if(input.type.indexOf('[') !== -1) { | ||
|
@@ -412,13 +412,13 @@ Takes a camelcase and shows it with spaces | |
@return {string} sentence The same name, sanitized, with spaces | ||
**/ | ||
Helpers.toSentence = function (inputString, noHTML) { | ||
if (typeof inputString == 'undefined') | ||
if (typeof inputString == 'undefined') | ||
return false; | ||
else { | ||
inputString = inputString.replace(/[^a-zA-Z0-9_]/g, ''); | ||
inputString = inputString.replace(/[^a-zA-Z0-9_]/g, ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess this can be better |
||
if (noHTML === true) // only consider explicit true | ||
return inputString.replace(/([A-Z]+|[0-9]+)/g, ' $1').trim(); | ||
else | ||
else | ||
return inputString.replace(/([A-Z]+|[0-9]+)/g, ' $1').trim().replace(/([\_])/g, '<span class="dapp-punctuation">$1</span>'); | ||
} | ||
} | ||
|
@@ -428,9 +428,85 @@ Helpers.toSentence = function (inputString, noHTML) { | |
Returns true if Main is the current network. | ||
|
||
@method isOnMainNetwork | ||
@return {Bool} | ||
@return {Bool} | ||
**/ | ||
Helpers.isOnMainNetwork = function () { | ||
return Session.get('network') == 'main'; | ||
}; | ||
|
||
/** | ||
ENS Functions | ||
**/ | ||
var sha3 = function(str, opt) { | ||
return '0x' + web3.sha3(str, opt).replace('0x',''); | ||
}; | ||
|
||
function namehash(name) { | ||
var node = '0x0000000000000000000000000000000000000000000000000000000000000000'; | ||
if (name != '') { | ||
var labels = name.split("."); | ||
for(var i = labels.length - 1; i >= 0; i--) { | ||
node = sha3(node + sha3(labels[i]).slice(2), {encoding: 'hex'}); | ||
} | ||
} | ||
return node.toString(); | ||
} | ||
|
||
|
||
var ensContractAbi = [{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"resolver","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"label","type":"bytes32"},{"name":"owner","type":"address"}],"name":"setSubnodeOwner","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"ttl","type":"uint64"}],"name":"setTTL","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"ttl","outputs":[{"name":"","type":"uint64"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"resolver","type":"address"}],"name":"setResolver","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"owner","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"owner","type":"address"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":true,"name":"label","type":"bytes32"},{"indexed":false,"name":"owner","type":"address"}],"name":"NewOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"resolver","type":"address"}],"name":"NewResolver","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"ttl","type":"uint64"}],"name":"NewTTL","type":"event"}]; | ||
|
||
var resolverContractAbi = [{"constant":true,"inputs":[{"name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"},{"name":"contentTypes","type":"uint256"}],"name":"ABI","outputs":[{"name":"contentType","type":"uint256"},{"name":"data","type":"bytes"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"x","type":"bytes32"},{"name":"y","type":"bytes32"}],"name":"setPubkey","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"content","outputs":[{"name":"ret","type":"bytes32"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"addr","outputs":[{"name":"ret","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"contentType","type":"uint256"},{"name":"data","type":"bytes"}],"name":"setABI","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"name","outputs":[{"name":"ret","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"name","type":"string"}],"name":"setName","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"hash","type":"bytes32"}],"name":"setContent","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"pubkey","outputs":[{"name":"x","type":"bytes32"},{"name":"y","type":"bytes32"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"node","type":"bytes32"},{"name":"addr","type":"address"}],"name":"setAddr","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"ensAddr","type":"address"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"a","type":"address"}],"name":"AddrChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"hash","type":"bytes32"}],"name":"ContentChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"name","type":"string"}],"name":"NameChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":true,"name":"contentType","type":"uint256"}],"name":"ABIChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"node","type":"bytes32"},{"indexed":false,"name":"x","type":"bytes32"},{"indexed":false,"name":"y","type":"bytes32"}],"name":"PubkeyChanged","type":"event"}]; | ||
|
||
var ensAddress = '0x314159265dd8dbb310642f98f50c066173c1259b'; | ||
|
||
|
||
/** | ||
Returns a string, given an address | ||
|
||
@method getENSName | ||
**/ | ||
Helpers.getENSName = function(address, callback) { | ||
|
||
if (Session.get('network') !== 'main' ) { | ||
callback('Cannot retrieve ENS addresses unless fully synced on main chain', null, null); | ||
return; | ||
} | ||
var node = namehash(address.toLowerCase().replace('0x','')+'.addr.reverse'); | ||
var ensContract = web3.eth.contract(ensContractAbi); | ||
var resolverContract = web3.eth.contract(resolverContractAbi); | ||
|
||
// instantiate ens | ||
ensContract.at(ensAddress, function(err, ens) { | ||
// get a resolver address for that name | ||
ens.resolver(node, function(err, resolverAddress) { | ||
if (err) callback(err, null, null); | ||
else if (resolverAddress == 0) callback('no resolver address', null, null); | ||
else { | ||
// if you find one, find the name on that resolver | ||
resolverContract.at(resolverAddress).name(node, function(error, name) { | ||
if (err) callback(err, null, null); | ||
else if (name == 0) callback('Found resolver but no name', null, null); | ||
else { | ||
// any address can claim any name, we need to check the name now | ||
var node = namehash(name); | ||
// get a resolver address for that name | ||
ens.resolver(node, function (err, resolverAddress) { | ||
if (err) callback(err, null, null); | ||
else if (resolverAddress == 0) callback('Name has no resolver', null, null); | ||
else { | ||
// if you find one, find the addr of that resolver | ||
resolverContract.at(resolverAddress).addr(node, function(error, returnAddr) { | ||
if (err) callback(err, null, null); | ||
else if (returnAddr == 0) callback('No address returned', null, null); | ||
else { | ||
callback(error, name, returnAddr); | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
}) | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Account balances are updated using the EthAccount package. Doing it here too would be double the call amounts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok! I applied those changes because I was trying to figure out why the accounts balances weren't changing - which is how I found that the bug was the block issue. I was confused on why it didn't apply to accounts, now it's explained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accounts should update, so i can revert that.