Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #303 from PureStake/jan/groups-of-groups
Browse files Browse the repository at this point in the history
Support nested array of Grouped Transactions
  • Loading branch information
PureBrent authored Oct 1, 2021
2 parents 09b55b4 + cc7c86a commit 3a15ec3
Show file tree
Hide file tree
Showing 8 changed files with 502 additions and 263 deletions.
1 change: 1 addition & 0 deletions packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum RequestErrors {
InvalidTransactionParams = '[RequestErrors.InvalidTransactionParams] Invalid transaction parameters.',
UnsupportedAlgod = '[RequestErrors.UnsupportedAlgod] The provided method is not supported.',
UnsupportedLedger = '[RequestErrors.UnsupportedLedger] The provided ledger is not supported.',
InvalidFormat = '[RequestErrors.InvalidFormat] Please provide an array of either valid transaction objects or nested arrays of valid transaction objects.',
Undefined = '[RequestErrors.Undefined] An undefined error occurred.',
}

Expand Down
30 changes: 17 additions & 13 deletions packages/dapp/src/fn/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,33 @@ export class Task extends Runtime implements ITask {
}

/**
* @param transactions array of valid wallet transaction objects
* @returns array of signed transactions
* @param transactionsOrGroups array or nested array of grouped transaction objects
* @returns array or nested array of signed transactions
*/
signTxn(
transactions: Array<WalletTransaction>,
transactionsOrGroups: Array<WalletTransaction>,
error: RequestErrors = RequestErrors.None
): Promise<JsonPayload> {
const formatError = new Error(
'There was a problem with the transaction(s) recieved. Please provide an array of valid transaction objects.'
);
if (!Array.isArray(transactions) || !transactions.length) throw formatError;
transactions.forEach((walletTx) => {
const formatError = new Error(RequestErrors.InvalidFormat);
// We check for empty arrays
if (!Array.isArray(transactionsOrGroups) || !transactionsOrGroups.length) throw formatError;
transactionsOrGroups.forEach((txOrGroup) => {
// We check for no null values and no empty nested arrays
if (
walletTx === null ||
typeof walletTx !== 'object' ||
walletTx.txn === null ||
!walletTx.txn.length
txOrGroup === null ||
txOrGroup === undefined ||
(!Array.isArray(txOrGroup) && typeof txOrGroup === 'object' &&
(!txOrGroup.txn || (txOrGroup.txn && !txOrGroup.txn.length))
) ||
(Array.isArray(txOrGroup) &&
(!txOrGroup.length || (txOrGroup.length && !txOrGroup.every((tx) => tx !== null)))
)
)
throw formatError;
});

const params = {
transactions: transactions,
transactionsOrGroups: transactionsOrGroups,
};
return MessageBuilder.promise(JsonRpcMethod.SignWalletTransaction, params, error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export class InternalMethods {
);
return true;
}

public static [JsonRpcMethod.LedgerGetSessionTxn](request: any, sendResponse: Function) {
if (session.txnWrap && 'body' in session.txnWrap) {
// The transaction may contain source and JSONRPC info, the body.params will be the transaction validation object
Expand Down Expand Up @@ -455,6 +456,7 @@ export class InternalMethods {
});
return true;
}

public static [JsonRpcMethod.AccountDetails](request: any, sendResponse: Function) {
const { ledger, address } = request.body.params;
const algod = this.getAlgod(ledger);
Expand Down Expand Up @@ -935,6 +937,7 @@ export class InternalMethods {
sendResponse({ error: e.message });
}
}

public static [JsonRpcMethod.GetLedgers](request: any, sendResponse: Function) {
getAvailableLedgersExt((availableLedgers) => {
sendResponse(availableLedgers);
Expand Down
Loading

0 comments on commit 3a15ec3

Please sign in to comment.