diff options
| author | Czarek Nakamoto <cyjan@mrcyjanek.net> | 2025-01-05 13:17:22 +0100 |
|---|---|---|
| committer | Czarek Nakamoto <cyjan@mrcyjanek.net> | 2025-01-05 13:17:22 +0100 |
| commit | 085d74b37b478be77bc873d66876247a751aa957 (patch) | |
| tree | d8434dd9c8c57df9b64ae93059d9ebb5a16b90f2 /impls/monero.ts/src/coins_info.ts | |
| parent | 8e7bc59509c40f00702ba568a0adcb3cf82e6e05 (diff) | |
| parent | c3dd64bdee37d361a2c1252d127fb575936e43e6 (diff) | |
Merge remote-tracking branch 'origin/develop' into rust-develop
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; + } +} |
