1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

add ocean.assets.transferOwnership()

This commit is contained in:
Matthias Kretschmann 2019-11-13 15:37:03 +01:00
parent f3df816e89
commit 347915a41e
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 36 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import { TransactionReceipt } from 'web3-core'
import ContractBase from './ContractBase'
import { zeroX, didPrefixed, didZeroX } from '../../utils'
import { InstantiableConfig } from '../../Instantiable.abstract'
@ -60,4 +61,8 @@ export default class DIDRegistry extends ContractBase {
public async getPermission(did: string, grantee: string): Promise<boolean> {
return this.call('getPermission', [didZeroX(did), zeroX(grantee)])
}
public async transferDIDOwnership(did: string, owner: string, newOwner: string): Promise<TransactionReceipt> {
return this.send('transferDIDOwnership', owner, [zeroX(did), zeroX(newOwner)])
}
}

View File

@ -1,3 +1,4 @@
import { TransactionReceipt } from 'web3-core'
import { SearchQuery } from '../aquarius/Aquarius'
import { DDO } from '../ddo/DDO'
import { MetaData } from '../ddo/MetaData'
@ -355,6 +356,17 @@ export class OceanAssets extends Instantiable {
return this.ocean.keeper.didRegistry.getAttributesByOwner(owner)
}
/**
* Transfer ownership of an asset.
* @param {string} did Asset DID.
* @param {string} owner Ethereum address of the current owner of the DID.
* @param {string} newOwner Ethereum address of the new owner of the DID.
* @return {Promise<TransactionReceipt>} Returns Web3 transaction receipt.
*/
public async transferOwnership(did: string, owner: string, newOwner: string): Promise<TransactionReceipt> {
return this.ocean.keeper.didRegistry.transferDIDOwnership(did, owner, newOwner)
}
/**
* Returns the assets of a consumer.
* @param {string} consumer Consumer address.

View File

@ -13,7 +13,7 @@ describe('DIDRegistry', () => {
before(async () => {
await TestContractHandler.prepareContracts()
ocean = await Ocean.getInstance(config)
didRegistry = ocean.keeper.didRegistry
;({ didRegistry } = ocean.keeper)
})
describe('#registerAttribute()', () => {
@ -67,4 +67,22 @@ describe('DIDRegistry', () => {
assert.equal(owner, `0x${'0'.repeat(40)}`)
})
})
describe('#transferDIDOwnership()', () => {
it('should be able to transfer ownership', async () => {
// create and register DID
const ownerAccount: Account = (await ocean.accounts.list())[0]
const did = generateId()
const data = 'my nice provider, is nice'
await didRegistry.registerAttribute(did, '0123456789abcdef', [], data, ownerAccount.getId())
// transfer
const newOwnerAccount: Account = (await ocean.accounts.list())[1]
await didRegistry.transferDIDOwnership(did, ownerAccount.getId(), newOwnerAccount.getId())
// check
const newOwner = await didRegistry.getDIDOwner(did)
assert.equal(newOwner, newOwnerAccount.getId(), `Got ${newOwner} but expected ${newOwnerAccount.getId()}`)
})
})
})