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

some fix and refactor

This commit is contained in:
paulo-ocean 2024-09-12 13:18:16 +01:00
parent 06fd7f8e18
commit 51ddf52d58
3 changed files with 57 additions and 47 deletions

View File

@ -300,8 +300,15 @@ export class ConfigHelper {
console.log(e) console.log(e)
addresses = null addresses = null
} }
const contractAddressesConfig = this.getAddressesFromEnv(config.network, addresses)
let contractAddressesConfig = this.getAddressesFromEnv(config.network, addresses)
// check oasis network name typos on addresses.json
if (!contractAddressesConfig && KNOWN_CONFIDENTIAL_EVMS.includes(config.chainId)) {
contractAddressesConfig = this.getAddressesFromEnv(
config.network.replaceAll('sapp', 'sap'),
addresses
)
}
config.confidentialEVM = config.confidentialEVM =
filterBy === 'chainId' filterBy === 'chainId'
? KNOWN_CONFIDENTIAL_EVMS.includes(Number(network)) ? KNOWN_CONFIDENTIAL_EVMS.includes(Number(network))

View File

@ -118,7 +118,7 @@ export async function calculateActiveTemplateIndex(
* @param name asset name * @param name asset name
* @param symbol asse symbol * @param symbol asse symbol
* @param owner owner address * @param owner owner address
* @param assetUrl asset url * @param assetUrl asset url, if present and confidential evm, add it to token create params
* @param templateIDorAddress either template address or id * @param templateIDorAddress either template address or id
* @param ddo ddo * @param ddo ddo
* @param encryptDDO encrypt or not? * @param encryptDDO encrypt or not?
@ -126,22 +126,20 @@ export async function calculateActiveTemplateIndex(
* @param providerFeeToken the provider fee token * @param providerFeeToken the provider fee token
* @param nftContractAddress the nft contract address * @param nftContractAddress the nft contract address
* @param aquariusInstance aquarius, could be node instance url * @param aquariusInstance aquarius, could be node instance url
* @param filesObject if present and confidential evm, add it to token create params
* @returns ddo id as string * @returns ddo id as string
*/ */
export async function createAsset( export async function createAsset(
name: string, name: string,
symbol: string, symbol: string,
owner: Signer, owner: Signer,
assetUrl: any, assetUrl: any, // files object
templateIDorAddress: string | number, // If string, it's template address , otherwise, it's templateId templateIDorAddress: string | number, // If string, it's template address , otherwise, it's templateId
ddo: any, ddo: any,
encryptDDO: boolean = true, // default is true encryptDDO: boolean = true, // default is true
providerUrl: string, providerUrl: string,
providerFeeToken: string, providerFeeToken: string,
nftContractAddress: string, // addresses.ERC721Factory,
aquariusInstance: Aquarius, aquariusInstance: Aquarius,
filesObject?: any nftContractAddress?: string // addresses.ERC721Factory,
): Promise<string> { ): Promise<string> {
const isAddress = typeof templateIDorAddress === 'string' const isAddress = typeof templateIDorAddress === 'string'
const isTemplateIndex = typeof templateIDorAddress === 'number' const isTemplateIndex = typeof templateIDorAddress === 'number'
@ -152,8 +150,9 @@ export async function createAsset(
const config = new ConfigHelper().getConfig(parseInt(String(chainID))) const config = new ConfigHelper().getConfig(parseInt(String(chainID)))
// This function does not consider the fact the template could be disabled if (!nftContractAddress) {
// let templateIndex = await calculateTemplateIndex(chainID, template) nftContractAddress = config.nftFactoryAddress
}
let templateIndex = await calculateActiveTemplateIndex( let templateIndex = await calculateActiveTemplateIndex(
owner, owner,
@ -180,7 +179,7 @@ export async function createAsset(
const nftParamsAsset: NftCreateData = { const nftParamsAsset: NftCreateData = {
name, name,
symbol, symbol,
templateIndex, templateIndex: 1,
tokenURI: 'aaa', tokenURI: 'aaa',
transferable: true, transferable: true,
owner: account owner: account
@ -196,12 +195,12 @@ export async function createAsset(
} }
// include fileObject in the DT constructor // include fileObject in the DT constructor
if (config.confidentialEVM && templateIndex === 4) { if (config.confidentialEVM) {
datatokenParams.filesObject = filesObject datatokenParams.filesObject = assetUrl
} }
let bundleNFT let bundleNFT
try {
if (!ddo.stats?.price?.value) { if (!ddo.stats?.price?.value) {
bundleNFT = await nftFactory.createNftWithDatatoken(nftParamsAsset, datatokenParams) bundleNFT = await nftFactory.createNftWithDatatoken(nftParamsAsset, datatokenParams)
} else if (ddo.stats?.price?.value === '0') { } else if (ddo.stats?.price?.value === '0') {
@ -237,6 +236,10 @@ export async function createAsset(
fixedPriceParams fixedPriceParams
) )
} }
} catch (err) {
console.log('ERROR creating NFT bundle', err)
return null
}
const trxReceipt = await bundleNFT.wait() const trxReceipt = await bundleNFT.wait()
// events have been emitted // events have been emitted

View File

@ -212,8 +212,8 @@ describe('Publish tests', async () => {
true, // encrypted ddo true, // encrypted ddo
providerUrl, providerUrl,
ZERO_ADDRESS, // provider fee token ZERO_ADDRESS, // provider fee token
addresses.ERC721Factory, // nft template factory aquarius,
aquarius addresses.ERC721Factory // nft template factory
) )
console.log('Published asset, ddo id:', asset) console.log('Published asset, ddo id:', asset)