Skip to content

Commit

Permalink
feat: map held as its own result type
Browse files Browse the repository at this point in the history
Instead of treating held as an error result, treat it as its own third
thing between success and failure.
  • Loading branch information
kanej committed Sep 12, 2023
1 parent 331c80e commit 5891fe5
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 45 deletions.
10 changes: 6 additions & 4 deletions packages/core/src/internal/journal/utils/emitExecutionEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ function convertExecutionResultToEventResult(
}
case ExecutionResultType.STRATEGY_HELD: {
return {
type: ExecutionEventResultType.ERROR,
error: result.reason,
type: ExecutionEventResultType.HELD,
heldId: result.heldId,
reason: result.reason,
};
}
}
Expand Down Expand Up @@ -249,8 +250,9 @@ function convertStaticCallResultToExecutionEventResult(
}
case ExecutionResultType.STRATEGY_HELD: {
return {
type: ExecutionEventResultType.ERROR,
error: result.reason,
type: ExecutionEventResultType.HELD,
heldId: result.heldId,
reason: result.reason,
};
}
}
Expand Down
17 changes: 16 additions & 1 deletion packages/core/src/types/execution-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,18 @@ export enum ExecutionEventNetworkInteractionType {
export enum ExecutionEventResultType {
SUCCESS = "SUCCESS",
ERROR = "ERROR",
HELD = "HELD",
}

/**
* The result of a future's completed execution.
*
* @beta
*/
export type ExecutionEventResult = ExecutionEventSuccess | ExecutionEventError;
export type ExecutionEventResult =
| ExecutionEventSuccess
| ExecutionEventError
| ExecutionEventHeld;

/**
* A successful result of a future's execution.
Expand All @@ -389,6 +393,17 @@ export interface ExecutionEventError {
error: string;
}

/**
* A hold result of a future's execution.
*
* @beta
*/
export interface ExecutionEventHeld {
type: ExecutionEventResultType.HELD;
heldId: number;
reason: string;
}

/**
* A mapping of execution event types to their corresponding event.
*
Expand Down
10 changes: 9 additions & 1 deletion packages/hardhat-plugin/src/ui/UiEventHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
UiBatches,
UiFuture,
UiFutureErrored,
UiFutureHeld,
UiFutureStatusType,
UiFutureSuccess,
UiState,
Expand Down Expand Up @@ -396,7 +397,7 @@ export class UiEventHandler implements ExecutionEventListener {

private _getFutureStatusFromEventResult(
result: ExecutionEventResult
): UiFutureSuccess | UiFutureErrored {
): UiFutureSuccess | UiFutureErrored | UiFutureHeld {
switch (result.type) {
case ExecutionEventResultType.SUCCESS: {
return {
Expand All @@ -410,6 +411,13 @@ export class UiEventHandler implements ExecutionEventListener {
message: result.error,
};
}
case ExecutionEventResultType.HELD: {
return {
type: UiFutureStatusType.HELD,
heldId: result.heldId,
reason: result.reason,
};
}
}
}

Expand Down
108 changes: 70 additions & 38 deletions packages/hardhat-plugin/src/ui/VerboseEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,24 @@ export class VerboseEventHandler implements ExecutionEventListener {
public deploymentExecutionStateComplete(
event: DeploymentExecutionStateCompleteEvent
): void {
if (event.result.type === ExecutionEventResultType.SUCCESS) {
console.log(
`Successfully completed the execution of deployment future ${
event.futureId
} with address ${event.result.result ?? "undefined"}`
);
} else {
console.log(
`Execution of future ${event.futureId} failed with reason: ${event.result.error}`
);
switch (event.result.type) {
case ExecutionEventResultType.SUCCESS: {
return console.log(
`Successfully completed the execution of deployment future ${
event.futureId
} with address ${event.result.result ?? "undefined"}`
);
}
case ExecutionEventResultType.ERROR: {
return console.log(
`Execution of future ${event.futureId} failed with reason: ${event.result.error}`
);
}
case ExecutionEventResultType.HELD: {
return console.log(
`Execution of future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}`
);
}
}
}

Expand All @@ -69,14 +77,22 @@ export class VerboseEventHandler implements ExecutionEventListener {
public callExecutionStateComplete(
event: CallExecutionStateCompleteEvent
): void {
if (event.result.type === ExecutionEventResultType.SUCCESS) {
console.log(
`Successfully completed the execution of call future ${event.futureId}`
);
} else {
console.log(
`Execution of future ${event.futureId} failed with reason: ${event.result.error}`
);
switch (event.result.type) {
case ExecutionEventResultType.SUCCESS: {
return console.log(
`Successfully completed the execution of call future ${event.futureId}`
);
}
case ExecutionEventResultType.ERROR: {
return console.log(
`Execution of call future ${event.futureId} failed with reason: ${event.result.error}`
);
}
case ExecutionEventResultType.HELD: {
return console.log(
`Execution of call future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}`
);
}
}
}

Expand All @@ -89,16 +105,24 @@ export class VerboseEventHandler implements ExecutionEventListener {
public staticCallExecutionStateComplete(
event: StaticCallExecutionStateCompleteEvent
): void {
if (event.result.type === ExecutionEventResultType.SUCCESS) {
console.log(
`Successfully completed the execution of static call future ${
event.futureId
} with result ${event.result.result ?? "undefined"}`
);
} else {
console.log(
`Execution of future ${event.futureId} failed with reason: ${event.result.error}`
);
switch (event.result.type) {
case ExecutionEventResultType.SUCCESS: {
return console.log(
`Successfully completed the execution of static call future ${
event.futureId
} with result ${event.result.result ?? "undefined"}`
);
}
case ExecutionEventResultType.ERROR: {
return console.log(
`Execution of static call future ${event.futureId} failed with reason: ${event.result.error}`
);
}
case ExecutionEventResultType.HELD: {
return console.log(
`Execution of static call future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}`
);
}
}
}

Expand All @@ -111,16 +135,24 @@ export class VerboseEventHandler implements ExecutionEventListener {
public sendDataExecutionStateComplete(
event: SendDataExecutionStateCompleteEvent
): void {
if (event.result.type === ExecutionEventResultType.SUCCESS) {
console.log(
`Successfully completed the execution of send data future ${
event.futureId
} in tx ${event.result.result ?? "undefined"}`
);
} else {
console.log(
`Execution of future ${event.futureId} failed with reason: ${event.result.error}`
);
switch (event.result.type) {
case ExecutionEventResultType.SUCCESS: {
return console.log(
`Successfully completed the execution of send data future ${
event.futureId
} in tx ${event.result.result ?? "undefined"}`
);
}
case ExecutionEventResultType.ERROR: {
return console.log(
`Execution of future ${event.futureId} failed with reason: ${event.result.error}`
);
}
case ExecutionEventResultType.HELD: {
return console.log(
`Execution of send future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}`
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ const StatusBadge = ({ future }: { future: UiFuture }) => {
case UiFutureStatusType.ERRORED:
badge = <Text></Text>;
break;
case UiFutureStatusType.HELD:
badge = <Text>🔶</Text>;
break;
}

return (
Expand Down Expand Up @@ -139,6 +142,12 @@ function resolveFutureColors(future: UiFuture): {
borderStyle: "bold",
textColor: "white",
};
case UiFutureStatusType.HELD:
return {
borderColor: "yellow",
borderStyle: "bold",
textColor: "white",
};
}
}

Expand Down
10 changes: 9 additions & 1 deletion packages/hardhat-plugin/src/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum UiFutureStatusType {
SUCCESS = "SUCCESS",
PENDING = "PENDING",
ERRORED = "ERRORED",
HELD = "HELD",
}

export enum UiStateDeploymentStatus {
Expand All @@ -31,11 +32,18 @@ export interface UiFutureErrored {
message: string;
}

export interface UiFutureHeld {
type: UiFutureStatusType.HELD;
heldId: number;
reason: string;
}

export type UiFutureStatus =
| UiFutureUnstarted
| UiFutureSuccess
| UiFuturePending
| UiFutureErrored;
| UiFutureErrored
| UiFutureHeld;

export interface UiFuture {
status: UiFutureStatus;
Expand Down

0 comments on commit 5891fe5

Please sign in to comment.