return true
}
const data: NamedData = {
- [address]: utf8.toBuffer(name)
+ [address]: {
+ id: address,
+ name
+ }
}
if (existingName != null) {
- const existingAddresses = await this.getAddresses(existingName)
- data[existingName] = existingAddresses.filter(a => a !== address).sort()
+ const addresses = (await this.getAddresses(existingName))
+ .filter(a => a !== address)
+ .sort()
+ data[existingName] = {
+ id: existingName,
+ addresses
+ }
+ }
+ const addresses = await this.getAddresses(name)
+ addresses.push(account.address)
+ data[name] = {
+ id: name,
+ addresses
}
- const existingAddresses = await this.getAddresses(name)
- existingAddresses.push(account.address)
- data[name] = existingAddresses
const results = await Database.put(data, this.#DB_NAME)
if (results.length !== Object.keys(data).length) {
throw new Error('Unexpected results from adding address', { cause: results })
}
const addresses = (await this.getAddresses(name)).filter(a => a !== address).sort()
const data = {
- [name]: addresses
+ [name]: {
+ id: name,
+ addresses
+ }
}
const isUpdated = await Database.put(data, this.#DB_NAME)
if (!isUpdated) {
* @returns {Promise<boolean>} Promise for true if name and related addresses successfully removed, else false
*/
static async deleteName (name: string): Promise<boolean> {
- const data = await this.getAddresses(name)
- data.push(name)
- return await Database.delete(data, this.#DB_NAME)
+ const records = await this.getAddresses(name)
+ records.push(name)
+ return await Database.delete(records, this.#DB_NAME)
}
/**
*/
static async getAddresses (name: string): Promise<string[]> {
try {
- const response = await Database.get<string[]>(name, this.#DB_NAME)
- const addresses = response[name]
- return addresses
- ? addresses.sort()
+ const records = await Database.get<NamedData<string[]>>(name, this.#DB_NAME)
+ const record = records[name]
+ return record?.addresses
+ ? record.addresses.sort()
: []
} catch (err) {
console.error(err)
*/
static async getAllNames (): Promise<string[]> {
try {
- const response = await Database.getAll(this.#DB_NAME)
- return Object.keys(response).filter(v => v.slice(0, 5) !== 'nano_')
+ const records = await Database.getAll<NamedData>(this.#DB_NAME)
+ return Object.keys(records).filter(v => v.slice(0, 5) !== 'nano_')
} catch (err) {
console.error(err)
return []
*/
static async getName (address: string): Promise<string | null> {
try {
- const response = await Database.get<string>(address, this.#DB_NAME)
- const name = response[address]
- return name
+ const records = await Database.get<NamedData<string>>(address, this.#DB_NAME)
+ const record = records[address]
+ return record?.name ?? null
} catch (err) {
console.error(err)
return null