2016-07-07 02:58:46 +02:00
|
|
|
/* CONTRACT NAMER
|
|
|
|
*
|
|
|
|
* Takes an address,
|
|
|
|
* Returns a nicname if we have one stored,
|
|
|
|
* otherwise returns null.
|
|
|
|
*/
|
|
|
|
|
2016-07-07 22:21:45 +02:00
|
|
|
// Nickname keys must be stored in lower case.
|
2016-07-07 02:58:46 +02:00
|
|
|
const nicknames = {}
|
|
|
|
|
2016-07-07 22:21:45 +02:00
|
|
|
module.exports = function(addr, identities = {}) {
|
2016-07-07 02:58:46 +02:00
|
|
|
|
2016-07-07 22:21:45 +02:00
|
|
|
const address = addr.toLowerCase()
|
|
|
|
const ids = hashFromIdentities(identities)
|
|
|
|
|
|
|
|
console.dir({ addr, ids })
|
|
|
|
return addrFromHash(address, ids) || addrFromHash(address, nicknames)
|
|
|
|
}
|
|
|
|
|
|
|
|
function hashFromIdentities(identities) {
|
|
|
|
const result = {}
|
|
|
|
for (let key in identities) {
|
|
|
|
result[key] = identities[key].name
|
2016-07-07 02:58:46 +02:00
|
|
|
}
|
2016-07-07 22:21:45 +02:00
|
|
|
return result
|
|
|
|
}
|
2016-07-07 02:58:46 +02:00
|
|
|
|
2016-07-07 22:21:45 +02:00
|
|
|
function addrFromHash(addr, hash) {
|
|
|
|
const address = addr.toLowerCase()
|
|
|
|
return hash[address] || null
|
2016-07-07 02:58:46 +02:00
|
|
|
}
|