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

New template interface almost completed.

This commit is contained in:
ssallam 2020-01-16 09:52:26 +01:00
parent 5439021e4a
commit c6876ca9e2
12 changed files with 283 additions and 100 deletions

View File

@ -48,7 +48,7 @@ describe('Register Escrow Access Secret Store Template', () => {
describe('Propose and approve template', () => { describe('Propose and approve template', () => {
it('should propose the template', async () => { it('should propose the template', async () => {
await keeper.templateStoreManager.proposeTemplate( await keeper.templateStoreManager.proposeTemplate(
template.getAddress(), template.getId(),
consumer.getId(), consumer.getId(),
true true
) )
@ -58,7 +58,7 @@ describe('Register Escrow Access Secret Store Template', () => {
it('should approve the template', async () => { it('should approve the template', async () => {
await keeper.templateStoreManager.approveTemplate( await keeper.templateStoreManager.approveTemplate(
template.getAddress(), template.getId(),
templateManagerOwner.getId(), templateManagerOwner.getId(),
true true
) )
@ -122,7 +122,9 @@ describe('Register Escrow Access Secret Store Template', () => {
}) })
it('should have condition instances asociated', async () => { it('should have condition instances asociated', async () => {
const conditionInstances = await template.getConditions() const conditionInstances = (await template.getConditionTypes()).map(address =>
keeper.getConditionByAddress(address)
)
assert.equal(conditionInstances.length, 3, 'Expected 3 conditions.') assert.equal(conditionInstances.length, 3, 'Expected 3 conditions.')
@ -145,13 +147,14 @@ describe('Register Escrow Access Secret Store Template', () => {
}) })
it('should create a new agreement', async () => { it('should create a new agreement', async () => {
const agreement = await template.createAgreement( const agreement = await keeper.agreementStoreManager.createAgreement(
agreementId, agreementId,
did, did,
[conditionIdAccess, conditionIdLock, conditionIdEscrow], template.getId(),
[conditionIdLock, conditionIdAccess, conditionIdEscrow],
[0, 0, 0], [0, 0, 0],
[0, 0, 0], [0, 0, 0],
consumer.getId(), [consumer.getId(), publisher.getId()],
publisher.getId() publisher.getId()
) )

View File

@ -48,7 +48,7 @@ describe('Register Escrow Compute Execution Template', () => {
describe('Propose and approve template', () => { describe('Propose and approve template', () => {
it('should propose the template', async () => { it('should propose the template', async () => {
await keeper.templateStoreManager.proposeTemplate( await keeper.templateStoreManager.proposeTemplate(
template.getAddress(), template.getId(),
consumer.getId(), consumer.getId(),
true true
) )
@ -58,7 +58,7 @@ describe('Register Escrow Compute Execution Template', () => {
it('should approve the template', async () => { it('should approve the template', async () => {
await keeper.templateStoreManager.approveTemplate( await keeper.templateStoreManager.approveTemplate(
template.getAddress(), template.getId(),
templateManagerOwner.getId(), templateManagerOwner.getId(),
true true
) )
@ -145,13 +145,14 @@ describe('Register Escrow Compute Execution Template', () => {
}) })
it('should create a new agreement', async () => { it('should create a new agreement', async () => {
const agreement = await template.createAgreement( const agreement = await keeper.agreementStoreManager.createAgreement(
agreementId, agreementId,
did, did,
template.getId(),
[conditionIdCompute, conditionIdLock, conditionIdEscrow], [conditionIdCompute, conditionIdLock, conditionIdEscrow],
[0, 0, 0], [0, 0, 0],
[0, 0, 0], [0, 0, 0],
consumer.getId(), [consumer.getId(), publisher.getId()],
publisher.getId() publisher.getId()
) )

83
package-lock.json generated
View File

@ -407,7 +407,7 @@
"ethereumjs-util": "^6.1.0", "ethereumjs-util": "^6.1.0",
"ethereumjs-wallet": "^0.6.3", "ethereumjs-wallet": "^0.6.3",
"web3": "1.2.1", "web3": "1.2.1",
"web3-provider-engine": "git+https://github.com/trufflesuite/provider-engine.git#web3-one" "web3-provider-engine": "git+https://github.com/trufflesuite/provider-engine.git#3538c60bc4836b73ccae1ac3f64c8fed8ef19c1a"
}, },
"dependencies": { "dependencies": {
"eth-lib": { "eth-lib": {
@ -714,7 +714,7 @@
"requires": { "requires": {
"underscore": "1.9.1", "underscore": "1.9.1",
"web3-core-helpers": "1.2.1", "web3-core-helpers": "1.2.1",
"websocket": "github:web3-js/WebSocket-Node#polyfill/globalThis" "websocket": "github:web3-js/WebSocket-Node#905deb4812572b344f5801f8c9ce8bb02799d82e"
}, },
"dependencies": { "dependencies": {
"nan": { "nan": {
@ -1550,7 +1550,7 @@
}, },
"util": { "util": {
"version": "0.10.3", "version": "0.10.3",
"resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", "resolved": "http://registry.npmjs.org/util/-/util-0.10.3.tgz",
"integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=", "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -1707,7 +1707,7 @@
}, },
"chalk": { "chalk": {
"version": "1.1.3", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -1720,7 +1720,7 @@
}, },
"strip-ansi": { "strip-ansi": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -2514,7 +2514,7 @@
}, },
"bl": { "bl": {
"version": "1.2.2", "version": "1.2.2",
"resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz", "resolved": "http://registry.npmjs.org/bl/-/bl-1.2.2.tgz",
"integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==", "integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==",
"requires": { "requires": {
"readable-stream": "^2.3.5", "readable-stream": "^2.3.5",
@ -2627,7 +2627,7 @@
}, },
"browserify-aes": { "browserify-aes": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", "resolved": "http://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz",
"integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==",
"requires": { "requires": {
"buffer-xor": "^1.0.3", "buffer-xor": "^1.0.3",
@ -2661,7 +2661,7 @@
}, },
"browserify-rsa": { "browserify-rsa": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz", "resolved": "http://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz",
"integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=", "integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=",
"requires": { "requires": {
"bn.js": "^4.1.0", "bn.js": "^4.1.0",
@ -3626,7 +3626,7 @@
}, },
"create-hash": { "create-hash": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", "resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
"integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==",
"requires": { "requires": {
"cipher-base": "^1.0.1", "cipher-base": "^1.0.1",
@ -3638,7 +3638,7 @@
}, },
"create-hmac": { "create-hmac": {
"version": "1.1.7", "version": "1.1.7",
"resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", "resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz",
"integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==",
"requires": { "requires": {
"cipher-base": "^1.0.3", "cipher-base": "^1.0.3",
@ -3881,12 +3881,12 @@
"dependencies": { "dependencies": {
"file-type": { "file-type": {
"version": "3.9.0", "version": "3.9.0",
"resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", "resolved": "http://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz",
"integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek=" "integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek="
}, },
"get-stream": { "get-stream": {
"version": "2.3.1", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-2.3.1.tgz", "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-2.3.1.tgz",
"integrity": "sha1-Xzj5PzRgCWZu4BUKBUFn+Rvdld4=", "integrity": "sha1-Xzj5PzRgCWZu4BUKBUFn+Rvdld4=",
"requires": { "requires": {
"object-assign": "^4.0.1", "object-assign": "^4.0.1",
@ -4071,7 +4071,7 @@
}, },
"diffie-hellman": { "diffie-hellman": {
"version": "5.0.3", "version": "5.0.3",
"resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", "resolved": "http://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
"integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==", "integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==",
"requires": { "requires": {
"bn.js": "^4.1.0", "bn.js": "^4.1.0",
@ -4867,7 +4867,7 @@
"integrity": "sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=", "integrity": "sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=",
"dev": true, "dev": true,
"requires": { "requires": {
"ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git", "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git#1cfbb13862f90f0b391d8a699544d5fe4dfb8c7b",
"ethereumjs-util": "^5.1.1" "ethereumjs-util": "^5.1.1"
}, },
"dependencies": { "dependencies": {
@ -6195,8 +6195,7 @@
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
@ -6239,8 +6238,7 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
@ -6251,8 +6249,7 @@
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -6369,8 +6366,7 @@
"inherits": { "inherits": {
"version": "2.0.4", "version": "2.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -6382,7 +6378,6 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@ -6405,14 +6400,12 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.9.0", "version": "2.9.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@ -6431,7 +6424,6 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@ -6521,8 +6513,7 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@ -6534,7 +6525,6 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -6620,8 +6610,7 @@
"safe-buffer": { "safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"safer-buffer": { "safer-buffer": {
"version": "2.1.2", "version": "2.1.2",
@ -6657,7 +6646,6 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
@ -6677,7 +6665,6 @@
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
@ -6721,14 +6708,12 @@
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"yallist": { "yallist": {
"version": "3.1.1", "version": "3.1.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
} }
} }
}, },
@ -8666,7 +8651,7 @@
}, },
"media-typer": { "media-typer": {
"version": "0.3.0", "version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
}, },
"mem": { "mem": {
@ -8865,7 +8850,7 @@
}, },
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
}, },
"minipass": { "minipass": {
@ -8941,7 +8926,7 @@
}, },
"mkdirp": { "mkdirp": {
"version": "0.5.1", "version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
@ -10120,7 +10105,7 @@
}, },
"path-is-absolute": { "path-is-absolute": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true "dev": true
}, },
@ -10450,7 +10435,7 @@
}, },
"query-string": { "query-string": {
"version": "5.1.1", "version": "5.1.1",
"resolved": "https://registry.npmjs.org/query-string/-/query-string-5.1.1.tgz", "resolved": "http://registry.npmjs.org/query-string/-/query-string-5.1.1.tgz",
"integrity": "sha512-gjWOsm2SoGlgLEdAGt7a6slVOk9mGiXmPFMqrEhLQ68rhQuBnpfs3+EmlvqKyxnCo9/PPlF+9MtY02S1aFg+Jw==", "integrity": "sha512-gjWOsm2SoGlgLEdAGt7a6slVOk9mGiXmPFMqrEhLQ68rhQuBnpfs3+EmlvqKyxnCo9/PPlF+9MtY02S1aFg+Jw==",
"requires": { "requires": {
"decode-uri-component": "^0.2.0", "decode-uri-component": "^0.2.0",
@ -10620,7 +10605,7 @@
}, },
"readable-stream": { "readable-stream": {
"version": "2.3.6", "version": "2.3.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
"requires": { "requires": {
"core-util-is": "~1.0.0", "core-util-is": "~1.0.0",
@ -11312,7 +11297,7 @@
}, },
"safe-regex": { "safe-regex": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", "resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
"integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=", "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -11360,7 +11345,7 @@
}, },
"scrypt-js": { "scrypt-js": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/scrypt-js/-/scrypt-js-2.0.3.tgz", "resolved": "http://registry.npmjs.org/scrypt-js/-/scrypt-js-2.0.3.tgz",
"integrity": "sha1-uwBAvgMEPamgEqLOqfyfhSz8h9Q=" "integrity": "sha1-uwBAvgMEPamgEqLOqfyfhSz8h9Q="
}, },
"scrypt.js": { "scrypt.js": {
@ -11565,7 +11550,7 @@
}, },
"sha.js": { "sha.js": {
"version": "2.4.11", "version": "2.4.11",
"resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", "resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
"integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==",
"requires": { "requires": {
"inherits": "^2.0.1", "inherits": "^2.0.1",
@ -12241,7 +12226,7 @@
}, },
"strip-eof": { "strip-eof": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", "resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=",
"dev": true "dev": true
}, },
@ -12584,7 +12569,7 @@
}, },
"through": { "through": {
"version": "2.3.8", "version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
}, },
"through2": { "through2": {

View File

@ -11,7 +11,6 @@ import {
ComputeExecutionCondition ComputeExecutionCondition
} from './contracts/conditions' } from './contracts/conditions'
import { import {
AgreementTemplate,
EscrowAccessSecretStoreTemplate, EscrowAccessSecretStoreTemplate,
EscrowComputeExecutionTemplate EscrowComputeExecutionTemplate
} from './contracts/templates' } from './contracts/templates'
@ -25,6 +24,7 @@ import { objectPromiseAll } from '../utils'
import { EventHandler } from './EventHandler' import { EventHandler } from './EventHandler'
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract' import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
import { AgreementTemplateBase } from "./contracts/templates/AgreementTemplateBase";
/** /**
* Interface with Ocean Keeper contracts. * Interface with Ocean Keeper contracts.
@ -204,22 +204,22 @@ export class Keeper extends Instantiable {
/** /**
* Returns a template by name. * Returns a template by name.
* @param {string} name Template name. * @param {string} name Template name.
* @return {AgreementTemplate} Agreement template instance. * @return {AgreementTemplateBase} AgreementTemplateBase instance.
*/ */
public getTemplateByName(name: string): AgreementTemplate { public getTemplateByName(name: string): AgreementTemplateBase {
return Object.values(this.templates).find( return Object.values(this.templates).find(
template => template.contractName === name template => template.templateName === name
) )
} }
/** /**
* Returns a template by address. * Returns a template by address.
* @param {string} address Template address. * @param {string} templateId Template id (hex representation of bytes32).
* @return {AgreementTemplate} Agreement template instance. * @return {AgreementTemplateBase} AgreementTemplateBase instance.
*/ */
public getTemplateByAddress(address: string): AgreementTemplate { public getTemplateById(templateId: string): AgreementTemplateBase {
return Object.values(this.templates).find( return Object.values(this.templates).find(
template => template.getAddress() === address template => template.getId() === templateId
) )
} }

View File

@ -82,4 +82,16 @@ export class AgreementStoreManager extends ContractBase {
from from
) )
} }
/**
* Generates and returns the agreement creation event.
* @param {string} agreementId Agreement ID.
* @return {Event} Agreement created event.
*/
public getAgreementCreatedEvent(agreementId: string) {
return this.getEvent('AgreementCreated', {
agreementId: zeroX(agreementId)
})
}
} }

View File

@ -14,6 +14,8 @@ export interface TemplateMetadata {
owner: string owner: string
lastUpdatedBy: string lastUpdatedBy: string
blockNumberUpdated: number blockNumberUpdated: number
conditionTypes: string[]
actorTypeIds: string[]
} }
export class TemplateStoreManager extends ContractBase { export class TemplateStoreManager extends ContractBase {
@ -27,54 +29,77 @@ export class TemplateStoreManager extends ContractBase {
return templateStoreManeger return templateStoreManeger
} }
public generateId(templateName: string) {
return this.call(
"generateId",
[templateName]
)
}
public getOwner(): Promise<string> { public getOwner(): Promise<string> {
return this.call('owner', []) return this.call('owner', [])
} }
public async proposeTemplate(address: string, from?: string, ignoreExists?: boolean) { public async proposeTemplate(templateId: string, from?: string, ignoreExists?: boolean) {
const template = await this.getTemplate(address) const template = await this.getTemplate(templateId)
if (template.blockNumberUpdated !== 0) { if (template.blockNumberUpdated !== 0) {
this.logger.warn(`Template "${address}" already exist.`) this.logger.warn(`Template "${templateId}" already exist.`)
if (!ignoreExists) { if (!ignoreExists) {
throw new Error('Template already exist.') throw new Error('Template already exist.')
} }
} else { } else {
return this.sendFrom('proposeTemplate', [zeroX(address)], from) return this.sendFrom('proposeTemplate', [zeroX(templateId)], from)
} }
} }
public async approveTemplate( public async approveTemplate(
address: string, templateId: string,
from?: string, from?: string,
ignoreApproved?: boolean ignoreApproved?: boolean
) { ) {
const template = await this.getTemplate(address) const template = await this.getTemplate(templateId)
if (template.state !== TemplateState.Proposed) { if (template.state !== TemplateState.Proposed) {
this.logger.warn(`Template "${address}" is not in "proposed" state.`) this.logger.warn(`Template "${templateId}" is not in "proposed" state.`)
if (!ignoreApproved) { if (!ignoreApproved) {
throw new Error(`Template not in "proposed" state.`) throw new Error(`Template not in "proposed" state.`)
} }
} else { } else {
return this.sendFrom('approveTemplate', [zeroX(address)], from) return this.sendFrom('approveTemplate', [zeroX(templateId)], from)
} }
} }
public revokeTemplate(address: string, from?: string) { public revokeTemplate(templateId: string, from?: string) {
return this.sendFrom('revokeTemplate', [zeroX(address)], from) return this.sendFrom('revokeTemplate', [zeroX(templateId)], from)
} }
public async getTemplate(address: string) { public async getConditionTypes(templateId: string): Promise<string[]> {
const { conditionTypes } = await this.getTemplate(templateId)
return conditionTypes
}
public getConditions(conditionTypes: string[]) {
return conditionTypes.map(address =>
this.ocean.keeper.getConditionByAddress(address)
)
}
public async getTemplate(templateId: string) {
const { const {
state, state,
owner, owner,
lastUpdatedBy, lastUpdatedBy,
blockNumberUpdated blockNumberUpdated,
} = await this.call('getTemplate', [zeroX(address)]) conditionTypes,
actorTypeIds
} = await this.call('getTemplate', [zeroX(templateId)])
return { return {
state: +state, state: +state,
owner, owner,
lastUpdatedBy, lastUpdatedBy,
blockNumberUpdated: +blockNumberUpdated blockNumberUpdated: +blockNumberUpdated,
conditionTypes,
actorTypeIds
} as TemplateMetadata } as TemplateMetadata
} }
} }

View File

@ -1,12 +1,14 @@
import { escrowAccessServiceAgreementTemplate } from './EscrowAccess.serviceAgreementTemplate' import { escrowAccessServiceAgreementTemplate } from './EscrowAccess.serviceAgreementTemplate'
import { TemplateStoreManager, AgreementStoreManager } from '../managers' import {TemplateStoreManager, AgreementStoreManager, ConditionStoreManager} from '../managers'
import DIDRegistry from '../DIDRegistry' import DIDRegistry from '../DIDRegistry'
import { LockRewardCondition } from '../conditions/LockRewardCondition' import { LockRewardCondition } from '../conditions/LockRewardCondition'
import { AccessSecretStoreCondition } from '../conditions/AccessSecretStoreCondition' import { AccessSecretStoreCondition } from '../conditions/AccessSecretStoreCondition'
import { EscrowReward } from '../conditions/EscrowReward' import { EscrowReward } from '../conditions/EscrowReward'
import { DDO } from '../../../ddo/DDO' import { DDO } from '../../../ddo/DDO'
import { generateId, zeroX } from '../../../utils' import {generateId, LoggerInstance, Logger, zeroX} from '../../../utils'
import { ComputeExecutionCondition } from '../conditions'
import {ComputeExecutionCondition, Condition, ConditionState, conditionStateNames} from '../conditions'
export interface Conditions { export interface Conditions {
lockRewardCondition: LockRewardCondition lockRewardCondition: LockRewardCondition
@ -15,8 +17,20 @@ export interface Conditions {
escrowReward: EscrowReward escrowReward: EscrowReward
} }
export interface AgreementConditionsStatus {
[condition: string]: {
condition: string
contractName: string
state: ConditionState
blocked: boolean
blockedBy: string[]
}
}
export class AgreementTemplateBase { export class AgreementTemplateBase {
public static templateName: string public templateName: string
public templateManager: TemplateStoreManager public templateManager: TemplateStoreManager
@ -26,6 +40,8 @@ export class AgreementTemplateBase {
public conditions: Conditions public conditions: Conditions
private logger: Logger
public constructor( public constructor(
templateManager: TemplateStoreManager, templateManager: TemplateStoreManager,
agreementStoreManager: AgreementStoreManager, agreementStoreManager: AgreementStoreManager,
@ -36,10 +52,8 @@ export class AgreementTemplateBase {
this.agreementStoreManager = agreementStoreManager this.agreementStoreManager = agreementStoreManager
this.didRegistry = didRegistry this.didRegistry = didRegistry
this.conditions = conditions this.conditions = conditions
}
public async getServiceAgreementTemplate() { this.logger = LoggerInstance
return escrowAccessServiceAgreementTemplate
} }
public async createAgreementFromDDO( public async createAgreementFromDDO(
@ -99,14 +113,15 @@ export class AgreementTemplateBase {
) )
const publisher = await this.didRegistry.getDIDOwner(did) const publisher = await this.didRegistry.getDIDOwner(did)
const timeouts = [0, 0, 0]
const timelocks = [0, 0, 0]
await this.agreementStoreManager.createAgreement( await this.agreementStoreManager.createAgreement(
agreementId, agreementId,
did, did,
this.getId(), this.getId(),
conditionIds, conditionIds,
[0, 0, 0], timelocks,
[0, 0, 0], timeouts,
[consumer, publisher], [consumer, publisher],
from from
) )
@ -119,7 +134,146 @@ export class AgreementTemplateBase {
did: string, did: string,
amount: number | string, amount: number | string,
consumer: string consumer: string
): Promise<any> { ): Promise<string[]> {
return null return null
} }
// getAgreementData
/**
* Conditions address list.
* @return {Promise<string[]>} Conditions address.
*/
public getConditionTypes(): Promise<string[]> {
return this.templateManager.getConditionTypes(this.getId())
}
/**
* List of condition contracts.
* @return {Promise<Condition[]>} Conditions contracts.
*/
public async getConditions(): Promise<Condition[]> {
return this.templateManager.getConditions(await this.getConditionTypes())
}
public async getServiceAgreementTemplate() {
return null
}
public async getServiceAgreementTemplateConditions() {
const serviceAgreementTemplate = await this.getServiceAgreementTemplate()
return serviceAgreementTemplate.conditions
}
public async getServiceAgreementTemplateConditionByRef(ref: string) {
const name = (await this.getServiceAgreementTemplateConditions()).find(
({ name: conditionRef }) => conditionRef === ref
).contractName
return (await this.getConditions()).find(
condition => condition.contractName === name
)
}
public async getServiceAgreementTemplateDependencies() {
const serviceAgreementTemplate = await this.getServiceAgreementTemplate()
return serviceAgreementTemplate.conditionDependency
}
/**
* Returns the status of the conditions.
* @param {string} agreementId Agreement ID.
* @param {ConditionStoreManager} conditionStoreManager
* @return {Promise} Conditions status.
*/
public async getAgreementStatus(
agreementId: string, conditionStoreManager: ConditionStoreManager
): Promise<AgreementConditionsStatus | false> {
const dependencies = await this.getServiceAgreementTemplateDependencies()
const { conditionIds } = await this.agreementStoreManager.getAgreement(agreementId)
if (!conditionIds.length) {
// this.logger.error(`Agreement not creeated yet: "${agreementId}"`)
return false
}
const conditionIdByCondition = (await this.getConditions()).reduce(
(acc, { contractName }, i) => ({
...acc,
[contractName]: conditionIds[i]
}),
{}
)
const statesPromises = Object.keys(dependencies).map(async (ref, i) => {
const { contractName } = await this.getServiceAgreementTemplateConditionByRef(
ref
)
return {
ref,
contractName,
state: (
await conditionStoreManager.getCondition(
conditionIdByCondition[contractName]
)
).state
}
})
const states = await Promise.all(statesPromises)
return states.reduce((acc, { contractName, ref, state }) => {
const blockers = dependencies[ref]
.map(dependency => states.find(_ => _.ref === dependency))
.filter(condition => condition.state !== ConditionState.Fulfilled)
return {
...acc,
[ref]: {
condition: ref,
contractName,
state,
blocked: !!blockers.length,
blockedBy: blockers.map(_ => _.ref)
}
}
}, {})
}
/**
* Prints the agreement status.
* @param {string} agreementId Agreement ID.
* @param {ConditionStoreManager} conditionStoreManager
*/
public async printAgreementStatus(agreementId: string, conditionStoreManager: ConditionStoreManager) {
const status = await this.getAgreementStatus(agreementId, conditionStoreManager)
this.logger.bypass('-'.repeat(80))
this.logger.bypass('Template:', this.templateName)
this.logger.bypass('Agreement ID:', agreementId)
this.logger.bypass('-'.repeat(40))
if (!status) {
this.logger.bypass('Agreement not created yet!')
}
Object.values(status || []).forEach(
({ condition, contractName, state, blocked, blockedBy }, i) => {
if (i) {
this.logger.bypass('-'.repeat(20))
}
this.logger.bypass(`${condition} (${contractName})`)
this.logger.bypass(' Status:', state, `(${conditionStateNames[state]})`)
if (blocked) {
this.logger.bypass(' Blocked by:', blockedBy)
}
}
)
this.logger.bypass('-'.repeat(80))
}
/**
* Generates and returns the agreement creation event.
* @param {string} agreementId Agreement ID.
* @return {Event} Agreement created event.
*/
public getAgreementCreatedEvent(agreementId: string) {
return this.agreementStoreManager.getAgreementCreatedEvent(agreementId)
}
} }

View File

@ -41,6 +41,10 @@ export class EscrowAccessSecretStoreTemplate extends AgreementTemplateBase {
accessSecretStoreConditionId accessSecretStoreConditionId
) )
return [lockRewardConditionId, accessSecretStoreConditionId, escrowRewardId] return [
lockRewardConditionId,
accessSecretStoreConditionId,
escrowRewardId
]
} }
} }

View File

@ -41,10 +41,10 @@ export class EscrowComputeExecutionTemplate extends AgreementTemplateBase {
computeExecutionConditionId computeExecutionConditionId
) )
return { return [
lockRewardConditionId, lockRewardConditionId,
computeExecutionConditionId, computeExecutionConditionId,
escrowRewardId escrowRewardId
} ]
} }
} }

View File

@ -1,4 +1,4 @@
export * from './AgreementTemplate.abstract' export * from './AgreementTemplateBase'
export { BaseEscrowTemplate } from './BaseEscrowTemplate.abstract' export { BaseEscrowTemplate } from './BaseEscrowTemplate.abstract'
export { EscrowAccessSecretStoreTemplate } from './EscrowAccessSecretStoreTemplate' export { EscrowAccessSecretStoreTemplate } from './EscrowAccessSecretStoreTemplate'
export { EscrowComputeExecutionTemplate } from './EscrowComputeExecutionTemplate' export { EscrowComputeExecutionTemplate } from './EscrowComputeExecutionTemplate'

View File

@ -3,7 +3,7 @@ import Account from './Account'
import DID from './DID' import DID from './DID'
import { zeroX, didPrefixed } from '../utils' import { zeroX, didPrefixed } from '../utils'
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract' import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
import { AgreementConditionsStatus } from '../keeper/contracts/templates/AgreementTemplate.abstract' import { AgreementConditionsStatus } from '../keeper/contracts/templates/AgreementTemplateBase'
import { ConditionState } from '../keeper/contracts/conditions/Condition.abstract' import { ConditionState } from '../keeper/contracts/conditions/Condition.abstract'
import { OceanAgreementsConditions } from './OceanAgreementsConditions' import { OceanAgreementsConditions } from './OceanAgreementsConditions'
@ -150,8 +150,8 @@ export class OceanAgreements extends Instantiable {
agreementId agreementId
) )
const fullStatus = await this.ocean.keeper const fullStatus = await this.ocean.keeper
.getTemplateByAddress(templateId) .getTemplateById(templateId)
.getAgreementStatus(agreementId) .getAgreementStatus(agreementId, this.ocean.keeper.conditionStoreManager)
if (!fullStatus) { if (!fullStatus) {
return return

View File

@ -21,7 +21,6 @@ export {
OceanPlatformVersions OceanPlatformVersions
} from './ocean/OceanVersions' } from './ocean/OceanVersions'
export { AgreementTemplate } from './keeper/contracts/templates'
export { Condition, ConditionState } from './keeper/contracts/conditions' export { Condition, ConditionState } from './keeper/contracts/conditions'
export { Ocean, Account, Config, DID, Logger, Keeper, conditions, templates, utils } export { Ocean, Account, Config, DID, Logger, Keeper, conditions, templates, utils }