Update lib
This commit is contained in:
parent
829deacb57
commit
384cb126dd
26
app/404.html
26
app/404.html
|
@ -17,12 +17,36 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
.app{
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
img{
|
img{
|
||||||
display: block;
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
h2{
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 20%;
|
||||||
|
left: 0;
|
||||||
|
color: #1b243d;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
h2 > a{
|
||||||
|
color: #1b243d;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<img src="./images/404.png" alt="">
|
<div class="app">
|
||||||
|
<img src="./images/404.png" alt="">
|
||||||
|
<h2>Powered by <a href="https://www.portal.network/">Portal Network</a></h2>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -16,7 +16,7 @@ module.exports = function (provider) {
|
||||||
clearTimeout(clearTime)
|
clearTimeout(clearTime)
|
||||||
let url = 'https://gateway.ipfs.io/ipfs/' + ipfsHash
|
let url = 'https://gateway.ipfs.io/ipfs/' + ipfsHash
|
||||||
return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => {
|
return fetch(url, { method: 'HEAD' }).then(response => response.status).then(statusCode => {
|
||||||
if (statusCode !== 200) return 'Local'
|
if (statusCode !== 200) return extension.tabs.update(tab.id, { url: '404.html' })
|
||||||
extension.tabs.update(tab.id, { url: url })
|
extension.tabs.update(tab.id, { url: url })
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
const namehash = require('eth-ens-namehash')
|
const namehash = require('eth-ens-namehash')
|
||||||
const multihash = require('multihashes')
|
const multihash = require('multihashes')
|
||||||
const REGISTRAR_ENS_MAIN_NET = '0x314159265dd8dbb310642f98f50c066173c1259b'
|
|
||||||
const HttpProvider = require('ethjs-provider-http')
|
const HttpProvider = require('ethjs-provider-http')
|
||||||
const Eth = require('ethjs-query')
|
const Eth = require('ethjs-query')
|
||||||
const EthContract = require('ethjs-contract')
|
const EthContract = require('ethjs-contract')
|
||||||
|
@ -8,32 +7,57 @@ const registrarAbi = require('./contracts/registrar')
|
||||||
const resolverAbi = require('./contracts/resolver')
|
const resolverAbi = require('./contracts/resolver')
|
||||||
|
|
||||||
function ens (name, provider) {
|
function ens (name, provider) {
|
||||||
const eth = new Eth(new HttpProvider(provider.rpcTarget))
|
const eth = new Eth(new HttpProvider(getProvider(provider.type)))
|
||||||
const hash = namehash.hash(name)
|
const hash = namehash.hash(name)
|
||||||
const contract = new EthContract(eth)
|
const contract = new EthContract(eth)
|
||||||
const Registrar = contract(registrarAbi).at(REGISTRAR_ENS_MAIN_NET)
|
const Registrar = contract(registrarAbi).at(getRegistrar(provider.type))
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (provider.type !== 'mainnet') reject('unsupport')
|
if (provider.type === 'mainnet' || provider.type === 'ropsten') {
|
||||||
Registrar.resolver(hash).then((address) => {
|
Registrar.resolver(hash).then((address) => {
|
||||||
if (address === '0x0000000000000000000000000000000000000000') {
|
if (address === '0x0000000000000000000000000000000000000000') {
|
||||||
reject(null)
|
reject(null)
|
||||||
} else {
|
} else {
|
||||||
const Resolver = contract(resolverAbi).at(address['0'])
|
const Resolver = contract(resolverAbi).at(address['0'])
|
||||||
return Resolver.content(hash)
|
return Resolver.content(hash)
|
||||||
}
|
}
|
||||||
}).then((contentHash) => {
|
}).then((contentHash) => {
|
||||||
if (contentHash['0'] === '0x0000000000000000000000000000000000000000000000000000000000000000') reject(null)
|
if (contentHash['0'] === '0x0000000000000000000000000000000000000000000000000000000000000000') reject(null)
|
||||||
if (contentHash.ret !== '0x') {
|
if (contentHash.ret !== '0x') {
|
||||||
const hex = contentHash['0'].substring(2)
|
const hex = contentHash['0'].substring(2)
|
||||||
const buf = multihash.fromHexString(hex)
|
const buf = multihash.fromHexString(hex)
|
||||||
resolve(multihash.toB58String(buf))
|
resolve(multihash.toB58String(multihash.encode(buf, 'sha2-256')))
|
||||||
} else {
|
} else {
|
||||||
reject(null)
|
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:3000/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRegistrar (type) {
|
||||||
|
switch (type) {
|
||||||
|
case 'mainnet':
|
||||||
|
return '0x314159265dd8dbb310642f98f50c066173c1259b'
|
||||||
|
case 'ropsten':
|
||||||
|
return '0x112234455c3a32fd11230c42e7bccd4a84e02010'
|
||||||
|
default:
|
||||||
|
return '0x0000000000000000000000000000000000000000'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.resolve = function (name, provider) {
|
module.exports.resolve = function (name, provider) {
|
||||||
const path = name.split('.')
|
const path = name.split('.')
|
||||||
const tld = path[path.length - 1]
|
const tld = path[path.length - 1]
|
||||||
|
|
Loading…
Reference in New Issue