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 { Ocean, MetaData, DDO, DID, Account/*, ServiceAgreement*/ } from '../../src' // @oceanprotocol/squid
|
||||
import { Ocean, MetaData, DDO, DID, Account/*, ServiceAgreement*/ } from "../../src" // @oceanprotocol/squid
|
||||
|
||||
describe("Consume Asset", () => {
|
||||
let ocean: Ocean
|
||||
@ -71,7 +71,7 @@ describe("Consume Asset", () => {
|
||||
})
|
||||
|
||||
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)
|
||||
|
||||
assert.equal((await consumer.getBalance()).ocn, initialBalance + metadata.base.price, "OCN Tokens not delivered")
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { assert } from "chai"
|
||||
import * as Web3 from "web3";
|
||||
import * as fs from "fs";
|
||||
import * as Web3 from "web3"
|
||||
import * as fs from "fs"
|
||||
|
||||
import { config } from "../config"
|
||||
|
||||
@ -17,7 +17,7 @@ describe("Consume Asset (Brizo)", () => {
|
||||
|
||||
const testHash = Math.random().toString(36).substr(2)
|
||||
let metadata: Partial<MetaData>
|
||||
let metadataGenerator = (name: string) => ({
|
||||
const metadataGenerator = (name: string) => ({
|
||||
...metadata,
|
||||
base: {
|
||||
...metadata.base,
|
||||
@ -28,7 +28,8 @@ describe("Consume Asset (Brizo)", () => {
|
||||
before(async () => {
|
||||
ocean = await Ocean.getInstance({
|
||||
...config,
|
||||
web3Provider: new Web3.providers.HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"),
|
||||
web3Provider: new Web3.providers
|
||||
.HttpProvider("http://localhost:8545", 0, "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e", "node0"),
|
||||
})
|
||||
|
||||
// Accounts
|
||||
@ -76,7 +77,7 @@ describe("Consume Asset (Brizo)", () => {
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
@ -99,10 +100,10 @@ describe("Consume Asset (Brizo)", () => {
|
||||
|
||||
assert.include(path, folder, "The storage path is not correct.")
|
||||
|
||||
const files = await new Promise(resolve => {
|
||||
fs.readdir(path, (err, files) => {
|
||||
resolve(files)
|
||||
});
|
||||
const files = await new Promise((resolve) => {
|
||||
fs.readdir(path, (err, fileList) => {
|
||||
resolve(fileList)
|
||||
})
|
||||
})
|
||||
|
||||
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 { 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 { EscrowAccessSecretStoreTemplate } = templates
|
||||
@ -13,7 +13,7 @@ describe("Register Escrow Access Secret Store Template", () => {
|
||||
|
||||
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 escrowAmount = 12
|
||||
|
||||
@ -46,13 +46,13 @@ describe("Register Escrow Access Secret Store Template", () => {
|
||||
it("should propose the template", async () => {
|
||||
await keeper.templateStoreManager.proposeTemplate(template.getAddress(), consumer.getId(), true)
|
||||
// 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 () => {
|
||||
await keeper.templateStoreManager.approveTemplate(template.getAddress(), templateManagerOwner.getId(), true)
|
||||
// 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 () => {
|
||||
const conditions = await template.getConditions()
|
||||
|
||||
assert.equal(conditions.length, 3, "Expected 3 conditions.")
|
||||
const conditionInstances = await template.getConditions()
|
||||
|
||||
assert.equal(conditionInstances.length, 3, "Expected 3 conditions.")
|
||||
|
||||
const conditionClasses = [AccessSecretStoreCondition, EscrowReward, LockRewardCondition]
|
||||
conditionClasses
|
||||
.forEach(conditionClass => {
|
||||
if (!conditions.find(condition => condition instanceof conditionClass)) {
|
||||
throw `${conditionClass.name} is not part of the conditions.`;
|
||||
.forEach((conditionClass) => {
|
||||
if (!conditionInstances.find((condition) => condition instanceof conditionClass)) {
|
||||
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 { Ocean, MetaData, Account, DDO } from '../../src' // @oceanprotocol/squid
|
||||
import { Ocean, MetaData, Account, DDO } from "../../src" // @oceanprotocol/squid
|
||||
|
||||
describe("Search Asset", () => {
|
||||
let ocean: Ocean
|
||||
@ -11,7 +11,7 @@ describe("Search Asset", () => {
|
||||
|
||||
const testHash = Math.random().toString(36).substr(2)
|
||||
let metadata: Partial<MetaData>
|
||||
let metadataGenerator = (name: string) => ({
|
||||
const metadataGenerator = (name: string) => ({
|
||||
...metadata,
|
||||
base: {
|
||||
...metadata.base,
|
||||
@ -95,7 +95,7 @@ describe("Search Asset", () => {
|
||||
const ddos: DDO[] = await ocean.assets.search(`Test1${testHash}`)
|
||||
|
||||
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 () => {
|
||||
@ -112,6 +112,6 @@ describe("Search Asset", () => {
|
||||
})
|
||||
|
||||
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 () => {
|
||||
await Ocean.getInstance({
|
||||
...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
|
||||
@ -69,8 +70,8 @@ describe("Signature", () => {
|
||||
metadata: {
|
||||
base: {
|
||||
price: 10,
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
} as any,
|
||||
],
|
||||
})
|
||||
|
@ -15,13 +15,13 @@
|
||||
"integration:cover": "nyc --report-dir coverage/integration mocha-parallel-tests --max-parallel 1 --opts integration/mocha.opts",
|
||||
"examples": "./src/examples/fire_lazers.sh",
|
||||
"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",
|
||||
"build": "npm run clean && npm run build:tsc && npm run build:dist",
|
||||
"build:tsc": "tsc --sourceMap",
|
||||
"build:dist": "cross-env NODE_ENV=production webpack",
|
||||
"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",
|
||||
"run": "ts-node",
|
||||
"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: {
|
||||
moduleName: string
|
||||
functionName: string
|
||||
version: string
|
||||
version: string,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,12 +101,12 @@ export class Keeper {
|
||||
*/
|
||||
public getConditionByAddress(address: string): Condition {
|
||||
return Object.values(this.conditions)
|
||||
.find(condition => condition.getAddress() === address)
|
||||
.find((condition) => condition.getAddress() === address)
|
||||
}
|
||||
|
||||
public getTemplateByName(name: string): AgreementTemplate {
|
||||
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 {
|
||||
|
||||
protected static instance = null
|
||||
public contractName: string
|
||||
|
||||
private contract: Contract = null
|
||||
contractName: string
|
||||
|
||||
constructor(contractName) {
|
||||
this.contractName = contractName
|
||||
@ -101,7 +101,7 @@ export default abstract class ContractBase {
|
||||
|
||||
private searchMethod(methodName: string, args: any[] = []) {
|
||||
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)
|
||||
const foundMethod = methods.find(({inputs}) => inputs.length === args.length) || methods[0]
|
||||
if (!foundMethod) {
|
||||
|
@ -7,15 +7,15 @@ export class AccessSecretStoreCondition extends Condition {
|
||||
return Condition.getInstance("AccessSecretStoreCondition", AccessSecretStoreCondition)
|
||||
}
|
||||
|
||||
hashValues(did: string, grantee: string) {
|
||||
public hashValues(did: string, grantee: string) {
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -14,35 +14,34 @@ export const conditionStateNames = ["Uninitialized", "Unfulfilled", "Fulfilled",
|
||||
|
||||
export abstract class Condition extends ContractBase {
|
||||
|
||||
protected constructor(contractName: string) {
|
||||
super(contractName)
|
||||
}
|
||||
|
||||
public static async getInstance(conditionName: string, conditionsClass: any): Promise<Condition & any> {
|
||||
const condition: Condition = new (conditionsClass as any)(conditionName)
|
||||
await condition.init()
|
||||
return condition
|
||||
}
|
||||
|
||||
protected constructor(contractName: string) {
|
||||
super(contractName)
|
||||
}
|
||||
|
||||
hashValues(...args: any[]): Promise<string> {
|
||||
public hashValues(...args: any[]): Promise<string> {
|
||||
return this.call("hashValues", args)
|
||||
}
|
||||
|
||||
fulfill(agreementId: string, ...args: any[])
|
||||
fulfill(agreementId: string, args: any[], from?: string) {
|
||||
public fulfill(agreementId: string, ...args: any[])
|
||||
public fulfill(agreementId: string, args: any[], from?: string) {
|
||||
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))
|
||||
}
|
||||
|
||||
generateId(agreementId: string, valueHash: string) {
|
||||
public generateId(agreementId: string, valueHash: string) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -7,11 +7,11 @@ export class EscrowReward extends Condition {
|
||||
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))
|
||||
}
|
||||
|
||||
fulfill(
|
||||
public fulfill(
|
||||
agreementId: string,
|
||||
amount: number,
|
||||
receiver: string,
|
||||
|
@ -7,11 +7,11 @@ export class LockRewardCondition extends Condition {
|
||||
return Condition.getInstance("LockRewardCondition", LockRewardCondition)
|
||||
}
|
||||
|
||||
hashValues(rewardAddress: string, amount: number) {
|
||||
public hashValues(rewardAddress: string, amount: number) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
export * from './Condition.abstract'
|
||||
export { AccessSecretStoreCondition } from './AccessSecretStoreCondition'
|
||||
export { EscrowReward } from './EscrowReward'
|
||||
export { LockRewardCondition } from './LockRewardCondition'
|
||||
export * from "./Condition.abstract"
|
||||
export { AccessSecretStoreCondition } from "./AccessSecretStoreCondition"
|
||||
export { EscrowReward } from "./EscrowReward"
|
||||
export { LockRewardCondition } from "./LockRewardCondition"
|
||||
|
@ -19,7 +19,7 @@ export class AgreementStoreManager extends ContractBase {
|
||||
return templateStoreManeger
|
||||
}
|
||||
|
||||
getOwner(): Promise<string> {
|
||||
public getOwner(): Promise<string> {
|
||||
return this.call("owner", [])
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ export class ConditionStoreManager extends ContractBase {
|
||||
return templateStoreManeger
|
||||
}
|
||||
|
||||
getOwner(): Promise<string> {
|
||||
public getOwner(): Promise<string> {
|
||||
return this.call("owner", [])
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ export class TemplateStoreManager extends ContractBase {
|
||||
return templateStoreManeger
|
||||
}
|
||||
|
||||
getOwner(): Promise<string> {
|
||||
public getOwner(): Promise<string> {
|
||||
return this.call("owner", [])
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
export * from './AgreementStoreManager'
|
||||
export * from './ConditionStoreManager'
|
||||
export * from './TemplateStoreManager'
|
||||
export * from "./AgreementStoreManager"
|
||||
export * from "./ConditionStoreManager"
|
||||
export * from "./TemplateStoreManager"
|
||||
|
@ -2,24 +2,24 @@ import ContractBase from "../ContractBase"
|
||||
import { AgreementStoreManager, ConditionStoreManager } from "../managers"
|
||||
import { Condition, ConditionState, conditionStateNames } from "../conditions/Condition.abstract"
|
||||
import Keeper from "../../Keeper"
|
||||
import { DDO } from '../../../ddo/DDO'
|
||||
import { ServiceAgreementTemplate } from '../../../ddo/ServiceAgreementTemplate'
|
||||
import { DDO } from "../../../ddo/DDO"
|
||||
import { ServiceAgreementTemplate } from "../../../ddo/ServiceAgreementTemplate"
|
||||
import { zeroX, Logger } from "../../../utils"
|
||||
import EventListener from "../../../keeper/EventListener"
|
||||
import Event from "../../../keeper/Event"
|
||||
|
||||
export abstract class AgreementTemplate extends ContractBase {
|
||||
|
||||
protected constructor(contractName: string) {
|
||||
super(contractName)
|
||||
}
|
||||
|
||||
public static async getInstance(conditionName: string, templateClass: any): Promise<AgreementTemplate & any> {
|
||||
const condition: AgreementTemplate = new (templateClass as any)(conditionName)
|
||||
await condition.init()
|
||||
return condition
|
||||
}
|
||||
|
||||
protected constructor(contractName: string) {
|
||||
super(contractName)
|
||||
}
|
||||
|
||||
// tslint:disable-next-line
|
||||
public createAgreement(agreementId: string, did: string, conditionIds: string[], timeLocks: number[], timeOuts: number[], ...args: any[])
|
||||
public createAgreement(
|
||||
@ -60,7 +60,7 @@ export abstract class AgreementTemplate extends ContractBase {
|
||||
public async getConditions(): Promise<Condition[]> {
|
||||
const keeper = await Keeper.getInstance()
|
||||
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.
|
||||
* @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.
|
||||
@ -79,9 +79,9 @@ export abstract class AgreementTemplate extends ContractBase {
|
||||
* @param {string} from Creator address.
|
||||
* @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() {
|
||||
const serviceAgreementTemplate = await this.getServiceAgreementTemplate()
|
||||
@ -93,7 +93,7 @@ export abstract class AgreementTemplate extends ContractBase {
|
||||
.find(({name: conditionRef}) => conditionRef === ref)
|
||||
.contractName
|
||||
return (await this.getConditions())
|
||||
.find(condition => condition.contractName === name)
|
||||
.find((condition) => condition.contractName === name)
|
||||
}
|
||||
|
||||
public async getServiceAgreementTemplateDependencies() {
|
||||
@ -107,15 +107,15 @@ export abstract class AgreementTemplate extends ContractBase {
|
||||
* @return {Promise} Conditions status.
|
||||
*/
|
||||
public async getAgreementStatus(
|
||||
agreementId: string
|
||||
agreementId: string,
|
||||
): Promise<{
|
||||
[condition: string]: {
|
||||
condition: string,
|
||||
contractName: string,
|
||||
state: ConditionState,
|
||||
blocked: boolean,
|
||||
blockedBy: string[]
|
||||
}
|
||||
blockedBy: string[],
|
||||
},
|
||||
} | false> {
|
||||
const agreementStore = await AgreementStoreManager.getInstance()
|
||||
const conditionStore = await ConditionStoreManager.getInstance()
|
||||
@ -137,7 +137,7 @@ export abstract class AgreementTemplate extends ContractBase {
|
||||
return {
|
||||
ref,
|
||||
contractName,
|
||||
state: (await conditionStore.getCondition(conditionIdByConddition[contractName])).state
|
||||
state: (await conditionStore.getCondition(conditionIdByConddition[contractName])).state,
|
||||
}
|
||||
})
|
||||
const states = await Promise.all(statesPromises)
|
||||
@ -145,8 +145,8 @@ export abstract class AgreementTemplate extends ContractBase {
|
||||
return states
|
||||
.reduce((acc, {contractName, ref, state}) => {
|
||||
const blockers = dependencies[ref]
|
||||
.map(dependency => states.find(({ref}) => ref === dependency))
|
||||
.filter(condition => condition.state !== ConditionState.Fulfilled)
|
||||
.map((dependency) => states.find((_) => _.ref === dependency))
|
||||
.filter((condition) => condition.state !== ConditionState.Fulfilled)
|
||||
return {
|
||||
...acc,
|
||||
[ref]: {
|
||||
@ -154,8 +154,8 @@ export abstract class AgreementTemplate extends ContractBase {
|
||||
contractName,
|
||||
state,
|
||||
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 = {
|
||||
"contractName": "EscrowAccessSecretStoreTemplate",
|
||||
"events": [
|
||||
contractName: "EscrowAccessSecretStoreTemplate",
|
||||
events: [
|
||||
{
|
||||
"name": "AgreementCreated",
|
||||
"actorType": "consumer",
|
||||
"handler": {
|
||||
"moduleName": "escrowAccessSecretStoreTemplate",
|
||||
"functionName": "fulfillLockRewardCondition",
|
||||
"version": "0.1"
|
||||
}
|
||||
}
|
||||
name: "AgreementCreated",
|
||||
actorType: "consumer",
|
||||
handler: {
|
||||
moduleName: "escrowAccessSecretStoreTemplate",
|
||||
functionName: "fulfillLockRewardCondition",
|
||||
version: "0.1",
|
||||
},
|
||||
},
|
||||
],
|
||||
"fulfillmentOrder": [
|
||||
fulfillmentOrder: [
|
||||
"lockReward.fulfill",
|
||||
"accessSecretStore.fulfill",
|
||||
"escrowReward.fulfill"
|
||||
"escrowReward.fulfill",
|
||||
],
|
||||
"conditionDependency": {
|
||||
"lockReward": [],
|
||||
"accessSecretStore": [],
|
||||
"escrowReward": [
|
||||
conditionDependency: {
|
||||
lockReward: [],
|
||||
accessSecretStore: [],
|
||||
escrowReward: [
|
||||
"lockReward",
|
||||
"accessSecretStore"
|
||||
]
|
||||
},
|
||||
"conditions": [
|
||||
{
|
||||
"name": "lockReward",
|
||||
"timelock": 0,
|
||||
"timeout": 0,
|
||||
"contractName": "LockRewardCondition",
|
||||
"functionName": "fulfill",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "_rewardAddress",
|
||||
"type": "address",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "_amount",
|
||||
"type": "uint256",
|
||||
"value": ""
|
||||
}
|
||||
"accessSecretStore",
|
||||
],
|
||||
"events": [
|
||||
},
|
||||
conditions: [
|
||||
{
|
||||
"name": "Fulfilled",
|
||||
"actorType": "publisher",
|
||||
"handler": {
|
||||
"moduleName": "lockRewardCondition",
|
||||
"functionName": "fulfillAccessSecretStoreCondition",
|
||||
"version": "0.1"
|
||||
}
|
||||
}
|
||||
]
|
||||
name: "lockReward",
|
||||
timelock: 0,
|
||||
timeout: 0,
|
||||
contractName: "LockRewardCondition",
|
||||
functionName: "fulfill",
|
||||
parameters: [
|
||||
{
|
||||
name: "_rewardAddress",
|
||||
type: "address",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
"name": "accessSecretStore",
|
||||
"timelock": 0,
|
||||
"timeout": 0,
|
||||
"contractName": "AccessSecretStoreCondition",
|
||||
"functionName": "fulfill",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "_documentId",
|
||||
"type": "bytes32",
|
||||
"value": ""
|
||||
name: "_amount",
|
||||
type: "uint256",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
"name": "_grantee",
|
||||
"type": "address",
|
||||
"value": ""
|
||||
}
|
||||
],
|
||||
"events": [
|
||||
events: [
|
||||
{
|
||||
"name": "Fulfilled",
|
||||
"actorType": "publisher",
|
||||
"handler": {
|
||||
"moduleName": "accessSecretStore",
|
||||
"functionName": "fulfillEscrowRewardCondition",
|
||||
"version": "0.1"
|
||||
}
|
||||
name: "Fulfilled",
|
||||
actorType: "publisher",
|
||||
handler: {
|
||||
moduleName: "lockRewardCondition",
|
||||
functionName: "fulfillAccessSecretStoreCondition",
|
||||
version: "0.1",
|
||||
},
|
||||
{
|
||||
"name": "TimedOut",
|
||||
"actorType": "consumer",
|
||||
"handler": {
|
||||
"moduleName": "accessSecretStore",
|
||||
"functionName": "fulfillEscrowRewardCondition",
|
||||
"version": "0.1"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "escrowReward",
|
||||
"timelock": 0,
|
||||
"timeout": 0,
|
||||
"contractName": "EscrowReward",
|
||||
"functionName": "fulfill",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "_amount",
|
||||
"type": "uint256",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "_receiver",
|
||||
"type": "address",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "_sender",
|
||||
"type": "address",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "_lockCondition",
|
||||
"type": "bytes32",
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"name": "_releaseCondition",
|
||||
"type": "bytes32",
|
||||
"value": ""
|
||||
}
|
||||
],
|
||||
"events": [
|
||||
},
|
||||
{
|
||||
"name": "Fulfilled",
|
||||
"actorType": "publisher",
|
||||
"handler": {
|
||||
"moduleName": "escrowRewardCondition",
|
||||
"functionName": "verifyRewardTokens",
|
||||
"version": "0.1"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
name: "accessSecretStore",
|
||||
timelock: 0,
|
||||
timeout: 0,
|
||||
contractName: "AccessSecretStoreCondition",
|
||||
functionName: "fulfill",
|
||||
parameters: [
|
||||
{
|
||||
name: "_documentId",
|
||||
type: "bytes32",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
name: "_grantee",
|
||||
type: "address",
|
||||
value: "",
|
||||
},
|
||||
],
|
||||
events: [
|
||||
{
|
||||
name: "Fulfilled",
|
||||
actorType: "publisher",
|
||||
handler: {
|
||||
moduleName: "accessSecretStore",
|
||||
functionName: "fulfillEscrowRewardCondition",
|
||||
version: "0.1",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "TimedOut",
|
||||
actorType: "consumer",
|
||||
handler: {
|
||||
moduleName: "accessSecretStore",
|
||||
functionName: "fulfillEscrowRewardCondition",
|
||||
version: "0.1",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "escrowReward",
|
||||
timelock: 0,
|
||||
timeout: 0,
|
||||
contractName: "EscrowReward",
|
||||
functionName: "fulfill",
|
||||
parameters: [
|
||||
{
|
||||
name: "_amount",
|
||||
type: "uint256",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
name: "_receiver",
|
||||
type: "address",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
name: "_sender",
|
||||
type: "address",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
name: "_lockCondition",
|
||||
type: "bytes32",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
name: "_releaseCondition",
|
||||
type: "bytes32",
|
||||
value: "",
|
||||
},
|
||||
],
|
||||
events: [
|
||||
{
|
||||
name: "Fulfilled",
|
||||
actorType: "publisher",
|
||||
handler: {
|
||||
moduleName: "escrowRewardCondition",
|
||||
functionName: "verifyRewardTokens",
|
||||
version: "0.1",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { AgreementTemplate } from "./AgreementTemplate.abstract"
|
||||
import { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } from '../conditions'
|
||||
import DIDRegistry from '../DIDRegistry'
|
||||
import { DDO } from '../../../ddo/DDO'
|
||||
import { generateId, zeroX } from '../../../utils'
|
||||
import { LockRewardCondition, EscrowReward, AccessSecretStoreCondition } from "../conditions"
|
||||
import DIDRegistry from "../DIDRegistry"
|
||||
import { DDO } from "../../../ddo/DDO"
|
||||
import { generateId, zeroX } from "../../../utils"
|
||||
|
||||
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) {
|
||||
return !!await this.createFullAgreement(
|
||||
ddo.shortId(),
|
||||
|
@ -1,2 +1,2 @@
|
||||
export * from './AgreementTemplate.abstract'
|
||||
export { EscrowAccessSecretStoreTemplate } from './EscrowAccessSecretStoreTemplate'
|
||||
export * from "./AgreementTemplate.abstract"
|
||||
export { EscrowAccessSecretStoreTemplate } from "./EscrowAccessSecretStoreTemplate"
|
||||
|
@ -43,7 +43,6 @@ export default class OceanAgreementsConditions {
|
||||
return !!receipt.events.Fulfilled
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Authorize the consumer defined in the agreement to access (consume) this asset.
|
||||
* @param {string} agreementId Agreement ID.
|
||||
|
@ -4,16 +4,14 @@ import BrizoProvider from "../brizo/BrizoProvider"
|
||||
import ConfigProvider from "../ConfigProvider"
|
||||
import { DDO } from "../ddo/DDO"
|
||||
import { MetaData } from "../ddo/MetaData"
|
||||
import { ServiceAgreementTemplate, ServiceAgreementTemplateCondition } from "../ddo/ServiceAgreementTemplate"
|
||||
import { ServiceAgreementTemplateCondition } from "../ddo/ServiceAgreementTemplate"
|
||||
import { Service, ServiceAuthorization } from "../ddo/Service"
|
||||
import EventListener from "../keeper/EventListener"
|
||||
import Keeper from "../keeper/Keeper"
|
||||
import SecretStoreProvider from "../secretstore/SecretStoreProvider"
|
||||
import { Logger, fillConditionsWithDDO } from "../utils"
|
||||
import Account from "./Account"
|
||||
import DID from "./DID"
|
||||
import OceanAgreements from "./OceanAgreements"
|
||||
import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
|
||||
|
||||
/**
|
||||
* 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 serviceAgreementTemplate: ServiceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate()
|
||||
const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate()
|
||||
|
||||
const serviceEndpoint = aquarius.getServiceEndpoint(did)
|
||||
|
||||
@ -145,8 +143,8 @@ export default class OceanAssets {
|
||||
})
|
||||
|
||||
// Overwritte initial service agreement conditions
|
||||
const rawConditions: ServiceAgreementTemplateCondition[] = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplateConditions()
|
||||
const conditions: ServiceAgreementTemplateCondition[] = fillConditionsWithDDO(rawConditions, ddo)
|
||||
const rawConditions = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplateConditions()
|
||||
const conditions = fillConditionsWithDDO(rawConditions, ddo)
|
||||
serviceAgreementTemplate.conditions = conditions
|
||||
|
||||
ddo.addChecksum()
|
||||
|
@ -7,7 +7,6 @@ import Logger from "../../utils/Logger"
|
||||
import Account from "../Account"
|
||||
import { signText, zeroX } from "../../utils"
|
||||
|
||||
|
||||
// TODO: move this class to helpers, it only contains pure functions
|
||||
export default class ServiceAgreement {
|
||||
|
||||
@ -58,7 +57,7 @@ export default class ServiceAgreement {
|
||||
timeoutValues,
|
||||
)
|
||||
|
||||
let serviceAgreementHashSignature = await signText(serviceAgreementHash, consumer.getId(), consumer.getPassword())
|
||||
const serviceAgreementHashSignature = await signText(serviceAgreementHash, consumer.getId(), consumer.getPassword())
|
||||
|
||||
return serviceAgreementHashSignature
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Logger } from './Logger'
|
||||
import { Logger } from "./Logger"
|
||||
|
||||
// Ox transformer
|
||||
export const zeroX = (input: string) => zeroXTransformer(input, true)
|
||||
@ -24,7 +24,7 @@ function inputMatch(input: string, regexp: RegExp, conversorName: string): {vali
|
||||
if (typeof input !== "string") {
|
||||
Logger.debug("Not input string:")
|
||||
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)
|
||||
if (!match) {
|
||||
|
@ -2,7 +2,7 @@ import { DDO } from "../ddo/DDO"
|
||||
import { ServiceAgreementTemplateCondition, ServiceAgreementTemplateParameter } from "../ddo/ServiceAgreementTemplate"
|
||||
|
||||
function fillParameterWithDDO(parameter: ServiceAgreementTemplateParameter, ddo: DDO): ServiceAgreementTemplateParameter {
|
||||
const getValue = name => {
|
||||
const getValue = (name) => {
|
||||
switch (name) {
|
||||
case "amount":
|
||||
case "price":
|
||||
@ -28,11 +28,11 @@ function fillParameterWithDDO(parameter: ServiceAgreementTemplateParameter, ddo:
|
||||
*/
|
||||
export function fillConditionsWithDDO(conditions: ServiceAgreementTemplateCondition[], ddo: DDO): ServiceAgreementTemplateCondition[] {
|
||||
return conditions
|
||||
.map(condition => ({
|
||||
.map((condition) => ({
|
||||
...condition,
|
||||
parameters: condition.parameters
|
||||
.map(parameter => ({
|
||||
...fillParameterWithDDO(parameter, ddo)
|
||||
}))
|
||||
.map((parameter) => ({
|
||||
...fillParameterWithDDO(parameter, ddo),
|
||||
})),
|
||||
}))
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ export class Logger {
|
||||
}
|
||||
|
||||
public static bypass(...args: any[]) {
|
||||
Logger.dispatch("log", <any>-Infinity, ...args)
|
||||
Logger.dispatch("log", -Infinity as any, ...args)
|
||||
}
|
||||
|
||||
public static debug(...args: any[]) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
export { Logger, LogLevel } from './Logger'
|
||||
export * from './SignatureHelpers'
|
||||
export * from './ConversionTypeHelpers'
|
||||
export * from './GeneratorHelpers'
|
||||
export * from './DDOHelpers'
|
||||
export { Logger, LogLevel } from "./Logger"
|
||||
export * from "./SignatureHelpers"
|
||||
export * from "./ConversionTypeHelpers"
|
||||
export * from "./GeneratorHelpers"
|
||||
export * from "./DDOHelpers"
|
||||
|
@ -62,7 +62,6 @@ export default class TestContractHandler extends ContractHandler {
|
||||
deployerAddress, conditionStoreManager.options.address, token.options.address,
|
||||
])
|
||||
|
||||
|
||||
// Templates
|
||||
await TestContractHandler.deployContract("EscrowAccessSecretStoreTemplate", deployerAddress, [
|
||||
deployerAddress,
|
||||
|
@ -9,7 +9,6 @@ import { generateId } from "../../src/utils/GeneratorHelpers"
|
||||
import config from "../config"
|
||||
import TestContractHandler from "../keeper/TestContractHandler"
|
||||
|
||||
|
||||
const did: DID = DID.generate()
|
||||
|
||||
describe("ServiceAgreement", () => {
|
||||
|
@ -20,7 +20,7 @@ describe("ConversionTypeHelpers", () => {
|
||||
it("should return the value without 0x prefix", async () => {
|
||||
const result1 = noZeroX("0x1234")
|
||||
const result2 = noZeroX("1234")
|
||||
assert.equal(result1, "1234",)
|
||||
assert.equal(result1, "1234")
|
||||
assert.equal(result2, "1234")
|
||||
})
|
||||
})
|
||||
|
@ -11,7 +11,8 @@
|
||||
"semicolon": [
|
||||
true,
|
||||
"never"
|
||||
]
|
||||
],
|
||||
"ordered-imports": false
|
||||
},
|
||||
"rulesDirectory": []
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user