Last active
May 30, 2017 05:59
-
-
Save jefflau/aeea4a6bf30d072c14d0626ea403d2c6 to your computer and use it in GitHub Desktop.
Async await vs promises
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
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