1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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;
}
}
|