Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add asset edit functionality #58

Merged
merged 25 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
aeada59
feat: add asset edit functionality
Abrom8 Sep 20, 2023
03e18dd
feat: add missing edit functions for services
Abrom8 Oct 27, 2023
5f37136
feat: add getPublisherTrustedAlgorithms helper
Abrom8 Nov 2, 2023
06fe332
fix: test config
LucaMilanese90 Nov 9, 2023
0b4591e
chore: fix typo
LucaMilanese90 Nov 9, 2023
92ee736
feat: update edit tests
LucaMilanese90 Nov 9, 2023
79f3bd7
chore: update package-lock
LucaMilanese90 Nov 10, 2023
0d7adf8
refactor: add resolvePublisherTrustedAlgorithms to publish and edit flow
Abrom8 Nov 15, 2023
d7a8d8d
fix: handle undefined trustedAlgorithmAssets
Abrom8 Nov 16, 2023
a745656
docs: add Trusted Algorithms docs link
Abrom8 Nov 16, 2023
d11e4fd
reafctor: rework asset retrieval and creation
Abrom8 Nov 17, 2023
e33eaad
refactor: change lifecyclestate flow
Abrom8 Nov 19, 2023
f079bb0
refactor: create checkIfFilesObjectChanged function
Abrom8 Nov 20, 2023
6676d0c
refactor: extract createDatatokenAndPricing call from publish and edit
Abrom8 Nov 20, 2023
0b68d27
docs: add TODO comment for price change via datatoken replacement
Abrom8 Nov 20, 2023
7a1b68c
refactor: expose editServicePrice via Nautilus
Abrom8 Nov 20, 2023
023fe2d
Merge remote-tracking branch 'origin/feat/edit' into feat/update-edit…
LucaMilanese90 Nov 23, 2023
d4ffe10
refactor: improve getAssets return type
Abrom8 Nov 23, 2023
ee5fcb3
refactor: add early continue to resolvePublisherTrustedAlgorithms
Abrom8 Nov 23, 2023
4314263
refactor: relocate transformAquariusAssetToDDO into utils folder
Abrom8 Nov 23, 2023
d1a4fe5
feat: update tests
LucaMilanese90 Nov 23, 2023
4f46325
refactor: add AssetSpecificProps type
Abrom8 Nov 24, 2023
e2cc885
Merge remote-tracking branch 'origin/feat/edit' into feat/update-edit…
LucaMilanese90 Nov 23, 2023
f7c5068
Merge pull request #60 from deltaDAO/feat/update-edit-tests
moritzkirstein Nov 24, 2023
f1a2ba6
docs: add TODO for AssetSpecificProps type
Abrom8 Nov 24, 2023
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
19 changes: 2 additions & 17 deletions src/Nautilus/Asset/NautilusDDO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
NautilusService,
ServiceTypes
} from './Service/NautilusService'
import { transformAquariusAssetToDDO } from '../../utils/aquarius'

export class NautilusDDO {
id: string
Expand All @@ -35,7 +36,7 @@ export class NautilusDDO {
}

static createFromAquariusAsset(aquariusAsset: Asset): NautilusDDO {
const ddo = this.transformAquariusAssetToDDO(aquariusAsset)
const ddo = transformAquariusAssetToDDO(aquariusAsset)

return this.createFromDDO(ddo)
}
Expand Down Expand Up @@ -239,20 +240,4 @@ export class NautilusDDO {
// Otherwise we return the replacement
return replacementService
}

static transformAquariusAssetToDDO(aquariusAsset: Asset): DDO {
const ddo = structuredClone(aquariusAsset)

const unwantedAssetAttributes = [
'nft',
'datatokens',
'event',
'stats',
'purgatory'
]
for (const attribute of unwantedAssetAttributes) {
delete ddo[attribute]
}
return ddo as DDO
}
}
2 changes: 1 addition & 1 deletion src/Nautilus/Nautilus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export class Nautilus {
)
}

async getAquariusAssets(dids: string[]): Promise<{ [key: string]: Asset }> {
async getAquariusAssets(dids: string[]): Promise<{ [did: string]: Asset }> {
try {
return await getAssets(this.config.metadataCacheUri, dids)
} catch (error) {
Expand Down
16 changes: 13 additions & 3 deletions src/utils/aquarius.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
import { Asset, DDO, LoggerInstance } from '@oceanprotocol/lib'
import axios, { AxiosResponse } from 'axios'
import { AQUARIUS_ASSET_EXTENDED_DDO_PROPS } from './constants'

export async function getAsset(
metadataCacheUri: string,
Expand Down Expand Up @@ -35,7 +36,7 @@ export async function getAsset(
export async function getAssets(
metadataCacheUri: string,
dids: string[]
): Promise<{ [key: string]: Asset }> {
): Promise<{ [did: string]: Asset }> {
const apiPath = '/api/aquarius/assets/query'

if (!metadataCacheUri) {
Expand All @@ -62,7 +63,7 @@ export async function getAssets(
}
}

const assets: { [key: string]: Asset } = {}
const assets: { [did: string]: Asset } = {}

try {
const fullAquariusUrl = new URL(apiPath, metadataCacheUri).href
Expand All @@ -88,3 +89,12 @@ export async function getAssets(
throw error
}
}

export function transformAquariusAssetToDDO(aquariusAsset: Asset): DDO {
const ddo = structuredClone(aquariusAsset)

for (const attribute of AQUARIUS_ASSET_EXTENDED_DDO_PROPS) {
delete ddo[attribute]
}
return ddo as DDO
}
12 changes: 12 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Asset, DDO } from '@oceanprotocol/lib'

export type AssetSpecificProps = Exclude<keyof Asset, keyof DDO>

// these are the props which extend the DDO interface to be an aquarius Asset
// this const is needed to strip these away from an Asset to convert it into an DDO
export const AQUARIUS_ASSET_EXTENDED_DDO_PROPS: AssetSpecificProps[] = [
Abrom8 marked this conversation as resolved.
Show resolved Hide resolved
'nft',
'datatokens',
'stats',
'purgatory'
]
63 changes: 31 additions & 32 deletions src/utils/helpers/trusted-algorithms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,40 @@ export async function resolvePublisherTrustedAlgorithms(
metadataCacheUri: string
) {
for (const service of nautilusDDOServices) {
if (service.addedPublisherTrustedAlgorithms.length > 0) {
const dids = service.addedPublisherTrustedAlgorithms.map(
(asset) => asset.did
)
const newPublisherTrustedAlgorithms = await getPublisherTrustedAlgorithms(
dids,
metadataCacheUri
)
if (service.addedPublisherTrustedAlgorithms?.length) continue

if (service.compute?.publisherTrustedAlgorithms?.length === 0) {
service.compute.publisherTrustedAlgorithms =
newPublisherTrustedAlgorithms
return
}
const dids = service.addedPublisherTrustedAlgorithms.map(
(asset) => asset.did
)
const newPublisherTrustedAlgorithms = await getPublisherTrustedAlgorithms(
dids,
metadataCacheUri
)

newPublisherTrustedAlgorithms.forEach((algorithm) => {
const index = service.compute.publisherTrustedAlgorithms.findIndex(
(existingAlgorithm) => existingAlgorithm.did === algorithm.did
)
if (service.compute?.publisherTrustedAlgorithms?.length === 0) {
service.compute.publisherTrustedAlgorithms = newPublisherTrustedAlgorithms
return
}

newPublisherTrustedAlgorithms.forEach((algorithm) => {
const index = service.compute.publisherTrustedAlgorithms.findIndex(
(existingAlgorithm) => existingAlgorithm.did === algorithm.did
)

if (index === -1) {
// Algorithm with the same DID doesn't exist, add it
service.compute.publisherTrustedAlgorithms.push(algorithm)
} else {
// If either checksum is different, replace the existing algorithm
const existing = service.compute.publisherTrustedAlgorithms[index]
if (
existing.containerSectionChecksum !==
algorithm.containerSectionChecksum ||
existing.filesChecksum !== algorithm.filesChecksum
) {
service.compute.publisherTrustedAlgorithms[index] = algorithm
}
if (index === -1) {
// Algorithm with the same DID doesn't exist, add it
service.compute.publisherTrustedAlgorithms.push(algorithm)
} else {
// If either checksum is different, replace the existing algorithm
const existing = service.compute.publisherTrustedAlgorithms[index]
if (
existing.containerSectionChecksum !==
algorithm.containerSectionChecksum ||
existing.filesChecksum !== algorithm.filesChecksum
) {
service.compute.publisherTrustedAlgorithms[index] = algorithm
}
})
}
}
})
}
}