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

Add initial condition and agreement store managers.

This commit is contained in:
Pedro Gutiérrez 2019-03-12 23:43:26 +01:00 committed by Pedro Gutiérrez
parent 6a4df9768a
commit 0ffa0e4204
3 changed files with 74 additions and 0 deletions

View File

@ -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<AgreementStoreManager> {
const templateStoreManeger: AgreementStoreManager = new AgreementStoreManager("AgreementStoreManager")
await templateStoreManeger.init()
return templateStoreManeger
}
getOwner(): Promise<string> {
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
}
}

View File

@ -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<ConditionStoreManager> {
const templateStoreManeger: ConditionStoreManager = new ConditionStoreManager("ConditionStoreManager")
await templateStoreManeger.init()
return templateStoreManeger
}
getOwner(): Promise<string> {
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
}
}

View File

@ -1 +1,3 @@
export * from './AgreementStoreManager'
export * from './ConditionStoreManager'
export * from './TemplateStoreManager' export * from './TemplateStoreManager'