Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

Updating production wallet #407

Merged
merged 100 commits into from
Jul 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
fcfa74f
added @frozeman's fix (#328)
luclu Dec 15, 2016
23aacfe
added @frozeman's fix (#328) (#329)
luclu Dec 15, 2016
52d9685
updates for gh-pages (#331)
luclu Dec 15, 2016
a73dfdc
updates for gh-pages (#332)
luclu Dec 15, 2016
bcf1e17
Update README (#335)
Projjol Jan 12, 2017
522b63b
Set placeholder contract's pragma version using Mist-API (#337)
luclu Jan 23, 2017
78dba9e
added missing 0x
frozeman Jan 23, 2017
f5dda54
merged master
frozeman Jan 23, 2017
54f6989
build
frozeman Jan 23, 2017
d192c0d
Merge Develop (#338)
frozeman Jan 23, 2017
c50ae83
Merge branch 'gh-pages' into master
frozeman Jan 23, 2017
d056bf3
reverted network id storage on accounts package
frozeman Jan 23, 2017
663000d
merged develop
frozeman Jan 23, 2017
cb31978
Merge branch 'gh-pages'
frozeman Jan 23, 2017
400ff5d
re-build
frozeman Jan 23, 2017
3c0bb8a
Error handling for previous versions of Mist (#342)
evertonfraga Jan 24, 2017
aaa83b5
rebuild
frozeman Jan 24, 2017
283e52d
Merge branch 'develop'
frozeman Jan 24, 2017
62abeab
remove amount param from coinbase widget (#347)
alexvansande Feb 8, 2017
eb917fa
sticky bar is failing to stick. terrible sticky bar, fake sticky (#348)
alexvansande Feb 9, 2017
cf317e1
Warning when trying to transfer a token to an empty recipient (#346)
evertonfraga Mar 2, 2017
0f1141a
authorize accounts callback fix
frozeman Mar 30, 2017
f04fd18
Merge branch 'develop' of github.com:ethereum/meteor-dapp-wallet into…
frozeman Mar 30, 2017
1050bb3
Add caret operator to contract example (#345)
luclu Apr 5, 2017
4f4e98a
Addresses need quotes (#351)
Apr 5, 2017
16e6425
[i18n] add missing meteor package; improve error message (#357)
luclu Apr 5, 2017
5180dd7
fix russian translation (#356)
ygun Apr 6, 2017
90572dc
fix renaming bug (#358)
luclu Apr 12, 2017
e889b50
update token contract link (#360)
luclu Apr 12, 2017
4cb9dc0
minor typo and other text corrections (#359)
JohnDoe389 Apr 12, 2017
42d5aba
fixes token selection when sending via the zebra-token-list (#361)
luclu Apr 12, 2017
3e64b51
fix (#362)
luclu Apr 12, 2017
23a5dfc
initialize send view correctly when switching from deploy view (#363)
luclu Apr 12, 2017
80f952a
update TX link: testnet.etherscan.io -> ropsten.etherscan.io (#364)
luclu Apr 12, 2017
c35592f
numeral.js: console.warn instead of console.error (#366)
luclu Apr 20, 2017
fb85462
Add ES6 support; correction to fr translation (#365)
iquidus Apr 24, 2017
fb4dec6
update i18n string 'accountNote' (#372)
luclu Apr 28, 2017
99daa14
remove whitespaces from address on token.add() (#370)
luclu Apr 28, 2017
16f1ee4
fix packages (#369)
luclu Apr 28, 2017
49a7010
Adding out of sync warning (#374)
evertonfraga Jun 2, 2017
98c2605
Changed http:// to https:// on one link (#384)
sandakersmann Jun 2, 2017
309eec5
update 'allow-deny' package to avert download timeout (#383)
luclu Jun 2, 2017
1cd03b2
build wallet
frozeman Jun 2, 2017
905b540
Darken network info font (#388)
evertonfraga Jun 13, 2017
1910914
Quick wallet fixes (#389)
alexvansande Jun 21, 2017
54cca96
some typo fixes; adjust some of the supporting text (#385)
JohnDoe389 Jun 21, 2017
9b8fec3
Adding two more currencies to price ticker (#387)
evertonfraga Jun 22, 2017
81a7c7d
Update coinbase success message (#390)
evertonfraga Jun 24, 2017
3430dc2
Removed disabled wallets (#393)
alexvansande Jun 28, 2017
a3bc1a1
Temporarily removing ES6 support: fixing indexeddb driver bug (#395)
evertonfraga Jun 29, 2017
d20a1d2
Including file to prevent 404 error (#394)
evertonfraga Jun 29, 2017
e24b3b3
add reactive (#396)
alexvansande Jun 29, 2017
8448f85
add ens support to input fields (#398)
alexvansande Jul 6, 2017
665c9d8
Creating travis file (#402)
evertonfraga Jul 10, 2017
91a1c31
Updating ethereum-elements; building for production (#405)
evertonfraga Jul 11, 2017
7646263
Adding travis badge
evertonfraga Jul 11, 2017
67589b9
reverse ENS lookup (#403)
alexvansande Jul 11, 2017
e932df0
Merge branch 'develop' of https://github.com/ethereum/meteor-dapp-wal…
evertonfraga Jul 11, 2017
f04ab9f
remove amount param from coinbase widget (#347)
alexvansande Feb 8, 2017
a0fdde0
sticky bar is failing to stick. terrible sticky bar, fake sticky (#348)
alexvansande Feb 9, 2017
ede224d
Warning when trying to transfer a token to an empty recipient (#346)
evertonfraga Mar 2, 2017
b5e6fef
authorize accounts callback fix
frozeman Mar 30, 2017
6c6552a
Add caret operator to contract example (#345)
luclu Apr 5, 2017
c70d1ab
Addresses need quotes (#351)
Apr 5, 2017
de7cdd3
[i18n] add missing meteor package; improve error message (#357)
luclu Apr 5, 2017
6410351
fix russian translation (#356)
ygun Apr 6, 2017
964c423
fix renaming bug (#358)
luclu Apr 12, 2017
f4c6634
update token contract link (#360)
luclu Apr 12, 2017
7b91854
minor typo and other text corrections (#359)
JohnDoe389 Apr 12, 2017
707a022
fixes token selection when sending via the zebra-token-list (#361)
luclu Apr 12, 2017
fe79f2e
fix (#362)
luclu Apr 12, 2017
d83feec
initialize send view correctly when switching from deploy view (#363)
luclu Apr 12, 2017
d747bf5
update TX link: testnet.etherscan.io -> ropsten.etherscan.io (#364)
luclu Apr 12, 2017
1ccf8c0
numeral.js: console.warn instead of console.error (#366)
luclu Apr 20, 2017
fe478b4
Add ES6 support; correction to fr translation (#365)
iquidus Apr 24, 2017
66ec29c
update i18n string 'accountNote' (#372)
luclu Apr 28, 2017
84c0373
remove whitespaces from address on token.add() (#370)
luclu Apr 28, 2017
731953f
fix packages (#369)
luclu Apr 28, 2017
a6fc78e
Adding out of sync warning (#374)
evertonfraga Jun 2, 2017
3841407
Changed http:// to https:// on one link (#384)
sandakersmann Jun 2, 2017
380623f
update 'allow-deny' package to avert download timeout (#383)
luclu Jun 2, 2017
853bf07
build wallet
frozeman Jun 2, 2017
6a614ac
Darken network info font (#388)
evertonfraga Jun 13, 2017
a874395
Quick wallet fixes (#389)
alexvansande Jun 21, 2017
8c1a446
some typo fixes; adjust some of the supporting text (#385)
JohnDoe389 Jun 21, 2017
28a1dc2
Adding two more currencies to price ticker (#387)
evertonfraga Jun 22, 2017
06d5f08
Update coinbase success message (#390)
evertonfraga Jun 24, 2017
b3921a2
Removed disabled wallets (#393)
alexvansande Jun 28, 2017
ff3c552
Temporarily removing ES6 support: fixing indexeddb driver bug (#395)
evertonfraga Jun 29, 2017
5092cc2
Including file to prevent 404 error (#394)
evertonfraga Jun 29, 2017
5e107db
add reactive (#396)
alexvansande Jun 29, 2017
c4819c5
add ens support to input fields (#398)
alexvansande Jul 6, 2017
70753c0
Creating travis file (#402)
evertonfraga Jul 10, 2017
0b9f4be
Updating ethereum-elements; building for production (#405)
evertonfraga Jul 11, 2017
114c061
Adding travis badge
evertonfraga Jul 11, 2017
393b984
reverse ENS lookup (#403)
alexvansande Jul 11, 2017
2975915
Merge branch 'gh-pages' into master
evertonfraga Jul 11, 2017
f33b38b
merged master
frozeman Jul 12, 2017
87a5011
Release fixes (#408)
frozeman Jul 12, 2017
ab0641b
Release fixes (#409)
frozeman Jul 12, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reverse ENS lookup (#403)
* 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
alexvansande authored and evertonfraga committed Jul 11, 2017
commit 393b9843b8cbfff0efe27a6e6bea36aacaf16d41
68 changes: 46 additions & 22 deletions app/client/lib/ethereum/observeBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,64 @@ Update wallet balances
@method updateBalances
*/
updateBalances = function() {
// UPDATE TOKEN BALANCES
Copy link
Contributor

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.

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.

Copy link
Contributor

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.

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()}});
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only checking on accounts addresses, will not show tokens on wallet contracts.

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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;

Expand All @@ -74,7 +89,7 @@ updateBalances = function() {
set['balances.'+ account._id] = '';
Tokens.update(token._id, {$unset: set});
}

}
});
});
Expand All @@ -88,11 +103,20 @@ Observe the latest blocks
@method observeLatestBlocks
*/
observeLatestBlocks = function(){
// update balances on start
console.log('observeLatestBlocks');
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this.


if(!e) {
// console.log('Block arrived ', res);
updateBalances();
Expand Down
23 changes: 18 additions & 5 deletions app/client/lib/ethereum/observeTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down Expand Up @@ -370,6 +372,16 @@ observeTransactions = function(){
});
}
}
};

// remove this if the filter works again
var interval = setInterval(function(e, blockHash) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this.

});
}
};
Expand Down Expand Up @@ -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 ||
Expand All @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions app/client/lib/ethereum/walletInterface.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 94 additions & 18 deletions app/client/lib/helpers/helperFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
};

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -342,7 +342,7 @@ Helpers.createTemplateDataFromInput = function (input, key){
input.displayName = input.name
.replace(/([A-Z])/g, ' $1')
.replace(/([\-\_])/g, '&thinsp;<span class="punctuation">$1</span>&thinsp;');

if(input.type.indexOf('[') === -1 &&
(input.typeShort === 'string' ||
input.typeShort === 'uint' ||
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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, '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess this can be better inputString.replace(/[^a-z0-9_]/gi, '')

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>');
}
}
Expand All @@ -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);
}
})
}
})
}
})
}
})
});
}
Loading