]> git.codecow.com Git - libnemo.git/commitdiff
Refactor db names as readonly getters.
authorChris Duncan <chris@zoso.dev>
Thu, 21 Aug 2025 19:58:41 +0000 (12:58 -0700)
committerChris Duncan <chris@zoso.dev>
Thu, 21 Aug 2025 19:58:41 +0000 (12:58 -0700)
src/lib/account.ts
src/lib/rolodex.ts
src/lib/wallet/index.ts

index bddbafa06e62c728b2bc7a0359d4d5a96ea6ac97..345ead0f04348d8e006c877a8952a67f2ba9559f 100644 (file)
@@ -15,6 +15,9 @@ import { Rpc } from './rpc'
 * be fetched from the network.\r
 */\r
 export class Account {\r
+       [key: string]: any\r
+       static get DB_NAME (): 'Account' { return 'Account' }\r
+\r
        static #isInternal: boolean = false\r
 \r
        #address: string\r
index 9be2e647e36ff558fc6de73b1579fa36cc0b77db..a3ce833e98707abc72329689eb04c9f052521a78 100644 (file)
@@ -11,7 +11,7 @@ import { verify } from './tools'
 * saved under one nickname.
 */
 export class Rolodex {
-       static #DB_NAME = 'Rolodex'
+       static get DB_NAME (): 'Rolodex' { return 'Rolodex' }
        /**
        * Adds an address to the rolodex under a specific nickname.
        *
@@ -72,7 +72,7 @@ export class Rolodex {
                                id: name,
                                addresses
                        }
-                       const results = await Database.put(data, Rolodex.#DB_NAME)
+                       const results = await Database.put(data, Rolodex.DB_NAME)
                        if (results.length !== Object.keys(data).length) {
                                throw new Error('Unexpected results from adding address', { cause: results })
                        }
@@ -100,11 +100,11 @@ export class Rolodex {
                                addresses
                        }
                }
-               const isUpdated = await Database.put(data, Rolodex.#DB_NAME)
+               const isUpdated = await Database.put(data, Rolodex.DB_NAME)
                if (!isUpdated) {
                        throw new Error('failed to remove address from existing name')
                }
-               const isDeleted = await Database.delete(address, Rolodex.#DB_NAME)
+               const isDeleted = await Database.delete(address, Rolodex.DB_NAME)
                return isDeleted
        }
 
@@ -117,7 +117,7 @@ export class Rolodex {
        static async deleteName (name: string): Promise<boolean> {
                const records = await this.getAddresses(name)
                records.push(name)
-               return await Database.delete(records, Rolodex.#DB_NAME)
+               return await Database.delete(records, Rolodex.DB_NAME)
        }
 
        /**
@@ -128,7 +128,7 @@ export class Rolodex {
        */
        static async getAddresses (name: string): Promise<string[]> {
                try {
-                       const records = await Database.get<NamedData<string[]>>(name, Rolodex.#DB_NAME)
+                       const records = await Database.get<NamedData<string[]>>(name, Rolodex.DB_NAME)
                        const record = records[name]
                        return record?.addresses
                                ? record.addresses.sort()
@@ -146,7 +146,7 @@ export class Rolodex {
        */
        static async getAllNames (): Promise<string[]> {
                try {
-                       const records = await Database.getAll<NamedData>(Rolodex.#DB_NAME)
+                       const records = await Database.getAll<NamedData>(Rolodex.DB_NAME)
                        return Object.keys(records).filter(v => v.slice(0, 5) !== 'nano_')
                } catch (err) {
                        console.error(err)
@@ -162,7 +162,7 @@ export class Rolodex {
        */
        static async getName (address: string): Promise<string | null> {
                try {
-                       const records = await Database.get<NamedData<string>>(address, Rolodex.#DB_NAME)
+                       const records = await Database.get<NamedData<string>>(address, Rolodex.DB_NAME)
                        const record = records[address]
                        return record?.name ?? null
                } catch (err) {
index c72aaf2820eb3a303f9b185edd72c31077c8bdf3..12b23e4a452fba9944539e7aaad69901ba3e60bc 100644 (file)
@@ -28,7 +28,7 @@ import { _verify } from './verify'
 * three types of wallets are supported: BIP-44, BLAKE2b, and Ledger.\r
 */\r
 export class Wallet {\r
-       static DB_NAME = 'Wallet'\r
+       static get DB_NAME (): 'Wallet' { return 'Wallet' }\r
 \r
        /**\r
        * Retrieves all encrypted wallets from the database.\r