2019-02-28 21:28:57 +01:00
|
|
|
import ContractBase from "../ContractBase"
|
|
|
|
import { Condition } from "../conditions/Condition.abstract"
|
|
|
|
import Keeper from "../../Keeper"
|
2019-03-04 14:34:24 +01:00
|
|
|
import { zeroX } from "../../../utils"
|
2019-02-28 21:28:57 +01:00
|
|
|
|
|
|
|
export abstract class AgreementTemplate extends ContractBase {
|
|
|
|
|
|
|
|
protected constructor(contractName: string) {
|
|
|
|
super(contractName)
|
|
|
|
}
|
|
|
|
|
2019-03-04 13:05:27 +01:00
|
|
|
public static async getInstance(conditionName: string, templateClass: any): Promise<AgreementTemplate & any> {
|
2019-02-28 21:28:57 +01:00
|
|
|
const condition: AgreementTemplate = new (templateClass as any)(conditionName)
|
|
|
|
await condition.init()
|
|
|
|
return condition
|
|
|
|
}
|
|
|
|
|
|
|
|
// tslint:disable-next-line
|
|
|
|
public createAgreement(agreementId: string, did: string, conditionIds: string[], timeLocks: number[], timeOuts: number[], ...args: any[])
|
|
|
|
public createAgreement(
|
|
|
|
agreementId: string,
|
|
|
|
did: string,
|
|
|
|
conditionIds: string[],
|
|
|
|
timeLocks: number[],
|
|
|
|
timeOuts: number[],
|
|
|
|
extraArgs: any[],
|
|
|
|
from?: string,
|
|
|
|
) {
|
|
|
|
return this.sendFrom(
|
|
|
|
"createAgreement",
|
|
|
|
[
|
2019-03-04 14:34:24 +01:00
|
|
|
zeroX(agreementId),
|
|
|
|
zeroX(did),
|
|
|
|
conditionIds.map(zeroX),
|
2019-02-28 21:28:57 +01:00
|
|
|
timeLocks,
|
|
|
|
timeOuts,
|
|
|
|
...extraArgs,
|
|
|
|
],
|
|
|
|
from,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
public getConditionTypes(): Promise<string[]> {
|
|
|
|
return this.call("getConditionTypes", [])
|
|
|
|
}
|
|
|
|
|
|
|
|
public async getConditions(): Promise<Condition[]> {
|
|
|
|
const keeper = await Keeper.getInstance()
|
|
|
|
return (await this.getConditionTypes())
|
|
|
|
.map(address => keeper.getConditionByAddress(address))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|