mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
tweak printWidth
This commit is contained in:
parent
0552bcc577
commit
143fcbecf3
@ -1,6 +1,6 @@
|
||||
{
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"printWidth": 120,
|
||||
"printWidth": 90,
|
||||
"trailingComma": "none"
|
||||
}
|
||||
|
@ -32,7 +32,10 @@ describe('Asset Owners', () => {
|
||||
it('should set the provider of an asset', async () => {
|
||||
const ddo = await ocean.assets.create(metadata as any, account1)
|
||||
|
||||
const isProvider = await ocean.keeper.didRegistry.isDIDProvider(ddo.id, config.brizoAddress)
|
||||
const isProvider = await ocean.keeper.didRegistry.isDIDProvider(
|
||||
ddo.id,
|
||||
config.brizoAddress
|
||||
)
|
||||
|
||||
assert.isTrue(isProvider)
|
||||
})
|
||||
@ -40,11 +43,19 @@ describe('Asset Owners', () => {
|
||||
it('should be added correctly a permission on an asset', async () => {
|
||||
const ddo = await ocean.assets.create(metadata as any, account1)
|
||||
|
||||
assert.isFalse(await ocean.keeper.didRegistry.getPermission(ddo.id, account2.getId()))
|
||||
assert.isFalse(
|
||||
await ocean.keeper.didRegistry.getPermission(ddo.id, account2.getId())
|
||||
)
|
||||
|
||||
await ocean.keeper.didRegistry.grantPermission(ddo.id, account2.getId(), account1.getId())
|
||||
await ocean.keeper.didRegistry.grantPermission(
|
||||
ddo.id,
|
||||
account2.getId(),
|
||||
account1.getId()
|
||||
)
|
||||
|
||||
assert.isTrue(await ocean.keeper.didRegistry.getPermission(ddo.id, account2.getId()))
|
||||
assert.isTrue(
|
||||
await ocean.keeper.didRegistry.getPermission(ddo.id, account2.getId())
|
||||
)
|
||||
})
|
||||
|
||||
it('should get the assets owned by a user', async () => {
|
||||
@ -61,16 +72,22 @@ describe('Asset Owners', () => {
|
||||
})
|
||||
|
||||
it('should get the assets that can be consumed by a user', async () => {
|
||||
const { length: initialLength } = await ocean.assets.consumerAssets(account2.getId())
|
||||
const { length: initialLength } = await ocean.assets.consumerAssets(
|
||||
account2.getId()
|
||||
)
|
||||
|
||||
const ddo = await ocean.assets.create(metadata as any, account1)
|
||||
|
||||
const { length: finalLength1 } = await ocean.assets.consumerAssets(account2.getId())
|
||||
const { length: finalLength1 } = await ocean.assets.consumerAssets(
|
||||
account2.getId()
|
||||
)
|
||||
assert.equal(finalLength1 - initialLength, 0)
|
||||
|
||||
// Granting access
|
||||
try {
|
||||
await account2.requestTokens(+metadata.main.price * 10 ** -(await ocean.keeper.token.decimals()))
|
||||
await account2.requestTokens(
|
||||
+metadata.main.price * 10 ** -(await ocean.keeper.token.decimals())
|
||||
)
|
||||
} catch {}
|
||||
|
||||
const { index } = ddo.findServiceByType('access')
|
||||
@ -78,7 +95,9 @@ describe('Asset Owners', () => {
|
||||
await ocean.assets.order(ddo.id, index, account2)
|
||||
// Access granted
|
||||
|
||||
const { length: finalLength2 } = await ocean.assets.consumerAssets(account2.getId())
|
||||
const { length: finalLength2 } = await ocean.assets.consumerAssets(
|
||||
account2.getId()
|
||||
)
|
||||
assert.equal(finalLength2 - initialLength, 1)
|
||||
})
|
||||
|
||||
|
@ -37,28 +37,48 @@ describe('Consume Asset', () => {
|
||||
assert.isDefined(ddo, 'Register has not returned a DDO')
|
||||
assert.match(ddo.id, /^did:op:[a-f0-9]{64}$/, 'DDO id is not valid')
|
||||
assert.isAtLeast(ddo.authentication.length, 1, 'Default authentication not added')
|
||||
assert.isDefined(ddo.findServiceByType('access'), "DDO access service doesn't exist")
|
||||
assert.isDefined(
|
||||
ddo.findServiceByType('access'),
|
||||
"DDO access service doesn't exist"
|
||||
)
|
||||
})
|
||||
|
||||
it('should be able to request tokens for consumer', async () => {
|
||||
const initialBalance = (await consumer.getBalance()).ocn
|
||||
const claimedTokens = +metadata.main.price * 10 ** -(await ocean.keeper.token.decimals())
|
||||
const claimedTokens =
|
||||
+metadata.main.price * 10 ** -(await ocean.keeper.token.decimals())
|
||||
|
||||
try {
|
||||
await consumer.requestTokens(claimedTokens)
|
||||
} catch {}
|
||||
|
||||
assert.equal((await consumer.getBalance()).ocn, initialBalance + claimedTokens, 'OCN Tokens not delivered')
|
||||
assert.equal(
|
||||
(await consumer.getBalance()).ocn,
|
||||
initialBalance + claimedTokens,
|
||||
'OCN Tokens not delivered'
|
||||
)
|
||||
})
|
||||
|
||||
it('should sign the service agreement', async () => {
|
||||
const accessService = ddo.findServiceByType('access')
|
||||
|
||||
serviceAgreementSignatureResult = await ocean.agreements.prepare(ddo.id, accessService.index, consumer)
|
||||
serviceAgreementSignatureResult = await ocean.agreements.prepare(
|
||||
ddo.id,
|
||||
accessService.index,
|
||||
consumer
|
||||
)
|
||||
|
||||
const { agreementId, signature } = serviceAgreementSignatureResult
|
||||
assert.match(agreementId, /^0x[a-f0-9]{64}$/, 'Service agreement ID seems not valid')
|
||||
assert.match(signature, /^0x[a-f0-9]{130}$/, 'Service agreement signature seems not valid')
|
||||
assert.match(
|
||||
agreementId,
|
||||
/^0x[a-f0-9]{64}$/,
|
||||
'Service agreement ID seems not valid'
|
||||
)
|
||||
assert.match(
|
||||
signature,
|
||||
/^0x[a-f0-9]{130}$/,
|
||||
'Service agreement signature seems not valid'
|
||||
)
|
||||
})
|
||||
|
||||
it('should execute the service agreement', async () => {
|
||||
@ -77,7 +97,9 @@ describe('Consume Asset', () => {
|
||||
})
|
||||
|
||||
it('should get the agreement conditions status not fulfilled', async () => {
|
||||
const status = await ocean.agreements.status(serviceAgreementSignatureResult.agreementId)
|
||||
const status = await ocean.agreements.status(
|
||||
serviceAgreementSignatureResult.agreementId
|
||||
)
|
||||
|
||||
assert.deepEqual(status, {
|
||||
lockReward: ConditionState.Unfulfilled,
|
||||
@ -118,7 +140,9 @@ describe('Consume Asset', () => {
|
||||
})
|
||||
|
||||
it('should get the agreement conditions status fulfilled', async () => {
|
||||
const status = await ocean.agreements.status(serviceAgreementSignatureResult.agreementId)
|
||||
const status = await ocean.agreements.status(
|
||||
serviceAgreementSignatureResult.agreementId
|
||||
)
|
||||
|
||||
assert.deepEqual(status, {
|
||||
lockReward: ConditionState.Fulfilled,
|
||||
@ -147,7 +171,11 @@ describe('Consume Asset', () => {
|
||||
})
|
||||
})
|
||||
|
||||
assert.deepEqual(files, ['README.md', 'package.json'], 'Stored files are not correct.')
|
||||
assert.deepEqual(
|
||||
files,
|
||||
['README.md', 'package.json'],
|
||||
'Stored files are not correct.'
|
||||
)
|
||||
})
|
||||
|
||||
it('should consume and store one asset', async () => {
|
||||
|
@ -41,7 +41,9 @@ describe('Consume Asset (Brizo)', () => {
|
||||
|
||||
it('should regiester an asset', async () => {
|
||||
const steps = []
|
||||
ddo = await ocean.assets.create(metadata as any, publisher).next(step => steps.push(step))
|
||||
ddo = await ocean.assets
|
||||
.create(metadata as any, publisher)
|
||||
.next(step => steps.push(step))
|
||||
|
||||
assert.instanceOf(ddo, DDO)
|
||||
assert.deepEqual(steps, [0, 1, 2, 3, 4, 5, 6, 7])
|
||||
@ -51,11 +53,15 @@ describe('Consume Asset (Brizo)', () => {
|
||||
const accessService = ddo.findServiceByType('access')
|
||||
|
||||
try {
|
||||
await consumer.requestTokens(+metadata.main.price * 10 ** -(await ocean.keeper.token.decimals()))
|
||||
await consumer.requestTokens(
|
||||
+metadata.main.price * 10 ** -(await ocean.keeper.token.decimals())
|
||||
)
|
||||
} catch {}
|
||||
|
||||
const steps = []
|
||||
agreementId = await ocean.assets.order(ddo.id, accessService.index, consumer).next(step => steps.push(step))
|
||||
agreementId = await ocean.assets
|
||||
.order(ddo.id, accessService.index, consumer)
|
||||
.next(step => steps.push(step))
|
||||
|
||||
assert.isDefined(agreementId)
|
||||
assert.deepEqual(steps, [0, 1, 2, 3])
|
||||
@ -65,7 +71,13 @@ describe('Consume Asset (Brizo)', () => {
|
||||
const accessService = ddo.findServiceByType('access')
|
||||
|
||||
const folder = '/tmp/ocean/squid-js'
|
||||
const path = await ocean.assets.consume(agreementId, ddo.id, accessService.index, consumer, folder)
|
||||
const path = await ocean.assets.consume(
|
||||
agreementId,
|
||||
ddo.id,
|
||||
accessService.index,
|
||||
consumer,
|
||||
folder
|
||||
)
|
||||
|
||||
assert.include(path, folder, 'The storage path is not correct.')
|
||||
|
||||
@ -75,6 +87,10 @@ describe('Consume Asset (Brizo)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
assert.deepEqual(files, ['README.md', 'package.json'], 'Stored files are not correct.')
|
||||
assert.deepEqual(
|
||||
files,
|
||||
['README.md', 'package.json'],
|
||||
'Stored files are not correct.'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
@ -32,7 +32,13 @@ xdescribe('Consume Asset (Large size)', () => {
|
||||
...baseMetadata,
|
||||
main: {
|
||||
...baseMetadata.main,
|
||||
files: [{ index: 0, contentType: 'hello/hello', url: 'https://speed.hetzner.de/1GB.bin' }]
|
||||
files: [
|
||||
{
|
||||
index: 0,
|
||||
contentType: 'hello/hello',
|
||||
url: 'https://speed.hetzner.de/1GB.bin'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -47,7 +53,9 @@ xdescribe('Consume Asset (Large size)', () => {
|
||||
const accessService = ddo.findServiceByType('access')
|
||||
|
||||
try {
|
||||
await consumer.requestTokens(+metadata.main.price * 10 ** -(await ocean.keeper.token.decimals()))
|
||||
await consumer.requestTokens(
|
||||
+metadata.main.price * 10 ** -(await ocean.keeper.token.decimals())
|
||||
)
|
||||
} catch {}
|
||||
|
||||
agreementId = await ocean.assets.order(ddo.id, accessService.index, consumer)
|
||||
@ -59,7 +67,13 @@ xdescribe('Consume Asset (Large size)', () => {
|
||||
const accessService = ddo.findServiceByType('access')
|
||||
|
||||
const folder = '/tmp/ocean/squid-js'
|
||||
const path = await ocean.assets.consume(agreementId, ddo.id, accessService.index, consumer, folder)
|
||||
const path = await ocean.assets.consume(
|
||||
agreementId,
|
||||
ddo.id,
|
||||
accessService.index,
|
||||
consumer,
|
||||
folder
|
||||
)
|
||||
|
||||
assert.include(path, folder, 'The storage path is not correct.')
|
||||
|
||||
|
@ -47,13 +47,21 @@ describe('Register Escrow Access Secret Store Template', () => {
|
||||
|
||||
describe('Propose and approve template', () => {
|
||||
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
|
||||
await new Promise(resolve => setTimeout(resolve, 2 * 1000))
|
||||
})
|
||||
|
||||
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
|
||||
await new Promise(resolve => setTimeout(resolve, 2 * 1000))
|
||||
})
|
||||
@ -68,11 +76,21 @@ describe('Register Escrow Access Secret Store Template', () => {
|
||||
let conditionIdEscrow: string
|
||||
|
||||
it('should register a DID', async () => {
|
||||
await keeper.didRegistry.registerAttribute(did, checksum, [], url, publisher.getId())
|
||||
await keeper.didRegistry.registerAttribute(
|
||||
did,
|
||||
checksum,
|
||||
[],
|
||||
url,
|
||||
publisher.getId()
|
||||
)
|
||||
})
|
||||
|
||||
it('should generate the condition IDs', async () => {
|
||||
conditionIdAccess = await accessSecretStoreCondition.generateIdHash(agreementId, did, consumer.getId())
|
||||
conditionIdAccess = await accessSecretStoreCondition.generateIdHash(
|
||||
agreementId,
|
||||
did,
|
||||
consumer.getId()
|
||||
)
|
||||
conditionIdLock = await lockRewardCondition.generateIdHash(
|
||||
agreementId,
|
||||
await escrowReward.getAddress(),
|
||||
@ -108,10 +126,20 @@ describe('Register Escrow Access Secret Store Template', () => {
|
||||
|
||||
assert.equal(conditionInstances.length, 3, 'Expected 3 conditions.')
|
||||
|
||||
const conditionClasses = [AccessSecretStoreCondition, EscrowReward, LockRewardCondition]
|
||||
const conditionClasses = [
|
||||
AccessSecretStoreCondition,
|
||||
EscrowReward,
|
||||
LockRewardCondition
|
||||
]
|
||||
conditionClasses.forEach(conditionClass => {
|
||||
if (!conditionInstances.find(condition => condition instanceof conditionClass)) {
|
||||
throw new Error(`${conditionClass.name} is not part of the conditions.`)
|
||||
if (
|
||||
!conditionInstances.find(
|
||||
condition => condition instanceof conditionClass
|
||||
)
|
||||
) {
|
||||
throw new Error(
|
||||
`${conditionClass.name} is not part of the conditions.`
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -131,7 +159,10 @@ describe('Register Escrow Access Secret Store Template', () => {
|
||||
})
|
||||
|
||||
it('should not grant the access to the consumer', async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(consumer.getId(), did)
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(
|
||||
consumer.getId(),
|
||||
did
|
||||
)
|
||||
|
||||
assert.isFalse(accessGranted, 'Consumer has been granted.')
|
||||
})
|
||||
@ -141,7 +172,11 @@ describe('Register Escrow Access Secret Store Template', () => {
|
||||
await consumer.requestTokens(escrowAmount)
|
||||
} catch {}
|
||||
|
||||
await keeper.token.approve(lockRewardCondition.getAddress(), escrowAmount, consumer.getId())
|
||||
await keeper.token.approve(
|
||||
lockRewardCondition.getAddress(),
|
||||
escrowAmount,
|
||||
consumer.getId()
|
||||
)
|
||||
|
||||
const fulfill = await lockRewardCondition.fulfill(
|
||||
agreementId,
|
||||
@ -179,7 +214,10 @@ describe('Register Escrow Access Secret Store Template', () => {
|
||||
})
|
||||
|
||||
it('should grant the access to the consumer', async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(consumer.getId(), did)
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(
|
||||
consumer.getId(),
|
||||
did
|
||||
)
|
||||
|
||||
assert.isTrue(accessGranted, 'Consumer has not been granted.')
|
||||
})
|
||||
@ -192,17 +230,31 @@ describe('Register Escrow Access Secret Store Template', () => {
|
||||
|
||||
it('should register a DID', async () => {
|
||||
// This part is executed inside Ocean.assets.create()
|
||||
await keeper.didRegistry.registerAttribute(did, checksum, [], url, publisher.getId())
|
||||
await keeper.didRegistry.registerAttribute(
|
||||
did,
|
||||
checksum,
|
||||
[],
|
||||
url,
|
||||
publisher.getId()
|
||||
)
|
||||
})
|
||||
|
||||
it('should create a new agreement (short way)', async () => {
|
||||
agreementId = await template.createFullAgreement(did, escrowAmount, consumer.getId(), publisher.getId())
|
||||
agreementId = await template.createFullAgreement(
|
||||
did,
|
||||
escrowAmount,
|
||||
consumer.getId(),
|
||||
publisher.getId()
|
||||
)
|
||||
|
||||
assert.match(agreementId, /^0x[a-f0-9]{64}$/i)
|
||||
})
|
||||
|
||||
it('should not grant the access to the consumer', async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(consumer.getId(), did)
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(
|
||||
consumer.getId(),
|
||||
did
|
||||
)
|
||||
|
||||
assert.isFalse(accessGranted, 'Consumer has been granted.')
|
||||
})
|
||||
@ -212,11 +264,20 @@ describe('Register Escrow Access Secret Store Template', () => {
|
||||
await consumer.requestTokens(escrowAmount)
|
||||
} catch {}
|
||||
|
||||
await ocean.agreements.conditions.lockReward(agreementId, escrowAmount, consumer)
|
||||
await ocean.agreements.conditions.lockReward(
|
||||
agreementId,
|
||||
escrowAmount,
|
||||
consumer
|
||||
)
|
||||
})
|
||||
|
||||
it('should fulfill the conditions from publisher side', async () => {
|
||||
await ocean.agreements.conditions.grantAccess(agreementId, did, consumer.getId(), publisher)
|
||||
await ocean.agreements.conditions.grantAccess(
|
||||
agreementId,
|
||||
did,
|
||||
consumer.getId(),
|
||||
publisher
|
||||
)
|
||||
await ocean.agreements.conditions.releaseReward(
|
||||
agreementId,
|
||||
escrowAmount,
|
||||
@ -228,7 +289,10 @@ describe('Register Escrow Access Secret Store Template', () => {
|
||||
})
|
||||
|
||||
it('should grant the access to the consumer', async () => {
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(consumer.getId(), did)
|
||||
const accessGranted = await accessSecretStoreCondition.checkPermissions(
|
||||
consumer.getId(),
|
||||
did
|
||||
)
|
||||
|
||||
assert.isTrue(accessGranted, 'Consumer has not been granted.')
|
||||
})
|
||||
|
@ -47,13 +47,21 @@ describe('Register Escrow Compute Execution Template', () => {
|
||||
|
||||
describe('Propose and approve template', () => {
|
||||
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
|
||||
await new Promise(resolve => setTimeout(resolve, 2 * 1000))
|
||||
})
|
||||
|
||||
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
|
||||
await new Promise(resolve => setTimeout(resolve, 2 * 1000))
|
||||
})
|
||||
@ -68,11 +76,21 @@ describe('Register Escrow Compute Execution Template', () => {
|
||||
let conditionIdEscrow: string
|
||||
|
||||
it('should register a DID', async () => {
|
||||
await keeper.didRegistry.registerAttribute(did, checksum, [], url, publisher.getId())
|
||||
await keeper.didRegistry.registerAttribute(
|
||||
did,
|
||||
checksum,
|
||||
[],
|
||||
url,
|
||||
publisher.getId()
|
||||
)
|
||||
})
|
||||
|
||||
it('should generate the condition IDs', async () => {
|
||||
conditionIdCompute = await computeExecutionCondition.generateIdHash(agreementId, did, consumer.getId())
|
||||
conditionIdCompute = await computeExecutionCondition.generateIdHash(
|
||||
agreementId,
|
||||
did,
|
||||
consumer.getId()
|
||||
)
|
||||
conditionIdLock = await lockRewardCondition.generateIdHash(
|
||||
agreementId,
|
||||
await escrowReward.getAddress(),
|
||||
@ -108,10 +126,20 @@ describe('Register Escrow Compute Execution Template', () => {
|
||||
|
||||
assert.equal(conditionInstances.length, 3, 'Expected 3 conditions.')
|
||||
|
||||
const conditionClasses = [ComputeExecutionCondition, EscrowReward, LockRewardCondition]
|
||||
const conditionClasses = [
|
||||
ComputeExecutionCondition,
|
||||
EscrowReward,
|
||||
LockRewardCondition
|
||||
]
|
||||
conditionClasses.forEach(conditionClass => {
|
||||
if (!conditionInstances.find(condition => condition instanceof conditionClass)) {
|
||||
throw new Error(`${conditionClass.name} is not part of the conditions.`)
|
||||
if (
|
||||
!conditionInstances.find(
|
||||
condition => condition instanceof conditionClass
|
||||
)
|
||||
) {
|
||||
throw new Error(
|
||||
`${conditionClass.name} is not part of the conditions.`
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -131,7 +159,10 @@ describe('Register Escrow Compute Execution Template', () => {
|
||||
})
|
||||
|
||||
it('should not trigger the compute', async () => {
|
||||
const computeTriggered = await computeExecutionCondition.wasComputeTriggered(did, consumer.getId())
|
||||
const computeTriggered = await computeExecutionCondition.wasComputeTriggered(
|
||||
did,
|
||||
consumer.getId()
|
||||
)
|
||||
|
||||
assert.isFalse(computeTriggered, 'Compute has been triggered.')
|
||||
})
|
||||
@ -141,7 +172,11 @@ describe('Register Escrow Compute Execution Template', () => {
|
||||
await consumer.requestTokens(escrowAmount)
|
||||
} catch {}
|
||||
|
||||
await keeper.token.approve(lockRewardCondition.getAddress(), escrowAmount, consumer.getId())
|
||||
await keeper.token.approve(
|
||||
lockRewardCondition.getAddress(),
|
||||
escrowAmount,
|
||||
consumer.getId()
|
||||
)
|
||||
|
||||
const fulfill = await lockRewardCondition.fulfill(
|
||||
agreementId,
|
||||
@ -179,7 +214,10 @@ describe('Register Escrow Compute Execution Template', () => {
|
||||
})
|
||||
|
||||
it('should grant the access to the consumer', async () => {
|
||||
const computeTriggered = await computeExecutionCondition.wasComputeTriggered(did, consumer.getId())
|
||||
const computeTriggered = await computeExecutionCondition.wasComputeTriggered(
|
||||
did,
|
||||
consumer.getId()
|
||||
)
|
||||
|
||||
assert.isTrue(computeTriggered, 'Compute has not been triggered.')
|
||||
})
|
||||
@ -192,17 +230,31 @@ describe('Register Escrow Compute Execution Template', () => {
|
||||
|
||||
it('should register a DID', async () => {
|
||||
// This part is executed inside Ocean.assets.create()
|
||||
await keeper.didRegistry.registerAttribute(did, checksum, [], url, publisher.getId())
|
||||
await keeper.didRegistry.registerAttribute(
|
||||
did,
|
||||
checksum,
|
||||
[],
|
||||
url,
|
||||
publisher.getId()
|
||||
)
|
||||
})
|
||||
|
||||
it('should create a new agreement (short way)', async () => {
|
||||
agreementId = await template.createFullAgreement(did, escrowAmount, consumer.getId(), publisher.getId())
|
||||
agreementId = await template.createFullAgreement(
|
||||
did,
|
||||
escrowAmount,
|
||||
consumer.getId(),
|
||||
publisher.getId()
|
||||
)
|
||||
|
||||
assert.match(agreementId, /^0x[a-f0-9]{64}$/i)
|
||||
})
|
||||
|
||||
it('should not grant the access to the consumer', async () => {
|
||||
const computeTriggered = await computeExecutionCondition.wasComputeTriggered(did, consumer.getId())
|
||||
const computeTriggered = await computeExecutionCondition.wasComputeTriggered(
|
||||
did,
|
||||
consumer.getId()
|
||||
)
|
||||
|
||||
assert.isFalse(computeTriggered, 'Compute has been triggered.')
|
||||
})
|
||||
@ -212,11 +264,20 @@ describe('Register Escrow Compute Execution Template', () => {
|
||||
await consumer.requestTokens(escrowAmount)
|
||||
} catch {}
|
||||
|
||||
await ocean.agreements.conditions.lockReward(agreementId, escrowAmount, consumer)
|
||||
await ocean.agreements.conditions.lockReward(
|
||||
agreementId,
|
||||
escrowAmount,
|
||||
consumer
|
||||
)
|
||||
})
|
||||
|
||||
it('should fulfill the conditions from computing side', async () => {
|
||||
await ocean.agreements.conditions.grantServiceExecution(agreementId, did, consumer.getId(), publisher)
|
||||
await ocean.agreements.conditions.grantServiceExecution(
|
||||
agreementId,
|
||||
did,
|
||||
consumer.getId(),
|
||||
publisher
|
||||
)
|
||||
await ocean.agreements.conditions.releaseReward(
|
||||
agreementId,
|
||||
escrowAmount,
|
||||
@ -228,7 +289,10 @@ describe('Register Escrow Compute Execution Template', () => {
|
||||
})
|
||||
|
||||
it('should grant the access to the consumer', async () => {
|
||||
const computeTriggered = await computeExecutionCondition.wasComputeTriggered(did, consumer.getId())
|
||||
const computeTriggered = await computeExecutionCondition.wasComputeTriggered(
|
||||
did,
|
||||
consumer.getId()
|
||||
)
|
||||
|
||||
assert.isTrue(computeTriggered, 'Compute has not been triggered.')
|
||||
})
|
||||
|
@ -15,7 +15,8 @@ describe('Search Asset', () => {
|
||||
.toString(36)
|
||||
.substr(2)
|
||||
let price
|
||||
const metadataGenerator = (name: string) => generateMetadata(`${name}${testHash}`, price)
|
||||
const metadataGenerator = (name: string) =>
|
||||
generateMetadata(`${name}${testHash}`, price)
|
||||
|
||||
let test1length
|
||||
let test2length
|
||||
@ -43,10 +44,22 @@ describe('Search Asset', () => {
|
||||
})
|
||||
|
||||
it('should register an asset', async () => {
|
||||
assert.instanceOf(await ocean.assets.create(metadataGenerator('Test1') as any, publisher), DDO)
|
||||
assert.instanceOf(await ocean.assets.create(metadataGenerator('Test2') as any, publisher), DDO)
|
||||
assert.instanceOf(await ocean.assets.create(metadataGenerator('Test2') as any, publisher), DDO)
|
||||
assert.instanceOf(await ocean.assets.create(metadataGenerator('Test3') as any, publisher), DDO)
|
||||
assert.instanceOf(
|
||||
await ocean.assets.create(metadataGenerator('Test1') as any, publisher),
|
||||
DDO
|
||||
)
|
||||
assert.instanceOf(
|
||||
await ocean.assets.create(metadataGenerator('Test2') as any, publisher),
|
||||
DDO
|
||||
)
|
||||
assert.instanceOf(
|
||||
await ocean.assets.create(metadataGenerator('Test2') as any, publisher),
|
||||
DDO
|
||||
)
|
||||
assert.instanceOf(
|
||||
await ocean.assets.create(metadataGenerator('Test3') as any, publisher),
|
||||
DDO
|
||||
)
|
||||
})
|
||||
|
||||
it('should search by text and see the increment of DDOs', async () => {
|
||||
@ -65,8 +78,14 @@ describe('Search Asset', () => {
|
||||
it('should return a list of DDOs', async () => {
|
||||
const { results: ddos } = 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'))
|
||||
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')
|
||||
)
|
||||
})
|
||||
|
||||
it('should be able to do a query to get a list of DDOs', async () => {
|
||||
@ -82,6 +101,8 @@ 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')
|
||||
)
|
||||
})
|
||||
})
|
||||
|
@ -13,12 +13,14 @@ const metadata: Partial<MetaData> = {
|
||||
{
|
||||
index: 0,
|
||||
contentType: 'application/json',
|
||||
url: 'https://raw.githubusercontent.com/oceanprotocol/squid-js/master/package.json'
|
||||
url:
|
||||
'https://raw.githubusercontent.com/oceanprotocol/squid-js/master/package.json'
|
||||
},
|
||||
{
|
||||
index: 1,
|
||||
contentType: 'text/plain',
|
||||
url: 'https://raw.githubusercontent.com/oceanprotocol/squid-js/master/README.md'
|
||||
url:
|
||||
'https://raw.githubusercontent.com/oceanprotocol/squid-js/master/README.md'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -6,23 +6,26 @@ module.exports = class AddVendorsPlugin {
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.emit.tapAsync(`AddVendorsPlugin ${this.base}`, (compilation, callback) => {
|
||||
const main = compilation.assets[`main.${this.base}`]
|
||||
const mainMap = compilation.assets[`main.${this.base}.map`]
|
||||
const vendor = compilation.assets[`vendors.${this.base}`]
|
||||
compiler.hooks.emit.tapAsync(
|
||||
`AddVendorsPlugin ${this.base}`,
|
||||
(compilation, callback) => {
|
||||
const main = compilation.assets[`main.${this.base}`]
|
||||
const mainMap = compilation.assets[`main.${this.base}.map`]
|
||||
const vendor = compilation.assets[`vendors.${this.base}`]
|
||||
|
||||
if (main && vendor) {
|
||||
const compiledAsset = new ConcatSource(main.children[0])
|
||||
compiledAsset.add(vendor)
|
||||
compiledAsset.add(main.children[1])
|
||||
compilation.assets = {}
|
||||
compilation.assets[this.base] = compiledAsset
|
||||
} else if (main && mainMap) {
|
||||
compilation.assets = {}
|
||||
compilation.assets[this.base] = main
|
||||
compilation.assets[`${this.base}.map`] = mainMap
|
||||
if (main && vendor) {
|
||||
const compiledAsset = new ConcatSource(main.children[0])
|
||||
compiledAsset.add(vendor)
|
||||
compiledAsset.add(main.children[1])
|
||||
compilation.assets = {}
|
||||
compilation.assets[this.base] = compiledAsset
|
||||
} else if (main && mainMap) {
|
||||
compilation.assets = {}
|
||||
compilation.assets[this.base] = main
|
||||
compilation.assets[`${this.base}.map`] = mainMap
|
||||
}
|
||||
callback()
|
||||
}
|
||||
callback()
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,9 @@ export interface InstantiableConfig {
|
||||
logger?: Logger
|
||||
}
|
||||
|
||||
export function generateIntantiableConfigFromConfig(config: Config): Partial<InstantiableConfig> {
|
||||
export function generateIntantiableConfigFromConfig(
|
||||
config: Config
|
||||
): Partial<InstantiableConfig> {
|
||||
const logLevel =
|
||||
typeof config.verbose !== 'number'
|
||||
? config.verbose
|
||||
|
@ -53,7 +53,10 @@ export class Aquarius extends Instantiable {
|
||||
return consumptionUrl
|
||||
})
|
||||
.catch(error => {
|
||||
this.logger.error('Error fetching the data asset consumption url: ', error)
|
||||
this.logger.error(
|
||||
'Error fetching the data asset consumption url: ',
|
||||
error
|
||||
)
|
||||
return null
|
||||
})
|
||||
|
||||
@ -72,7 +75,11 @@ export class Aquarius extends Instantiable {
|
||||
if (response.ok) {
|
||||
return response.json() as DDO[]
|
||||
}
|
||||
this.logger.error('queryMetadata failed:', response.status, response.statusText)
|
||||
this.logger.error(
|
||||
'queryMetadata failed:',
|
||||
response.status,
|
||||
response.statusText
|
||||
)
|
||||
return this.transformResult()
|
||||
})
|
||||
.then(results => {
|
||||
@ -94,7 +101,10 @@ export class Aquarius extends Instantiable {
|
||||
public async queryMetadataByText(query: SearchQuery): Promise<QueryResult> {
|
||||
const fullUrl = new URL(`${this.url}${apiPath}/query`)
|
||||
fullUrl.searchParams.append('text', query.text)
|
||||
fullUrl.searchParams.append('sort', decodeURIComponent(JSON.stringify(query.sort)))
|
||||
fullUrl.searchParams.append(
|
||||
'sort',
|
||||
decodeURIComponent(JSON.stringify(query.sort))
|
||||
)
|
||||
fullUrl.searchParams.append('offset', query.offset.toString())
|
||||
fullUrl.searchParams.append('page', query.page.toString())
|
||||
const result: QueryResult = await this.ocean.utils.fetch
|
||||
@ -103,7 +113,11 @@ export class Aquarius extends Instantiable {
|
||||
if (response.ok) {
|
||||
return response.json() as DDO[]
|
||||
}
|
||||
this.logger.log('queryMetadataByText failed:', response.status, response.statusText)
|
||||
this.logger.log(
|
||||
'queryMetadataByText failed:',
|
||||
response.status,
|
||||
response.statusText
|
||||
)
|
||||
return this.transformResult()
|
||||
})
|
||||
.then(results => {
|
||||
@ -130,7 +144,12 @@ export class Aquarius extends Instantiable {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
this.logger.error('storeDDO failed:', response.status, response.statusText, ddo)
|
||||
this.logger.error(
|
||||
'storeDDO failed:',
|
||||
response.status,
|
||||
response.statusText,
|
||||
ddo
|
||||
)
|
||||
return null as DDO
|
||||
})
|
||||
.then((response: DDO) => {
|
||||
@ -149,7 +168,10 @@ export class Aquarius extends Instantiable {
|
||||
* @param {DID | string} did DID of the asset.
|
||||
* @return {Promise<DDO>} DDO of the asset.
|
||||
*/
|
||||
public async retrieveDDO(did: DID | string, metadataServiceEndpoint?: string): Promise<DDO> {
|
||||
public async retrieveDDO(
|
||||
did: DID | string,
|
||||
metadataServiceEndpoint?: string
|
||||
): Promise<DDO> {
|
||||
did = did && DID.parse(did)
|
||||
const fullUrl = metadataServiceEndpoint || `${this.url}${apiPath}/${did.getDid()}`
|
||||
const result = await this.ocean.utils.fetch
|
||||
@ -158,7 +180,12 @@ export class Aquarius extends Instantiable {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
this.logger.log('retrieveDDO failed:', response.status, response.statusText, did)
|
||||
this.logger.log(
|
||||
'retrieveDDO failed:',
|
||||
response.status,
|
||||
response.statusText,
|
||||
did
|
||||
)
|
||||
return null as DDO
|
||||
})
|
||||
.then((response: DDO) => {
|
||||
|
@ -35,7 +35,12 @@ export class Brizo extends Instantiable {
|
||||
return `${this.url}${apiPath}/publish`
|
||||
}
|
||||
|
||||
public getComputeEndpoint(pubKey: string, serviceIndex: number, _notUsed: string, container: string) {
|
||||
public getComputeEndpoint(
|
||||
pubKey: string,
|
||||
serviceIndex: number,
|
||||
_notUsed: string,
|
||||
container: string
|
||||
) {
|
||||
return `${this.url}${apiPath}/compute`
|
||||
}
|
||||
|
||||
@ -55,7 +60,10 @@ export class Brizo extends Instantiable {
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.ocean.utils.fetch.post(this.getPurchaseEndpoint(), decodeURI(JSON.stringify(args)))
|
||||
return await this.ocean.utils.fetch.post(
|
||||
this.getPurchaseEndpoint(),
|
||||
decodeURI(JSON.stringify(args))
|
||||
)
|
||||
} catch (e) {
|
||||
this.logger.error(e)
|
||||
throw new Error('HTTP request failed')
|
||||
@ -72,7 +80,10 @@ export class Brizo extends Instantiable {
|
||||
): Promise<string> {
|
||||
const signature =
|
||||
(await account.getToken()) ||
|
||||
(await this.ocean.utils.signature.signText(noZeroX(agreementId), account.getId()))
|
||||
(await this.ocean.utils.signature.signText(
|
||||
noZeroX(agreementId),
|
||||
account.getId()
|
||||
))
|
||||
const filesPromises = files
|
||||
.filter((_, i) => index === -1 || i === index)
|
||||
.map(async ({ index: i }) => {
|
||||
@ -94,7 +105,12 @@ export class Brizo extends Instantiable {
|
||||
return destination
|
||||
}
|
||||
|
||||
public async encrypt(did: string, signature: string, document: any, publisher: string): Promise<string> {
|
||||
public async encrypt(
|
||||
did: string,
|
||||
signature: string,
|
||||
document: any,
|
||||
publisher: string
|
||||
): Promise<string> {
|
||||
const args = {
|
||||
documentId: did,
|
||||
signature,
|
||||
|
@ -50,7 +50,8 @@ export class DDO {
|
||||
|
||||
public constructor(ddo: Partial<DDO> = {}) {
|
||||
Object.assign(this, ddo, {
|
||||
created: (ddo && ddo.created) || new Date().toISOString().replace(/\.[0-9]{3}/, '')
|
||||
created:
|
||||
(ddo && ddo.created) || new Date().toISOString().replace(/\.[0-9]{3}/, '')
|
||||
})
|
||||
}
|
||||
|
||||
@ -114,10 +115,18 @@ export class DDO {
|
||||
* @param {string} password Password if it's required.
|
||||
* @return {Promise<Proof>} Proof object.
|
||||
*/
|
||||
public async generateProof(ocean: Ocean, publicKey: string, password?: string): Promise<Proof> {
|
||||
public async generateProof(
|
||||
ocean: Ocean,
|
||||
publicKey: string,
|
||||
password?: string
|
||||
): Promise<Proof> {
|
||||
const checksum = this.getChecksum()
|
||||
|
||||
const signature = await ocean.utils.signature.signText(checksum, publicKey, password)
|
||||
const signature = await ocean.utils.signature.signText(
|
||||
checksum,
|
||||
publicKey,
|
||||
password
|
||||
)
|
||||
|
||||
return {
|
||||
created: new Date().toISOString().replace(/\.[0-9]{3}/, ''),
|
||||
@ -134,7 +143,11 @@ export class DDO {
|
||||
* @param {string} password Password if it's required.
|
||||
* @return {Promise<Proof>} Proof object.
|
||||
*/
|
||||
public async addProof(ocean: Ocean, publicKey: string, password?: string): Promise<void> {
|
||||
public async addProof(
|
||||
ocean: Ocean,
|
||||
publicKey: string,
|
||||
password?: string
|
||||
): Promise<void> {
|
||||
if (this.proof) {
|
||||
throw new Error('Proof already exists')
|
||||
}
|
||||
|
@ -13,7 +13,11 @@ export interface PublicKey {
|
||||
* Type of key.
|
||||
* @type {string}
|
||||
*/
|
||||
type: 'Ed25519VerificationKey2018' | 'RsaVerificationKey2018' | 'EdDsaSAPublicKeySecp256k1' | 'EthereumECDSAKey'
|
||||
type:
|
||||
| 'Ed25519VerificationKey2018'
|
||||
| 'RsaVerificationKey2018'
|
||||
| 'EdDsaSAPublicKeySecp256k1'
|
||||
| 'EthereumECDSAKey'
|
||||
|
||||
/**
|
||||
* Key owner.
|
||||
|
@ -2,7 +2,13 @@ import { MetaData } from './MetaData'
|
||||
import { ServiceAgreementTemplate } from './ServiceAgreementTemplate'
|
||||
import { Provider } from './ComputingProvider'
|
||||
|
||||
export type ServiceType = 'authorization' | 'metadata' | 'access' | 'compute' | 'computing' | 'fitchainCompute'
|
||||
export type ServiceType =
|
||||
| 'authorization'
|
||||
| 'metadata'
|
||||
| 'access'
|
||||
| 'compute'
|
||||
| 'computing'
|
||||
| 'fitchainCompute'
|
||||
|
||||
export interface ServiceCommon {
|
||||
type: ServiceType
|
||||
@ -52,7 +58,9 @@ export interface ServiceCompute extends ServiceCommon {
|
||||
templateId?: string
|
||||
}
|
||||
|
||||
export type Service<T extends ServiceType | 'default' = 'default'> = T extends 'authorization'
|
||||
export type Service<
|
||||
T extends ServiceType | 'default' = 'default'
|
||||
> = T extends 'authorization'
|
||||
? ServiceAuthorization
|
||||
: T extends 'metadata'
|
||||
? ServiceMetadata
|
||||
|
@ -6,7 +6,11 @@ export default class ContractHandler extends Instantiable {
|
||||
return ContractHandler.contracts.get(this.getHash(what, networkId))
|
||||
}
|
||||
|
||||
protected static setContract(what: string, networkId: number, contractInstance: Contract) {
|
||||
protected static setContract(
|
||||
what: string,
|
||||
networkId: number,
|
||||
contractInstance: Contract
|
||||
) {
|
||||
ContractHandler.contracts.set(this.getHash(what, networkId), contractInstance)
|
||||
}
|
||||
|
||||
@ -29,7 +33,10 @@ export default class ContractHandler extends Instantiable {
|
||||
const where = (await this.ocean.keeper.getNetworkName()).toLowerCase()
|
||||
const networkId = await this.ocean.keeper.getNetworkId()
|
||||
try {
|
||||
return ContractHandler.getContract(what, networkId) || (await this.load(what, where, networkId))
|
||||
return (
|
||||
ContractHandler.getContract(what, networkId) ||
|
||||
(await this.load(what, where, networkId))
|
||||
)
|
||||
} catch (err) {
|
||||
if (!optional) {
|
||||
this.logger.error('Failed to load', what, 'from', where, err)
|
||||
@ -38,7 +45,11 @@ export default class ContractHandler extends Instantiable {
|
||||
}
|
||||
}
|
||||
|
||||
private async load(what: string, where: string, networkId: number): Promise<Contract> {
|
||||
private async load(
|
||||
what: string,
|
||||
where: string,
|
||||
networkId: number
|
||||
): Promise<Contract> {
|
||||
this.logger.debug('Loading', what, 'from', where)
|
||||
const artifact = require(`@oceanprotocol/keeper-contracts/artifacts/${what}.${where}.json`)
|
||||
// Logger.log('Loaded artifact', artifact)
|
||||
@ -49,7 +60,14 @@ export default class ContractHandler extends Instantiable {
|
||||
}
|
||||
const contract = new this.web3.eth.Contract(artifact.abi, artifact.address)
|
||||
|
||||
this.logger.debug('Getting instance of', what, 'from', where, 'at address', artifact.address)
|
||||
this.logger.debug(
|
||||
'Getting instance of',
|
||||
what,
|
||||
'from',
|
||||
where,
|
||||
'at address',
|
||||
artifact.address
|
||||
)
|
||||
ContractHandler.setContract(what, networkId, contract)
|
||||
return ContractHandler.getContract(what, networkId)
|
||||
}
|
||||
|
@ -41,7 +41,11 @@ export class EventHandler extends Instantiable {
|
||||
}
|
||||
}
|
||||
|
||||
public getEvent(contract: ContractBase, eventName: string, filter: { [key: string]: any }) {
|
||||
public getEvent(
|
||||
contract: ContractBase,
|
||||
eventName: string,
|
||||
filter: { [key: string]: any }
|
||||
) {
|
||||
return new ContractEvent(this, contract, eventName, filter)
|
||||
}
|
||||
|
||||
@ -61,6 +65,9 @@ export class EventHandler extends Instantiable {
|
||||
this.events.forEach(fn => fn(this.lastBlock + 1))
|
||||
this.lastBlock = blockNumber
|
||||
}
|
||||
this.lastTimeout = global.setTimeout(() => this.checkBlock(true, n++), this.interval)
|
||||
this.lastTimeout = global.setTimeout(
|
||||
() => this.checkBlock(true, n++),
|
||||
this.interval
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,11 @@ import {
|
||||
EscrowAccessSecretStoreTemplate,
|
||||
EscrowComputeExecutionTemplate
|
||||
} from './contracts/templates'
|
||||
import { TemplateStoreManager, AgreementStoreManager, ConditionStoreManager } from './contracts/managers'
|
||||
import {
|
||||
TemplateStoreManager,
|
||||
AgreementStoreManager,
|
||||
ConditionStoreManager
|
||||
} from './contracts/managers'
|
||||
|
||||
import { objectPromiseAll } from '../utils'
|
||||
import { EventHandler } from './EventHandler'
|
||||
@ -55,11 +59,17 @@ export class Keeper extends Instantiable {
|
||||
// Conditions
|
||||
lockRewardCondition: LockRewardCondition.getInstance(config),
|
||||
escrowReward: EscrowReward.getInstance(config),
|
||||
accessSecretStoreCondition: AccessSecretStoreCondition.getInstance(config),
|
||||
accessSecretStoreCondition: AccessSecretStoreCondition.getInstance(
|
||||
config
|
||||
),
|
||||
computeExecutionCondition: ComputeExecutionCondition.getInstance(config),
|
||||
// Templates
|
||||
escrowAccessSecretStoreTemplate: EscrowAccessSecretStoreTemplate.getInstance(config),
|
||||
escrowComputeExecutionTemplate: EscrowComputeExecutionTemplate.getInstance(config)
|
||||
escrowAccessSecretStoreTemplate: EscrowAccessSecretStoreTemplate.getInstance(
|
||||
config
|
||||
),
|
||||
escrowComputeExecutionTemplate: EscrowComputeExecutionTemplate.getInstance(
|
||||
config
|
||||
)
|
||||
})
|
||||
|
||||
keeper.connected = true
|
||||
@ -92,8 +102,10 @@ export class Keeper extends Instantiable {
|
||||
}
|
||||
// Conditions
|
||||
keeper.templates = {
|
||||
escrowAccessSecretStoreTemplate: keeper.instances.escrowAccessSecretStoreTemplate,
|
||||
escrowComputeExecutionTemplate: keeper.instances.escrowComputeExecutionTemplate
|
||||
escrowAccessSecretStoreTemplate:
|
||||
keeper.instances.escrowAccessSecretStoreTemplate,
|
||||
escrowComputeExecutionTemplate:
|
||||
keeper.instances.escrowComputeExecutionTemplate
|
||||
}
|
||||
// Utils
|
||||
keeper.utils = {
|
||||
@ -178,7 +190,9 @@ export class Keeper extends Instantiable {
|
||||
* @return {Condition} Condition instance.
|
||||
*/
|
||||
public getConditionByAddress(address: string): Condition {
|
||||
return Object.values(this.conditions).find(condition => condition.getAddress() === address)
|
||||
return Object.values(this.conditions).find(
|
||||
condition => condition.getAddress() === address
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,7 +201,9 @@ export class Keeper extends Instantiable {
|
||||
* @return {AgreementTemplate} Agreement template instance.
|
||||
*/
|
||||
public getTemplateByName(name: string): AgreementTemplate {
|
||||
return Object.values(this.templates).find(template => template.contractName === name)
|
||||
return Object.values(this.templates).find(
|
||||
template => template.contractName === name
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,7 +212,9 @@ export class Keeper extends Instantiable {
|
||||
* @return {AgreementTemplate} Agreement template instance.
|
||||
*/
|
||||
public getTemplateByAddress(address: string): AgreementTemplate {
|
||||
return Object.values(this.templates).find(template => template.getAddress() === address)
|
||||
return Object.values(this.templates).find(
|
||||
template => template.getAddress() === address
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,6 +7,10 @@ export default class Web3Provider {
|
||||
* @return {Web3}
|
||||
*/
|
||||
public static getWeb3(config: Partial<Config> = {}): Web3 {
|
||||
return new Web3(config.web3Provider || Web3.givenProvider || new Web3.providers.HttpProvider(config.nodeUri))
|
||||
return new Web3(
|
||||
config.web3Provider ||
|
||||
Web3.givenProvider ||
|
||||
new Web3.providers.HttpProvider(config.nodeUri)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,9 @@ export abstract class ContractBase extends Instantiable {
|
||||
|
||||
public async getEventData(eventName: string, options: any) {
|
||||
if (!this.contract.events[eventName]) {
|
||||
throw new Error(`Event "${eventName}" not found on contract "${this.contractName}"`)
|
||||
throw new Error(
|
||||
`Event "${eventName}" not found on contract "${this.contractName}"`
|
||||
)
|
||||
}
|
||||
return this.contract.getPastEvents(eventName, options)
|
||||
}
|
||||
@ -62,14 +64,24 @@ export abstract class ContractBase extends Instantiable {
|
||||
return from
|
||||
}
|
||||
|
||||
protected async sendFrom(name: string, args: any[], from?: string): Promise<TransactionReceipt> {
|
||||
protected async sendFrom(
|
||||
name: string,
|
||||
args: any[],
|
||||
from?: string
|
||||
): Promise<TransactionReceipt> {
|
||||
from = await this.getFromAddress(from)
|
||||
return this.send(name, from, args)
|
||||
}
|
||||
|
||||
protected async send(name: string, from: string, args: any[]): Promise<TransactionReceipt> {
|
||||
protected async send(
|
||||
name: string,
|
||||
from: string,
|
||||
args: any[]
|
||||
): Promise<TransactionReceipt> {
|
||||
if (!this.contract.methods[name]) {
|
||||
throw new Error(`Method "${name}" is not part of contract "${this.contractName}"`)
|
||||
throw new Error(
|
||||
`Method "${name}" is not part of contract "${this.contractName}"`
|
||||
)
|
||||
}
|
||||
// Logger.log(name, args)
|
||||