Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update event listener names #439

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function deploy<
defaultSender?: string;
}): Promise<DeploymentResult<ContractNameT, IgnitionModuleResultsT>> {
if (executionEventListener !== undefined) {
executionEventListener.SET_MODULE_ID({
executionEventListener.setModuleId({
type: ExecutionEventType.SET_MODULE_ID,
moduleName: ignitionModule.id,
});
Expand All @@ -72,7 +72,7 @@ export async function deploy<

if (validationResult !== null) {
if (executionEventListener !== undefined) {
executionEventListener.DEPLOYMENT_COMPLETE({
executionEventListener.deploymentComplete({
type: ExecutionEventType.DEPLOYMENT_COMPLETE,
result: validationResult,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/internal/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class Deployer {
return;
}

this._executionEventListener.DEPLOYMENT_START({
this._executionEventListener.deploymentStart({
type: ExecutionEventType.DEPLOYMENT_START,
moduleName: moduleId,
});
Expand All @@ -255,7 +255,7 @@ export class Deployer {
return;
}

this._executionEventListener.BATCH_INITIALIZE({
this._executionEventListener.batchInitialize({
type: ExecutionEventType.BATCH_INITIALIZE,
batches,
});
Expand All @@ -268,7 +268,7 @@ export class Deployer {
return;
}

this._executionEventListener.DEPLOYMENT_COMPLETE({
this._executionEventListener.deploymentComplete({
type: ExecutionEventType.DEPLOYMENT_COMPLETE,
result,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/internal/execution/execution-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export class ExecutionEngine {
*/
private _emitBeginNextBatchEvent(): void {
if (this._executionEventListener !== undefined) {
this._executionEventListener.BEGIN_NEXT_BATCH({
this._executionEventListener.beginNextBatch({
type: ExecutionEventType.BEGIN_NEXT_BATCH,
});
}
Expand Down
62 changes: 21 additions & 41 deletions packages/core/src/internal/journal/utils/emitExecutionEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,106 +27,88 @@ export function emitExecutionEvent(
): void {
switch (message.type) {
case JournalMessageType.RUN_START: {
executionEventListener[ExecutionEventType.RUN_START]({
executionEventListener.runStart({
type: ExecutionEventType.RUN_START,
chainId: message.chainId,
});
break;
}
case JournalMessageType.WIPE_EXECUTION_STATE: {
executionEventListener[ExecutionEventType.WIPE_EXECUTION_STATE]({
executionEventListener.wipeExecutionState({
type: ExecutionEventType.WIPE_EXECUTION_STATE,
futureId: message.futureId,
});
break;
}
case JournalMessageType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE: {
executionEventListener[
ExecutionEventType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE
]({
executionEventListener.deploymentExecutionStateInitialize({
type: ExecutionEventType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE,
futureId: message.futureId,
});
break;
}
case JournalMessageType.DEPLOYMENT_EXECUTION_STATE_COMPLETE: {
executionEventListener[
ExecutionEventType.DEPLOYMENT_EXECUTION_STATE_COMPLETE
]({
executionEventListener.deploymentExecutionStateComplete({
type: ExecutionEventType.DEPLOYMENT_EXECUTION_STATE_COMPLETE,
futureId: message.futureId,
result: convertExecutionResultToEventResult(message.result),
});
break;
}
case JournalMessageType.CALL_EXECUTION_STATE_INITIALIZE: {
executionEventListener[
ExecutionEventType.CALL_EXECUTION_STATE_INITIALIZE
]({
executionEventListener.callExecutionStateInitialize({
type: ExecutionEventType.CALL_EXECUTION_STATE_INITIALIZE,
futureId: message.futureId,
});
break;
}
case JournalMessageType.CALL_EXECUTION_STATE_COMPLETE: {
executionEventListener[ExecutionEventType.CALL_EXECUTION_STATE_COMPLETE]({
executionEventListener.callExecutionStateComplete({
type: ExecutionEventType.CALL_EXECUTION_STATE_COMPLETE,
futureId: message.futureId,
result: convertExecutionResultToEventResult(message.result),
});
break;
}
case JournalMessageType.STATIC_CALL_EXECUTION_STATE_INITIALIZE: {
executionEventListener[
ExecutionEventType.STATIC_CALL_EXECUTION_STATE_INITIALIZE
]({
executionEventListener.staticCallExecutionStateInitialize({
type: ExecutionEventType.STATIC_CALL_EXECUTION_STATE_INITIALIZE,
futureId: message.futureId,
});
break;
}
case JournalMessageType.STATIC_CALL_EXECUTION_STATE_COMPLETE: {
executionEventListener[
ExecutionEventType.STATIC_CALL_EXECUTION_STATE_COMPLETE
]({
executionEventListener.staticCallExecutionStateComplete({
type: ExecutionEventType.STATIC_CALL_EXECUTION_STATE_COMPLETE,
futureId: message.futureId,
result: convertStaticCallResultToExecutionEventResult(message.result),
});
break;
}
case JournalMessageType.SEND_DATA_EXECUTION_STATE_INITIALIZE: {
executionEventListener[
ExecutionEventType.SEND_DATA_EXECUTION_STATE_INITIALIZE
]({
executionEventListener.sendDataExecutionStateInitialize({
type: ExecutionEventType.SEND_DATA_EXECUTION_STATE_INITIALIZE,
futureId: message.futureId,
});
break;
}
case JournalMessageType.SEND_DATA_EXECUTION_STATE_COMPLETE: {
executionEventListener[
ExecutionEventType.STATIC_CALL_EXECUTION_STATE_COMPLETE
]({
type: ExecutionEventType.STATIC_CALL_EXECUTION_STATE_COMPLETE,
executionEventListener.sendDataExecutionStateComplete({
type: ExecutionEventType.SEND_DATA_EXECUTION_STATE_COMPLETE,
futureId: message.futureId,
result: convertExecutionResultToEventResult(message.result),
});
break;
}
case JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE: {
executionEventListener[
ExecutionEventType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE
]({
executionEventListener.contractAtExecutionStateInitialize({
type: ExecutionEventType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE,
futureId: message.futureId,
});
break;
}
case JournalMessageType.READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE: {
executionEventListener[
ExecutionEventType.READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE
]({
executionEventListener.readEventArgumentExecutionStateInitialize({
type: ExecutionEventType.READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE,
futureId: message.futureId,
result: {
Expand All @@ -137,7 +119,7 @@ export function emitExecutionEvent(
break;
}
case JournalMessageType.NETWORK_INTERACTION_REQUEST: {
executionEventListener[ExecutionEventType.NETWORK_INTERACTION_REQUEST]({
executionEventListener.networkInteractionRequest({
type: ExecutionEventType.NETWORK_INTERACTION_REQUEST,
networkInteractionType:
message.networkInteraction.type ===
Expand All @@ -149,53 +131,51 @@ export function emitExecutionEvent(
break;
}
case JournalMessageType.TRANSACTION_SEND: {
executionEventListener[ExecutionEventType.TRANSACTION_SEND]({
executionEventListener.transactionSend({
type: ExecutionEventType.TRANSACTION_SEND,
futureId: message.futureId,
hash: message.transaction.hash,
});
break;
}
case JournalMessageType.TRANSACTION_CONFIRM: {
executionEventListener[ExecutionEventType.TRANSACTION_CONFIRM]({
executionEventListener.transactionConfirm({
type: ExecutionEventType.TRANSACTION_CONFIRM,
futureId: message.futureId,
hash: message.hash,
});
break;
}
case JournalMessageType.STATIC_CALL_COMPLETE: {
executionEventListener[ExecutionEventType.STATIC_CALL_COMPLETE]({
executionEventListener.staticCallComplete({
type: ExecutionEventType.STATIC_CALL_COMPLETE,
futureId: message.futureId,
});
break;
}
case JournalMessageType.ONCHAIN_INTERACTION_BUMP_FEES: {
executionEventListener[ExecutionEventType.ONCHAIN_INTERACTION_BUMP_FEES]({
executionEventListener.onchainInteractionBumpFees({
type: ExecutionEventType.ONCHAIN_INTERACTION_BUMP_FEES,
futureId: message.futureId,
});
break;
}
case JournalMessageType.ONCHAIN_INTERACTION_DROPPED: {
executionEventListener[ExecutionEventType.ONCHAIN_INTERACTION_DROPPED]({
executionEventListener.onchainInteractionDropped({
type: ExecutionEventType.ONCHAIN_INTERACTION_DROPPED,
futureId: message.futureId,
});
break;
}
case JournalMessageType.ONCHAIN_INTERACTION_REPLACED_BY_USER: {
executionEventListener[
ExecutionEventType.ONCHAIN_INTERACTION_REPLACED_BY_USER
]({
executionEventListener.onchainInteractionReplacedByUser({
type: ExecutionEventType.ONCHAIN_INTERACTION_REPLACED_BY_USER,
futureId: message.futureId,
});
break;
}
case JournalMessageType.ONCHAIN_INTERACTION_TIMEOUT: {
executionEventListener[ExecutionEventType.ONCHAIN_INTERACTION_TIMEOUT]({
executionEventListener.onchainInteractionTimeout({
type: ExecutionEventType.ONCHAIN_INTERACTION_TIMEOUT,
futureId: message.futureId,
});
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/types/execution-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,23 @@ export interface ExecutionEventTypeMap {
[ExecutionEventType.SET_MODULE_ID]: SetModuleIdEvent;
}

/**
* A utility type for mapping enum values to function names
*
* @beta
*/
export type SnakeToCamelCase<S extends string> =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy with this being in the public API, as opposed to the mapping type it replaced.

S extends `${infer T}_${infer U}`
? `${Lowercase<T>}${Capitalize<SnakeToCamelCase<Lowercase<U>>>}`
: S;

/**
* A listener for execution events.
*
* @beta
*/
export type ExecutionEventListener = {
[eventType in ExecutionEventType]: (
[eventType in ExecutionEventType as SnakeToCamelCase<eventType>]: (
event: ExecutionEventTypeMap[eventType]
) => void;
};
Loading
Loading