Skip to content
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d7bb124
Put nft object within indexedMetadata for new DDO structure.
mariacarmina Jan 27, 2025
24a6a25
Merge branch 'feature/new-ddo-structure' into feature/new-nft
mariacarmina Jan 27, 2025
780c2f3
Add nft within indexedMetadata.
mariacarmina Jan 28, 2025
fccd61d
Fix DDO structure.
mariacarmina Jan 28, 2025
73162eb
Enforce indexedMetadata when validating the DDO.
mariacarmina Jan 28, 2025
9c272d7
Make it optional.
mariacarmina Jan 28, 2025
fcc7884
Add new logic.
mariacarmina Jan 28, 2025
56fd3b7
Fix conflicts.
mariacarmina Jan 29, 2025
b03d028
Merge branch 'feature/new-ddo-structure' into feature/new-nft
mariacarmina Jan 30, 2025
2c65948
Updated ddo with correct details.
mariacarmina Jan 30, 2025
447121d
Add services.
mariacarmina Jan 30, 2025
e9c1572
Fixed service format.
mariacarmina Feb 3, 2025
dada3c5
Modified sample ddo structure.
mariacarmina Feb 3, 2025
4554b13
debug test.
mariacarmina Feb 3, 2025
013344e
Fix download ddo structure for new nft format.
mariacarmina Feb 5, 2025
df1a58a
Add debug logs for consume flow.
mariacarmina Feb 6, 2025
dddf70e
debug log.
mariacarmina Feb 6, 2025
9228388
remove indexed metadata key.
mariacarmina Feb 6, 2025
b4c1c08
Test only consume flow.
mariacarmina Feb 6, 2025
75a433e
Changed consumer address.
mariacarmina Feb 6, 2025
6e0c667
remove indexed metadata.
mariacarmina Feb 6, 2025
4d3477c
fix import.
mariacarmina Feb 6, 2025
248d670
Added test back.
mariacarmina Feb 6, 2025
2631bbc
delete testing purpose statements w/o effect.
mariacarmina Feb 6, 2025
ebdd8c6
run only c2d tests.
mariacarmina Feb 8, 2025
201ee4d
add back the tests.
mariacarmina Feb 8, 2025
15708a3
Fix conflicts. Add debug log.
mariacarmina Feb 10, 2025
8594c0a
Debug log.
mariacarmina Feb 10, 2025
c1cb301
Remove indexedMetadata from DDO.
mariacarmina Feb 10, 2025
e9393f4
Added modifications to the tests.
mariacarmina Feb 10, 2025
1e01cc4
Use structuredClone for genericAsset.
mariacarmina Feb 11, 2025
f0690fd
Tests only pricing.
mariacarmina Feb 11, 2025
6be6ad1
Fixed test.
mariacarmina Feb 11, 2025
c6a0ef0
Updated the timeouts and await and indexedMetadata key in processor.
mariacarmina Feb 11, 2025
e42dce9
Fixed all the awaits in the processor.
mariacarmina Feb 11, 2025
f63c36a
Debug key.
mariacarmina Feb 11, 2025
8101858
Fix asset.
mariacarmina Feb 11, 2025
21f2a0d
Increase timeout.
mariacarmina Feb 11, 2025
7954d32
Add tests back.
mariacarmina Feb 11, 2025
30cd879
Updated key in createOrUpdateDDO.
mariacarmina Feb 11, 2025
32b1f78
Fix variable of ddo assignment.
mariacarmina Feb 11, 2025
945ee90
Tweak.
mariacarmina Feb 11, 2025
43be7b1
Updated query to be searchable.
mariacarmina Feb 11, 2025
c4f48f6
Fix.
mariacarmina Feb 11, 2025
afc8102
Add debug logs for METADATA UPDATED event.
mariacarmina Feb 17, 2025
36900d0
Include DISPENSER CREATED event as well.
mariacarmina Feb 17, 2025
1251b32
Fix conflicts.
mariacarmina Feb 17, 2025
0dc75f4
Monitor DispenserCreated event.
mariacarmina Feb 17, 2025
b6ae44c
try.
mariacarmina Feb 17, 2025
970ab52
update timeouts for testing purposes.
mariacarmina Feb 18, 2025
3fef3d7
force awaiting for event.
mariacarmina Feb 18, 2025
6125b53
Updated typesense test.
mariacarmina Feb 18, 2025
d235bf6
fix query params.
mariacarmina Feb 18, 2025
9d09450
remove test.
mariacarmina Feb 18, 2025
b9f24bf
comment.
mariacarmina Feb 18, 2025
549c03d
Solve review part 1.
mariacarmina Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ returns an empty object if it is valid otherwise an array with error
| ---------- | -------- | -------- | ------------------------------------------------- |
| command | string | v | command name |
| node | string | | if not present it means current node |
| multiAddrs | string[] | | if passed, use this instead of peerStore & DHT |
| multiAddrs | string[] | | if passed, use this instead of peerStore & DHT |
| id | string | v | document id or did |
| chainId | number | v | chain id of network on which document is provided |
| nftAddress | string | v | address of nft token |
Expand Down Expand Up @@ -1161,7 +1161,7 @@ returns the current indexing queue, as an array of objects

## PolicyServer Passthrough

### `HTTP` POST /PolicyServerPassthrough
### `HTTP` POST /api/services/PolicyServerPassthrough

### `P2P` command: PolicyServerPassthrough

Expand Down
3 changes: 0 additions & 3 deletions src/@types/DDO/DDO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Service } from './Service'
import { Metadata } from './Metadata'
import { Credentials } from './Credentials'
import { IndexedMetadata } from './IndexedMetadata'
import { Nft } from './Nft'

/**
* DID Descriptor Object.
Expand Down Expand Up @@ -60,7 +59,5 @@ export interface DDO {
*/
credentials?: Credentials

nft?: Nft

indexedMetadata?: IndexedMetadata
}
2 changes: 2 additions & 0 deletions src/@types/DDO/IndexedMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Nft } from './Nft'
import { Event } from './Event'

export type PriceType = 'fixedrate' | 'dispenser'
Expand All @@ -20,6 +21,7 @@ export interface ServiceStats {
}

export interface IndexedMetadata {
nft: Nft
stats?: ServiceStats[]
/**
* Describes the event of last metadata event
Expand Down
29 changes: 18 additions & 11 deletions src/components/Indexer/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ export class MetadataEventProcessor extends BaseEventProcessor {
metadata
)
const clonedDdo = structuredClone(ddo)
INDEXER_LOGGER.logMessage(`clonedDdo: ${JSON.stringify(clonedDdo)}`)
const updatedDdo = deleteIndexedMetadataIfExists(clonedDdo)
if (updatedDdo.id !== makeDid(event.address, chainId.toString(10))) {
INDEXER_LOGGER.error(
Expand All @@ -446,12 +447,6 @@ export class MetadataEventProcessor extends BaseEventProcessor {
ddo.chainId = chainId
ddo.nftAddress = event.address
ddo.datatokens = await this.getTokenInfo(ddo.services, signer)
ddo.nft = await this.getNFTInfo(
ddo.nftAddress,
signer,
owner,
parseInt(decodedEventData.args[6])
)

INDEXER_LOGGER.logMessage(
`Processed new DDO data ${ddo.id} with txHash ${event.transactionHash} from block ${event.blockNumber}`,
Expand Down Expand Up @@ -573,9 +568,16 @@ export class MetadataEventProcessor extends BaseEventProcessor {
}
}
}
ddo.indexedMetadata.nft = await this.getNFTInfo(
ddo.nftAddress,
signer,
owner,
parseInt(decodedEventData.args[6])
)
if (!ddo.indexedMetadata.event) {
ddo.indexedMetadata.event = {}
}

ddo.indexedMetadata.event.tx = event.transactionHash
ddo.indexedMetadata.event.from = from
ddo.indexedMetadata.event.contract = event.address
Expand Down Expand Up @@ -725,11 +727,14 @@ export class MetadataStateEventProcessor extends BaseEventProcessor {
}
INDEXER_LOGGER.logMessage(`Found did ${did} on network ${chainId}`)

if ('nft' in ddo && ddo.nft.state !== metadataState) {
if (
'nft' in ddo.indexedMetadata &&
ddo.indexedMetadata.nft.state !== metadataState
) {
let shortVersion = null

if (
ddo.nft.state === MetadataStates.ACTIVE &&
ddo.indexedMetadata.nft.state === MetadataStates.ACTIVE &&
[MetadataStates.REVOKED, MetadataStates.DEPRECATED].includes(metadataState)
) {
INDEXER_LOGGER.logMessage(
Expand All @@ -739,16 +744,18 @@ export class MetadataStateEventProcessor extends BaseEventProcessor {
id: ddo.id,
chainId,
nftAddress: ddo.nftAddress,
nft: {
state: metadataState
indexedMetadata: {
nft: {
state: metadataState
}
}
}
}

// We should keep it here, because in further development we'll store
// the previous structure of the non-visible DDOs (full version)
// in case their state changes back to active.
ddo.nft.state = metadataState
ddo.indexedMetadata.nft.state = metadataState
if (shortVersion) {
ddo = shortVersion
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/core/handler/ddoHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
try {
encryptedDocument = ethers.getBytes(task.encryptedDocument)
flags = Number(task.flags)
documentHash = task.documentHash

Check warning on line 242 in src/components/core/handler/ddoHandler.ts

View workflow job for this annotation

GitHub Actions / lint

Use object destructuring
} catch (error) {
CORE_LOGGER.logMessage(`Decrypt DDO: error ${error}`, true)
return {
Expand Down Expand Up @@ -756,7 +756,8 @@
credentials: ddoData.credentials,
indexedMetadata: {
stats: ddoData.indexedMetadata.stats,
event: ddoData.indexedMetadata.event
event: ddoData.indexedMetadata.event,
nft: ddoData.indexedMetadata.nft
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/core/handler/downloadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export function isOrderingAllowedForAsset(asset: DDO): OrdableAssetResponse {
reason: `Asset provided is either null, either undefined ${asset}`
}
} else if (
asset.nft &&
!(asset.nft.state in [MetadataStates.ACTIVE, MetadataStates.UNLISTED])
asset.indexedMetadata.nft &&
!(asset.indexedMetadata.nft.state in [MetadataStates.ACTIVE, MetadataStates.UNLISTED])
) {
return {
isOrdable: false,
Expand Down
9 changes: 7 additions & 2 deletions src/components/database/ElasticSearchDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export class ElasticsearchDdoDatabase extends AbstractDdoDatabase {

getDDOSchema(ddo: Record<string, any>) {
let schemaName: string | undefined
if (ddo.nft?.state !== 0) {
if (ddo.indexedMetadata?.nft?.state !== 0) {
schemaName = 'op_ddo_short'
} else if (ddo.version) {
schemaName = `op_ddo_v${ddo.version}`
Expand All @@ -487,7 +487,12 @@ export class ElasticsearchDdoDatabase extends AbstractDdoDatabase {
}

async validateDDO(ddo: Record<string, any>): Promise<boolean> {
if (ddo.nft?.state !== 0) {
if ('indexedMetadata' in ddo && ddo.indexedMetadata.nft?.state !== 0) {
// Skipping validation for short DDOs as it currently doesn't work
// TODO: DDO validation needs to be updated to consider the fields required by the schema
// See github issue: https://github.com/oceanprotocol/ocean-node/issues/256
return true
} else if ('nft' in ddo && ddo.nft?.state !== 0) {
return true
} else {
const validation = await validateObject(ddo, ddo.chainId, ddo.nftAddress)
Expand Down
6 changes: 4 additions & 2 deletions src/components/database/TypenseDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export class TypesenseDdoDatabase extends AbstractDdoDatabase {
getDDOSchema(ddo: Record<string, any>): TypesenseSchema {
// Find the schema based on the DDO version OR use the short DDO schema when state !== 0
let schemaName: string
if (ddo.nft?.state !== 0) {
if (ddo.indexedMetadata?.nft?.state !== 0) {
schemaName = 'op_ddo_short'
} else if (ddo.version) {
schemaName = `op_ddo_v${ddo.version}`
Expand All @@ -387,11 +387,13 @@ export class TypesenseDdoDatabase extends AbstractDdoDatabase {
}

async validateDDO(ddo: Record<string, any>): Promise<boolean> {
if (ddo.nft?.state !== 0) {
if ('indexedMetadata' in ddo && ddo.indexedMetadata.nft?.state !== 0) {
// Skipping validation for short DDOs as it currently doesn't work
// TODO: DDO validation needs to be updated to consider the fields required by the schema
// See github issue: https://github.com/oceanprotocol/ocean-node/issues/256
return true
} else if ('nft' in ddo && ddo.nft?.state !== 0) {
return true
} else {
const validation = await validateObject(ddo, ddo.chainId, ddo.nftAddress)
if (validation[0] === true) {
Expand Down
4 changes: 3 additions & 1 deletion src/components/httpRoutes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { queueRoutes } from './queue.js'
// import { getConfiguration } from '../../utils/config.js'
import { jobsRoutes } from './jobs.js'
import { addMapping, allRoutesMapping, findPathName } from './routeUtils.js'
import { PolicyServerPassthroughRoute } from './policyServer.js'

export * from './getOceanPeers.js'

Expand Down Expand Up @@ -57,7 +58,8 @@ httpRoutes.use(computeRoutes)
httpRoutes.use(queueRoutes)
// running jobs
httpRoutes.use(jobsRoutes)

// policy server passthrough
httpRoutes.use(PolicyServerPassthroughRoute)
export function getAllServiceEndpoints() {
httpRoutes.stack.forEach(addMapping.bind(null, []))
const data: any = {}
Expand Down
5 changes: 5 additions & 0 deletions src/components/httpRoutes/routeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ routesNames.set('indexQueue', {
method: 'get'
})

routesNames.set('PolicyServerPassthrough', {
path: `${SERVICES_API_BASE_PATH}/PolicyServerPassthrough`,
method: 'post'
})

export function addMapping(path: any, layer: any) {
if (layer.route) {
layer.route.stack.forEach(addMapping.bind(null, path.concat(split(layer.route.path))))
Expand Down
6 changes: 5 additions & 1 deletion src/components/policyServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export class PolicyServer {
return { success: true, message: '', httpStatus: 0 }
}
if (response.status === 200) {
return { success: true, message: '', httpStatus: response.status }
return {
success: true,
message: await response.text(),
httpStatus: response.status
}
}
return { success: false, message: await response.text(), httpStatus: response.status }
}
Expand Down
11 changes: 5 additions & 6 deletions src/test/data/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,16 @@ export const downloadAsset = {
owner: '',
created: ''
},
purgatory: {
state: false
},
datatokens: [] as any,
stats: {
allocated: 0,
orders: 0,
price: {
value: '0'
}
}
},
purgatory: {
state: false
},
datatokens: [] as any
}

const nftLevelCredentials: Credentials = {
Expand Down
25 changes: 18 additions & 7 deletions src/test/data/ddo.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
export const ddo = {
hashType: 'sha256',
'@context': ['https://w3id.org/did/v1'],
id: 'did:op:fa0e8fa9550e8eb13392d6eeb9ba9f8111801b332c8d2345b350b3bc66b379d7',
nftAddress: '0xBB1081DbF3227bbB233Db68f7117114baBb43656',
id: 'did:op:b5ef03b7f0d148cde2942c8a330625d4fc71dd32b67a0093da24fcb9a4439887',
nftAddress: '0xca63894B1c911515F1C034BE3509AfC008B42d83',
version: '4.1.0',
chainId: 137,
metadata: {
created: '2022-12-30T08:40:06Z',
updated: '2022-12-30T08:40:06Z',
type: 'dataset',
name: 'DEX volume in details',
name: 'ETH/USDT orderbook',
description:
'Volume traded and locked of Decentralized Exchanges (Uniswap, Sushiswap, Curve, Balancer, ...), daily in details',
tags: ['index', 'defi', 'tvl'],
author: 'DEX',
'Real time ETH/USDT orderbook\n\nTo take the bid orders, access data.bids array\nTo take the ask orders, access data.asks array\n\nResponse schema:\n\n```json\n{\n "code":"200000",\n "data":\n {\n "time":1665865828392,\n "sequence":"357821345",\n "bids":\n [\n ["1280","0.00078381"],\n ["1279.9","0.02901545"],\n ....\n ],\n "asks":\n [\n ["1280.2","0.0288382"],\n ["1280.3","0.00167897"],\n ...\n ]\n }\n}\n```\n\nAccess is permited for 1 day after buying.',
tags: ['defi', 'orderbook'],
author: '0x4Ab0C24005c410111e21aE16Df5e19180fAD0f6a',
license: 'https://market.oceanprotocol.com/terms',
additionalInformation: {
termsAndConditions: true
}
}
},
services: [
{
id: '24654b91482a3351050510ff72694d88edae803cf31a5da993da963ba0087648',
type: 'access',
files:
'0x04beba2f90639ff7559618160df5a81729904022578e6bd5f60c3bebfe5cb2aca59d7e062228a98ed88c4582c290045f47cdf3824d1c8bb25b46b8e10eb9dc0763ce82af826fd347517011855ce1396ac94af8cc6f29b78012b679cb78a594d9064b6f6f4a8229889f0bb53262b6ab62b56fa5c608ea126ba228dd0f87290c0628fe07023416280c067beb01a42d0a4df95fdb5a857f1f59b3e6a13b0ae4619080369ba5bede6c7beff6afc7fc31c71ed8100e7817d965d1f8f1abfaace3c01f0bd5d0127df308175941088a1f120a4d9a0290be590d65a7b4de01ae1efe24286d7a06fadeeafba83b5eab25b90961abf1f24796991f06de6c8e1c2357fbfb31f484a94e87e7dba80a489e12fffa1adde89f113b4c8c4c8877914911a008dbed0a86bdd9d14598c35894395fb4a8ea764ed2f9459f6acadac66e695b3715536338f6cdee616b721b0130f726c78ca60ec02fc86c',
datatokenAddress: '0xfF4AE9869Cafb5Ff725f962F3Bbc22Fb303A8aD8',
serviceEndpoint: 'https://v4.provider.polygon.oceanprotocol.com',
timeout: 0
}
]
}
export const genericAlgorithm = {
'@context': ['https://w3id.org/did/v1'],
Expand Down
8 changes: 7 additions & 1 deletion src/test/integration/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('Should run a complete node flow.', () => {
let publishedDataset: any
let actualDDO: any
let indexer: OceanIndexer
let anotherConsumer: ethers.Wallet

const mockSupportedNetworks: RPCS = getMockSupportedNetworks()
const serviceId = '0'
Expand Down Expand Up @@ -98,6 +99,10 @@ describe('Should run a complete node flow.', () => {
}

provider = new JsonRpcProvider('http://127.0.0.1:8545')
anotherConsumer = new ethers.Wallet(
ENVIRONMENT_VARIABLES.NODE2_PRIVATE_KEY.value,
provider
)

publisherAccount = (await provider.getSigner(0)) as Signer
consumerAccount = (await provider.getSigner(1)) as Signer
Expand Down Expand Up @@ -191,6 +196,7 @@ describe('Should run a complete node flow.', () => {
id: publishedDataset.ddo.id
}
const response = await new GetDdoHandler(oceanNode).handle(getDDOTask)
console.log('get ddo: ', JSON.stringify(response))
actualDDO = await streamToObject(response.stream as Readable)
assert(actualDDO.id === publishedDataset.ddo.id, 'DDO id not matching')
})
Expand Down Expand Up @@ -294,7 +300,7 @@ describe('Should run a complete node flow.', () => {
serviceId,
transferTxId: orderTxId,
nonce: Date.now().toString(),
consumerAddress: '0xBE5449a6A97aD46c8558A3356267Ee5D2731ab57',
consumerAddress: await anotherConsumer.getAddress(),
signature: '0xBE5449a6',
command: PROTOCOL_COMMANDS.DOWNLOAD
}
Expand Down
Loading
Loading