Skip to content

Commit

Permalink
Removing logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiehewitt15 committed Oct 9, 2024
1 parent 0734f96 commit 55127c7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 39 deletions.
13 changes: 2 additions & 11 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ export async function createSapphireAsset(
encryptDDO: boolean = true,
) {
const { chainId } = await owner.provider.getNetwork();
console.log("Chain ID: ", chainId);
const nftFactory = new NftFactory(config.nftFactoryAddress, owner);

// Wrap the signer for Sapphire
Expand All @@ -233,10 +232,8 @@ export async function createSapphireAsset(
await owner.getAddress(),
[await owner.getAddress(), ZERO_ADDRESS]
);
console.log("Allow List Address: ", allowListAddress);

ddo.chainId = parseInt(chainId.toString(10));
console.log("DDO Chain ID: ", ddo.chainId);
const nftParamsAsset: NftCreateData = {
name,
symbol,
Expand Down Expand Up @@ -301,9 +298,9 @@ export async function createSapphireAsset(
const tokenCreatedEvent = getEventFromTx(trxReceipt, "TokenCreated");

const nftAddress = nftCreatedEvent.args.newTokenAddress;
console.log("NFT Address: ", nftAddress);
console.log("NFT publish with address: ", nftAddress);
const datatokenAddressAsset = tokenCreatedEvent.args.newTokenAddress;
console.log("Datatoken Address: ", datatokenAddressAsset)
console.log("Datatoken published with address: ", datatokenAddressAsset)

assetUrl.datatokenAddress = datatokenAddressAsset;
assetUrl.nftAddress = nftAddress;
Expand Down Expand Up @@ -342,7 +339,6 @@ export async function createSapphireAsset(

// Use Nft class to set metadata on the NFT
const nft = new Nft(wrappedSigner, chainId);
console.log("setting metadata")
// Set metadata using Nft
await nft.setMetadata(
nftAddress,
Expand All @@ -354,10 +350,8 @@ console.log("setting metadata")
metadata,
metadataHash
);
console.log('metadata updated')

// Use Datatoken4 for file object
console.log('Use Datatoken4 for file object')
const datatoken = new Datatoken4(
wrappedSigner,
ethers.utils.toUtf8Bytes(JSON.stringify(assetUrl.files)),
Expand All @@ -366,18 +360,15 @@ console.log("setting metadata")
);

// Set file object
console.log('Set file object')
await datatoken.setFileObject(datatokenAddressAsset, await wrappedSigner.getAddress());

// Set allow list for the datatoken
console.log('Set allow list for the datatoken')
await datatoken.setAllowListContract(
datatokenAddressAsset,
allowListAddress,
await wrappedSigner.getAddress()
);

console.log('returning ddo.id')
return ddo.id;
}

Expand Down
39 changes: 18 additions & 21 deletions src/interactiveFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function interactiveFlow(providerUrl: string): Promise<PublishAsset
console.log(chalk.cyan('Welcome to the Ocean Protocol Asset Publisher!\n'));

// Prompting for basic information
const basicAnswers = await prompt<Omit<PublishAssetParams, 'isCharged' | 'chainId' | 'timeout'>>([
const basicAnswers = await prompt<Omit<PublishAssetParams, 'isCharged' | 'chainId' | 'storageType' | 'assetLocation'>>([
{
type: 'input',
name: 'title',
Expand All @@ -48,25 +48,23 @@ export async function interactiveFlow(providerUrl: string): Promise<PublishAsset
message: chalk.green('Please provide tags to make this asset more easily discoverable (comma separated):\n'),
required: true
},
{
type: 'select',
name: 'timeout',
message: chalk.green('After purchasing your asset, how long should the consumer be allowed to access it for?\n'),
choices: [
{name: 'Forever', value: "0"},
{name: '1 day', value: "86400"},
{name: '1 week', value: "604800"},
{name: '1 month', value: "2592000"},
{name: '1 year', value: "31536000"}
],
result(value) {
return this.choices.find(choice => choice.name === value).value;
}
},
]);

// Timeout prompt
const { timeout } = await prompt<{ timeout: number }>({
type: 'select',
name: 'timeout',
message: chalk.green('After purchasing your asset, how long should the consumer be allowed to access it for?\n'),
choices: [
{name: 'Forever', value: 0},
{name: '1 day', value: 86400},
{name: '1 week', value: 604800},
{name: '1 month', value: 2592000},
{name: '1 year', value: 31536000}
],
result(value) {
return this.choices.find(choice => choice.name === value).value;
}
});

// Storage type prompt
const { storageType } = await prompt<{ storageType: PublishAssetParams['storageType'] }>({
type: 'select',
Expand Down Expand Up @@ -135,15 +133,15 @@ export async function interactiveFlow(providerUrl: string): Promise<PublishAsset
type: 'select',
name: 'chainId',
message: chalk.green('What network will your asset be available for purchase through?\n'),
choices: [{name: 'Oasis Sapphire', value: 23295}, {name: 'Ethereum', value: 1}, {name: 'Polygon', value: 137}],
choices: [{name: 'Oasis Sapphire', value: 23294}, {name: 'Oasis Sapphire Testnet', value: 23295}, {name: 'Ethereum', value: 1}, {name: 'Polygon', value: 137}],
result(value) {
return this.choices.find(choice => choice.name === value).value;
}
});

// Template prompt
let template: number | undefined;
if (chainId !== 23295) {
if (chainId !== 23295 && chainId !== 23294) {
const templateAnswer = await prompt<{ template: number }>({
type: 'select',
name: 'template',
Expand All @@ -162,7 +160,6 @@ export async function interactiveFlow(providerUrl: string): Promise<PublishAsset
// Combine all answers
const allAnswers: PublishAssetParams = {
...basicAnswers,
timeout,
storageType,
assetLocation,
isCharged,
Expand Down
10 changes: 3 additions & 7 deletions src/publishAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface PublishAssetParams {
description: string;
author: string;
tags: string[];
timeout: number;
timeout: string;
storageType: 'ipfs' | 'arweave' | 'url';
assetLocation: string;
isCharged: boolean;
Expand All @@ -26,12 +26,8 @@ export interface PublishAssetParams {

export async function publishAsset(params: PublishAssetParams, signer: Signer, config: Config) {
try {
console.log('Publishing asset using helper functions...');

const aquarius = new Aquarius(config.metadataCacheUri);

console.log('asset timeout: ', params.timeout)

// Prepare initial metadata for the asset
const metadata: DDO = {
'@context': ['https://w3id.org/did/v1'],
Expand Down Expand Up @@ -64,7 +60,7 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c
files: '',
datatokenAddress: '0x0', // Will be updated after creating asset
serviceEndpoint: params.providerUrl,
timeout: 0,
timeout: Number(params.timeout),
},
],
nft: {
Expand All @@ -87,7 +83,7 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c

let did: string;

if (params.chainId === 23295) {
if (params.chainId === 23295 || params.chainId === 23294) {
// Oasis Sapphire
console.log('Publishing to Oasis Sapphire network...');

Expand Down

0 comments on commit 55127c7

Please sign in to comment.