mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Fix linter errors.
This commit is contained in:
parent
01465dc164
commit
eaac2f4f68
@ -1,8 +1,8 @@
|
|||||||
import { assert } from 'chai'
|
import { assert } from "chai"
|
||||||
|
|
||||||
import { config } from "../config"
|
import { config } from "../config"
|
||||||
|
|
||||||
import { Ocean, MetaData, DDO, DID, Account/*, ServiceAgreement*/ } from '../../src' // @oceanprotocol/squid
|
import { Ocean, MetaData, DDO, DID, Account/*, ServiceAgreement*/ } from "../../src" // @oceanprotocol/squid
|
||||||
|
|
||||||
describe("Consume Asset", () => {
|
describe("Consume Asset", () => {
|
||||||
let ocean: Ocean
|
let ocean: Ocean
|
||||||
@ -71,7 +71,7 @@ describe("Consume Asset", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to request tokens for consumer", async () => {
|
it("should be able to request tokens for consumer", async () => {
|
||||||
const initialBalance = (await consumer.getBalance()).ocn;
|
const initialBalance = (await consumer.getBalance()).ocn
|
||||||
await consumer.requestTokens(metadata.base.price)
|
await consumer.requestTokens(metadata.base.price)
|
||||||
|
|
||||||
assert.equal((await consumer.getBalance()).ocn, initialBalance + metadata.base.price, "OCN Tokens not delivered")
|
assert.equal((await consumer.getBalance()).ocn, initialBalance + metadata.base.price, "OCN Tokens not delivered")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert } from "chai"
|
import { assert } from "chai"
|
||||||
import * as Web3 from "web3";
|
import * as Web3 from "web3"
|
||||||
import * as fs from "fs";
|
import * as fs from "fs"
|
||||||
|
|
||||||
import { config } from "../config"
|
import { config } from "../config"
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ describe("Consume Asset (Brizo)", () => {
|
|||||||
|
|
||||||
const testHash = Math.random().toString(36).substr(2)
|
const testHash = Math.random().toString(36).substr(2)
|
||||||
let metadata: Partial<MetaData>
|
let metadata: Partial<MetaData>
|
||||||
let metadataGenerator = (name: string) => ({
|
const metadataGenerator = (name: string) => ({
|
||||||
...metadata,
|
...metadata,
|
||||||
base: {
|
base: {
|
||||||
...metadata.base,
|
...metadata.base,
|
||||||
@ -28,7 +28,8 @@ describe("Consume Asset (Brizo)", () => {
|
|||||||
before(async () => {
|
before(async () => {
|
||||||
ocean = await Ocean.getInstance({
|
ocean = await Ocean.getInstance({
|
||||||
...config,
|
...config,
|
||||||
web3Provider: new Web3.providers.HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"),
|
web3Provider: new Web3.providers
|
||||||
|
.HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"),
|
||||||
})
|
})
|
||||||
|
|
||||||
// Accounts
|
// Accounts
|
||||||
@ -76,7 +77,7 @@ describe("Consume Asset (Brizo)", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("should regiester an asset", async () => {
|
it("should regiester an asset", async () => {
|
||||||
ddo = await ocean.assets.create(metadataGenerator("ToBeConsumed") as any, publisher);
|
ddo = await ocean.assets.create(metadataGenerator("ToBeConsumed") as any, publisher)
|
||||||
|
|
||||||
assert.instanceOf(ddo, DDO)
|
assert.instanceOf(ddo, DDO)
|
||||||
})
|
})
|
||||||
@ -99,10 +100,10 @@ describe("Consume Asset (Brizo)", () => {
|
|||||||
|
|
||||||
assert.include(path, folder, "The storage path is not correct.")
|
assert.include(path, folder, "The storage path is not correct.")
|
||||||
|
|
||||||
const files = await new Promise(resolve => {
|
const files = await new Promise((resolve) => {
|
||||||
fs.readdir(path, (err, files) => {
|
fs.readdir(path, (err, fileList) => {
|
||||||
resolve(files)
|
resolve(fileList)
|
||||||
});
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.deepEqual(files, ["README.md", "testzkp.pdf"], "Stored files are not correct.")
|
assert.deepEqual(files, ["README.md", "testzkp.pdf"], "Stored files are not correct.")
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { assert } from 'chai'
|
import { assert } from "chai"
|
||||||
|
|
||||||
import { config } from "../config"
|
import { config } from "../config"
|
||||||
|
|
||||||
import { Ocean, templates, conditions, utils, Keeper, Account } from '../../src' // @oceanprotocol/squid
|
import { Ocean, templates, conditions, utils, Keeper, Account } from "../../src" // @oceanprotocol/squid
|
||||||
|
|
||||||
const { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } = conditions
|
const { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } = conditions
|
||||||
const { EscrowAccessSecretStoreTemplate } = templates
|
const { EscrowAccessSecretStoreTemplate } = templates
|
||||||
@ -13,7 +13,7 @@ describe("Register Escrow Access Secret Store Template", () => {
|
|||||||
|
|
||||||
let template: templates.EscrowAccessSecretStoreTemplate
|
let template: templates.EscrowAccessSecretStoreTemplate
|
||||||
|
|
||||||
const url = 'https://example.com/did/ocean/test-attr-example.txt'
|
const url = "https://example.com/did/ocean/test-attr-example.txt"
|
||||||
const checksum = "b".repeat(32)
|
const checksum = "b".repeat(32)
|
||||||
const escrowAmount = 12
|
const escrowAmount = 12
|
||||||
|
|
||||||
@ -46,13 +46,13 @@ describe("Register Escrow Access Secret Store Template", () => {
|
|||||||
it("should propose the template", async () => {
|
it("should propose the template", async () => {
|
||||||
await keeper.templateStoreManager.proposeTemplate(template.getAddress(), consumer.getId(), true)
|
await keeper.templateStoreManager.proposeTemplate(template.getAddress(), consumer.getId(), true)
|
||||||
// TODO: Use a event to detect template mined
|
// TODO: Use a event to detect template mined
|
||||||
await new Promise(_ => setTimeout(_, 6 * 1000))
|
await new Promise((_) => setTimeout(_, 6 * 1000))
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should approve the template", async () => {
|
it("should approve the template", async () => {
|
||||||
await keeper.templateStoreManager.approveTemplate(template.getAddress(), templateManagerOwner.getId(), true)
|
await keeper.templateStoreManager.approveTemplate(template.getAddress(), templateManagerOwner.getId(), true)
|
||||||
// TODO: Use a event to detect template mined
|
// TODO: Use a event to detect template mined
|
||||||
await new Promise(_ => setTimeout(_, 6 * 1000))
|
await new Promise((_) => setTimeout(_, 6 * 1000))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -93,16 +93,15 @@ describe("Register Escrow Access Secret Store Template", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("should have condition instances asociated", async () => {
|
it("should have condition instances asociated", async () => {
|
||||||
const conditions = await template.getConditions()
|
const conditionInstances = await template.getConditions()
|
||||||
|
|
||||||
assert.equal(conditions.length, 3, "Expected 3 conditions.")
|
|
||||||
|
|
||||||
|
assert.equal(conditionInstances.length, 3, "Expected 3 conditions.")
|
||||||
|
|
||||||
const conditionClasses = [AccessSecretStoreCondition, EscrowReward, LockRewardCondition]
|
const conditionClasses = [AccessSecretStoreCondition, EscrowReward, LockRewardCondition]
|
||||||
conditionClasses
|
conditionClasses
|
||||||
.forEach(conditionClass => {
|
.forEach((conditionClass) => {
|
||||||
if (!conditions.find(condition => condition instanceof conditionClass)) {
|
if (!conditionInstances.find((condition) => condition instanceof conditionClass)) {
|
||||||
throw `${conditionClass.name} is not part of the conditions.`;
|
throw new Error(`${conditionClass.name} is not part of the conditions.`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { assert } from 'chai'
|
import { assert } from "chai"
|
||||||
|
|
||||||
import { config } from "../config"
|
import { config } from "../config"
|
||||||
|
|
||||||
import { Ocean, MetaData, Account, DDO } from '../../src' // @oceanprotocol/squid
|
import { Ocean, MetaData, Account, DDO } from "../../src" // @oceanprotocol/squid
|
||||||
|
|
||||||
describe("Search Asset", () => {
|
describe("Search Asset", () => {
|
||||||
let ocean: Ocean
|
let ocean: Ocean
|
||||||
@ -11,7 +11,7 @@ describe("Search Asset", () => {
|
|||||||
|
|
||||||
const testHash = Math.random().toString(36).substr(2)
|
const testHash = Math.random().toString(36).substr(2)
|
||||||
let metadata: Partial<MetaData>
|
let metadata: Partial<MetaData>
|
||||||
let metadataGenerator = (name: string) => ({
|
const metadataGenerator = (name: string) => ({
|
||||||
...metadata,
|
...metadata,
|
||||||
base: {
|
base: {
|
||||||
...metadata.base,
|
...metadata.base,
|
||||||
@ -95,7 +95,7 @@ describe("Search Asset", () => {
|
|||||||
const ddos: DDO[] = await ocean.assets.search(`Test1${testHash}`)
|
const ddos: DDO[] = await ocean.assets.search(`Test1${testHash}`)
|
||||||
|
|
||||||
assert.equal(ddos.length - test1length, 1, "Something was wrong searching the assets")
|
assert.equal(ddos.length - test1length, 1, "Something was wrong searching the assets")
|
||||||
ddos.map(ddo => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO"))
|
ddos.map((ddo) => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO"))
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to do a query to get a list of DDOs", async () => {
|
it("should be able to do a query to get a list of DDOs", async () => {
|
||||||
@ -112,6 +112,6 @@ describe("Search Asset", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
assert.equal(ddos.length, 1, "Something was wrong searching the assets")
|
assert.equal(ddos.length, 1, "Something was wrong searching the assets")
|
||||||
ddos.map(ddo => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO"))
|
ddos.map((ddo) => assert.instanceOf(ddo, DDO, "The DDO is not an instance of a DDO"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -16,7 +16,8 @@ describe("Signature", () => {
|
|||||||
before(async () => {
|
before(async () => {
|
||||||
await Ocean.getInstance({
|
await Ocean.getInstance({
|
||||||
...config,
|
...config,
|
||||||
web3Provider: new (Web3 as any).providers.HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"),
|
web3Provider: new (Web3 as any).providers
|
||||||
|
.HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"),
|
||||||
})
|
})
|
||||||
|
|
||||||
// Accounts
|
// Accounts
|
||||||
@ -69,8 +70,8 @@ describe("Signature", () => {
|
|||||||
metadata: {
|
metadata: {
|
||||||
base: {
|
base: {
|
||||||
price: 10,
|
price: 10,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
} as any,
|
} as any,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
@ -15,13 +15,13 @@
|
|||||||
"integration:cover": "nyc --report-dir coverage/integration mocha-parallel-tests --max-parallel 1 --opts integration/mocha.opts",
|
"integration:cover": "nyc --report-dir coverage/integration mocha-parallel-tests --max-parallel 1 --opts integration/mocha.opts",
|
||||||
"examples": "./src/examples/fire_lazers.sh",
|
"examples": "./src/examples/fire_lazers.sh",
|
||||||
"clean": "rm -rf ./dist/ ./doc/ ./coverage ./.nyc_output",
|
"clean": "rm -rf ./dist/ ./doc/ ./coverage ./.nyc_output",
|
||||||
"lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts'",
|
"lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts' 'integration/**/*.ts'",
|
||||||
"start": "npm link @oceanprotocol/keeper-contracts @oceanprotocol/secret-store-client && npm run build:watch",
|
"start": "npm link @oceanprotocol/keeper-contracts @oceanprotocol/secret-store-client && npm run build:watch",
|
||||||
"build": "npm run clean && npm run build:tsc && npm run build:dist",
|
"build": "npm run clean && npm run build:tsc && npm run build:dist",
|
||||||
"build:tsc": "tsc --sourceMap",
|
"build:tsc": "tsc --sourceMap",
|
||||||
"build:dist": "cross-env NODE_ENV=production webpack",
|
"build:dist": "cross-env NODE_ENV=production webpack",
|
||||||
"build:watch": "tsc -w",
|
"build:watch": "tsc -w",
|
||||||
"doc": "typedoc --mode modules --out ./doc/ ./src/",
|
"doc": "typedoc --mode modules --exclude \"**/examples/**\" --out ./doc/ ./src/",
|
||||||
"report-coverage": "cat ./coverage/unit/lcov.info | codacy-coverage --token 71ef0d15f6f04ac29b31d704b28f866a",
|
"report-coverage": "cat ./coverage/unit/lcov.info | codacy-coverage --token 71ef0d15f6f04ac29b31d704b28f866a",
|
||||||
"run": "ts-node",
|
"run": "ts-node",
|
||||||
"release": "./node_modules/release-it/bin/release-it.js --src.tagName='v%s' --github.release --npm.publish --non-interactive",
|
"release": "./node_modules/release-it/bin/release-it.js --src.tagName='v%s' --github.release --npm.publish --non-interactive",
|
||||||
|
@ -10,7 +10,7 @@ export interface ServiceAgreementTemplateEvent {
|
|||||||
handler: {
|
handler: {
|
||||||
moduleName: string
|
moduleName: string
|
||||||
functionName: string
|
functionName: string
|
||||||
version: string
|
version: string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,12 +101,12 @@ export class Keeper {
|
|||||||
*/
|
*/
|
||||||
public getConditionByAddress(address: string): Condition {
|
public getConditionByAddress(address: string): Condition {
|
||||||
return Object.values(this.conditions)
|
return Object.values(this.conditions)
|
||||||
.find(condition => condition.getAddress() === address)
|
.find((condition) => condition.getAddress() === address)
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTemplateByName(name: string): AgreementTemplate {
|
public getTemplateByName(name: string): AgreementTemplate {
|
||||||
return Object.values(this.templates)
|
return Object.values(this.templates)
|
||||||
.find(template => template.contractName === name)
|
.find((template) => template.contractName === name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,9 +7,9 @@ import Web3Provider from "../Web3Provider"
|
|||||||
export default abstract class ContractBase {
|
export default abstract class ContractBase {
|
||||||
|
|
||||||
protected static instance = null
|
protected static instance = null
|
||||||
|
public contractName: string
|
||||||
|
|
||||||
private contract: Contract = null
|
private contract: Contract = null
|
||||||
contractName: string
|
|
||||||
|
|
||||||
constructor(contractName) {
|
constructor(contractName) {
|
||||||
this.contractName = contractName
|
this.contractName = contractName
|
||||||
@ -101,7 +101,7 @@ export default abstract class ContractBase {
|
|||||||
|
|
||||||
private searchMethod(methodName: string, args: any[] = []) {
|
private searchMethod(methodName: string, args: any[] = []) {
|
||||||
const methods = this.contract.options.jsonInterface
|
const methods = this.contract.options.jsonInterface
|
||||||
.map(method => ({...method, signature: (method as any).signature}))
|
.map((method) => ({...method, signature: (method as any).signature}))
|
||||||
.filter((method: any) => method.name === methodName)
|
.filter((method: any) => method.name === methodName)
|
||||||
const foundMethod = methods.find(({inputs}) => inputs.length === args.length) || methods[0]
|
const foundMethod = methods.find(({inputs}) => inputs.length === args.length) || methods[0]
|
||||||
if (!foundMethod) {
|
if (!foundMethod) {
|
||||||
|
@ -7,15 +7,15 @@ export class AccessSecretStoreCondition extends Condition {
|
|||||||
return Condition.getInstance("AccessSecretStoreCondition", AccessSecretStoreCondition)
|
return Condition.getInstance("AccessSecretStoreCondition", AccessSecretStoreCondition)
|
||||||
}
|
}
|
||||||
|
|
||||||
hashValues(did: string, grantee: string) {
|
public hashValues(did: string, grantee: string) {
|
||||||
return super.hashValues(zeroX(did), zeroX(grantee))
|
return super.hashValues(zeroX(did), zeroX(grantee))
|
||||||
}
|
}
|
||||||
|
|
||||||
fulfill(agreementId: string, did: string, grantee: string, from?: string) {
|
public fulfill(agreementId: string, did: string, grantee: string, from?: string) {
|
||||||
return super.fulfill(agreementId, [didZeroX(did), grantee].map(zeroX), from)
|
return super.fulfill(agreementId, [didZeroX(did), grantee].map(zeroX), from)
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPermissions(grantee: string, did: string, from?: string) {
|
public checkPermissions(grantee: string, did: string, from?: string) {
|
||||||
return this.call<boolean>("checkPermissions", [grantee, didZeroX(did)].map(zeroX), from)
|
return this.call<boolean>("checkPermissions", [grantee, didZeroX(did)].map(zeroX), from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,35 +14,34 @@ export const conditionStateNames = ["Uninitialized", "Unfulfilled", "Fulfilled",
|
|||||||
|
|
||||||
export abstract class Condition extends ContractBase {
|
export abstract class Condition extends ContractBase {
|
||||||
|
|
||||||
protected constructor(contractName: string) {
|
|
||||||
super(contractName)
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async getInstance(conditionName: string, conditionsClass: any): Promise<Condition & any> {
|
public static async getInstance(conditionName: string, conditionsClass: any): Promise<Condition & any> {
|
||||||
const condition: Condition = new (conditionsClass as any)(conditionName)
|
const condition: Condition = new (conditionsClass as any)(conditionName)
|
||||||
await condition.init()
|
await condition.init()
|
||||||
return condition
|
return condition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected constructor(contractName: string) {
|
||||||
|
super(contractName)
|
||||||
|
}
|
||||||
|
|
||||||
hashValues(...args: any[]): Promise<string> {
|
public hashValues(...args: any[]): Promise<string> {
|
||||||
return this.call("hashValues", args)
|
return this.call("hashValues", args)
|
||||||
}
|
}
|
||||||
|
|
||||||
fulfill(agreementId: string, ...args: any[])
|
public fulfill(agreementId: string, ...args: any[])
|
||||||
fulfill(agreementId: string, args: any[], from?: string) {
|
public fulfill(agreementId: string, args: any[], from?: string) {
|
||||||
return this.sendFrom("fulfill", [zeroX(agreementId), ...args], from)
|
return this.sendFrom("fulfill", [zeroX(agreementId), ...args], from)
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateIdHash(agreementId: string, ...values: any[]) {
|
public async generateIdHash(agreementId: string, ...values: any[]) {
|
||||||
return this.generateId(agreementId, await this.hashValues(...values))
|
return this.generateId(agreementId, await this.hashValues(...values))
|
||||||
}
|
}
|
||||||
|
|
||||||
generateId(agreementId: string, valueHash: string) {
|
public generateId(agreementId: string, valueHash: string) {
|
||||||
return this.call<string>("generateId", [zeroX(agreementId), valueHash])
|
return this.call<string>("generateId", [zeroX(agreementId), valueHash])
|
||||||
}
|
}
|
||||||
|
|
||||||
abortByTimeOut(agreementId: string, from?: string) {
|
public abortByTimeOut(agreementId: string, from?: string) {
|
||||||
return this.sendFrom("abortByTimeOut", [zeroX(agreementId)], from)
|
return this.sendFrom("abortByTimeOut", [zeroX(agreementId)], from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,11 +7,11 @@ export class EscrowReward extends Condition {
|
|||||||
return Condition.getInstance("EscrowReward", EscrowReward)
|
return Condition.getInstance("EscrowReward", EscrowReward)
|
||||||
}
|
}
|
||||||
|
|
||||||
hashValues(amount: number, receiver: string, sender: string, lockCondition: string, releaseCondition: string) {
|
public hashValues(amount: number, receiver: string, sender: string, lockCondition: string, releaseCondition: string) {
|
||||||
return super.hashValues(amount, ...[receiver, sender, lockCondition, releaseCondition].map(zeroX))
|
return super.hashValues(amount, ...[receiver, sender, lockCondition, releaseCondition].map(zeroX))
|
||||||
}
|
}
|
||||||
|
|
||||||
fulfill(
|
public fulfill(
|
||||||
agreementId: string,
|
agreementId: string,
|
||||||
amount: number,
|
amount: number,
|
||||||
receiver: string,
|
receiver: string,
|
||||||
|
@ -7,11 +7,11 @@ export class LockRewardCondition extends Condition {
|
|||||||
return Condition.getInstance("LockRewardCondition", LockRewardCondition)
|
return Condition.getInstance("LockRewardCondition", LockRewardCondition)
|
||||||
}
|
}
|
||||||
|
|
||||||
hashValues(rewardAddress: string, amount: number) {
|
public hashValues(rewardAddress: string, amount: number) {
|
||||||
return super.hashValues(zeroX(rewardAddress), amount)
|
return super.hashValues(zeroX(rewardAddress), amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
fulfill(agreementId: string, rewardAddress: string, amount: number, from?: string) {
|
public fulfill(agreementId: string, rewardAddress: string, amount: number, from?: string) {
|
||||||
return super.fulfill(agreementId, [zeroX(rewardAddress), amount], from)
|
return super.fulfill(agreementId, [zeroX(rewardAddress), amount], from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export * from './Condition.abstract'
|
export * from "./Condition.abstract"
|
||||||
export { AccessSecretStoreCondition } from './AccessSecretStoreCondition'
|
export { AccessSecretStoreCondition } from "./AccessSecretStoreCondition"
|
||||||
export { EscrowReward } from './EscrowReward'
|
export { EscrowReward } from "./EscrowReward"
|
||||||
export { LockRewardCondition } from './LockRewardCondition'
|
export { LockRewardCondition } from "./LockRewardCondition"
|
||||||
|
@ -19,7 +19,7 @@ export class AgreementStoreManager extends ContractBase {
|
|||||||
return templateStoreManeger
|
return templateStoreManeger
|
||||||
}
|
}
|
||||||
|
|
||||||
getOwner(): Promise<string> {
|
public getOwner(): Promise<string> {
|
||||||
return this.call("owner", [])
|
return this.call("owner", [])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ export class ConditionStoreManager extends ContractBase {
|
|||||||
return templateStoreManeger
|
return templateStoreManeger
|
||||||
}
|
}
|
||||||
|
|
||||||
getOwner(): Promise<string> {
|
public getOwner(): Promise<string> {
|
||||||
return this.call("owner", [])
|
return this.call("owner", [])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ export class TemplateStoreManager extends ContractBase {
|
|||||||
return templateStoreManeger
|
return templateStoreManeger
|
||||||
}
|
}
|
||||||
|
|
||||||
getOwner(): Promise<string> {
|
public getOwner(): Promise<string> {
|
||||||
return this.call("owner", [])
|
return this.call("owner", [])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
export * from './AgreementStoreManager'
|
export * from "./AgreementStoreManager"
|
||||||
export * from './ConditionStoreManager'
|
export * from "./ConditionStoreManager"
|
||||||
export * from './TemplateStoreManager'
|
export * from "./TemplateStoreManager"
|
||||||
|
@ -2,24 +2,24 @@ import ContractBase from "../ContractBase"
|
|||||||
import { AgreementStoreManager, ConditionStoreManager } from "../managers"
|
import { AgreementStoreManager, ConditionStoreManager } from "../managers"
|
||||||
import { Condition, ConditionState, conditionStateNames } from "../conditions/Condition.abstract"
|
import { Condition, ConditionState, conditionStateNames } from "../conditions/Condition.abstract"
|
||||||
import Keeper from "../../Keeper"
|
import Keeper from "../../Keeper"
|
||||||
import { DDO } from '../../../ddo/DDO'
|
import { DDO } from "../../../ddo/DDO"
|
||||||
import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate'
|
import { ServiceAgreementTemplate } from "../../../ddo/ServiceAgreementTemplate"
|
||||||
import { zeroX, Logger } from "../../../utils"
|
import { zeroX, Logger } from "../../../utils"
|
||||||
import EventListener from "../../../keeper/EventListener"
|
import EventListener from "../../../keeper/EventListener"
|
||||||
import Event from "../../../keeper/Event"
|
import Event from "../../../keeper/Event"
|
||||||
|
|
||||||
export abstract class AgreementTemplate extends ContractBase {
|
export abstract class AgreementTemplate extends ContractBase {
|
||||||
|
|
||||||
protected constructor(contractName: string) {
|
|
||||||
super(contractName)
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async getInstance(conditionName: string, templateClass: any): Promise<AgreementTemplate & any> {
|
public static async getInstance(conditionName: string, templateClass: any): Promise<AgreementTemplate & any> {
|
||||||
const condition: AgreementTemplate = new (templateClass as any)(conditionName)
|
const condition: AgreementTemplate = new (templateClass as any)(conditionName)
|
||||||
await condition.init()
|
await condition.init()
|
||||||
return condition
|
return condition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected constructor(contractName: string) {
|
||||||
|
super(contractName)
|
||||||
|
}
|
||||||
|
|
||||||
// tslint:disable-next-line
|
// 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[], ...args: any[])
|
||||||
public createAgreement(
|
public createAgreement(
|
||||||
@ -60,7 +60,7 @@ export abstract class AgreementTemplate extends ContractBase {
|
|||||||
public async getConditions(): Promise<Condition[]> {
|
public async getConditions(): Promise<Condition[]> {
|
||||||
const keeper = await Keeper.getInstance()
|
const keeper = await Keeper.getInstance()
|
||||||
return (await this.getConditionTypes())
|
return (await this.getConditionTypes())
|
||||||
.map(address => keeper.getConditionByAddress(address))
|
.map((address) => keeper.getConditionByAddress(address))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,7 +70,7 @@ export abstract class AgreementTemplate extends ContractBase {
|
|||||||
* @param {string} from Consumer address.
|
* @param {string} from Consumer address.
|
||||||
* @return {Promise<string[]>} Condition IDs.
|
* @return {Promise<string[]>} Condition IDs.
|
||||||
*/
|
*/
|
||||||
abstract getAgreementIdsFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string): Promise<string[]>
|
public abstract getAgreementIdsFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string): Promise<string[]>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new agreement using the data of a DDO.
|
* Create a new agreement using the data of a DDO.
|
||||||
@ -79,9 +79,9 @@ export abstract class AgreementTemplate extends ContractBase {
|
|||||||
* @param {string} from Creator address.
|
* @param {string} from Creator address.
|
||||||
* @return {Promise<boolean>} Success.
|
* @return {Promise<boolean>} Success.
|
||||||
*/
|
*/
|
||||||
abstract createAgreementFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string): Promise<boolean>
|
public abstract createAgreementFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string): Promise<boolean>
|
||||||
|
|
||||||
abstract async getServiceAgreementTemplate(): Promise<ServiceAgreementTemplate>
|
public abstract async getServiceAgreementTemplate(): Promise<ServiceAgreementTemplate>
|
||||||
|
|
||||||
public async getServiceAgreementTemplateConditions() {
|
public async getServiceAgreementTemplateConditions() {
|
||||||
const serviceAgreementTemplate = await this.getServiceAgreementTemplate()
|
const serviceAgreementTemplate = await this.getServiceAgreementTemplate()
|
||||||
@ -93,7 +93,7 @@ export abstract class AgreementTemplate extends ContractBase {
|
|||||||
.find(({name: conditionRef}) => conditionRef === ref)
|
.find(({name: conditionRef}) => conditionRef === ref)
|
||||||
.contractName
|
.contractName
|
||||||
return (await this.getConditions())
|
return (await this.getConditions())
|
||||||
.find(condition => condition.contractName === name)
|
.find((condition) => condition.contractName === name)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getServiceAgreementTemplateDependencies() {
|
public async getServiceAgreementTemplateDependencies() {
|
||||||
@ -107,15 +107,15 @@ export abstract class AgreementTemplate extends ContractBase {
|
|||||||
* @return {Promise} Conditions status.
|
* @return {Promise} Conditions status.
|
||||||
*/
|
*/
|
||||||
public async getAgreementStatus(
|
public async getAgreementStatus(
|
||||||
agreementId: string
|
agreementId: string,
|
||||||
): Promise<{
|
): Promise<{
|
||||||
[condition: string]: {
|
[condition: string]: {
|
||||||
condition: string,
|
condition: string,
|
||||||
contractName: string,
|
contractName: string,
|
||||||
state: ConditionState,
|
state: ConditionState,
|
||||||
blocked: boolean,
|
blocked: boolean,
|
||||||
blockedBy: string[]
|
blockedBy: string[],
|
||||||
}
|
},
|
||||||
} | false> {
|
} | false> {
|
||||||
const agreementStore = await AgreementStoreManager.getInstance()
|
const agreementStore = await AgreementStoreManager.getInstance()
|
||||||
const conditionStore = await ConditionStoreManager.getInstance()
|
const conditionStore = await ConditionStoreManager.getInstance()
|
||||||
@ -137,7 +137,7 @@ export abstract class AgreementTemplate extends ContractBase {
|
|||||||
return {
|
return {
|
||||||
ref,
|
ref,
|
||||||
contractName,
|
contractName,
|
||||||
state: (await conditionStore.getCondition(conditionIdByConddition[contractName])).state
|
state: (await conditionStore.getCondition(conditionIdByConddition[contractName])).state,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const states = await Promise.all(statesPromises)
|
const states = await Promise.all(statesPromises)
|
||||||
@ -145,8 +145,8 @@ export abstract class AgreementTemplate extends ContractBase {
|
|||||||
return states
|
return states
|
||||||
.reduce((acc, {contractName, ref, state}) => {
|
.reduce((acc, {contractName, ref, state}) => {
|
||||||
const blockers = dependencies[ref]
|
const blockers = dependencies[ref]
|
||||||
.map(dependency => states.find(({ref}) => ref === dependency))
|
.map((dependency) => states.find((_) => _.ref === dependency))
|
||||||
.filter(condition => condition.state !== ConditionState.Fulfilled)
|
.filter((condition) => condition.state !== ConditionState.Fulfilled)
|
||||||
return {
|
return {
|
||||||
...acc,
|
...acc,
|
||||||
[ref]: {
|
[ref]: {
|
||||||
@ -154,8 +154,8 @@ export abstract class AgreementTemplate extends ContractBase {
|
|||||||
contractName,
|
contractName,
|
||||||
state,
|
state,
|
||||||
blocked: !!blockers.length,
|
blocked: !!blockers.length,
|
||||||
blockedBy: blockers.map(_ => _.ref),
|
blockedBy: blockers.map((_) => _.ref),
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
|
@ -1,145 +1,145 @@
|
|||||||
import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate'
|
import { ServiceAgreementTemplate } from "../../../ddo/ServiceAgreementTemplate"
|
||||||
|
|
||||||
export const escrowAccessSecretStoreTemplateServiceAgreementTemplate: ServiceAgreementTemplate = {
|
export const escrowAccessSecretStoreTemplateServiceAgreementTemplate: ServiceAgreementTemplate = {
|
||||||
"contractName": "EscrowAccessSecretStoreTemplate",
|
contractName: "EscrowAccessSecretStoreTemplate",
|
||||||
"events": [
|
events: [
|
||||||
{
|
{
|
||||||
"name": "AgreementCreated",
|
name: "AgreementCreated",
|
||||||
"actorType": "consumer",
|
actorType: "consumer",
|
||||||
"handler": {
|
handler: {
|
||||||
"moduleName": "escrowAccessSecretStoreTemplate",
|
moduleName: "escrowAccessSecretStoreTemplate",
|
||||||
"functionName": "fulfillLockRewardCondition",
|
functionName: "fulfillLockRewardCondition",
|
||||||
"version": "0.1"
|
version: "0.1",
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
"fulfillmentOrder": [
|
fulfillmentOrder: [
|
||||||
"lockReward.fulfill",
|
"lockReward.fulfill",
|
||||||
"accessSecretStore.fulfill",
|
"accessSecretStore.fulfill",
|
||||||
"escrowReward.fulfill"
|
"escrowReward.fulfill",
|
||||||
],
|
],
|
||||||
"conditionDependency": {
|
conditionDependency: {
|
||||||
"lockReward": [],
|
lockReward: [],
|
||||||
"accessSecretStore": [],
|
accessSecretStore: [],
|
||||||
"escrowReward": [
|
escrowReward: [
|
||||||
"lockReward",
|
"lockReward",
|
||||||
"accessSecretStore"
|
"accessSecretStore",
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
"conditions": [
|
conditions: [
|
||||||
{
|
{
|
||||||
"name": "lockReward",
|
name: "lockReward",
|
||||||
"timelock": 0,
|
timelock: 0,
|
||||||
"timeout": 0,
|
timeout: 0,
|
||||||
"contractName": "LockRewardCondition",
|
contractName: "LockRewardCondition",
|
||||||
"functionName": "fulfill",
|
functionName: "fulfill",
|
||||||
"parameters": [
|
parameters: [
|
||||||
{
|
{
|
||||||
"name": "_rewardAddress",
|
name: "_rewardAddress",
|
||||||
"type": "address",
|
type: "address",
|
||||||
"value": ""
|
value: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "_amount",
|
name: "_amount",
|
||||||
"type": "uint256",
|
type: "uint256",
|
||||||
"value": ""
|
value: "",
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
"events": [
|
events: [
|
||||||
{
|
{
|
||||||
"name": "Fulfilled",
|
name: "Fulfilled",
|
||||||
"actorType": "publisher",
|
actorType: "publisher",
|
||||||
"handler": {
|
handler: {
|
||||||
"moduleName": "lockRewardCondition",
|
moduleName: "lockRewardCondition",
|
||||||
"functionName": "fulfillAccessSecretStoreCondition",
|
functionName: "fulfillAccessSecretStoreCondition",
|
||||||
"version": "0.1"
|
version: "0.1",
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "accessSecretStore",
|
name: "accessSecretStore",
|
||||||
"timelock": 0,
|
timelock: 0,
|
||||||
"timeout": 0,
|
timeout: 0,
|
||||||
"contractName": "AccessSecretStoreCondition",
|
contractName: "AccessSecretStoreCondition",
|
||||||
"functionName": "fulfill",
|
functionName: "fulfill",
|
||||||
"parameters": [
|
parameters: [
|
||||||
{
|
{
|
||||||
"name": "_documentId",
|
name: "_documentId",
|
||||||
"type": "bytes32",
|
type: "bytes32",
|
||||||
"value": ""
|
value: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "_grantee",
|
name: "_grantee",
|
||||||
"type": "address",
|
type: "address",
|
||||||
"value": ""
|
value: "",
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
"events": [
|
events: [
|
||||||
{
|
{
|
||||||
"name": "Fulfilled",
|
name: "Fulfilled",
|
||||||
"actorType": "publisher",
|
actorType: "publisher",
|
||||||
"handler": {
|
handler: {
|
||||||
"moduleName": "accessSecretStore",
|
moduleName: "accessSecretStore",
|
||||||
"functionName": "fulfillEscrowRewardCondition",
|
functionName: "fulfillEscrowRewardCondition",
|
||||||
"version": "0.1"
|
version: "0.1",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "TimedOut",
|
name: "TimedOut",
|
||||||
"actorType": "consumer",
|
actorType: "consumer",
|
||||||
"handler": {
|
handler: {
|
||||||
"moduleName": "accessSecretStore",
|
moduleName: "accessSecretStore",
|
||||||
"functionName": "fulfillEscrowRewardCondition",
|
functionName: "fulfillEscrowRewardCondition",
|
||||||
"version": "0.1"
|
version: "0.1",
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "escrowReward",
|
name: "escrowReward",
|
||||||
"timelock": 0,
|
timelock: 0,
|
||||||
"timeout": 0,
|
timeout: 0,
|
||||||
"contractName": "EscrowReward",
|
contractName: "EscrowReward",
|
||||||
"functionName": "fulfill",
|
functionName: "fulfill",
|
||||||
"parameters": [
|
parameters: [
|
||||||
{
|
{
|
||||||
"name": "_amount",
|
name: "_amount",
|
||||||
"type": "uint256",
|
type: "uint256",
|
||||||
"value": ""
|
value: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "_receiver",
|
name: "_receiver",
|
||||||
"type": "address",
|
type: "address",
|
||||||
"value": ""
|
value: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "_sender",
|
name: "_sender",
|
||||||
"type": "address",
|
type: "address",
|
||||||
"value": ""
|
value: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "_lockCondition",
|
name: "_lockCondition",
|
||||||
"type": "bytes32",
|
type: "bytes32",
|
||||||
"value": ""
|
value: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "_releaseCondition",
|
name: "_releaseCondition",
|
||||||
"type": "bytes32",
|
type: "bytes32",
|
||||||
"value": ""
|
value: "",
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
"events": [
|
events: [
|
||||||
{
|
{
|
||||||
"name": "Fulfilled",
|
name: "Fulfilled",
|
||||||
"actorType": "publisher",
|
actorType: "publisher",
|
||||||
"handler": {
|
handler: {
|
||||||
"moduleName": "escrowRewardCondition",
|
moduleName: "escrowRewardCondition",
|
||||||
"functionName": "verifyRewardTokens",
|
functionName: "verifyRewardTokens",
|
||||||
"version": "0.1"
|
version: "0.1",
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { AgreementTemplate } from "./AgreementTemplate.abstract"
|
import { AgreementTemplate } from "./AgreementTemplate.abstract"
|
||||||
import { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } from '../conditions'
|
import { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } from "../conditions"
|
||||||
import DIDRegistry from '../DIDRegistry'
|
import DIDRegistry from "../DIDRegistry"
|
||||||
import { DDO } from '../../../ddo/DDO'
|
import { DDO } from "../../../ddo/DDO"
|
||||||
import { generateId, zeroX } from '../../../utils'
|
import { generateId, zeroX } from "../../../utils"
|
||||||
|
|
||||||
import { escrowAccessSecretStoreTemplateServiceAgreementTemplate } from "./EscrowAccessSecretStoreTemplate.serviceAgreementTemplate"
|
import { escrowAccessSecretStoreTemplateServiceAgreementTemplate } from "./EscrowAccessSecretStoreTemplate.serviceAgreementTemplate"
|
||||||
|
|
||||||
@ -47,7 +47,6 @@ export class EscrowAccessSecretStoreTemplate extends AgreementTemplate {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async createAgreementFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string) {
|
public async createAgreementFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string) {
|
||||||
return !!await this.createFullAgreement(
|
return !!await this.createFullAgreement(
|
||||||
ddo.shortId(),
|
ddo.shortId(),
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
export * from './AgreementTemplate.abstract'
|
export * from "./AgreementTemplate.abstract"
|
||||||
export { EscrowAccessSecretStoreTemplate } from './EscrowAccessSecretStoreTemplate'
|
export { EscrowAccessSecretStoreTemplate } from "./EscrowAccessSecretStoreTemplate"
|
||||||
|
@ -43,7 +43,6 @@ export default class OceanAgreementsConditions {
|
|||||||
return !!receipt.events.Fulfilled
|
return !!receipt.events.Fulfilled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authorize the consumer defined in the agreement to access (consume) this asset.
|
* Authorize the consumer defined in the agreement to access (consume) this asset.
|
||||||
* @param {string} agreementId Agreement ID.
|
* @param {string} agreementId Agreement ID.
|
||||||
|
@ -4,16 +4,14 @@ import BrizoProvider from "../brizo/BrizoProvider"
|
|||||||
import ConfigProvider from "../ConfigProvider"
|
import ConfigProvider from "../ConfigProvider"
|
||||||
import { DDO } from "../ddo/DDO"
|
import { DDO } from "../ddo/DDO"
|
||||||
import { MetaData } from "../ddo/MetaData"
|
import { MetaData } from "../ddo/MetaData"
|
||||||
import { ServiceAgreementTemplate, ServiceAgreementTemplateCondition } from "../ddo/ServiceAgreementTemplate"
|
import { ServiceAgreementTemplateCondition } from "../ddo/ServiceAgreementTemplate"
|
||||||
import { Service, ServiceAuthorization } from "../ddo/Service"
|
import { Service, ServiceAuthorization } from "../ddo/Service"
|
||||||
import EventListener from "../keeper/EventListener"
|
|
||||||
import Keeper from "../keeper/Keeper"
|
import Keeper from "../keeper/Keeper"
|
||||||
import SecretStoreProvider from "../secretstore/SecretStoreProvider"
|
import SecretStoreProvider from "../secretstore/SecretStoreProvider"
|
||||||
import { Logger, fillConditionsWithDDO } from "../utils"
|
import { Logger, fillConditionsWithDDO } from "../utils"
|
||||||
import Account from "./Account"
|
import Account from "./Account"
|
||||||
import DID from "./DID"
|
import DID from "./DID"
|
||||||
import OceanAgreements from "./OceanAgreements"
|
import OceanAgreements from "./OceanAgreements"
|
||||||
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assets submodule of Ocean Protocol.
|
* Assets submodule of Ocean Protocol.
|
||||||
@ -70,7 +68,7 @@ export default class OceanAssets {
|
|||||||
|
|
||||||
const encryptedFiles = await SecretStoreProvider.getSecretStore(secretStoreConfig).encryptDocument(did.getId(), metadata.base.files)
|
const encryptedFiles = await SecretStoreProvider.getSecretStore(secretStoreConfig).encryptDocument(did.getId(), metadata.base.files)
|
||||||
|
|
||||||
const serviceAgreementTemplate: ServiceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate()
|
const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate()
|
||||||
|
|
||||||
const serviceEndpoint = aquarius.getServiceEndpoint(did)
|
const serviceEndpoint = aquarius.getServiceEndpoint(did)
|
||||||
|
|
||||||
@ -145,8 +143,8 @@ export default class OceanAssets {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Overwritte initial service agreement conditions
|
// Overwritte initial service agreement conditions
|
||||||
const rawConditions: ServiceAgreementTemplateCondition[] = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplateConditions()
|
const rawConditions = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplateConditions()
|
||||||
const conditions: ServiceAgreementTemplateCondition[] = fillConditionsWithDDO(rawConditions, ddo)
|
const conditions = fillConditionsWithDDO(rawConditions, ddo)
|
||||||
serviceAgreementTemplate.conditions = conditions
|
serviceAgreementTemplate.conditions = conditions
|
||||||
|
|
||||||
ddo.addChecksum()
|
ddo.addChecksum()
|
||||||
|
@ -7,7 +7,6 @@ import Logger from "../../utils/Logger"
|
|||||||
import Account from "../Account"
|
import Account from "../Account"
|
||||||
import { signText, zeroX } from "../../utils"
|
import { signText, zeroX } from "../../utils"
|
||||||
|
|
||||||
|
|
||||||
// TODO: move this class to helpers, it only contains pure functions
|
// TODO: move this class to helpers, it only contains pure functions
|
||||||
export default class ServiceAgreement {
|
export default class ServiceAgreement {
|
||||||
|
|
||||||
@ -58,7 +57,7 @@ export default class ServiceAgreement {
|
|||||||
timeoutValues,
|
timeoutValues,
|
||||||
)
|
)
|
||||||
|
|
||||||
let serviceAgreementHashSignature = await signText(serviceAgreementHash, consumer.getId(), consumer.getPassword())
|
const serviceAgreementHashSignature = await signText(serviceAgreementHash, consumer.getId(), consumer.getPassword())
|
||||||
|
|
||||||
return serviceAgreementHashSignature
|
return serviceAgreementHashSignature
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Logger } from './Logger'
|
import { Logger } from "./Logger"
|
||||||
|
|
||||||
// Ox transformer
|
// Ox transformer
|
||||||
export const zeroX = (input: string) => zeroXTransformer(input, true)
|
export const zeroX = (input: string) => zeroXTransformer(input, true)
|
||||||
@ -24,12 +24,12 @@ function inputMatch(input: string, regexp: RegExp, conversorName: string): {vali
|
|||||||
if (typeof input !== "string") {
|
if (typeof input !== "string") {
|
||||||
Logger.debug("Not input string:")
|
Logger.debug("Not input string:")
|
||||||
Logger.debug(input)
|
Logger.debug(input)
|
||||||
throw new Error(`[${conversorName}] Expected string, input type: ${typeof input}`);
|
throw new Error(`[${conversorName}] Expected string, input type: ${typeof input}`)
|
||||||
}
|
}
|
||||||
const match = input.match(regexp)
|
const match = input.match(regexp)
|
||||||
if (!match) {
|
if (!match) {
|
||||||
Logger.warn(`[${conversorName}] Input transformation failed.`)
|
Logger.warn(`[${conversorName}] Input transformation failed.`)
|
||||||
return {valid: false, output: input}
|
return {valid: false, output: input}
|
||||||
}
|
}
|
||||||
return {valid: true, output: match[1]}
|
return {valid: true, output: match[1]}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { DDO } from "../ddo/DDO"
|
|||||||
import { ServiceAgreementTemplateCondition, ServiceAgreementTemplateParameter } from "../ddo/ServiceAgreementTemplate"
|
import { ServiceAgreementTemplateCondition, ServiceAgreementTemplateParameter } from "../ddo/ServiceAgreementTemplate"
|
||||||
|
|
||||||
function fillParameterWithDDO(parameter: ServiceAgreementTemplateParameter, ddo: DDO): ServiceAgreementTemplateParameter {
|
function fillParameterWithDDO(parameter: ServiceAgreementTemplateParameter, ddo: DDO): ServiceAgreementTemplateParameter {
|
||||||
const getValue = name => {
|
const getValue = (name) => {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "amount":
|
case "amount":
|
||||||
case "price":
|
case "price":
|
||||||
@ -28,11 +28,11 @@ function fillParameterWithDDO(parameter: ServiceAgreementTemplateParameter, ddo:
|
|||||||
*/
|
*/
|
||||||
export function fillConditionsWithDDO(conditions: ServiceAgreementTemplateCondition[], ddo: DDO): ServiceAgreementTemplateCondition[] {
|
export function fillConditionsWithDDO(conditions: ServiceAgreementTemplateCondition[], ddo: DDO): ServiceAgreementTemplateCondition[] {
|
||||||
return conditions
|
return conditions
|
||||||
.map(condition => ({
|
.map((condition) => ({
|
||||||
...condition,
|
...condition,
|
||||||
parameters: condition.parameters
|
parameters: condition.parameters
|
||||||
.map(parameter => ({
|
.map((parameter) => ({
|
||||||
...fillParameterWithDDO(parameter, ddo)
|
...fillParameterWithDDO(parameter, ddo),
|
||||||
}))
|
})),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ export class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static bypass(...args: any[]) {
|
public static bypass(...args: any[]) {
|
||||||
Logger.dispatch("log", <any>-Infinity, ...args)
|
Logger.dispatch("log", -Infinity as any, ...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static debug(...args: any[]) {
|
public static debug(...args: any[]) {
|
||||||
|
@ -11,7 +11,7 @@ export async function signText(text: string, publicKey: string, password?: strin
|
|||||||
Logger.error(e)
|
Logger.error(e)
|
||||||
try {
|
try {
|
||||||
return await web3.eth.sign(text, publicKey, password)
|
return await web3.eth.sign(text, publicKey, password)
|
||||||
} catch(e2) {
|
} catch (e2) {
|
||||||
Logger.error("Error on sign.")
|
Logger.error("Error on sign.")
|
||||||
Logger.error(e2)
|
Logger.error(e2)
|
||||||
throw new Error("Error executing personal sign")
|
throw new Error("Error executing personal sign")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export { Logger, LogLevel } from './Logger'
|
export { Logger, LogLevel } from "./Logger"
|
||||||
export * from './SignatureHelpers'
|
export * from "./SignatureHelpers"
|
||||||
export * from './ConversionTypeHelpers'
|
export * from "./ConversionTypeHelpers"
|
||||||
export * from './GeneratorHelpers'
|
export * from "./GeneratorHelpers"
|
||||||
export * from './DDOHelpers'
|
export * from "./DDOHelpers"
|
||||||
|
@ -62,7 +62,6 @@ export default class TestContractHandler extends ContractHandler {
|
|||||||
deployerAddress, conditionStoreManager.options.address, token.options.address,
|
deployerAddress, conditionStoreManager.options.address, token.options.address,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
// Templates
|
// Templates
|
||||||
await TestContractHandler.deployContract("EscrowAccessSecretStoreTemplate", deployerAddress, [
|
await TestContractHandler.deployContract("EscrowAccessSecretStoreTemplate", deployerAddress, [
|
||||||
deployerAddress,
|
deployerAddress,
|
||||||
|
@ -9,7 +9,6 @@ import { generateId } from "../../src/utils/GeneratorHelpers"
|
|||||||
import config from "../config"
|
import config from "../config"
|
||||||
import TestContractHandler from "../keeper/TestContractHandler"
|
import TestContractHandler from "../keeper/TestContractHandler"
|
||||||
|
|
||||||
|
|
||||||
const did: DID = DID.generate()
|
const did: DID = DID.generate()
|
||||||
|
|
||||||
describe("ServiceAgreement", () => {
|
describe("ServiceAgreement", () => {
|
||||||
|
@ -20,7 +20,7 @@ describe("ConversionTypeHelpers", () => {
|
|||||||
it("should return the value without 0x prefix", async () => {
|
it("should return the value without 0x prefix", async () => {
|
||||||
const result1 = noZeroX("0x1234")
|
const result1 = noZeroX("0x1234")
|
||||||
const result2 = noZeroX("1234")
|
const result2 = noZeroX("1234")
|
||||||
assert.equal(result1, "1234",)
|
assert.equal(result1, "1234")
|
||||||
assert.equal(result2, "1234")
|
assert.equal(result2, "1234")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
"semicolon": [
|
"semicolon": [
|
||||||
true,
|
true,
|
||||||
"never"
|
"never"
|
||||||
]
|
],
|
||||||
|
"ordered-imports": false
|
||||||
},
|
},
|
||||||
"rulesDirectory": []
|
"rulesDirectory": []
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user