@0xobelisk/sui-cli 1.1.5 → 1.1.7
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/README.md +0 -2
- package/dist/dubhe.js.map +1 -1
- package/package.json +11 -7
- package/src/commands/build.ts +49 -49
- package/src/commands/call.ts +71 -71
- package/src/commands/checkBalance.ts +20 -20
- package/src/commands/configStore.ts +31 -35
- package/src/commands/faucet.ts +63 -71
- package/src/commands/generateKey.ts +25 -25
- package/src/commands/hello.ts +5 -5
- package/src/commands/index.ts +15 -15
- package/src/commands/indexer.ts +41 -46
- package/src/commands/localnode.ts +13 -13
- package/src/commands/publish.ts +35 -39
- package/src/commands/query.ts +70 -70
- package/src/commands/schemagen.ts +26 -26
- package/src/commands/test.ts +37 -37
- package/src/commands/upgrade.ts +29 -29
- package/src/commands/watch.ts +12 -12
- package/src/dubhe.ts +14 -12
- package/src/modules.d.ts +2 -2
- package/src/utils/callHandler.ts +117 -122
- package/src/utils/checkBalance.ts +25 -33
- package/src/utils/errors.ts +28 -28
- package/src/utils/generateAccount.ts +76 -91
- package/src/utils/indexerHandler.ts +183 -151
- package/src/utils/printDubhe.ts +1 -1
- package/src/utils/publishHandler.ts +322 -371
- package/src/utils/queryStorage.ts +126 -126
- package/src/utils/startNode.ts +99 -111
- package/src/utils/storeConfig.ts +33 -45
- package/src/utils/upgradeHandler.ts +208 -234
- package/src/utils/utils.ts +150 -176
package/src/utils/utils.ts
CHANGED
|
@@ -8,221 +8,195 @@ import chalk from 'chalk';
|
|
|
8
8
|
import { spawn } from 'child_process';
|
|
9
9
|
|
|
10
10
|
export type DeploymentJsonType = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
projectName: string;
|
|
12
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
13
|
+
packageId: string;
|
|
14
|
+
schemaId: string;
|
|
15
|
+
upgradeCap: string;
|
|
16
|
+
version: number;
|
|
17
|
+
schemas: Record<string, string>;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export function validatePrivateKey(privateKey: string): false | string {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
if (privateKey.startsWith(SUI_PRIVATE_KEY_PREFIX)) {
|
|
22
|
+
if (privateKey.length === 70) {
|
|
23
|
+
return privateKey;
|
|
24
|
+
} else {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
} else if (privateKey.startsWith('0x')) {
|
|
28
|
+
const strippedPrivateKey = privateKey.slice(2);
|
|
29
|
+
if (strippedPrivateKey.length === 64) {
|
|
30
|
+
return strippedPrivateKey;
|
|
31
|
+
} else {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
if (privateKey.length === 64) {
|
|
36
|
+
return privateKey;
|
|
37
|
+
} else {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export async function updateVersionInFile(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
} catch {
|
|
60
|
-
throw new FsIibError('Fs update version failed.');
|
|
61
|
-
}
|
|
43
|
+
export async function updateVersionInFile(projectPath: string, newVersion: string) {
|
|
44
|
+
try {
|
|
45
|
+
const filePath = `${projectPath}/sources/script/migrate.move`;
|
|
46
|
+
const data = await fsAsync.readFile(filePath, 'utf8');
|
|
47
|
+
|
|
48
|
+
// update version data
|
|
49
|
+
const updatedData = data.replace(
|
|
50
|
+
/const VERSION: u64 = \d+;/,
|
|
51
|
+
`const VERSION: u64 = ${newVersion};`
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// write new version
|
|
55
|
+
writeOutput(updatedData, filePath, 'Update package version');
|
|
56
|
+
} catch {
|
|
57
|
+
throw new FsIibError('Fs update version failed.');
|
|
58
|
+
}
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
async function getDeploymentJson(projectPath: string, network: string) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
try {
|
|
63
|
+
const data = await fsAsync.readFile(
|
|
64
|
+
`${projectPath}/.history/sui_${network}/latest.json`,
|
|
65
|
+
'utf8'
|
|
66
|
+
);
|
|
67
|
+
return JSON.parse(data) as DeploymentJsonType;
|
|
68
|
+
} catch {
|
|
69
|
+
throw new FsIibError('Fs read deployment file failed.');
|
|
70
|
+
}
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
export async function getOnchainSchemas(
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
projectPath: string,
|
|
75
|
+
network: string
|
|
79
76
|
): Promise<Record<string, string>> {
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
78
|
+
return deployment.schemas;
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
export async function getVersion(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
): Promise<number> {
|
|
88
|
-
const deployment = await getDeploymentJson(projectPath, network);
|
|
89
|
-
return deployment.version;
|
|
81
|
+
export async function getVersion(projectPath: string, network: string): Promise<number> {
|
|
82
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
83
|
+
return deployment.version;
|
|
90
84
|
}
|
|
91
85
|
|
|
92
86
|
export async function getNetwork(
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
projectPath: string,
|
|
88
|
+
network: string
|
|
95
89
|
): Promise<'mainnet' | 'testnet' | 'devnet' | 'localnet'> {
|
|
96
|
-
|
|
97
|
-
|
|
90
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
91
|
+
return deployment.network;
|
|
98
92
|
}
|
|
99
93
|
|
|
100
|
-
export async function getOldPackageId(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
): Promise<string> {
|
|
104
|
-
const deployment = await getDeploymentJson(projectPath, network);
|
|
105
|
-
return deployment.packageId;
|
|
94
|
+
export async function getOldPackageId(projectPath: string, network: string): Promise<string> {
|
|
95
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
96
|
+
return deployment.packageId;
|
|
106
97
|
}
|
|
107
98
|
|
|
108
|
-
export async function getSchemaId(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
): Promise<string> {
|
|
112
|
-
const deployment = await getDeploymentJson(projectPath, network);
|
|
113
|
-
return deployment.schemaId;
|
|
99
|
+
export async function getSchemaId(projectPath: string, network: string): Promise<string> {
|
|
100
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
101
|
+
return deployment.schemaId;
|
|
114
102
|
}
|
|
115
103
|
|
|
116
|
-
export async function getUpgradeCap(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
): Promise<string> {
|
|
120
|
-
const deployment = await getDeploymentJson(projectPath, network);
|
|
121
|
-
return deployment.upgradeCap;
|
|
104
|
+
export async function getUpgradeCap(projectPath: string, network: string): Promise<string> {
|
|
105
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
106
|
+
return deployment.upgradeCap;
|
|
122
107
|
}
|
|
123
108
|
|
|
124
109
|
export function saveContractData(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
110
|
+
projectName: string,
|
|
111
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
112
|
+
packageId: string,
|
|
113
|
+
schemaId: string,
|
|
114
|
+
upgradeCap: string,
|
|
115
|
+
version: number,
|
|
116
|
+
schemas: Record<string, string>
|
|
132
117
|
) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
118
|
+
const DeploymentData: DeploymentJsonType = {
|
|
119
|
+
projectName,
|
|
120
|
+
network,
|
|
121
|
+
packageId,
|
|
122
|
+
schemaId,
|
|
123
|
+
schemas,
|
|
124
|
+
upgradeCap,
|
|
125
|
+
version
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const path = process.cwd();
|
|
129
|
+
const storeDeploymentData = JSON.stringify(DeploymentData, null, 2);
|
|
130
|
+
writeOutput(
|
|
131
|
+
storeDeploymentData,
|
|
132
|
+
`${path}/contracts/${projectName}/.history/sui_${network}/latest.json`,
|
|
133
|
+
'Update deploy log'
|
|
134
|
+
);
|
|
150
135
|
}
|
|
151
136
|
|
|
152
137
|
export async function writeOutput(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
138
|
+
output: string,
|
|
139
|
+
fullOutputPath: string,
|
|
140
|
+
logPrefix?: string
|
|
156
141
|
): Promise<void> {
|
|
157
|
-
|
|
142
|
+
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
158
143
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
144
|
+
writeFileSync(fullOutputPath, output);
|
|
145
|
+
if (logPrefix !== undefined) {
|
|
146
|
+
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
147
|
+
}
|
|
163
148
|
}
|
|
164
149
|
|
|
165
|
-
function getDubheDependency(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
throw new Error(`Unsupported network: ${network}`);
|
|
177
|
-
}
|
|
150
|
+
function getDubheDependency(network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'): string {
|
|
151
|
+
switch (network) {
|
|
152
|
+
case 'localnet':
|
|
153
|
+
return 'Dubhe = { local = "../dubhe-framework" }';
|
|
154
|
+
case 'testnet':
|
|
155
|
+
return 'Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-testnet-v1.1.0" }';
|
|
156
|
+
case 'mainnet':
|
|
157
|
+
return 'Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-mainnet-v1.1.0" }';
|
|
158
|
+
default:
|
|
159
|
+
throw new Error(`Unsupported network: ${network}`);
|
|
160
|
+
}
|
|
178
161
|
}
|
|
179
162
|
|
|
180
163
|
export async function updateDubheDependency(
|
|
181
|
-
|
|
182
|
-
|
|
164
|
+
filePath: string,
|
|
165
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
183
166
|
) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
167
|
+
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
168
|
+
const newDependency = getDubheDependency(network);
|
|
169
|
+
const updatedContent = fileContent.replace(/Dubhe = \{.*\}/, newDependency);
|
|
170
|
+
fs.writeFileSync(filePath, updatedContent, 'utf-8');
|
|
171
|
+
console.log(`Updated Dubhe dependency in ${filePath} for ${network}.`);
|
|
189
172
|
}
|
|
190
|
-
export async function switchEnv(
|
|
191
|
-
|
|
192
|
-
) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
resolve(); // Resolve promise on successful exit
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
} catch (error) {
|
|
222
|
-
console.error(chalk.red('\n❌ Failed to Switch Env'));
|
|
223
|
-
console.error(chalk.red(` └─ Error: ${error}`));
|
|
224
|
-
}
|
|
173
|
+
export async function switchEnv(network: 'mainnet' | 'testnet' | 'devnet' | 'localnet') {
|
|
174
|
+
try {
|
|
175
|
+
return new Promise<void>((resolve, reject) => {
|
|
176
|
+
const suiProcess = spawn('sui', ['client', 'switch', '--env', network], {
|
|
177
|
+
env: { ...process.env },
|
|
178
|
+
stdio: 'pipe'
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
suiProcess.on('error', (error) => {
|
|
182
|
+
console.error(chalk.red('\n❌ Failed to Switch Env'));
|
|
183
|
+
console.error(chalk.red(` Error: ${error.message}`));
|
|
184
|
+
reject(error); // Reject promise on error
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
suiProcess.on('exit', (code) => {
|
|
188
|
+
if (code !== 0) {
|
|
189
|
+
console.error(chalk.red(`\n❌ Process exited with code: ${code}`));
|
|
190
|
+
reject(new Error(`Process exited with code: ${code}`));
|
|
191
|
+
} else {
|
|
192
|
+
resolve(); // Resolve promise on successful exit
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.error(chalk.red('\n❌ Failed to Switch Env'));
|
|
198
|
+
console.error(chalk.red(` └─ Error: ${error}`));
|
|
199
|
+
}
|
|
225
200
|
}
|
|
226
201
|
|
|
227
|
-
export const delay = (ms: number) =>
|
|
228
|
-
new Promise(resolve => setTimeout(resolve, ms));
|
|
202
|
+
export const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|