mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
prototype DDO updating for transferOwnership
This commit is contained in:
parent
dd7dcc4572
commit
ac76380ba9
@ -215,6 +215,40 @@ export class Aquarius {
|
||||
return this.retrieveDDO(undefined, metadataServiceEndpoint)
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a DDO.
|
||||
* @param {DID | string} did DID of the asset to update.
|
||||
* @param {DDO} newDdo New DDO of the asset.
|
||||
* @return {Promise<DDO>} Updated DDO of the asset.
|
||||
*/
|
||||
public async updateDDO(did: DID | string, newDdo: DDO): Promise<DDO> {
|
||||
did = did && DID.parse(did)
|
||||
const fullUrl = `${this.url}${apiPath}/${did.getDid()}`
|
||||
const result = await this.fetch
|
||||
.put(fullUrl, DDO.serialize(newDdo))
|
||||
.then((response: any) => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
this.logger.log(
|
||||
'updateDDO failed:',
|
||||
response.status,
|
||||
response.statusText,
|
||||
did
|
||||
)
|
||||
return null as DDO
|
||||
})
|
||||
.then((response: DDO) => {
|
||||
return new DDO(response) as DDO
|
||||
})
|
||||
.catch(error => {
|
||||
this.logger.error('Error updating metadata: ', error)
|
||||
return null as DDO
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
public getServiceEndpoint(did: DID) {
|
||||
return `${this.url}/api/v1/aquarius/assets/ddo/did:op:${did.getId()}`
|
||||
}
|
||||
|
@ -418,8 +418,22 @@ export class OceanAssets extends Instantiable {
|
||||
did: string,
|
||||
newOwner: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const owner = await this.ocean.assets.owner(did)
|
||||
return this.ocean.keeper.didRegistry.transferDIDOwnership(did, newOwner, owner)
|
||||
const oldOwner = await this.ocean.assets.owner(did)
|
||||
const oldDdo = await this.ocean.aquarius.retrieveDDO(did)
|
||||
|
||||
// update owner on-chain
|
||||
const txReceipt = this.ocean.keeper.didRegistry.transferDIDOwnership(
|
||||
did,
|
||||
newOwner,
|
||||
oldOwner
|
||||
)
|
||||
|
||||
// update owner off-chain in DDO
|
||||
const newDdo = oldDdo
|
||||
newDdo.publicKey[0].owner = newOwner
|
||||
await this.ocean.aquarius.updateDDO(did, newDdo)
|
||||
|
||||
return txReceipt
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user