]> zoso.dev Git - libnemo.git/commitdiff
Get pending transactions and vote weight from account_info RPC when refreshing an...
authorChris Duncan <chris@zoso.dev>
Mon, 7 Oct 2024 19:19:11 +0000 (12:19 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 7 Oct 2024 19:19:11 +0000 (12:19 -0700)
src/lib/account.ts

index b783d69b957213bedaa15b4b9c61c867a21364a4..cf977ca591a3f5756598ab9725e73739d9d4ce55 100644 (file)
@@ -21,7 +21,9 @@ export class Account {
        #i?: number\r
        #f?: string\r
        #b?: bigint\r
+       #p?: bigint\r
        #r?: Account\r
+       #w?: bigint\r
        #s: Safe\r
 \r
        get address () { return `${PREFIX}${this.#a}` }\r
@@ -30,10 +32,13 @@ export class Account {
        get index () { return this.#i }\r
        get frontier () { return this.#f }\r
        get balance () { return this.#b?.toString() }\r
+       get pending () { return this.#p?.toString() }\r
        get representative () { return this.#r }\r
+       get weight () { return this.#w?.toString() }\r
 \r
        set frontier (v) { this.#f = v }\r
        set balance (v) { this.#b = v ? BigInt(v) : undefined }\r
+       set pending (v) { this.#p = v ? BigInt(v) : undefined }\r
        set representative (v) {\r
                if (v?.constructor === Account) {\r
                        this.#r = v\r
@@ -43,6 +48,7 @@ export class Account {
                        throw new TypeError(`Invalid argument for account representative: ${v}`)\r
                }\r
        }\r
+       set weight (v) { this.#w = v ? BigInt(v) : undefined }\r
 \r
        constructor (address: string, index?: number) {\r
                Account.validate(address)\r
@@ -161,16 +167,20 @@ export class Account {
                        throw new TypeError('RPC must be a valid node')\r
                }\r
                const data = {\r
+                       "account": this.address,\r
+                       "pending": "true",\r
                        "representative": "true",\r
-                       "account": this.address\r
+                       "weight": "true"\r
                }\r
-               const { balance, frontier, representative } = await node.call('account_info', data)\r
+               const { balance, frontier, pending, representative, weight } = await node.call('account_info', data)\r
                if (frontier == null) {\r
                        throw new Error('Account not found')\r
                }\r
                this.#b = BigInt(balance)\r
                this.#f = frontier\r
+               this.#p = BigInt(pending)\r
                this.#r = new Account(representative)\r
+               this.#w = BigInt(weight)\r
        }\r
 \r
        static #addressToKey (v: string): string {\r