Skip to content

Commit

Permalink
feat(sdk): batch create actions + enforce method order
Browse files Browse the repository at this point in the history
someone shouldn't be able to call `txBuilder.withProposal().withApproval().withProposal()`, Typescript should stop them
  • Loading branch information
joeymeere committed Oct 18, 2024
1 parent a205ebb commit ec367d2
Show file tree
Hide file tree
Showing 7 changed files with 613 additions and 219 deletions.
106 changes: 106 additions & 0 deletions sdk/multisig/src/actions/actionTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
export type Methods<T extends keyof MethodProgression> = {
[K in keyof MethodProgression]: T extends K ? MethodProgression[K] : never;
}[keyof MethodProgression];

export type BatchMethods<T extends keyof BatchMethodProgression> = {
[K in keyof BatchMethodProgression]: T extends K
? BatchMethodProgression[K]
: never;
}[keyof BatchMethodProgression];

type BaseMethodKeys =
| "getInstructions"
| "transaction"
| "send"
| "sendAndConfirm"
| "customSend";

type BaseGetKeys = "getInstructions";
type BaseSendKeys = "send" | "sendAndConfirm" | "customSend";

type TransactionGetKeys =
| "getIndex"
| "getTransactionKey"
| "getProposalKey"
| "getTransactionAccount"
| "getProposalAccount";

type TransactionActionKeys =
| "withProposal"
| "withApproval"
| "withRejection"
| "withExecute";

type BatchGetKeys =
| "getBatchKey"
| "getBatchTransactionKey"
| "getAllBatchTransactionKeys"
| "getBatchAccount";

type BatchActionKeys = "addTransaction" | TransactionActionKeys;

type MethodProgression = {
// Senders
send: never;
sendAndConfirm: never;
customSend: never;
// Transaction Actions
withProposal:
| "withApproval"
| "withRejection"
| BaseSendKeys
| TransactionGetKeys;
withApproval:
| "withExecute"
| "withRejection"
| BaseSendKeys
| TransactionGetKeys;
withRejection:
| "withExecute"
| "withApproval"
| BaseSendKeys
| TransactionGetKeys;
withExecute: BaseSendKeys | TransactionGetKeys;
// Synchronous Getters
getInstructions: BaseMethodKeys | BaseSendKeys;
getIndex:
| BaseMethodKeys
| TransactionActionKeys
| TransactionGetKeys
| BatchActionKeys
| BatchGetKeys;
getTransactionKey:
| BaseMethodKeys
| TransactionActionKeys
| TransactionGetKeys
| BatchActionKeys
| BatchGetKeys;
getProposalKey:
| BaseMethodKeys
| TransactionActionKeys
| TransactionGetKeys
| BatchActionKeys
| BatchGetKeys;
// Asynchronous Getters
getTransactionAccount: never;
getProposalAccount: never;
};

type BatchMethodProgression = {
send: never;
sendAndConfirm: never;
customSend: never;
withProposal: "withApproval" | "withRejection" | BaseSendKeys;
withApproval: "withExecute" | "withRejection" | BaseSendKeys | BatchGetKeys;
withRejection: "withExecute" | "withApproval" | BaseSendKeys;
withExecute: BaseSendKeys;
getBatchKey:
| BaseMethodKeys
| TransactionActionKeys
| TransactionGetKeys
| BatchActionKeys
| BatchGetKeys;
getBatchTransactionKey: BatchActionKeys | BatchGetKeys;
getBatchAccount: never;
addTransaction: never;
};
Loading

0 comments on commit ec367d2

Please sign in to comment.