mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Allow create a Ocean instance in wrong network. #188
This commit is contained in:
parent
8f8766d700
commit
c116cde4ca
@ -5,6 +5,7 @@ import { Condition, LockRewardCondition, EscrowReward, AccessSecretStoreConditio
|
||||
import { AgreementTemplate, EscrowAccessSecretStoreTemplate } from "./contracts/templates"
|
||||
import { TemplateStoreManager, AgreementStoreManager, ConditionStoreManager } from "./contracts/managers"
|
||||
|
||||
import { objectPromiseAll } from "../utils"
|
||||
import { EventHandler } from "./EventHandler"
|
||||
|
||||
import { Instantiable, InstantiableConfig } from "../Instantiable.abstract"
|
||||
@ -29,40 +30,48 @@ export class Keeper extends Instantiable {
|
||||
// Adding keeper inside Ocean to prevent `Keeper not defined yet` error
|
||||
config.ocean.keeper = keeper
|
||||
|
||||
const resolvedInstances = await Promise.all([
|
||||
let instances = {} as any
|
||||
try {
|
||||
instances = await objectPromiseAll({
|
||||
// Main contracts
|
||||
Dispenser.getInstance(config),
|
||||
OceanToken.getInstance(config),
|
||||
DIDRegistry.getInstance(config),
|
||||
dispenser: Dispenser.getInstance(config),
|
||||
token: OceanToken.getInstance(config),
|
||||
didRegistry: DIDRegistry.getInstance(config),
|
||||
// Managers
|
||||
TemplateStoreManager.getInstance(config),
|
||||
AgreementStoreManager.getInstance(config),
|
||||
ConditionStoreManager.getInstance(config),
|
||||
templateStoreManager: TemplateStoreManager.getInstance(config),
|
||||
agreementStoreManager: AgreementStoreManager.getInstance(config),
|
||||
conditionStoreManager: ConditionStoreManager.getInstance(config),
|
||||
// Conditions
|
||||
LockRewardCondition.getInstance(config),
|
||||
EscrowReward.getInstance(config),
|
||||
AccessSecretStoreCondition.getInstance(config),
|
||||
lockRewardCondition: LockRewardCondition.getInstance(config),
|
||||
escrowReward: EscrowReward.getInstance(config),
|
||||
accessSecretStoreCondition: AccessSecretStoreCondition.getInstance(config),
|
||||
// Conditions
|
||||
EscrowAccessSecretStoreTemplate.getInstance(config),
|
||||
])
|
||||
escrowAccessSecretStoreTemplate: EscrowAccessSecretStoreTemplate.getInstance(config),
|
||||
})
|
||||
|
||||
keeper.connected = true
|
||||
} catch {
|
||||
keeper.connected = false
|
||||
return
|
||||
}
|
||||
|
||||
// Main contracts
|
||||
keeper.dispenser = resolvedInstances[0]
|
||||
keeper.token = resolvedInstances[1]
|
||||
keeper.didRegistry = resolvedInstances[2]
|
||||
keeper.dispenser = instances.dispenser
|
||||
keeper.token = instances.token
|
||||
keeper.didRegistry = instances.didRegistry
|
||||
// Managers
|
||||
keeper.templateStoreManager = resolvedInstances[3]
|
||||
keeper.agreementStoreManager = resolvedInstances[4]
|
||||
keeper.conditionStoreManager = resolvedInstances[5]
|
||||
keeper.templateStoreManager = instances.templateStoreManager
|
||||
keeper.agreementStoreManager = instances.agreementStoreManager
|
||||
keeper.conditionStoreManager = instances.conditionStoreManager
|
||||
// Conditions
|
||||
keeper.conditions = {
|
||||
lockRewardCondition: resolvedInstances[6],
|
||||
escrowReward: resolvedInstances[7],
|
||||
accessSecretStoreCondition: resolvedInstances[8],
|
||||
lockRewardCondition: instances.lockRewardCondition,
|
||||
escrowReward: instances.escrowReward,
|
||||
accessSecretStoreCondition: instances.accessSecretStoreCondition,
|
||||
}
|
||||
// Conditions
|
||||
keeper.templates = {
|
||||
escrowAccessSecretStoreTemplate: resolvedInstances[9],
|
||||
escrowAccessSecretStoreTemplate: instances.escrowAccessSecretStoreTemplate,
|
||||
}
|
||||
|
||||
// Utils
|
||||
@ -73,6 +82,12 @@ export class Keeper extends Instantiable {
|
||||
return keeper
|
||||
}
|
||||
|
||||
/**
|
||||
* Is connected to the correct network or not.
|
||||
* @type {boolean}
|
||||
*/
|
||||
public connected: boolean = false
|
||||
|
||||
/**
|
||||
* Ocean Token smart contract instance.
|
||||
* @type {OceanToken}
|
||||
|
12
src/utils/PromiseResolver.ts
Normal file
12
src/utils/PromiseResolver.ts
Normal file
@ -0,0 +1,12 @@
|
||||
const zipObject = (keys = [], values = []) => {
|
||||
return keys.reduce((acc, key, index) => ({
|
||||
...acc,
|
||||
[key]: values[index],
|
||||
}), {})
|
||||
}
|
||||
|
||||
export const objectPromiseAll = async (obj: {[key: string]: Promise<any>}) => {
|
||||
const keys = Object.keys(obj)
|
||||
const result = await Promise.all(Object.values(obj))
|
||||
return zipObject(keys, result)
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
export * from "./PromiseResolver"
|
||||
export * from "./Logger"
|
||||
export * from "./ConversionTypeHelpers"
|
||||
export * from "./GeneratorHelpers"
|
||||
|
Loading…
Reference in New Issue
Block a user