Skip to content

Instantly share code, notes, and snippets.

@jefflau
Last active May 30, 2017 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jefflau/aeea4a6bf30d072c14d0626ea403d2c6 to your computer and use it in GitHub Desktop.
Save jefflau/aeea4a6bf30d072c14d0626ea403d2c6 to your computer and use it in GitHub Desktop.
Async await vs promises
export const getSubdomains = async name => {
let namehash = await getNamehash(name)
let logs = await getENSEvent('NewOwner', {node: namehash}, {fromBlock: 900000, toBlock: 'latest'})
let labels = await decryptHashes(...logs.map(log => log.args.label))
let ownerPromises = labels.map(label => getOwner(`${label}.${name}`))
return Promise.all(ownerPromises).then(owners => {
let subdomains = labels.map((value, index) => {
//if(label === false)
// TODO add check for labels that haven't been found
return {
label: value,
node: name,
owner: owners[index],
name: value + '.' + name,
nodes: []
}
})
return subdomains
})
}
export const getSubdomains = name => {
return namehash(name).then(namehash =>
getENSEvent('NewOwner', {node: namehash}, {fromBlock: 900000, toBlock: 'latest'}).then(logs => {
let labelsPromise = decryptHashes(...logs.map(log => log.args.label))
return labelsPromise.then(labels => {
let ownerPromises = labels.map(label => getOwner(`${label}.${name}`))
return Promise.all(ownerPromises).then(owners => {
let subdomains = labels.map((value, index) => {
//if(label === false)
// TODO add check for labels that haven't been found
return {
label: value,
node: name,
owner: owners[index],
name: value + '.' + name,
nodes: []
}
})
return subdomains
})
})
})
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment