Skip to content

Commit

Permalink
Some nits.
Browse files Browse the repository at this point in the history
  • Loading branch information
vladilen11 committed Sep 8, 2023
1 parent 68d7950 commit 85aea69
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
8 changes: 5 additions & 3 deletions packages/cli/src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ObeliskConfig } from "../../../common/src/codegen/types";
type Options = {
configPath: string,
network: any
savePath?: string
}

const commandModule: CommandModule<Options, Options> = {
Expand All @@ -17,15 +18,16 @@ const commandModule: CommandModule<Options, Options> = {
builder(yargs) {
return yargs.options({
configPath: { type: "string", default: ".", decs: "Path to the config file" },
network: { type: 'string', choices: ['mainnet', 'testnet', 'devnet', 'localnet'], desc: "Network of the node (mainnet/testnet/devnet/localnet)" }
network: { type: 'string', choices: ['mainnet', 'testnet', 'devnet', 'localnet'], desc: "Network of the node (mainnet/testnet/devnet/localnet)" },
savePath: { type: 'string', desc: "Path to the save template file" }
});
},

async handler({ configPath, network}) {
async handler({ configPath, network, savePath}) {
try {
const obeliskConfig = await loadConfig(configPath) as ObeliskConfig;

await publishHandler(obeliskConfig.project_name, network);
await publishHandler(obeliskConfig.project_name, network, savePath);
} catch (error: any) {
logError(error);
process.exit(1);
Expand Down
21 changes: 18 additions & 3 deletions packages/cli/src/utils/publishHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ import chalk from "chalk";
import {ObeliskCliError} from "./errors";
import {getFullnodeUrl, SuiClient} from "@mysten/sui.js/client";
import {validatePrivateKey} from "./validatePrivateKey";
import { generateIdConfig } from "../../../common/src/codegen";

export async function publishHandler(projectName: string, nodeUrl: 'mainnet' | 'testnet' | 'devnet' | 'localnet') {
// type publishRes = {
// projectName: string,
// transactionHash: string,
// packageId: string,
// worldId: string
// }

export async function publishHandler(projectName: string, network: 'mainnet' | 'testnet' | 'devnet' | 'localnet', savePath?: string | undefined) {
const privateKey = process.env.PRIVATE_KEY;
if (!privateKey)
throw new ObeliskCliError(
Expand All @@ -35,7 +43,7 @@ in your contracts directory to use the default sui private key.`
// const keypair = Ed25519Keypair.fromSecretKey(privateKeyRaw);
const keypair = Ed25519Keypair.fromSecretKey(privateKeyRaw);
const client = new SuiClient({
url: getFullnodeUrl(nodeUrl),
url: getFullnodeUrl(network),
});

const path = process.cwd()
Expand All @@ -60,13 +68,20 @@ in your contracts directory to use the default sui private key.`
});
console.log("")
console.log(chalk.blue(`Transaction Digest: ${result.digest}`))


let packageId = ""
let worldId = ""
result.objectChanges!.map((object) => {
if (object.type === "published") {
console.log(chalk.green(`${projectName} PackageId: ${object.packageId}`))
packageId = object.packageId
}
if (object.type === "created" && object.objectType.endsWith('::world::World')) {
console.log(chalk.green(`${projectName} WorldId: ${object.objectId}`))
worldId = object.objectId
}
})
if (savePath !== undefined) {
generateIdConfig(network, packageId, worldId, savePath)
}
}
1 change: 1 addition & 0 deletions packages/common/src/codegen/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from "./format";
export * from "./formatAndWrite";
export * from "./posixPath";
export * from "./renderMove/worldgen";
export * from "./renderMove/genIdConfig";
export * from "./config";
20 changes: 20 additions & 0 deletions packages/common/src/codegen/utils/renderMove/genIdConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ObeliskConfig } from '../../types';
import { formatAndWriteMove } from '../formatAndWrite';

export function generateIdConfig(network: string, packageId: string, worldId: string, savePath: string) {
let code = `type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
const NETWORK: NetworkType = '${network}';
const PACKAGE_ID = '${packageId}'
const WORLD_ID = '${worldId}'
export {
NETWORK,
PACKAGE_ID,
WORLD_ID,
}
`
const path = process.cwd()
formatAndWriteMove(code, `${path}/${savePath}`, "formatAndWriteMove");
}

0 comments on commit 85aea69

Please sign in to comment.