From 123df69d12ab33a3ad0ed2bc65e26d3e24756b66 Mon Sep 17 00:00:00 2001 From: zoeyTM Date: Tue, 25 Jul 2023 03:08:31 -0400 Subject: [PATCH] remove isAdapters and move types/journals to internal Fixes #315 --- .../core/src/new-api/internal/deployer.ts | 2 +- .../ephemeral-deployment-loader.ts | 2 +- .../file-deployment-loader.ts | 2 +- .../internal/execution/execution-engine.ts | 18 ++++----- .../execution/execution-state-reducer.ts | 2 +- .../execution/execution-strategy-cycler.ts | 7 ++-- .../internal/execution/execution-strategy.ts | 38 +++++++++---------- .../src/new-api/internal/execution/guards.ts | 2 +- .../execution/onchain-action-reducer.ts | 2 +- .../execution/onchain-state-transitions.ts | 2 +- .../new-api/internal/journal/file-journal.ts | 2 +- .../internal/journal/memory-journal.ts | 2 +- .../new-api/internal/journal/type-guards.ts | 6 +-- .../src/new-api/internal/journal/utils/log.ts | 2 +- .../internal/types/execution-engine.ts | 10 ++--- .../new-api/internal/types/execution-state.ts | 3 +- .../new-api/{ => internal}/types/journal.ts | 6 ++- packages/core/src/new-api/internal/wiper.ts | 2 +- packages/core/src/new-api/type-guards.ts | 17 --------- .../src/new-api/types/deployment-loader.ts | 3 +- packages/core/test/new-api/helpers.ts | 5 ++- packages/core/test/new-api/wipe.ts | 2 +- 22 files changed, 64 insertions(+), 73 deletions(-) rename packages/core/src/new-api/{ => internal}/types/journal.ts (99%) diff --git a/packages/core/src/new-api/internal/deployer.ts b/packages/core/src/new-api/internal/deployer.ts index 4dcc049f5c..dda1e05361 100644 --- a/packages/core/src/new-api/internal/deployer.ts +++ b/packages/core/src/new-api/internal/deployer.ts @@ -18,7 +18,6 @@ import { import { Artifact, ArtifactResolver } from "../types/artifact"; import { DeployConfig, DeploymentResult } from "../types/deployer"; import { DeploymentLoader } from "../types/deployment-loader"; -import { Journal } from "../types/journal"; import { Batcher } from "./batcher"; import { ExecutionEngine } from "./execution/execution-engine"; @@ -36,6 +35,7 @@ import { DeploymentExecutionState, ExecutionStateMap, } from "./types/execution-state"; +import { Journal } from "./types/journal"; import { TransactionLookupTimer } from "./types/transaction-timer"; import { assertIgnitionInvariant } from "./utils/assertions"; import { getFuturesFromModule } from "./utils/get-futures-from-module"; diff --git a/packages/core/src/new-api/internal/deployment-loader/ephemeral-deployment-loader.ts b/packages/core/src/new-api/internal/deployment-loader/ephemeral-deployment-loader.ts index 856384e4ab..49e59eff60 100644 --- a/packages/core/src/new-api/internal/deployment-loader/ephemeral-deployment-loader.ts +++ b/packages/core/src/new-api/internal/deployment-loader/ephemeral-deployment-loader.ts @@ -1,7 +1,7 @@ import { Artifact, ArtifactResolver, BuildInfo } from "../../types/artifact"; import { DeploymentLoader } from "../../types/deployment-loader"; -import { Journal } from "../../types/journal"; import { MemoryJournal } from "../journal/memory-journal"; +import { Journal } from "../types/journal"; import { assertIgnitionInvariant } from "../utils/assertions"; /** diff --git a/packages/core/src/new-api/internal/deployment-loader/file-deployment-loader.ts b/packages/core/src/new-api/internal/deployment-loader/file-deployment-loader.ts index f1622e4bf2..2909f4ffcc 100644 --- a/packages/core/src/new-api/internal/deployment-loader/file-deployment-loader.ts +++ b/packages/core/src/new-api/internal/deployment-loader/file-deployment-loader.ts @@ -3,8 +3,8 @@ import path from "path"; import { Artifact, BuildInfo } from "../../types/artifact"; import { DeploymentLoader } from "../../types/deployment-loader"; -import { Journal } from "../../types/journal"; import { FileJournal } from "../journal/file-journal"; +import { Journal } from "../types/journal"; export class FileDeploymentLoader implements DeploymentLoader { public journal: Journal; diff --git a/packages/core/src/new-api/internal/execution/execution-engine.ts b/packages/core/src/new-api/internal/execution/execution-engine.ts index 34c66e947d..2c559905a1 100644 --- a/packages/core/src/new-api/internal/execution/execution-engine.ts +++ b/packages/core/src/new-api/internal/execution/execution-engine.ts @@ -16,15 +16,6 @@ import { DeploymentResultContracts, } from "../../types/deployer"; import { DeploymentLoader } from "../../types/deployment-loader"; -import { - ExecutionResultMessage, - ExecutionTimeout, - FutureStartMessage, - JournalableMessage, - OnchainTransactionReset, - StartRunMessage, - TransactionMessage, -} from "../../types/journal"; import { AccountRuntimeValue, ArgumentType, @@ -53,6 +44,15 @@ import { ExecutionStateMap, ExecutionStatus, } from "../types/execution-state"; +import { + ExecutionResultMessage, + ExecutionTimeout, + FutureStartMessage, + JournalableMessage, + OnchainTransactionReset, + StartRunMessage, + TransactionMessage, +} from "../types/journal"; import { assertIgnitionInvariant } from "../utils/assertions"; import { getFuturesFromModule } from "../utils/get-futures-from-module"; import { replaceWithinArg } from "../utils/replace-within-arg"; diff --git a/packages/core/src/new-api/internal/execution/execution-state-reducer.ts b/packages/core/src/new-api/internal/execution/execution-state-reducer.ts index 22d65a059d..effc69f8c5 100644 --- a/packages/core/src/new-api/internal/execution/execution-state-reducer.ts +++ b/packages/core/src/new-api/internal/execution/execution-state-reducer.ts @@ -1,5 +1,4 @@ import { IgnitionError } from "../../../errors"; -import { FutureStartMessage, JournalableMessage } from "../../types/journal"; import { isCallFunctionStartMessage, isContractAtStartMessage, @@ -24,6 +23,7 @@ import { SendDataExecutionState, StaticCallExecutionState, } from "../types/execution-state"; +import { FutureStartMessage, JournalableMessage } from "../types/journal"; import { assertIgnitionInvariant } from "../utils/assertions"; import { diff --git a/packages/core/src/new-api/internal/execution/execution-strategy-cycler.ts b/packages/core/src/new-api/internal/execution/execution-strategy-cycler.ts index 4aa3e4feba..2f1160ea57 100644 --- a/packages/core/src/new-api/internal/execution/execution-strategy-cycler.ts +++ b/packages/core/src/new-api/internal/execution/execution-strategy-cycler.ts @@ -1,12 +1,11 @@ +import { isOnChainResultMessage } from "../journal/type-guards"; +import { ExecutionState } from "../types/execution-state"; import { ExecutionSuccess, OnchainInteractionMessage, OnchainResultMessage, TransactionMessage, -} from "../../types/journal"; -import { isOnChainResultMessage } from "../journal/type-guards"; -import { ExecutionState } from "../types/execution-state"; - +} from "../types/journal"; export class ExecutionStategyCycler { /** * Given a execution strategy and history of on chain transactions diff --git a/packages/core/src/new-api/internal/execution/execution-strategy.ts b/packages/core/src/new-api/internal/execution/execution-strategy.ts index 71d55fa203..70ed92825e 100644 --- a/packages/core/src/new-api/internal/execution/execution-strategy.ts +++ b/packages/core/src/new-api/internal/execution/execution-strategy.ts @@ -1,4 +1,22 @@ import { IgnitionError } from "../../../errors"; +import { + isCallExecutionState, + isContractAtExecutionState, + isDeploymentExecutionState, + isReadEventArgumentExecutionState, + isSendDataExecutionState, + isStaticCallExecutionState, +} from "../type-guards"; +import { ExecutionStrategy } from "../types/execution-engine"; +import { + CallExecutionState, + ContractAtExecutionState, + DeploymentExecutionState, + ExecutionState, + ReadEventArgumentExecutionState, + SendDataExecutionState, + StaticCallExecutionState, +} from "../types/execution-state"; import { CallFunctionInteractionMessage, CalledFunctionExecutionSuccess, @@ -21,25 +39,7 @@ import { SendDataInteractionMessage, StaticCallExecutionSuccess, StaticCallInteractionMessage, -} from "../../types/journal"; -import { - isCallExecutionState, - isContractAtExecutionState, - isDeploymentExecutionState, - isReadEventArgumentExecutionState, - isSendDataExecutionState, - isStaticCallExecutionState, -} from "../type-guards"; -import { ExecutionStrategy } from "../types/execution-engine"; -import { - CallExecutionState, - ContractAtExecutionState, - DeploymentExecutionState, - ExecutionState, - ReadEventArgumentExecutionState, - SendDataExecutionState, - StaticCallExecutionState, -} from "../types/execution-state"; +} from "../types/journal"; import { assertIgnitionInvariant } from "../utils/assertions"; export class BasicExecutionStrategy implements ExecutionStrategy { diff --git a/packages/core/src/new-api/internal/execution/guards.ts b/packages/core/src/new-api/internal/execution/guards.ts index 02e6b7b188..9243d4e34d 100644 --- a/packages/core/src/new-api/internal/execution/guards.ts +++ b/packages/core/src/new-api/internal/execution/guards.ts @@ -18,7 +18,7 @@ import { SendDataInteractionMessage, StaticCallExecutionSuccess, StaticCallInteractionMessage, -} from "../../types/journal"; +} from "../types/journal"; export function isExecutionResultMessage( potential: JournalableMessage diff --git a/packages/core/src/new-api/internal/execution/onchain-action-reducer.ts b/packages/core/src/new-api/internal/execution/onchain-action-reducer.ts index 927a3f6dd3..97df27aaf0 100644 --- a/packages/core/src/new-api/internal/execution/onchain-action-reducer.ts +++ b/packages/core/src/new-api/internal/execution/onchain-action-reducer.ts @@ -1,5 +1,4 @@ import { IgnitionError } from "../../../errors"; -import { TransactionMessage } from "../../types/journal"; import { isOnchainCallFunctionSuccessMessage, isOnchainContractAtSuccessMessage, @@ -14,6 +13,7 @@ import { } from "../journal/type-guards"; import { serializeReplacer } from "../journal/utils/serialize-replacer"; import { OnchainState, OnchainStatuses } from "../types/execution-state"; +import { TransactionMessage } from "../types/journal"; import { assertIgnitionInvariant } from "../utils/assertions"; import { diff --git a/packages/core/src/new-api/internal/execution/onchain-state-transitions.ts b/packages/core/src/new-api/internal/execution/onchain-state-transitions.ts index ce9d4fd9bc..4c428d0021 100644 --- a/packages/core/src/new-api/internal/execution/onchain-state-transitions.ts +++ b/packages/core/src/new-api/internal/execution/onchain-state-transitions.ts @@ -22,7 +22,7 @@ import { SendDataInteractionMessage, StaticCallInteractionMessage, TransactionMessage, -} from "../../types/journal"; +} from "../../internal/types/journal"; import { ArgumentType } from "../../types/module"; import { isOnChainResultMessage, diff --git a/packages/core/src/new-api/internal/journal/file-journal.ts b/packages/core/src/new-api/internal/journal/file-journal.ts index da718bb6e0..9991f4bc3e 100644 --- a/packages/core/src/new-api/internal/journal/file-journal.ts +++ b/packages/core/src/new-api/internal/journal/file-journal.ts @@ -2,7 +2,7 @@ import fs, { closeSync, constants, openSync, writeFileSync } from "fs"; import { parse } from "ndjson"; -import { Journal, JournalableMessage } from "../../types/journal"; +import { Journal, JournalableMessage } from "../types/journal"; import { deserializeReplacer } from "./utils/deserialize-replacer"; import { logJournalableMessage } from "./utils/log"; diff --git a/packages/core/src/new-api/internal/journal/memory-journal.ts b/packages/core/src/new-api/internal/journal/memory-journal.ts index fcd711f814..86332878e0 100644 --- a/packages/core/src/new-api/internal/journal/memory-journal.ts +++ b/packages/core/src/new-api/internal/journal/memory-journal.ts @@ -1,4 +1,4 @@ -import { Journal, JournalableMessage } from "../../types/journal"; +import { Journal, JournalableMessage } from "../types/journal"; import { deserializeReplacer } from "./utils/deserialize-replacer"; import { logJournalableMessage } from "./utils/log"; diff --git a/packages/core/src/new-api/internal/journal/type-guards.ts b/packages/core/src/new-api/internal/journal/type-guards.ts index e936801f50..a8bba39245 100644 --- a/packages/core/src/new-api/internal/journal/type-guards.ts +++ b/packages/core/src/new-api/internal/journal/type-guards.ts @@ -1,3 +1,5 @@ +import { FutureType } from "../../types/module"; +import { isOnchainInteractionMessage } from "../execution/guards"; import { CallFunctionStartMessage, ContractAtStartMessage, @@ -22,9 +24,7 @@ import { StaticCallStartMessage, TransactionMessage, WipeMessage, -} from "../../types/journal"; -import { FutureType } from "../../types/module"; -import { isOnchainInteractionMessage } from "../execution/guards"; +} from "../types/journal"; /** * Determines if potential is a StartRunMessage. diff --git a/packages/core/src/new-api/internal/journal/utils/log.ts b/packages/core/src/new-api/internal/journal/utils/log.ts index 7bef1d6e25..ab5c05b81b 100644 --- a/packages/core/src/new-api/internal/journal/utils/log.ts +++ b/packages/core/src/new-api/internal/journal/utils/log.ts @@ -1,4 +1,3 @@ -import { JournalableMessage } from "../../../types/journal"; import { SolidityParameterType } from "../../../types/module"; import { isCallFunctionInteraction, @@ -17,6 +16,7 @@ import { isStaticCallExecutionSuccess, isStaticCallInteraction, } from "../../execution/guards"; +import { JournalableMessage } from "../../types/journal"; import { isCallFunctionStartMessage, isContractAtStartMessage, diff --git a/packages/core/src/new-api/internal/types/execution-engine.ts b/packages/core/src/new-api/internal/types/execution-engine.ts index 10fc0a006e..50a0778874 100644 --- a/packages/core/src/new-api/internal/types/execution-engine.ts +++ b/packages/core/src/new-api/internal/types/execution-engine.ts @@ -1,10 +1,5 @@ import { ArtifactResolver } from "../../types/artifact"; import { DeploymentLoader } from "../../types/deployment-loader"; -import { - ExecutionSuccess, - OnchainInteractionMessage, - OnchainResultMessage, -} from "../../types/journal"; import { IgnitionModule, IgnitionModuleResult, @@ -13,6 +8,11 @@ import { import { ChainDispatcher } from "./chain-dispatcher"; import { ExecutionState, ExecutionStateMap } from "./execution-state"; +import { + ExecutionSuccess, + OnchainInteractionMessage, + OnchainResultMessage, +} from "./journal"; import { TransactionLookupTimer } from "./transaction-timer"; interface ExecutionConfig { diff --git a/packages/core/src/new-api/internal/types/execution-state.ts b/packages/core/src/new-api/internal/types/execution-state.ts index e538ec05e6..3c3d0bb835 100644 --- a/packages/core/src/new-api/internal/types/execution-state.ts +++ b/packages/core/src/new-api/internal/types/execution-state.ts @@ -1,10 +1,11 @@ -import { TransactionMessage } from "../../types/journal"; import { ArgumentType, FutureType, SolidityParameterType, } from "../../types/module"; +import { TransactionMessage } from "./journal"; + /** * The execution history of a future is a sequence of onchain interactions. */ diff --git a/packages/core/src/new-api/types/journal.ts b/packages/core/src/new-api/internal/types/journal.ts similarity index 99% rename from packages/core/src/new-api/types/journal.ts rename to packages/core/src/new-api/internal/types/journal.ts index 42d30ffa38..4c70676de4 100644 --- a/packages/core/src/new-api/types/journal.ts +++ b/packages/core/src/new-api/internal/types/journal.ts @@ -1,4 +1,8 @@ -import { ArgumentType, FutureType, SolidityParameterType } from "./module"; +import { + ArgumentType, + FutureType, + SolidityParameterType, +} from "../../types/module"; /** * Store a deployments execution state as a transaction log. diff --git a/packages/core/src/new-api/internal/wiper.ts b/packages/core/src/new-api/internal/wiper.ts index 0ea02270cb..48939d2df4 100644 --- a/packages/core/src/new-api/internal/wiper.ts +++ b/packages/core/src/new-api/internal/wiper.ts @@ -1,8 +1,8 @@ import { IgnitionError } from "../../errors"; -import { Journal, WipeMessage } from "../types/journal"; import { executionStateReducer } from "./execution/execution-state-reducer"; import { ExecutionStateMap } from "./types/execution-state"; +import { Journal, WipeMessage } from "./types/journal"; export class Wiper { constructor(private _journal: Journal) {} diff --git a/packages/core/src/new-api/type-guards.ts b/packages/core/src/new-api/type-guards.ts index 4515b8caa7..d9eda251a2 100644 --- a/packages/core/src/new-api/type-guards.ts +++ b/packages/core/src/new-api/type-guards.ts @@ -1,4 +1,3 @@ -import { Adapters } from "./types/adapters"; import { Artifact } from "./types/artifact"; import { AccountRuntimeValue, @@ -331,19 +330,3 @@ export function isModuleParameterRuntimeValue( potential.type === RuntimeValueType.MODULE_PARAMETER ); } - -/** - * Returns true if potential is a set of adapters. - * - * @beta - */ -export function isAdapters(potential: unknown): potential is Adapters { - return ( - typeof potential === "object" && - potential !== null && - /* TODO: make this type safe */ - "signer" in potential && - "gas" in potential && - "transactions" in potential - ); -} diff --git a/packages/core/src/new-api/types/deployment-loader.ts b/packages/core/src/new-api/types/deployment-loader.ts index a445560aab..d4d11d77cd 100644 --- a/packages/core/src/new-api/types/deployment-loader.ts +++ b/packages/core/src/new-api/types/deployment-loader.ts @@ -1,5 +1,6 @@ +import { Journal } from "../internal/types/journal"; + import { Artifact, BuildInfo } from "./artifact"; -import { Journal } from "./journal"; /** * Read and write to the deployment storage. diff --git a/packages/core/test/new-api/helpers.ts b/packages/core/test/new-api/helpers.ts index 7c76bb97f8..540112d036 100644 --- a/packages/core/test/new-api/helpers.ts +++ b/packages/core/test/new-api/helpers.ts @@ -11,13 +11,16 @@ import { OnchainState, OnchainStatuses, } from "../../src/new-api/internal/types/execution-state"; +import { + Journal, + JournalableMessage, +} from "../../src/new-api/internal/types/journal"; import { DeploymentResult, DeploymentResultContract, DeploymentResultContracts, } from "../../src/new-api/types/deployer"; import { DeploymentLoader } from "../../src/new-api/types/deployment-loader"; -import { Journal, JournalableMessage } from "../../src/new-api/types/journal"; export const exampleAccounts: string[] = [ "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", diff --git a/packages/core/test/new-api/wipe.ts b/packages/core/test/new-api/wipe.ts index 70fff7ac66..b07c300ade 100644 --- a/packages/core/test/new-api/wipe.ts +++ b/packages/core/test/new-api/wipe.ts @@ -3,8 +3,8 @@ import { assert } from "chai"; import { defineModule } from "../../src/new-api/define-module"; import { MemoryJournal } from "../../src/new-api/internal/journal/memory-journal"; +import { Journal } from "../../src/new-api/internal/types/journal"; import { Wiper } from "../../src/new-api/internal/wiper"; -import { Journal } from "../../src/new-api/types/journal"; import { IgnitionModuleResult } from "../../src/new-api/types/module"; import { IgnitionModuleDefinition } from "../../src/new-api/types/module-builder";