From 0ffa0e420481e5d00575fdc7a7886c97017b49a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Tue, 12 Mar 2019 23:43:26 +0100 Subject: [PATCH] Add initial condition and agreement store managers. --- .../managers/AgreementStoreManager.ts | 31 ++++++++++++++ .../managers/ConditionStoreManager.ts | 41 +++++++++++++++++++ src/keeper/contracts/managers/index.ts | 2 + 3 files changed, 74 insertions(+) create mode 100644 src/keeper/contracts/managers/AgreementStoreManager.ts create mode 100644 src/keeper/contracts/managers/ConditionStoreManager.ts diff --git a/src/keeper/contracts/managers/AgreementStoreManager.ts b/src/keeper/contracts/managers/AgreementStoreManager.ts new file mode 100644 index 0000000..7390f3b --- /dev/null +++ b/src/keeper/contracts/managers/AgreementStoreManager.ts @@ -0,0 +1,31 @@ +import Logger from "../../../utils/Logger" +import ContractBase from "../ContractBase" +import { zeroX } from "../../../utils" + +export interface AgreementData { + did: string + didOwner: string + templateId: string + conditionIds: string[] + lastUpdatedBy: string + blockNumberUpdated: number +} + +export class AgreementStoreManager extends ContractBase { + + public static async getInstance(): Promise { + const templateStoreManeger: AgreementStoreManager = new AgreementStoreManager("AgreementStoreManager") + await templateStoreManeger.init() + return templateStoreManeger + } + + getOwner(): Promise { + return this.call("owner", []) + } + + public async getAgreement(agreementId: string) { + const {did, didOwner, templateId, conditionIds, lastUpdatedBy, blockNumberUpdated} = + await this.call("getAgreement", [zeroX(agreementId)]) + return {did, didOwner, templateId, conditionIds, lastUpdatedBy, blockNumberUpdated: +blockNumberUpdated} as AgreementData + } +} diff --git a/src/keeper/contracts/managers/ConditionStoreManager.ts b/src/keeper/contracts/managers/ConditionStoreManager.ts new file mode 100644 index 0000000..ba31430 --- /dev/null +++ b/src/keeper/contracts/managers/ConditionStoreManager.ts @@ -0,0 +1,41 @@ +import Logger from "../../../utils/Logger" +import ContractBase from "../ContractBase" +import { ConditionState } from "../conditions/Condition.abstract" +import { zeroX } from "../../../utils" + +export interface ConditionData { + typeRef: string + state: ConditionState + timeLock: number + timeOut: number + blockNumber: number + lastUpdatedBy: string + blockNumberUpdated: number +} + +export class ConditionStoreManager extends ContractBase { + + public static async getInstance(): Promise { + const templateStoreManeger: ConditionStoreManager = new ConditionStoreManager("ConditionStoreManager") + await templateStoreManeger.init() + return templateStoreManeger + } + + getOwner(): Promise { + return this.call("owner", []) + } + + public async getCondition(conditionId: string) { + const {typeRef, state, timeLock, timeOut, blockNumber, lastUpdatedBy, blockNumberUpdated} = + await this.call("getCondition", [zeroX(conditionId)]) + return { + typeRef, + state: +state, + timeLock: +timeLock, + timeOut: +timeOut, + blockNumber: +blockNumber, + lastUpdatedBy, + blockNumberUpdated: +blockNumberUpdated, + } as ConditionData + } +} diff --git a/src/keeper/contracts/managers/index.ts b/src/keeper/contracts/managers/index.ts index 3b106a2..f5c247d 100644 --- a/src/keeper/contracts/managers/index.ts +++ b/src/keeper/contracts/managers/index.ts @@ -1 +1,3 @@ +export * from './AgreementStoreManager' +export * from './ConditionStoreManager' export * from './TemplateStoreManager'