From: Chris Duncan Date: Mon, 7 Oct 2024 19:19:11 +0000 (-0700) Subject: Get pending transactions and vote weight from account_info RPC when refreshing an... X-Git-Tag: v0.0.2~4 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=0108174335ac10076e7dd4abe8ae47d098f762bc;p=libnemo.git Get pending transactions and vote weight from account_info RPC when refreshing an Account. --- diff --git a/src/lib/account.ts b/src/lib/account.ts index b783d69..cf977ca 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -21,7 +21,9 @@ export class Account { #i?: number #f?: string #b?: bigint + #p?: bigint #r?: Account + #w?: bigint #s: Safe get address () { return `${PREFIX}${this.#a}` } @@ -30,10 +32,13 @@ export class Account { get index () { return this.#i } get frontier () { return this.#f } get balance () { return this.#b?.toString() } + get pending () { return this.#p?.toString() } get representative () { return this.#r } + get weight () { return this.#w?.toString() } set frontier (v) { this.#f = v } set balance (v) { this.#b = v ? BigInt(v) : undefined } + set pending (v) { this.#p = v ? BigInt(v) : undefined } set representative (v) { if (v?.constructor === Account) { this.#r = v @@ -43,6 +48,7 @@ export class Account { throw new TypeError(`Invalid argument for account representative: ${v}`) } } + set weight (v) { this.#w = v ? BigInt(v) : undefined } constructor (address: string, index?: number) { Account.validate(address) @@ -161,16 +167,20 @@ export class Account { throw new TypeError('RPC must be a valid node') } const data = { + "account": this.address, + "pending": "true", "representative": "true", - "account": this.address + "weight": "true" } - const { balance, frontier, representative } = await node.call('account_info', data) + const { balance, frontier, pending, representative, weight } = await node.call('account_info', data) if (frontier == null) { throw new Error('Account not found') } this.#b = BigInt(balance) this.#f = frontier + this.#p = BigInt(pending) this.#r = new Account(representative) + this.#w = BigInt(weight) } static #addressToKey (v: string): string {