@connext/apps
Advanced tools
Comparing version 7.1.0 to 7.1.1
@@ -139,2 +139,12 @@ this.window = this.window || {}; | ||
}; | ||
const installDepositMiddleware = async (context, provider) => { | ||
const { appInstance, stateChannel } = context; | ||
const depositApp = stateChannel.appInstances.find(([id, app]) => { | ||
return (app.appDefinition === appInstance.appDefinition && | ||
app.latestState["assetId"] === appInstance.latestState["assetId"]); | ||
}); | ||
if (depositApp) { | ||
throw new Error(`Cannot install two deposit apps with the same asset id simultaneously. Existing app: ${depositApp[0]}`); | ||
} | ||
}; | ||
const proposeDepositMiddleware = async (context, provider) => { | ||
@@ -147,3 +157,3 @@ const { proposal, stateChannel, params } = context; | ||
if (depositApp) { | ||
throw new Error(`Cannot install two deposit apps with the same asset id simultaneously. Existing app: ${depositApp[0]}`); | ||
throw new Error(`Channel already has an installed deposit app with the same asset id. Existing app: ${depositApp[0]}`); | ||
} | ||
@@ -436,4 +446,7 @@ await validateDepositApp(params, stateChannel, provider); | ||
} | ||
case types.ProtocolNames.install: { | ||
await installMiddleware(networkContexts, middlewareContext); | ||
break; | ||
} | ||
case types.ProtocolNames.setup: | ||
case types.ProtocolNames.install: | ||
case types.ProtocolNames.takeAction: { | ||
@@ -462,2 +475,16 @@ break; | ||
}; | ||
const installMiddleware = async (networkContexts, middlewareContext) => { | ||
const { appInstance, stateChannel } = middlewareContext; | ||
const { contractAddresses, provider } = networkContexts[stateChannel.chainId]; | ||
const appDef = appInstance.appDefinition; | ||
switch (appDef) { | ||
case contractAddresses.DepositApp: { | ||
await installDepositMiddleware(middlewareContext); | ||
break; | ||
} | ||
default: { | ||
return; | ||
} | ||
} | ||
}; | ||
const proposeMiddleware = async (networkContexts, middlewareContext, supportedTokenAddresses, getSwapRate) => { | ||
@@ -533,2 +560,3 @@ const { proposal, stateChannel } = middlewareContext; | ||
exports.generateValidationMiddleware = generateValidationMiddleware; | ||
exports.installDepositMiddleware = installDepositMiddleware; | ||
exports.proposeDepositMiddleware = proposeDepositMiddleware; | ||
@@ -535,0 +563,0 @@ exports.proposeGraphBatchedTransferMiddleware = proposeGraphBatchedTransferMiddleware; |
@@ -140,2 +140,12 @@ import { constants, Contract, utils, BigNumber } from 'ethers'; | ||
}; | ||
const installDepositMiddleware = async (context, provider) => { | ||
const { appInstance, stateChannel } = context; | ||
const depositApp = stateChannel.appInstances.find(([id, app]) => { | ||
return (app.appDefinition === appInstance.appDefinition && | ||
app.latestState["assetId"] === appInstance.latestState["assetId"]); | ||
}); | ||
if (depositApp) { | ||
throw new Error(`Cannot install two deposit apps with the same asset id simultaneously. Existing app: ${depositApp[0]}`); | ||
} | ||
}; | ||
const proposeDepositMiddleware = async (context, provider) => { | ||
@@ -148,3 +158,3 @@ const { proposal, stateChannel, params } = context; | ||
if (depositApp) { | ||
throw new Error(`Cannot install two deposit apps with the same asset id simultaneously. Existing app: ${depositApp[0]}`); | ||
throw new Error(`Channel already has an installed deposit app with the same asset id. Existing app: ${depositApp[0]}`); | ||
} | ||
@@ -437,4 +447,7 @@ await validateDepositApp(params, stateChannel, provider); | ||
} | ||
case ProtocolNames.install: { | ||
await installMiddleware(networkContexts, middlewareContext); | ||
break; | ||
} | ||
case ProtocolNames.setup: | ||
case ProtocolNames.install: | ||
case ProtocolNames.takeAction: { | ||
@@ -463,2 +476,16 @@ break; | ||
}; | ||
const installMiddleware = async (networkContexts, middlewareContext) => { | ||
const { appInstance, stateChannel } = middlewareContext; | ||
const { contractAddresses, provider } = networkContexts[stateChannel.chainId]; | ||
const appDef = appInstance.appDefinition; | ||
switch (appDef) { | ||
case contractAddresses.DepositApp: { | ||
await installDepositMiddleware(middlewareContext); | ||
break; | ||
} | ||
default: { | ||
return; | ||
} | ||
} | ||
}; | ||
const proposeMiddleware = async (networkContexts, middlewareContext, supportedTokenAddresses, getSwapRate) => { | ||
@@ -511,2 +538,2 @@ const { proposal, stateChannel } = middlewareContext; | ||
export { AppRegistry, DEFAULT_APP_TIMEOUT, DEPOSIT_STATE_TIMEOUT, DepositAppRegistryInfo, GRAPH_SIGNED_TRANSFER_STATE_TIMEOUT, GraphBatchSignedTransferAppRegistryInfo, GraphSignedTransferAppRegistryInfo, HASHLOCK_TRANSFER_STATE_TIMEOUT, HashLockTransferAppRegistryInfo, LINKED_TRANSFER_STATE_TIMEOUT, MINIMUM_APP_TIMEOUT, SIGNED_TRANSFER_STATE_TIMEOUT, SWAP_STATE_TIMEOUT, SimpleLinkedTransferAppRegistryInfo, SimpleSignedTransferAppRegistryInfo, SimpleTwoPartySwapAppRegistryInfo, TRANSFER_TIMEOUT, WITHDRAW_STATE_TIMEOUT, WithdrawAppRegistryInfo, WithdrawCommitment, baseCoinTransferValidation, commonAppProposalValidation, generateValidationMiddleware, proposeDepositMiddleware, proposeGraphBatchedTransferMiddleware, proposeGraphSignedTransferMiddleware, proposeHashLockTransferMiddleware, proposeLinkedTransferMiddleware, proposeSignedTransferMiddleware, proposeSwapMiddleware, proposeWithdrawMiddleware, sharedProposalMiddleware, unidirectionalCoinTransferValidation, uninstallDepositMiddleware, validateDepositApp, validateGraphBatchedTransferApp, validateGraphSignedTransferApp, validateHashLockTransferApp, validateSignedTransferApp, validateSimpleLinkedTransferApp, validateSimpleSwapApp, validateWithdrawApp }; | ||
export { AppRegistry, DEFAULT_APP_TIMEOUT, DEPOSIT_STATE_TIMEOUT, DepositAppRegistryInfo, GRAPH_SIGNED_TRANSFER_STATE_TIMEOUT, GraphBatchSignedTransferAppRegistryInfo, GraphSignedTransferAppRegistryInfo, HASHLOCK_TRANSFER_STATE_TIMEOUT, HashLockTransferAppRegistryInfo, LINKED_TRANSFER_STATE_TIMEOUT, MINIMUM_APP_TIMEOUT, SIGNED_TRANSFER_STATE_TIMEOUT, SWAP_STATE_TIMEOUT, SimpleLinkedTransferAppRegistryInfo, SimpleSignedTransferAppRegistryInfo, SimpleTwoPartySwapAppRegistryInfo, TRANSFER_TIMEOUT, WITHDRAW_STATE_TIMEOUT, WithdrawAppRegistryInfo, WithdrawCommitment, baseCoinTransferValidation, commonAppProposalValidation, generateValidationMiddleware, installDepositMiddleware, proposeDepositMiddleware, proposeGraphBatchedTransferMiddleware, proposeGraphSignedTransferMiddleware, proposeHashLockTransferMiddleware, proposeLinkedTransferMiddleware, proposeSignedTransferMiddleware, proposeSwapMiddleware, proposeWithdrawMiddleware, sharedProposalMiddleware, unidirectionalCoinTransferValidation, uninstallDepositMiddleware, validateDepositApp, validateGraphBatchedTransferApp, validateGraphSignedTransferApp, validateHashLockTransferApp, validateSignedTransferApp, validateSimpleLinkedTransferApp, validateSimpleSwapApp, validateWithdrawApp }; |
@@ -144,2 +144,12 @@ 'use strict'; | ||
}; | ||
const installDepositMiddleware = async (context, provider) => { | ||
const { appInstance, stateChannel } = context; | ||
const depositApp = stateChannel.appInstances.find(([id, app]) => { | ||
return (app.appDefinition === appInstance.appDefinition && | ||
app.latestState["assetId"] === appInstance.latestState["assetId"]); | ||
}); | ||
if (depositApp) { | ||
throw new Error(`Cannot install two deposit apps with the same asset id simultaneously. Existing app: ${depositApp[0]}`); | ||
} | ||
}; | ||
const proposeDepositMiddleware = async (context, provider) => { | ||
@@ -152,3 +162,3 @@ const { proposal, stateChannel, params } = context; | ||
if (depositApp) { | ||
throw new Error(`Cannot install two deposit apps with the same asset id simultaneously. Existing app: ${depositApp[0]}`); | ||
throw new Error(`Channel already has an installed deposit app with the same asset id. Existing app: ${depositApp[0]}`); | ||
} | ||
@@ -441,4 +451,7 @@ await validateDepositApp(params, stateChannel, provider); | ||
} | ||
case types.ProtocolNames.install: { | ||
await installMiddleware(networkContexts, middlewareContext); | ||
break; | ||
} | ||
case types.ProtocolNames.setup: | ||
case types.ProtocolNames.install: | ||
case types.ProtocolNames.takeAction: { | ||
@@ -467,2 +480,16 @@ break; | ||
}; | ||
const installMiddleware = async (networkContexts, middlewareContext) => { | ||
const { appInstance, stateChannel } = middlewareContext; | ||
const { contractAddresses, provider } = networkContexts[stateChannel.chainId]; | ||
const appDef = appInstance.appDefinition; | ||
switch (appDef) { | ||
case contractAddresses.DepositApp: { | ||
await installDepositMiddleware(middlewareContext); | ||
break; | ||
} | ||
default: { | ||
return; | ||
} | ||
} | ||
}; | ||
const proposeMiddleware = async (networkContexts, middlewareContext, supportedTokenAddresses, getSwapRate) => { | ||
@@ -538,2 +565,3 @@ const { proposal, stateChannel } = middlewareContext; | ||
exports.generateValidationMiddleware = generateValidationMiddleware; | ||
exports.installDepositMiddleware = installDepositMiddleware; | ||
exports.proposeDepositMiddleware = proposeDepositMiddleware; | ||
@@ -540,0 +568,0 @@ exports.proposeGraphBatchedTransferMiddleware = proposeGraphBatchedTransferMiddleware; |
@@ -1,4 +0,5 @@ | ||
import { ProposeMiddlewareContext, UninstallMiddlewareContext, JsonRpcProvider } from "@connext/types"; | ||
import { ProposeMiddlewareContext, UninstallMiddlewareContext, JsonRpcProvider, InstallMiddlewareContext } from "@connext/types"; | ||
export declare const uninstallDepositMiddleware: (context: UninstallMiddlewareContext, provider: JsonRpcProvider) => Promise<void>; | ||
export declare const installDepositMiddleware: (context: InstallMiddlewareContext, provider: JsonRpcProvider) => Promise<void>; | ||
export declare const proposeDepositMiddleware: (context: ProposeMiddlewareContext, provider: JsonRpcProvider) => Promise<void>; | ||
//# sourceMappingURL=middleware.d.ts.map |
@@ -22,2 +22,12 @@ import { Contract, CONVENTION_FOR_ETH_ASSET_ID, ProtocolRoles, } from "@connext/types"; | ||
}; | ||
export const installDepositMiddleware = async (context, provider) => { | ||
const { appInstance, stateChannel } = context; | ||
const depositApp = stateChannel.appInstances.find(([id, app]) => { | ||
return (app.appDefinition === appInstance.appDefinition && | ||
app.latestState["assetId"] === appInstance.latestState["assetId"]); | ||
}); | ||
if (depositApp) { | ||
throw new Error(`Cannot install two deposit apps with the same asset id simultaneously. Existing app: ${depositApp[0]}`); | ||
} | ||
}; | ||
export const proposeDepositMiddleware = async (context, provider) => { | ||
@@ -30,3 +40,3 @@ const { proposal, stateChannel, params } = context; | ||
if (depositApp) { | ||
throw new Error(`Cannot install two deposit apps with the same asset id simultaneously. Existing app: ${depositApp[0]}`); | ||
throw new Error(`Channel already has an installed deposit app with the same asset id. Existing app: ${depositApp[0]}`); | ||
} | ||
@@ -33,0 +43,0 @@ await validateDepositApp(params, stateChannel, provider); |
import { ProtocolNames, } from "@connext/types"; | ||
import { stringify } from "@connext/utils"; | ||
import { uninstallDepositMiddleware, proposeDepositMiddleware } from "./DepositApp"; | ||
import { uninstallDepositMiddleware, proposeDepositMiddleware, installDepositMiddleware, } from "./DepositApp"; | ||
import { proposeLinkedTransferMiddleware } from "./SimpleLinkedTransferApp"; | ||
@@ -37,4 +37,7 @@ import { proposeHashLockTransferMiddleware } from "./HashLockTransferApp"; | ||
} | ||
case ProtocolNames.install: { | ||
await installMiddleware(networkContexts, middlewareContext); | ||
break; | ||
} | ||
case ProtocolNames.setup: | ||
case ProtocolNames.install: | ||
case ProtocolNames.takeAction: { | ||
@@ -63,2 +66,16 @@ break; | ||
}; | ||
const installMiddleware = async (networkContexts, middlewareContext) => { | ||
const { appInstance, stateChannel } = middlewareContext; | ||
const { contractAddresses, provider } = networkContexts[stateChannel.chainId]; | ||
const appDef = appInstance.appDefinition; | ||
switch (appDef) { | ||
case contractAddresses.DepositApp: { | ||
await installDepositMiddleware(middlewareContext, provider); | ||
break; | ||
} | ||
default: { | ||
return; | ||
} | ||
} | ||
}; | ||
const proposeMiddleware = async (networkContexts, middlewareContext, supportedTokenAddresses, getSwapRate) => { | ||
@@ -65,0 +82,0 @@ const { proposal, stateChannel } = middlewareContext; |
{ | ||
"name": "@connext/apps", | ||
"version": "7.1.0", | ||
"version": "7.1.1", | ||
"description": "Connext Counterfactual Apps", | ||
@@ -22,4 +22,4 @@ "main": "dist/index.js", | ||
"@connext/contracts": "3.4.1", | ||
"@connext/types": "7.1.0", | ||
"@connext/utils": "7.1.0", | ||
"@connext/types": "7.1.1", | ||
"@connext/utils": "7.1.1", | ||
"@rollup/plugin-json": "4.1.0", | ||
@@ -26,0 +26,0 @@ "ethers": "5.0.7", |
@@ -9,2 +9,3 @@ import { | ||
JsonRpcProvider, | ||
InstallMiddlewareContext, | ||
} from "@connext/types"; | ||
@@ -55,2 +56,20 @@ import { getSignerAddressFromPublicIdentifier } from "@connext/utils"; | ||
export const installDepositMiddleware = async ( | ||
context: InstallMiddlewareContext, | ||
provider: JsonRpcProvider, | ||
) => { | ||
const { appInstance, stateChannel } = context; | ||
const depositApp = stateChannel.appInstances.find(([id, app]) => { | ||
return ( | ||
app.appDefinition === appInstance.appDefinition && | ||
app.latestState["assetId"] === appInstance.latestState["assetId"] | ||
); | ||
}); | ||
if (depositApp) { | ||
throw new Error( | ||
`Cannot install two deposit apps with the same asset id simultaneously. Existing app: ${depositApp[0]}`, | ||
); | ||
} | ||
}; | ||
export const proposeDepositMiddleware = async ( | ||
@@ -69,3 +88,3 @@ context: ProposeMiddlewareContext, | ||
throw new Error( | ||
`Cannot install two deposit apps with the same asset id simultaneously. Existing app: ${depositApp[0]}`, | ||
`Channel already has an installed deposit app with the same asset id. Existing app: ${depositApp[0]}`, | ||
); | ||
@@ -72,0 +91,0 @@ } |
@@ -11,6 +11,11 @@ import { | ||
ValidationMiddleware, | ||
InstallMiddlewareContext, | ||
} from "@connext/types"; | ||
import { stringify } from "@connext/utils"; | ||
import { uninstallDepositMiddleware, proposeDepositMiddleware } from "./DepositApp"; | ||
import { | ||
uninstallDepositMiddleware, | ||
proposeDepositMiddleware, | ||
installDepositMiddleware, | ||
} from "./DepositApp"; | ||
import { proposeLinkedTransferMiddleware } from "./SimpleLinkedTransferApp"; | ||
@@ -75,4 +80,7 @@ import { proposeHashLockTransferMiddleware } from "./HashLockTransferApp"; | ||
} | ||
case ProtocolNames.install: { | ||
await installMiddleware(networkContexts, middlewareContext as InstallMiddlewareContext); | ||
break; | ||
} | ||
case ProtocolNames.setup: | ||
case ProtocolNames.install: | ||
case ProtocolNames.takeAction: { | ||
@@ -108,2 +116,20 @@ break; | ||
const installMiddleware = async ( | ||
networkContexts: NetworkContexts, | ||
middlewareContext: InstallMiddlewareContext, | ||
) => { | ||
const { appInstance, stateChannel } = middlewareContext; | ||
const { contractAddresses, provider } = networkContexts[stateChannel.chainId]; | ||
const appDef = appInstance.appDefinition; | ||
switch (appDef) { | ||
case contractAddresses.DepositApp: { | ||
await installDepositMiddleware(middlewareContext, provider); | ||
break; | ||
} | ||
default: { | ||
return; | ||
} | ||
} | ||
}; | ||
const proposeMiddleware = async ( | ||
@@ -110,0 +136,0 @@ networkContexts: NetworkContexts, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
792051
3358