@0xobelisk/sui-cli 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +92 -0
- package/README.md +90 -0
- package/dist/obelisk.js +27 -0
- package/dist/obelisk.js.map +1 -0
- package/package.json +68 -0
- package/src/commands/faucet.ts +73 -0
- package/src/commands/hello.ts +18 -0
- package/src/commands/index.ts +20 -0
- package/src/commands/localnode.ts +28 -0
- package/src/commands/publish.ts +43 -0
- package/src/commands/schemagen.ts +32 -0
- package/src/commands/test.ts +38 -0
- package/src/commands/upgrade.ts +53 -0
- package/src/modules.d.ts +11 -0
- package/src/obelisk.ts +36 -0
- package/src/utils/errors.ts +46 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/printObelisk.ts +20 -0
- package/src/utils/publishHandler.ts +184 -0
- package/src/utils/upgradeHandler.ts +237 -0
- package/src/utils/utils.ts +153 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import * as fsAsync from "fs/promises";
|
|
2
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
3
|
+
import { dirname } from "path";
|
|
4
|
+
import { FsIibError } from "./errors";
|
|
5
|
+
|
|
6
|
+
export type DeploymentJsonType = {
|
|
7
|
+
projectName: string;
|
|
8
|
+
network: "mainnet" | "testnet" | "devnet" | "localnet";
|
|
9
|
+
packageId: string;
|
|
10
|
+
worldId: string;
|
|
11
|
+
upgradeCap: string;
|
|
12
|
+
adminCap: string;
|
|
13
|
+
version: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function validatePrivateKey(privateKey: string): boolean | string {
|
|
17
|
+
if (privateKey.startsWith("0x")) {
|
|
18
|
+
const strippedPrivateKey = privateKey.slice(2);
|
|
19
|
+
if (strippedPrivateKey.length === 64) {
|
|
20
|
+
return strippedPrivateKey;
|
|
21
|
+
} else {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
if (privateKey.length === 64) {
|
|
26
|
+
return privateKey;
|
|
27
|
+
} else {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function updateVersionInFile(
|
|
34
|
+
projectPath: string,
|
|
35
|
+
newVersion: string
|
|
36
|
+
) {
|
|
37
|
+
try {
|
|
38
|
+
const filePath = `${projectPath}/sources/codegen/eps/world.move`;
|
|
39
|
+
const data = await fsAsync.readFile(filePath, "utf8");
|
|
40
|
+
|
|
41
|
+
// update version data
|
|
42
|
+
const updatedData = data.replace(
|
|
43
|
+
/const VERSION: u64 = \d+;/,
|
|
44
|
+
`const VERSION: u64 = ${newVersion};`
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// write new version
|
|
48
|
+
writeOutput(updatedData, filePath, "Update package version");
|
|
49
|
+
} catch {
|
|
50
|
+
throw new FsIibError("Fs update version failed.");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function getDeploymentJson(projectPath: string, network: string) {
|
|
55
|
+
try {
|
|
56
|
+
const data = await fsAsync.readFile(
|
|
57
|
+
`${projectPath}/.history/sui_${network}/latest.json`,
|
|
58
|
+
"utf8"
|
|
59
|
+
);
|
|
60
|
+
return JSON.parse(data) as DeploymentJsonType;
|
|
61
|
+
} catch {
|
|
62
|
+
throw new FsIibError("Fs read deployment file failed.");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function getVersion(
|
|
67
|
+
projectPath: string,
|
|
68
|
+
network: string
|
|
69
|
+
): Promise<number> {
|
|
70
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
71
|
+
return deployment.version;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function getNetwork(
|
|
75
|
+
projectPath: string,
|
|
76
|
+
network: string
|
|
77
|
+
): Promise<"mainnet" | "testnet" | "devnet" | "localnet"> {
|
|
78
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
79
|
+
return deployment.network;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function getOldPackageId(
|
|
83
|
+
projectPath: string,
|
|
84
|
+
network: string
|
|
85
|
+
): Promise<string> {
|
|
86
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
87
|
+
return deployment.packageId;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function getWorldId(
|
|
91
|
+
projectPath: string,
|
|
92
|
+
network: string
|
|
93
|
+
): Promise<string> {
|
|
94
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
95
|
+
return deployment.worldId;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function getUpgradeCap(
|
|
99
|
+
projectPath: string,
|
|
100
|
+
network: string
|
|
101
|
+
): Promise<string> {
|
|
102
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
103
|
+
return deployment.upgradeCap;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function getAdminCap(
|
|
107
|
+
projectPath: string,
|
|
108
|
+
network: string
|
|
109
|
+
): Promise<string> {
|
|
110
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
111
|
+
return deployment.adminCap;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function saveContractData(
|
|
115
|
+
projectName: string,
|
|
116
|
+
network: "mainnet" | "testnet" | "devnet" | "localnet",
|
|
117
|
+
packageId: string,
|
|
118
|
+
worldId: string,
|
|
119
|
+
upgradeCap: string,
|
|
120
|
+
adminCap: string,
|
|
121
|
+
version: number
|
|
122
|
+
) {
|
|
123
|
+
const DeploymentData: DeploymentJsonType = {
|
|
124
|
+
projectName,
|
|
125
|
+
network,
|
|
126
|
+
packageId,
|
|
127
|
+
worldId,
|
|
128
|
+
upgradeCap,
|
|
129
|
+
adminCap,
|
|
130
|
+
version,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const path = process.cwd();
|
|
134
|
+
const storeDeploymentData = JSON.stringify(DeploymentData, null, 2);
|
|
135
|
+
writeOutput(
|
|
136
|
+
storeDeploymentData,
|
|
137
|
+
`${path}/contracts/${projectName}/.history/sui_${network}/latest.json`,
|
|
138
|
+
"Update deploy log"
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function writeOutput(
|
|
143
|
+
output: string,
|
|
144
|
+
fullOutputPath: string,
|
|
145
|
+
logPrefix?: string
|
|
146
|
+
): Promise<void> {
|
|
147
|
+
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
148
|
+
|
|
149
|
+
writeFileSync(fullOutputPath, output);
|
|
150
|
+
if (logPrefix !== undefined) {
|
|
151
|
+
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
152
|
+
}
|
|
153
|
+
}
|