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/unsigned_transaction.ts | |
| parent | 24076c5a32bbec3c77cc996cb74dd08d8077a7e0 (diff) | |
| parent | 40c1a1bda4b6f125c702f5a37ecc48a6ebec24b8 (diff) | |
Merge branch 'develop' into zano
Diffstat (limited to 'impls/monero.ts/src/unsigned_transaction.ts')
| -rw-r--r-- | impls/monero.ts/src/unsigned_transaction.ts | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/impls/monero.ts/src/unsigned_transaction.ts b/impls/monero.ts/src/unsigned_transaction.ts new file mode 100644 index 0000000..c5d8ed7 --- /dev/null +++ b/impls/monero.ts/src/unsigned_transaction.ts @@ -0,0 +1,79 @@ +import { fns } from "./bindings.ts"; +import { C_SEPARATOR, CString, maybeMultipleStrings, readCString } from "./utils.ts"; + +export type UnsignedTransactionPtr = Deno.PointerObject<"pendingTransaction">; + +export class UnsignedTransaction<MultDest extends boolean = false> { + #ptr: UnsignedTransactionPtr; + + #amount!: string | string[] | null; + #fee!: string | string[] | null; + #txCount!: bigint; + #paymentId!: string | null; + #recipientAddress!: string | string[] | null; + + constructor(ptr: UnsignedTransactionPtr) { + this.#ptr = ptr; + } + + async status(): Promise<number> { + return await fns.UnsignedTransaction_status(this.#ptr); + } + + async errorString(): Promise<string | null> { + return await readCString(await fns.UnsignedTransaction_errorString(this.#ptr)); + } + + static async new(ptr: UnsignedTransactionPtr): Promise<UnsignedTransaction> { + const instance = new UnsignedTransaction(ptr); + + const [amount, paymentId, fee, txCount, recipientAddress] = await Promise.all([ + fns.UnsignedTransaction_amount(ptr, C_SEPARATOR).then(readCString), + fns.UnsignedTransaction_paymentId(ptr, C_SEPARATOR).then(readCString), + fns.UnsignedTransaction_fee(ptr, C_SEPARATOR).then(readCString), + fns.UnsignedTransaction_txCount(ptr), + fns.UnsignedTransaction_recipientAddress(ptr, C_SEPARATOR).then(readCString), + ]); + + instance.#amount = maybeMultipleStrings(amount); + instance.#fee = maybeMultipleStrings(fee); + instance.#recipientAddress = maybeMultipleStrings(recipientAddress); + instance.#txCount = txCount; + instance.#paymentId = paymentId; + + return instance; + } + + get amount(): string | string[] | null { + return this.#amount; + } + + get fee(): string | string[] | null { + return this.#fee; + } + + get txCount(): bigint { + return this.#txCount; + } + + get paymentId(): string | null { + return this.#paymentId; + } + + get recipientAddress(): string | string[] | null { + return this.#recipientAddress; + } + + async sign(signedFileName: string): Promise<boolean> { + return await fns.UnsignedTransaction_sign(this.#ptr, CString(signedFileName)); + } + + async signUR(maxFragmentLength: number): Promise<string | null> { + const signUR = fns.UnsignedTransaction_signUR; + if (!signUR) return null; + + return await readCString( + await signUR(this.#ptr, maxFragmentLength), + ); + } +} |
