diff options
| author | Czarek Nakamoto <cyjan@mrcyjanek.net> | 2024-12-04 12:26:45 -0500 |
|---|---|---|
| committer | Czarek Nakamoto <cyjan@mrcyjanek.net> | 2024-12-04 12:26:45 -0500 |
| commit | ecc31787c2174a829848aac403bd13e663fe33c3 (patch) | |
| tree | 7f505dc9bfe9c34c36c5043911be0cfc0d146a8d /impls/monero.ts/src/coins_info.ts | |
| parent | 24076c5a32bbec3c77cc996cb74dd08d8077a7e0 (diff) | |
| parent | 40c1a1bda4b6f125c702f5a37ecc48a6ebec24b8 (diff) | |
Merge branch 'develop' into zano
Diffstat (limited to 'impls/monero.ts/src/coins_info.ts')
| -rw-r--r-- | impls/monero.ts/src/coins_info.ts | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/impls/monero.ts/src/coins_info.ts b/impls/monero.ts/src/coins_info.ts new file mode 100644 index 0000000..7ea18aa --- /dev/null +++ b/impls/monero.ts/src/coins_info.ts @@ -0,0 +1,85 @@ +import { fns } from "./bindings.ts"; +import { readCString } from "./utils.ts"; + +export type CoinsInfoPtr = Deno.PointerObject<"coinsInfo">; + +export class CoinsInfo { + #ptr: CoinsInfoPtr; + + #hash!: string | null; + #keyImage!: string | null; + #blockHeight!: bigint; + #amount!: bigint; + #spent!: boolean; + #spentHeight!: bigint; + #frozen!: boolean; + #unlocked!: boolean; + + constructor(ptr: CoinsInfoPtr) { + this.#ptr = ptr; + } + + getPointer(): CoinsInfoPtr { + return this.#ptr; + } + + static async new(ptr: CoinsInfoPtr): Promise<CoinsInfo> { + const instance = new CoinsInfo(ptr); + await instance.refresh(); + return instance; + } + + async refresh() { + const [hash, keyImage, blockHeight, amount, spent, spentHeight, frozen, unlocked] = await Promise.all([ + fns.CoinsInfo_hash(this.#ptr).then(readCString), + fns.CoinsInfo_keyImage(this.#ptr).then(readCString), + fns.CoinsInfo_blockHeight(this.#ptr), + fns.CoinsInfo_amount(this.#ptr), + fns.CoinsInfo_spent(this.#ptr), + fns.CoinsInfo_spentHeight(this.#ptr), + fns.CoinsInfo_frozen(this.#ptr), + fns.CoinsInfo_unlocked(this.#ptr), + ]); + + this.#hash = hash; + this.#keyImage = keyImage; + this.#blockHeight = blockHeight; + this.#amount = amount; + this.#spent = spent; + this.#spentHeight = spentHeight; + this.#frozen = frozen; + this.#unlocked = unlocked; + } + + get hash(): string | null { + return this.#hash; + } + + get keyImage(): string | null { + return this.#keyImage; + } + + get blockHeight(): bigint { + return this.#blockHeight; + } + + get amount(): bigint { + return this.#amount; + } + + get spent(): boolean { + return this.#spent; + } + + get spentHeight(): bigint { + return this.#spentHeight; + } + + get frozen(): boolean { + return this.#frozen; + } + + get unlocked(): boolean { + return this.#unlocked; + } +} |
