1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/src/keeper/Keeper.ts

126 lines
4.0 KiB
TypeScript
Raw Normal View History

import AccessConditions from "./contracts/conditions/AccessConditions"
import PaymentConditions from "./contracts/conditions/PaymentConditions"
import DIDRegistry from "./contracts/DIDRegistry"
2019-01-28 15:41:19 +01:00
import Dispenser from "./contracts/Dispenser"
import ServiceExecutionAgreement from "./contracts/ServiceExecutionAgreement"
import OceanToken from "./contracts/Token"
2018-12-17 17:37:36 +01:00
2018-10-16 14:56:18 +02:00
import Web3Provider from "./Web3Provider"
/**
* Interface with Ocean Keeper contracts.
* Ocean Keeper implementation where we put the following modules together:
* - TCRs: users create challenges and resolve them through voting to maintain registries.
* - Ocean Tokens: the intrinsic tokens circulated inside Ocean network, which is used in the voting of TCRs.
* - Marketplace: the core marketplace where people can transact with each other with Ocean tokens.
*/
export default class Keeper {
/**
* Returns Keeper instance.
* @return {Promise<Keeper>}
*/
public static async getInstance(): Promise<Keeper> {
2018-10-16 14:56:18 +02:00
if (Keeper.instance === null) {
Keeper.instance = new Keeper()
2019-01-28 15:41:19 +01:00
Keeper.instance.dispenser = await Dispenser.getInstance()
2018-10-16 14:56:18 +02:00
Keeper.instance.token = await OceanToken.getInstance()
Keeper.instance.serviceAgreement = await ServiceExecutionAgreement.getInstance()
Keeper.instance.accessConditions = await AccessConditions.getInstance()
Keeper.instance.paymentConditions = await PaymentConditions.getInstance()
Keeper.instance.didRegistry = await DIDRegistry.getInstance()
2018-10-16 14:56:18 +02:00
}
return Keeper.instance
}
/**
* Keeper instance.
* @type {Keeper}
*/
2018-10-16 14:56:18 +02:00
private static instance: Keeper = null
/**
* Ocean Token smart contract instance.
* @type {OceanToken}
*/
2018-10-02 10:06:26 +02:00
public token: OceanToken
/**
* Ocean Market smart contract instance.
2019-01-28 15:41:19 +01:00
* @type {Dispenser}
*/
2019-01-28 15:41:19 +01:00
public dispenser: Dispenser
/**
* Service agreement smart contract instance.
* @type {ServiceExecutionAgreement}
*/
public serviceAgreement: ServiceExecutionAgreement
/**
* Access conditions smart contract instance.
* @type {AccessConditions}
*/
public accessConditions: AccessConditions
/**
* Payment conditions smart contract instance.
* @type {PaymentConditions}
*/
public paymentConditions: PaymentConditions
/**
* DID registry smart contract instance.
* @type {DIDRegistry}
*/
public didRegistry: DIDRegistry
/**
* Returns the network by name.
* @return {Promise<string>} Network name.
*/
2018-10-16 14:56:18 +02:00
public async getNetworkName(): Promise<string> {
return Web3Provider.getWeb3().eth.net.getId()
.then((networkId) => {
2018-11-14 09:36:37 +01:00
let network: string = "Unknown"
2018-10-16 14:56:18 +02:00
switch (networkId) {
case 1:
network = "Main"
break
case 2:
network = "Morden"
break
case 3:
network = "Ropsten"
break
case 4:
network = "Rinkeby"
break
case 77:
network = "POA_Sokol"
break
case 99:
network = "POA_Core"
break
2018-10-16 14:56:18 +02:00
case 42:
network = "Kovan"
break
2018-11-23 09:57:37 +01:00
case 8996:
2018-12-07 15:19:16 +01:00
network = "Spree"
// network = "ocean_poa_net_local"
2018-11-23 09:57:37 +01:00
break
2018-11-14 09:36:37 +01:00
case 8995:
2018-12-07 15:19:16 +01:00
network = "Nile"
2018-11-14 09:36:37 +01:00
break
2018-10-16 14:56:18 +02:00
default:
// Logger.log(`NetworkId ${networkId} not found defaulting`)
2018-11-14 09:36:37 +01:00
network = "Development"
2018-10-16 14:56:18 +02:00
}
return network
})
}
}