@0xobelisk/sui-cli 0.5.7 → 0.5.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/dist/obelisk.js +9 -9
- package/dist/obelisk.js.map +1 -1
- package/package.json +2 -1
- package/src/commands/faucet.ts +58 -58
- package/src/utils/publishHandler.ts +183 -175
- package/src/utils/upgradeHandler.ts +238 -227
- package/src/utils/utils.ts +119 -109
package/src/utils/utils.ts
CHANGED
|
@@ -1,153 +1,163 @@
|
|
|
1
|
-
import * as fsAsync from
|
|
2
|
-
import { mkdirSync, writeFileSync } from
|
|
3
|
-
import { dirname } from
|
|
4
|
-
import {
|
|
1
|
+
import * as fsAsync from 'fs/promises';
|
|
2
|
+
import { mkdirSync, writeFileSync } from 'fs';
|
|
3
|
+
import { dirname } from 'path';
|
|
4
|
+
import {
|
|
5
|
+
SUI_PRIVATE_KEY_PREFIX,
|
|
6
|
+
decodeSuiPrivateKey,
|
|
7
|
+
} from '@mysten/sui.js/cryptography';
|
|
8
|
+
import { FsIibError } from './errors';
|
|
5
9
|
|
|
6
10
|
export type DeploymentJsonType = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
projectName: string;
|
|
12
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
13
|
+
packageId: string;
|
|
14
|
+
worldId: string;
|
|
15
|
+
upgradeCap: string;
|
|
16
|
+
adminCap: string;
|
|
17
|
+
version: number;
|
|
14
18
|
};
|
|
15
19
|
|
|
16
|
-
export function validatePrivateKey(privateKey: string):
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
export function validatePrivateKey(privateKey: string): false | string {
|
|
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
|
+
}
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
export async function updateVersionInFile(
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
projectPath: string,
|
|
45
|
+
newVersion: string
|
|
36
46
|
) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
try {
|
|
48
|
+
const filePath = `${projectPath}/sources/codegen/eps/world.move`;
|
|
49
|
+
const data = await fsAsync.readFile(filePath, 'utf8');
|
|
50
|
+
|
|
51
|
+
// update version data
|
|
52
|
+
const updatedData = data.replace(
|
|
53
|
+
/const VERSION: u64 = \d+;/,
|
|
54
|
+
`const VERSION: u64 = ${newVersion};`
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// write new version
|
|
58
|
+
writeOutput(updatedData, filePath, 'Update package version');
|
|
59
|
+
} catch {
|
|
60
|
+
throw new FsIibError('Fs update version failed.');
|
|
61
|
+
}
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
async function getDeploymentJson(projectPath: string, network: string) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
try {
|
|
66
|
+
const data = await fsAsync.readFile(
|
|
67
|
+
`${projectPath}/.history/sui_${network}/latest.json`,
|
|
68
|
+
'utf8'
|
|
69
|
+
);
|
|
70
|
+
return JSON.parse(data) as DeploymentJsonType;
|
|
71
|
+
} catch {
|
|
72
|
+
throw new FsIibError('Fs read deployment file failed.');
|
|
73
|
+
}
|
|
64
74
|
}
|
|
65
75
|
|
|
66
76
|
export async function getVersion(
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
projectPath: string,
|
|
78
|
+
network: string
|
|
69
79
|
): Promise<number> {
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
81
|
+
return deployment.version;
|
|
72
82
|
}
|
|
73
83
|
|
|
74
84
|
export async function getNetwork(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
): Promise<
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
projectPath: string,
|
|
86
|
+
network: string
|
|
87
|
+
): Promise<'mainnet' | 'testnet' | 'devnet' | 'localnet'> {
|
|
88
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
89
|
+
return deployment.network;
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
export async function getOldPackageId(
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
projectPath: string,
|
|
94
|
+
network: string
|
|
85
95
|
): Promise<string> {
|
|
86
|
-
|
|
87
|
-
|
|
96
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
97
|
+
return deployment.packageId;
|
|
88
98
|
}
|
|
89
99
|
|
|
90
100
|
export async function getWorldId(
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
projectPath: string,
|
|
102
|
+
network: string
|
|
93
103
|
): Promise<string> {
|
|
94
|
-
|
|
95
|
-
|
|
104
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
105
|
+
return deployment.worldId;
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
export async function getUpgradeCap(
|
|
99
|
-
|
|
100
|
-
|
|
109
|
+
projectPath: string,
|
|
110
|
+
network: string
|
|
101
111
|
): Promise<string> {
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
113
|
+
return deployment.upgradeCap;
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
export async function getAdminCap(
|
|
107
|
-
|
|
108
|
-
|
|
117
|
+
projectPath: string,
|
|
118
|
+
network: string
|
|
109
119
|
): Promise<string> {
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
const deployment = await getDeploymentJson(projectPath, network);
|
|
121
|
+
return deployment.adminCap;
|
|
112
122
|
}
|
|
113
123
|
|
|
114
124
|
export function saveContractData(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
125
|
+
projectName: string,
|
|
126
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
127
|
+
packageId: string,
|
|
128
|
+
worldId: string,
|
|
129
|
+
upgradeCap: string,
|
|
130
|
+
adminCap: string,
|
|
131
|
+
version: number
|
|
122
132
|
) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
const DeploymentData: DeploymentJsonType = {
|
|
134
|
+
projectName,
|
|
135
|
+
network,
|
|
136
|
+
packageId,
|
|
137
|
+
worldId,
|
|
138
|
+
upgradeCap,
|
|
139
|
+
adminCap,
|
|
140
|
+
version,
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const path = process.cwd();
|
|
144
|
+
const storeDeploymentData = JSON.stringify(DeploymentData, null, 2);
|
|
145
|
+
writeOutput(
|
|
146
|
+
storeDeploymentData,
|
|
147
|
+
`${path}/contracts/${projectName}/.history/sui_${network}/latest.json`,
|
|
148
|
+
'Update deploy log'
|
|
149
|
+
);
|
|
140
150
|
}
|
|
141
151
|
|
|
142
152
|
export async function writeOutput(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
153
|
+
output: string,
|
|
154
|
+
fullOutputPath: string,
|
|
155
|
+
logPrefix?: string
|
|
146
156
|
): Promise<void> {
|
|
147
|
-
|
|
157
|
+
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
148
158
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
writeFileSync(fullOutputPath, output);
|
|
160
|
+
if (logPrefix !== undefined) {
|
|
161
|
+
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
162
|
+
}
|
|
153
163
|
}
|