-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): batch create actions + enforce method order
someone shouldn't be able to call `txBuilder.withProposal().withApproval().withProposal()`, Typescript should stop them
- Loading branch information
Showing
7 changed files
with
613 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
Oops, something went wrong.