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 { AgreementTemplate, EscrowAccessSecretStoreTemplate } from "./contracts/templates"
|
||||||
import { TemplateStoreManager, AgreementStoreManager, ConditionStoreManager } from "./contracts/managers"
|
import { TemplateStoreManager, AgreementStoreManager, ConditionStoreManager } from "./contracts/managers"
|
||||||
|
|
||||||
|
import { objectPromiseAll } from "../utils"
|
||||||
import { EventHandler } from "./EventHandler"
|
import { EventHandler } from "./EventHandler"
|
||||||
|
|
||||||
import { Instantiable, InstantiableConfig } from "../Instantiable.abstract"
|
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
|
// Adding keeper inside Ocean to prevent `Keeper not defined yet` error
|
||||||
config.ocean.keeper = keeper
|
config.ocean.keeper = keeper
|
||||||
|
|
||||||
const resolvedInstances = await Promise.all([
|
let instances = {} as any
|
||||||
// Main contracts
|
try {
|
||||||
Dispenser.getInstance(config),
|
instances = await objectPromiseAll({
|
||||||
OceanToken.getInstance(config),
|
// Main contracts
|
||||||
DIDRegistry.getInstance(config),
|
dispenser: Dispenser.getInstance(config),
|
||||||
// Managers
|
token: OceanToken.getInstance(config),
|
||||||
TemplateStoreManager.getInstance(config),
|
didRegistry: DIDRegistry.getInstance(config),
|
||||||
AgreementStoreManager.getInstance(config),
|
// Managers
|
||||||
ConditionStoreManager.getInstance(config),
|
templateStoreManager: TemplateStoreManager.getInstance(config),
|
||||||
// Conditions
|
agreementStoreManager: AgreementStoreManager.getInstance(config),
|
||||||
LockRewardCondition.getInstance(config),
|
conditionStoreManager: ConditionStoreManager.getInstance(config),
|
||||||
EscrowReward.getInstance(config),
|
// Conditions
|
||||||
AccessSecretStoreCondition.getInstance(config),
|
lockRewardCondition: LockRewardCondition.getInstance(config),
|
||||||
// Conditions
|
escrowReward: EscrowReward.getInstance(config),
|
||||||
EscrowAccessSecretStoreTemplate.getInstance(config),
|
accessSecretStoreCondition: AccessSecretStoreCondition.getInstance(config),
|
||||||
])
|
// Conditions
|
||||||
|
escrowAccessSecretStoreTemplate: EscrowAccessSecretStoreTemplate.getInstance(config),
|
||||||
|
})
|
||||||
|
|
||||||
|
keeper.connected = true
|
||||||
|
} catch {
|
||||||
|
keeper.connected = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Main contracts
|
// Main contracts
|
||||||
keeper.dispenser = resolvedInstances[0]
|
keeper.dispenser = instances.dispenser
|
||||||
keeper.token = resolvedInstances[1]
|
keeper.token = instances.token
|
||||||
keeper.didRegistry = resolvedInstances[2]
|
keeper.didRegistry = instances.didRegistry
|
||||||
// Managers
|
// Managers
|
||||||
keeper.templateStoreManager = resolvedInstances[3]
|
keeper.templateStoreManager = instances.templateStoreManager
|
||||||
keeper.agreementStoreManager = resolvedInstances[4]
|
keeper.agreementStoreManager = instances.agreementStoreManager
|
||||||
keeper.conditionStoreManager = resolvedInstances[5]
|
keeper.conditionStoreManager = instances.conditionStoreManager
|
||||||
// Conditions
|
// Conditions
|
||||||
keeper.conditions = {
|
keeper.conditions = {
|
||||||
lockRewardCondition: resolvedInstances[6],
|
lockRewardCondition: instances.lockRewardCondition,
|
||||||
escrowReward: resolvedInstances[7],
|
escrowReward: instances.escrowReward,
|
||||||
accessSecretStoreCondition: resolvedInstances[8],
|
accessSecretStoreCondition: instances.accessSecretStoreCondition,
|
||||||
}
|
}
|
||||||
// Conditions
|
// Conditions
|
||||||
keeper.templates = {
|
keeper.templates = {
|
||||||
escrowAccessSecretStoreTemplate: resolvedInstances[9],
|
escrowAccessSecretStoreTemplate: instances.escrowAccessSecretStoreTemplate,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
@ -73,6 +82,12 @@ export class Keeper extends Instantiable {
|
|||||||
return keeper
|
return keeper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is connected to the correct network or not.
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
public connected: boolean = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ocean Token smart contract instance.
|
* Ocean Token smart contract instance.
|
||||||
* @type {OceanToken}
|
* @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 "./Logger"
|
||||||
export * from "./ConversionTypeHelpers"
|
export * from "./ConversionTypeHelpers"
|
||||||
export * from "./GeneratorHelpers"
|
export * from "./GeneratorHelpers"
|
||||||
|
Loading…
Reference in New Issue
Block a user