-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from aleph-im/add_enslookup-fix_explorer-rem_helia
Add ENS lookup, fix explorer urls, disable helia/ipfs
- Loading branch information
Showing
9 changed files
with
8,442 additions
and
11,687 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,15 @@ | ||
import { providers } from 'ethers' | ||
|
||
const provider = new providers.JsonRpcProvider('https://eth.drpc.org') | ||
|
||
export const EnsNameLookup = async ( | ||
address?: string, | ||
): Promise<string | undefined> => { | ||
return (address && (await provider.lookupAddress(address))) || undefined | ||
} | ||
|
||
export const EnsAddressLookup = async ( | ||
ens?: string, | ||
): Promise<string | undefined> => { | ||
return (ens && (await provider.resolveName(ens))) || undefined | ||
} |
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 |
---|---|---|
@@ -1,20 +1,47 @@ | ||
import { createLibp2p } from 'libp2p' | ||
/* import { createLibp2p } from 'libp2p' | ||
import { webSockets } from '@libp2p/websockets' | ||
import { all as allFilters } from '@libp2p/websockets/filters' | ||
import { mplex } from '@libp2p/mplex' | ||
import { noise } from '@libp2p/noise' | ||
import { webTransport } from '@libp2p/webtransport' | ||
import { yamux } from '@chainsafe/libp2p-yamux' | ||
import { noise } from '@chainsafe/libp2p-noise' | ||
import { bootstrap } from '@libp2p/bootstrap' | ||
import { kadDHT } from '@libp2p/kad-dht' | ||
/** | ||
* Creates a custom LibP2P node using WebSockets | ||
*/ | ||
export const getP2PNode = async () => | ||
await createLibp2p({ | ||
transports: [ | ||
webSockets({ | ||
// connect to all sockets, even insecure ones | ||
filter: allFilters, | ||
}), | ||
], | ||
streamMuxers: [mplex()], | ||
// Requires: npm i libp2p @libp2p/websockets @libp2p/webtransport @chainsafe/libp2p-yamux @chainsafe/libp2p-noise @libp2p/bootstrap @libp2p/kad-dht | ||
const peers = [ | ||
'/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN', | ||
'/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa', | ||
'/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb', | ||
'/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt', | ||
] | ||
export const getP2PNode = async () => { | ||
const node = await createLibp2p({ | ||
//transports: [webSockets({ filter: allFilters }), webTransport()], | ||
transports: [webSockets(), webTransport()], | ||
streamMuxers: [yamux()], | ||
connectionEncryption: [noise()], | ||
peerDiscovery: [bootstrap({ list: peers })], | ||
services: { dht: kadDHT({ clientMode: false }) }, | ||
}) | ||
node.services.dht.setMode('server') | ||
console.log(node.peerId.toString()) | ||
node.getMultiaddrs().forEach((ma) => console.log(ma.toString())) | ||
node.addEventListener('peer:discovery', (evt) => { | ||
const peer = evt.detail | ||
node | ||
.dial(peer.id) | ||
.then(() => console.log('Found peer: ', evt.detail.id.toString())) | ||
.catch((err) => { | ||
console.log(`Could not dial ${peer.id}`, err) | ||
}) | ||
}) | ||
node.addEventListener('peer:connect', (evt) => { | ||
console.log(`Connected to ${evt.detail.toString()}`) | ||
}) | ||
node.addEventListener('peer:disconnect', (evt) => { | ||
console.log(`Disconnected from ${evt.detail.toString()}`) | ||
}) | ||
return node | ||
} */ |
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,18 @@ | ||
import { useEffect, useState } from 'react' | ||
import { EnsNameLookup, EnsAddressLookup } from '@/domain/ens' | ||
|
||
export const useEnsNameLookup = (address?: string) => { | ||
const [ensName, setEnsName] = useState('') | ||
useEffect(() => { | ||
EnsNameLookup(address).then((name) => name && setEnsName(name)) | ||
}, [address]) | ||
return ensName | ||
} | ||
|
||
export const useEnsAddressLookup = (ens?: string) => { | ||
const [ensAddress, setEnsAddress] = useState('') | ||
useEffect(() => { | ||
EnsAddressLookup(ens).then((address) => address && setEnsAddress(address)) | ||
}, [ens]) | ||
return ensAddress | ||
} |
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