-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
display better error messages for insufficient funds
- Loading branch information
Showing
7 changed files
with
530 additions
and
62 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
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
52 changes: 52 additions & 0 deletions
52
packages/core/src/internal/execution/future-processor/helpers/decode-simulation-result.ts
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,52 @@ | ||
import { assertIgnitionInvariant } from "../../../utils/assertions"; | ||
import { | ||
ExecutionResultType, | ||
SimulationErrorExecutionResult, | ||
StrategySimulationErrorExecutionResult, | ||
} from "../../types/execution-result"; | ||
import { | ||
CallExecutionState, | ||
DeploymentExecutionState, | ||
SendDataExecutionState, | ||
} from "../../types/execution-state"; | ||
import { | ||
CallStrategyGenerator, | ||
DeploymentStrategyGenerator, | ||
OnchainInteractionResponseType, | ||
SIMULATION_SUCCESS_SIGNAL_TYPE, | ||
} from "../../types/execution-strategy"; | ||
import { RawStaticCallResult } from "../../types/jsonrpc"; | ||
|
||
export function decodeSimulationResult( | ||
strategyGenerator: DeploymentStrategyGenerator | CallStrategyGenerator, | ||
exState: | ||
| DeploymentExecutionState | ||
| CallExecutionState | ||
| SendDataExecutionState | ||
) { | ||
return async ( | ||
simulationResult: RawStaticCallResult | ||
): Promise< | ||
| SimulationErrorExecutionResult | ||
| StrategySimulationErrorExecutionResult | ||
| undefined | ||
> => { | ||
const response = await strategyGenerator.next({ | ||
type: OnchainInteractionResponseType.SIMULATION_RESULT, | ||
result: simulationResult, | ||
}); | ||
|
||
assertIgnitionInvariant( | ||
response.value.type === SIMULATION_SUCCESS_SIGNAL_TYPE || | ||
response.value.type === ExecutionResultType.STRATEGY_SIMULATION_ERROR || | ||
response.value.type === ExecutionResultType.SIMULATION_ERROR, | ||
`Invalid response received from strategy after a simulation was run before sending a transaction for ExecutionState ${exState.id}` | ||
); | ||
|
||
if (response.value.type === SIMULATION_SUCCESS_SIGNAL_TYPE) { | ||
return undefined; | ||
} | ||
|
||
return response.value; | ||
}; | ||
} |
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
Oops, something went wrong.