1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

Refactor OnChainMetadataCache (#551)

* update naming, add helper update

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* fix test

* fix

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* fix test

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* fix test

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2021-01-18 14:03:56 +02:00 committed by GitHub
parent 16c21e1ecb
commit 002e38d8b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 25 deletions

View File

@ -13,7 +13,7 @@ import { LZMA } from 'lzma/src/lzma-c'
* Provides an interface with Metadata Cache.
* Metadata Cache provides an off-chain database store for metadata about data assets.
*/
export class OnChainMetadataCache {
export class OnChainMetadata {
public GASLIMIT_DEFAULT = 1000000
public DDOContractAddress: string
public DDOContractABI: AbiItem | AbiItem[]

View File

@ -1,7 +1,7 @@
import { SearchQuery, QueryResult } from '../metadatacache/MetadataCache'
import { DDO } from '../ddo/DDO'
import { Metadata } from '../ddo/interfaces/Metadata'
import { Service, ServiceAccess, ServiceComputePrivacy } from '../ddo/interfaces/Service'
import { Service, ServiceAccess } from '../ddo/interfaces/Service'
import { EditableMetadata } from '../ddo/interfaces/EditableMetadata'
import Account from './Account'
import DID from './DID'
@ -12,7 +12,7 @@ import BigNumber from 'bignumber.js'
import { Provider } from '../provider/Provider'
import { isAddress } from 'web3-utils'
import { MetadataMain } from '../ddo/interfaces'
import { DataTokens } from '../lib'
import { TransactionReceipt } from 'web3-core'
export enum CreateProgressStep {
CreatingDataToken,
@ -91,7 +91,7 @@ export class Assets extends Instantiable {
if (!dtAddress) {
this.logger.log('Creating datatoken')
observer.next(CreateProgressStep.CreatingDataToken)
// const metadataCacheUri = this.ocean.metadatacache.getURI()
// const metadataCacheUri = this.ocean.metadataCache.getURI()
// const jsonBlob = { t: 1, url: metadataCacheUri }
dtAddress = await datatokens.create('', publisher.getId(), cap, name, symbol)
@ -188,8 +188,8 @@ export class Assets extends Instantiable {
}
this.logger.log('Storing DDO')
observer.next(CreateProgressStep.StoringDdo)
// const storedDdo = await this.ocean.metadatacache.storeDDO(ddo)
const storeTx = await this.ocean.OnChainMetadataCache.publish(
// const storedDdo = await this.ocean.metadataCache.storeDDO(ddo)
const storeTx = await this.ocean.onChainMetadata.publish(
ddo.id,
ddo,
publisher.getId()
@ -207,7 +207,7 @@ export class Assets extends Instantiable {
* @return {Promise<string[]>} List of DIDs.
*/
public async ownerAssets(owner: string): Promise<QueryResult> {
return this.ocean.metadatacache.getOwnerAssets(owner)
return this.ocean.metadataCache.getOwnerAssets(owner)
}
/**
@ -216,7 +216,7 @@ export class Assets extends Instantiable {
* @return {Promise<DDO>}
*/
public async resolve(did: string): Promise<DDO> {
return this.ocean.metadatacache.retrieveDDO(did)
return this.ocean.metadataCache.retrieveDDO(did)
}
public async resolveByDTAddress(
@ -236,17 +236,17 @@ export class Assets extends Instantiable {
},
text: dtAddress
} as SearchQuery
return (await this.ocean.metadatacache.queryMetadata(searchQuery)).results
return (await this.ocean.metadataCache.queryMetadata(searchQuery)).results
}
/** Metadata updates
* Don't forget to call ocean.OnChainMetadataCache.update after using this functions
* ie: ocean.OnChainMetadataCache.update(ddo.id,ddo,account.getId())
* Don't forget to call ocean.OnChainmetadataCache.update after using this functions
* ie: ocean.OnChainmetadataCache.update(ddo.id,ddo,account.getId())
*/
/**
* Edit Metadata for a DID.
* @param {ddo} DDO if empty, will trigger a retrieve
* @param {ddo} DDO
* @param {newMetadata} EditableMetadata Metadata fields & new values.
* @return {Promise<DDO>} the new DDO
*/
@ -266,6 +266,19 @@ export class Assets extends Instantiable {
return ddo
}
/**
* Update Metadata on chain.
* @param {ddo} DDO
* @param {String} consumerAccount
* @return {Promise<TransactionReceipt>} exchangeId
*/
public async updateMetadata(
ddo: DDO,
consumerAccount: string
): Promise<TransactionReceipt> {
return await this.ocean.onChainMetadata.update(ddo.id, ddo, consumerAccount)
}
/**
* Edit Service Timeouts
* @param {ddo} DDO if empty, will trigger a retrieve
@ -312,7 +325,7 @@ export class Assets extends Instantiable {
* @return {Promise<QueryResult>}
*/
public async query(query: SearchQuery): Promise<QueryResult> {
return this.ocean.metadatacache.queryMetadata(query)
return this.ocean.metadataCache.queryMetadata(query)
}
/**
@ -321,7 +334,7 @@ export class Assets extends Instantiable {
* @return {Promise<QueryResult>}
*/
public async search(text: string): Promise<QueryResult> {
return this.ocean.metadatacache.queryMetadata({
return this.ocean.metadataCache.queryMetadata({
text,
page: 1,
offset: 100,

View File

@ -3,7 +3,7 @@ import { Assets } from './Assets'
import { Versions } from './Versions'
import { OceanUtils } from './utils/Utils'
import { MetadataCache } from '../metadatacache/MetadataCache'
import { OnChainMetadataCache } from '../metadatacache/OnChainMetaDataCache'
import { OnChainMetadata } from '../metadatacache/OnChainMetaData'
import { Provider } from '../provider/Provider'
import { DataTokens } from '../datatokens/Datatokens'
import { Network } from '../datatokens/Network'
@ -37,7 +37,7 @@ export class Ocean extends Instantiable {
instance.utils = await OceanUtils.getInstance(instanceConfig)
instance.provider = new Provider(instanceConfig)
instance.metadatacache = new MetadataCache(
instance.metadataCache = new MetadataCache(
instanceConfig.config.metadataCacheUri,
instanceConfig.logger
)
@ -71,7 +71,7 @@ export class Ocean extends Instantiable {
instance.datatokens,
instanceConfig.config.startBlock
)
instance.OnChainMetadataCache = new OnChainMetadataCache(
instance.onChainMetadata = new OnChainMetadata(
instanceConfig.config.web3Provider,
instanceConfig.logger,
instanceConfig.config.metadataContractAddress,
@ -104,12 +104,12 @@ export class Ocean extends Instantiable {
* MetadataCache instance.
* @type {MetadataCache}
*/
public metadatacache: MetadataCache
public metadataCache: MetadataCache
/**
* OnChainMetadataCache instance.
* @type {OnChainMetadataCache}
*/
public OnChainMetadataCache: OnChainMetadataCache
public onChainMetadata: OnChainMetadata
/**
* Ocean account submodule
* @type {Accounts}

View File

@ -51,7 +51,7 @@ export class Versions extends Instantiable {
// MetadataCache
try {
const { software: name, version } = await this.ocean.metadatacache.getVersionInfo()
const { software: name, version } = await this.ocean.metadataCache.getVersionInfo()
versions.metadataCache = {
name,
status: OceanPlatformTechStatus.Working,

View File

@ -474,7 +474,7 @@ describe('Compute flow', () => {
newComputePrivacy
)
assert(newDdo !== null)
const txid = await ocean.OnChainMetadataCache.update(newDdo.id, newDdo, alice.getId())
const txid = await ocean.onChainMetadata.update(newDdo.id, newDdo, alice.getId())
assert(txid !== null)
await sleep(60000)
const metaData = await ocean.assets.getServiceByType(ddo.id, 'compute')

View File

@ -214,7 +214,7 @@ describe('Marketplace flow', () => {
}
const newDdo = await ocean.assets.editMetadata(ddo, newMetaData)
assert(newDdo !== null)
const txid = await ocean.OnChainMetadataCache.update(newDdo.id, newDdo, alice.getId())
const txid = await ocean.onChainMetadata.update(newDdo.id, newDdo, alice.getId())
assert(txid !== null)
await sleep(60000)
const metaData = await ocean.assets.getServiceByType(ddo.id, 'metadata')
@ -233,7 +233,7 @@ describe('Marketplace flow', () => {
const newTimeout = 123
const newDdo = await ocean.assets.editServiceTimeout(ddo, serviceIndex, newTimeout)
assert(newDdo !== null)
const txid = await ocean.OnChainMetadataCache.update(newDdo.id, newDdo, alice.getId())
const txid = await ocean.onChainMetadata.update(newDdo.id, newDdo, alice.getId())
assert(txid !== null)
await sleep(60000)
const metaData = await ocean.assets.getServiceByType(ddo.id, 'access')

View File

@ -16,7 +16,7 @@ describe('MetadataCache', () => {
beforeEach(async () => {
ocean = await Ocean.getInstance(config)
metadataCache = ocean.metadatacache // eslint-disable-line prefer-destructuring
metadataCache = ocean.metadataCache // eslint-disable-line prefer-destructuring
})
afterEach(() => {

View File

@ -15,7 +15,7 @@ describe('Assets', () => {
beforeEach(async () => {
ocean = await Ocean.getInstance(config)
metadataCache = ocean.metadatacache // eslint-disable-line prefer-destructuring
metadataCache = ocean.metadataCache // eslint-disable-line prefer-destructuring
})
afterEach(() => {