Skip to content

Commit

Permalink
feat(monero.ts): support returning multiple values whenever necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Beast committed Nov 20, 2024
1 parent 0e888c1 commit 07ed34e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
9 changes: 7 additions & 2 deletions impls/monero.ts/src/pending_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,19 @@ export class PendingTransaction {
return await getSymbol("PendingTransaction_fee")(this.#pendingTxPtr);
}

async txid(separator: string, sanitize = true): Promise<string | null> {
async txid(separator: string, sanitize = true): Promise<string | string[] | null> {
const result = await getSymbol("PendingTransaction_txid")(
this.#pendingTxPtr,
CString(separator),
);
if (!result) return null;
await this.throwIfError(sanitize);
return await readCString(result) || null;

const txids = (await readCString(result))?.split(separator);

if (!txids) return null;
if (txids.length > 1) return txids;
return txids[0];
}

async txCount(): Promise<bigint> {
Expand Down
34 changes: 28 additions & 6 deletions impls/monero.ts/src/unsigned_transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,47 @@ export class UnsignedTransaction {
}
}

async amount(separator = ","): Promise<string | null> {
return readCString(await getSymbol("UnsignedTransaction_amount")(this.#unsignedTxPtr, CString(separator)));
async amount(separator = ","): Promise<string | string[] | null> {
const amounts = (await readCString(
await getSymbol("UnsignedTransaction_amount")(this.#unsignedTxPtr, CString(separator)),
))?.split(separator);

if (!amounts) return null;
if (amounts.length > 1) {
return amounts;
}
return amounts[0];
}

async fee(separator = ","): Promise<string | null> {
return readCString(await getSymbol("UnsignedTransaction_fee")(this.#unsignedTxPtr, CString(separator)));
async fee(separator = ","): Promise<string | string[] | null> {
const fees = (await readCString(
await getSymbol("UnsignedTransaction_fee")(this.#unsignedTxPtr, CString(separator)),
))?.split(separator);

if (!fees) return null;
if (fees.length > 1) {
return fees;
}
return fees[0];
}

async txCount(): Promise<bigint> {
return await getSymbol("UnsignedTransaction_txCount")(this.#unsignedTxPtr);
}

async recipientAddress(separator = ","): Promise<string | null> {
async recipientAddress(separator = ","): Promise<string | string[] | null> {
const result = await getSymbol("UnsignedTransaction_recipientAddress")(
this.#unsignedTxPtr,
CString(separator),
);
await this.throwIfError();
return await readCString(result);
const addresses = (await readCString(result))?.split(separator);

if (!addresses) return null;
if (addresses.length > 1) {
return addresses;
}
return addresses[0];
}

async sign(signedFileName: string): Promise<boolean> {
Expand Down

0 comments on commit 07ed34e

Please sign in to comment.