diff options
author | kumavis <kumavis@users.noreply.github.com> | 2018-10-21 17:48:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-21 17:48:15 +0800 |
commit | 6d09f60bbfe5ee737ff7a138260cc33e3db5ca46 (patch) | |
tree | a0642d45087aca57ad3e06bd93dac6bfc042f233 /app/scripts/lib/resolver.js | |
parent | b0c649a4e3c68293e08e764bbf4d53939df88e2d (diff) | |
download | tangerine-wallet-browser-6d09f60bbfe5ee737ff7a138260cc33e3db5ca46.tar tangerine-wallet-browser-6d09f60bbfe5ee737ff7a138260cc33e3db5ca46.tar.gz tangerine-wallet-browser-6d09f60bbfe5ee737ff7a138260cc33e3db5ca46.tar.bz2 tangerine-wallet-browser-6d09f60bbfe5ee737ff7a138260cc33e3db5ca46.tar.lz tangerine-wallet-browser-6d09f60bbfe5ee737ff7a138260cc33e3db5ca46.tar.xz tangerine-wallet-browser-6d09f60bbfe5ee737ff7a138260cc33e3db5ca46.tar.zst tangerine-wallet-browser-6d09f60bbfe5ee737ff7a138260cc33e3db5ca46.zip |
ens-ipfs - refactor for readability (#5568)
* ens-ipfs - refactor for readability
* ens-ipfs - use official ipfs gateway for better performance
* lint - remove unused code
* ens-ipfs - support path and search
* lint - gotta love that linter
* ens-ipfs - improve loading page formatting
* ens-ipfs - loading - redirect to 404 after 1 min timeout
* ens-ipfs - destructure for cleaner code
Diffstat (limited to 'app/scripts/lib/resolver.js')
-rw-r--r-- | app/scripts/lib/resolver.js | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/app/scripts/lib/resolver.js b/app/scripts/lib/resolver.js deleted file mode 100644 index ff0fed161..000000000 --- a/app/scripts/lib/resolver.js +++ /dev/null @@ -1,71 +0,0 @@ -const namehash = require('eth-ens-namehash') -const multihash = require('multihashes') -const HttpProvider = require('ethjs-provider-http') -const Eth = require('ethjs-query') -const EthContract = require('ethjs-contract') -const registrarAbi = require('./contracts/registrar') -const resolverAbi = require('./contracts/resolver') - -function ens (name, provider) { - const eth = new Eth(new HttpProvider(getProvider(provider.type))) - const hash = namehash.hash(name) - const contract = new EthContract(eth) - const Registrar = contract(registrarAbi).at(getRegistrar(provider.type)) - return new Promise((resolve, reject) => { - if (provider.type === 'mainnet' || provider.type === 'ropsten') { - Registrar.resolver(hash).then((address) => { - if (address === '0x0000000000000000000000000000000000000000') { - reject(null) - } else { - const Resolver = contract(resolverAbi).at(address['0']) - return Resolver.content(hash) - } - }).then((contentHash) => { - if (contentHash['0'] === '0x0000000000000000000000000000000000000000000000000000000000000000') reject(null) - if (contentHash.ret !== '0x') { - const hex = contentHash['0'].substring(2) - const buf = multihash.fromHexString(hex) - resolve(multihash.toB58String(multihash.encode(buf, 'sha2-256'))) - } else { - reject(null) - } - }) - } else { - return reject('unsupport') - } - }) -} - -function getProvider (type) { - switch (type) { - case 'mainnet': - return 'https://mainnet.infura.io/' - case 'ropsten': - return 'https://ropsten.infura.io/' - default: - return 'http://localhost:8545/' - } -} - -function getRegistrar (type) { - switch (type) { - case 'mainnet': - return '0x314159265dd8dbb310642f98f50c066173c1259b' - case 'ropsten': - return '0x112234455c3a32fd11230c42e7bccd4a84e02010' - default: - return '0x0000000000000000000000000000000000000000' - } -} - -module.exports.resolve = function (name, provider) { - const path = name.split('.') - const topLevelDomain = path[path.length - 1] - if (topLevelDomain === 'eth' || topLevelDomain === 'test') { - return ens(name, provider) - } else { - return new Promise((resolve, reject) => { - reject(null) - }) - } -} |