summaryrefslogtreecommitdiff
path: root/impls/monero.ts/src/coins.ts
diff options
context:
space:
mode:
authorCzarek Nakamoto <cyjan@mrcyjanek.net>2025-01-05 13:17:22 +0100
committerCzarek Nakamoto <cyjan@mrcyjanek.net>2025-01-05 13:17:22 +0100
commit085d74b37b478be77bc873d66876247a751aa957 (patch)
treed8434dd9c8c57df9b64ae93059d9ebb5a16b90f2 /impls/monero.ts/src/coins.ts
parent8e7bc59509c40f00702ba568a0adcb3cf82e6e05 (diff)
parentc3dd64bdee37d361a2c1252d127fb575936e43e6 (diff)
Merge remote-tracking branch 'origin/develop' into rust-develop
Diffstat (limited to 'impls/monero.ts/src/coins.ts')
-rw-r--r--impls/monero.ts/src/coins.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/impls/monero.ts/src/coins.ts b/impls/monero.ts/src/coins.ts
new file mode 100644
index 0000000..45a222f
--- /dev/null
+++ b/impls/monero.ts/src/coins.ts
@@ -0,0 +1,53 @@
+import { CoinsInfo, type CoinsInfoPtr } from "./coins_info.ts";
+import { fns } from "./bindings.ts";
+
+export type CoinsPtr = Deno.PointerObject<"coins">;
+
+export class Coins {
+ #ptr: CoinsPtr;
+
+ #coins: CoinsInfo[] = [];
+
+ constructor(ptr: CoinsPtr) {
+ this.#ptr = ptr;
+ }
+
+ async count(): Promise<number> {
+ return await fns.Coins_count(this.#ptr);
+ }
+
+ async coin(index: number): Promise<CoinsInfo | null> {
+ if (this.#coins[index]) {
+ return this.#coins[index];
+ }
+
+ const coinPtr = await fns.Coins_coin(this.#ptr, index);
+ if (!coinPtr) return null;
+
+ return CoinsInfo.new(coinPtr as CoinsInfoPtr);
+ }
+
+ async setFrozen(index: number) {
+ return await fns.Coins_setFrozen(this.#ptr, index);
+ }
+
+ async thaw(index: number) {
+ return await fns.Coins_thaw(this.#ptr, index);
+ }
+
+ async getAllSize(): Promise<number> {
+ return await fns.Coins_getAll_size(this.#ptr);
+ }
+
+ async getAllByIndex(index: number): Promise<unknown> {
+ return await fns.Coins_getAll_byIndex(this.#ptr, index);
+ }
+
+ async refresh(): Promise<void> {
+ await fns.Coins_refresh(this.#ptr);
+
+ for (const coin of this.#coins) {
+ coin.refresh();
+ }
+ }
+}