@0xobelisk/sui-cli 0.5.17 → 0.5.18
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 +6 -10
- package/dist/obelisk.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/index.ts +15 -15
- package/src/commands/localnode.ts +48 -19
- package/src/commands/publish.ts +39 -32
- package/src/commands/schemagen.ts +36 -25
- package/src/commands/upgrade.ts +53 -53
- package/src/utils/index.ts +5 -5
- package/src/utils/localnode/index.ts +3 -0
- package/src/utils/localnode/start.ts +87 -0
- package/src/utils/localnode/status.ts +39 -0
- package/src/utils/localnode/stop.ts +35 -0
- package/src/utils/publishHandler.ts +30 -14
- package/src/utils/upgradeHandler.ts +246 -246
- package/src/utils/utils.ts +7 -5
|
@@ -1,246 +1,246 @@
|
|
|
1
|
-
import { Obelisk } from '@0xobelisk/sui-client';
|
|
2
|
-
import { Transaction, UpgradePolicy } from '@mysten/sui/transactions';
|
|
3
|
-
import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';
|
|
4
|
-
import { execSync } from 'child_process';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import { ObeliskCliError, UpgradeError } from './errors';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from './utils';
|
|
15
|
-
|
|
16
|
-
type ObjectContent = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export async function upgradeHandler(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Run 'echo "PRIVATE_KEY=YOUR_PRIVATE_KEY" > .env'
|
|
35
|
-
in your contracts directory to use the default sui private key.`
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
1
|
+
// import { Obelisk } from '@0xobelisk/sui-client';
|
|
2
|
+
// import { Transaction, UpgradePolicy } from '@mysten/sui/transactions';
|
|
3
|
+
// import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';
|
|
4
|
+
// import { execSync } from 'child_process';
|
|
5
|
+
// import chalk from 'chalk';
|
|
6
|
+
// import { ObeliskCliError, UpgradeError } from './errors';
|
|
7
|
+
// import {
|
|
8
|
+
// updateVersionInFile,
|
|
9
|
+
// getOldPackageId,
|
|
10
|
+
// getVersion,
|
|
11
|
+
// getUpgradeCap,
|
|
12
|
+
// saveContractData,
|
|
13
|
+
// validatePrivateKey,
|
|
14
|
+
// } from './utils';
|
|
15
|
+
|
|
16
|
+
// type ObjectContent = {
|
|
17
|
+
// type: string;
|
|
18
|
+
// fields: Record<string, any>;
|
|
19
|
+
// hasPublicTransfer: boolean;
|
|
20
|
+
// dataType: string;
|
|
21
|
+
// };
|
|
22
|
+
|
|
23
|
+
// export async function upgradeHandler(
|
|
24
|
+
// name: string,
|
|
25
|
+
// network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
26
|
+
// schemaNames: string[]
|
|
27
|
+
// ) {
|
|
28
|
+
// const path = process.cwd();
|
|
29
|
+
// const projectPath = `${path}/contracts/${name}`;
|
|
30
|
+
// const privateKey = process.env.PRIVATE_KEY;
|
|
31
|
+
// if (!privateKey)
|
|
32
|
+
// throw new ObeliskCliError(
|
|
33
|
+
// `Missing PRIVATE_KEY environment variable.
|
|
34
|
+
// Run 'echo "PRIVATE_KEY=YOUR_PRIVATE_KEY" > .env'
|
|
35
|
+
// in your contracts directory to use the default sui private key.`
|
|
36
|
+
// );
|
|
37
|
+
|
|
38
|
+
// const privateKeyFormat = validatePrivateKey(privateKey);
|
|
39
|
+
// if (privateKeyFormat === false) {
|
|
40
|
+
// throw new ObeliskCliError(`Please check your privateKey.`);
|
|
41
|
+
// }
|
|
42
|
+
// const obelisk = new Obelisk({
|
|
43
|
+
// secretKey: privateKeyFormat,
|
|
44
|
+
// });
|
|
45
|
+
// const keypair = obelisk.getKeypair();
|
|
46
|
+
|
|
47
|
+
// const client = new SuiClient({
|
|
48
|
+
// url: getFullnodeUrl(network),
|
|
49
|
+
// });
|
|
50
|
+
|
|
51
|
+
// let oldVersion = Number(await getVersion(projectPath, network));
|
|
52
|
+
// let oldPackageId = await getOldPackageId(projectPath, network);
|
|
53
|
+
// let worldId = await getWorldId(projectPath, network);
|
|
54
|
+
// let upgradeCap = await getUpgradeCap(projectPath, network);
|
|
55
|
+
// let adminCap = await getAdminCap(projectPath, network);
|
|
56
|
+
|
|
57
|
+
// const newVersion = oldVersion + 1;
|
|
58
|
+
// await updateVersionInFile(projectPath, newVersion.toString());
|
|
59
|
+
|
|
60
|
+
// try {
|
|
61
|
+
// let modules: any, dependencies: any, digest: any;
|
|
62
|
+
// try {
|
|
63
|
+
// const {
|
|
64
|
+
// modules: extractedModules,
|
|
65
|
+
// dependencies: extractedDependencies,
|
|
66
|
+
// digest: extractedDigest,
|
|
67
|
+
// } = JSON.parse(
|
|
68
|
+
// execSync(
|
|
69
|
+
// `sui move build --dump-bytecode-as-base64 --path ${path}/contracts/${name}`,
|
|
70
|
+
// {
|
|
71
|
+
// encoding: 'utf-8',
|
|
72
|
+
// }
|
|
73
|
+
// )
|
|
74
|
+
// );
|
|
75
|
+
|
|
76
|
+
// modules = extractedModules;
|
|
77
|
+
// dependencies = extractedDependencies;
|
|
78
|
+
// digest = extractedDigest;
|
|
79
|
+
// } catch (error: any) {
|
|
80
|
+
// throw new UpgradeError(error.stdout);
|
|
81
|
+
// }
|
|
82
|
+
|
|
83
|
+
// const tx = new Transaction();
|
|
84
|
+
// const ticket = tx.moveCall({
|
|
85
|
+
// target: '0x2::package::authorize_upgrade',
|
|
86
|
+
// arguments: [
|
|
87
|
+
// tx.object(upgradeCap),
|
|
88
|
+
// tx.pure.u8(UpgradePolicy.COMPATIBLE),
|
|
89
|
+
// tx.pure.vector('u8', digest),
|
|
90
|
+
// ],
|
|
91
|
+
// });
|
|
92
|
+
|
|
93
|
+
// const receipt = tx.upgrade({
|
|
94
|
+
// modules,
|
|
95
|
+
// dependencies,
|
|
96
|
+
// package: oldPackageId,
|
|
97
|
+
// ticket,
|
|
98
|
+
// });
|
|
99
|
+
|
|
100
|
+
// tx.moveCall({
|
|
101
|
+
// target: '0x2::package::commit_upgrade',
|
|
102
|
+
// arguments: [tx.object(upgradeCap), receipt],
|
|
103
|
+
// });
|
|
104
|
+
|
|
105
|
+
// tx.transferObjects(
|
|
106
|
+
// [tx.object(upgradeCap)],
|
|
107
|
+
// keypair.toSuiAddress()
|
|
108
|
+
// );
|
|
109
|
+
|
|
110
|
+
// const result = await client.signAndExecuteTransaction({
|
|
111
|
+
// signer: keypair,
|
|
112
|
+
// transaction: tx,
|
|
113
|
+
// options: {
|
|
114
|
+
// showObjectChanges: true,
|
|
115
|
+
// },
|
|
116
|
+
// });
|
|
117
|
+
|
|
118
|
+
// console.log('');
|
|
119
|
+
// console.log(`${name} WorldId: ${worldId}`);
|
|
120
|
+
|
|
121
|
+
// let newPackageId = '';
|
|
122
|
+
// let newUpgradeCap = '';
|
|
123
|
+
// result.objectChanges!.map(object => {
|
|
124
|
+
// if (object.type === 'published') {
|
|
125
|
+
// console.log(
|
|
126
|
+
// chalk.blue(`${name} PackageId: ${object.packageId}`)
|
|
127
|
+
// );
|
|
128
|
+
// newPackageId = object.packageId;
|
|
129
|
+
// }
|
|
130
|
+
// if (
|
|
131
|
+
// object.type === 'mutated' &&
|
|
132
|
+
// object.objectType === '0x2::package::UpgradeCap'
|
|
133
|
+
// ) {
|
|
134
|
+
// console.log(
|
|
135
|
+
// chalk.blue(`${name} UpgradeCap: ${object.objectId}`)
|
|
136
|
+
// );
|
|
137
|
+
// newUpgradeCap = object.objectId;
|
|
138
|
+
// }
|
|
139
|
+
// });
|
|
140
|
+
|
|
141
|
+
// console.log(
|
|
142
|
+
// chalk.green(`Upgrade Transaction Digest: ${result.digest}`)
|
|
143
|
+
// );
|
|
144
|
+
|
|
145
|
+
// saveContractData(
|
|
146
|
+
// name,
|
|
147
|
+
// network,
|
|
148
|
+
// newPackageId,
|
|
149
|
+
// worldId,
|
|
150
|
+
// newUpgradeCap,
|
|
151
|
+
// adminCap,
|
|
152
|
+
// newVersion
|
|
153
|
+
// );
|
|
154
|
+
|
|
155
|
+
// oldPackageId = newPackageId;
|
|
156
|
+
// upgradeCap = newUpgradeCap;
|
|
157
|
+
// oldVersion = newVersion;
|
|
158
|
+
|
|
159
|
+
// console.log('\nExecuting the migrate: ');
|
|
160
|
+
// const delay = (ms: number) =>
|
|
161
|
+
// new Promise(resolve => setTimeout(resolve, ms));
|
|
162
|
+
// await delay(5000);
|
|
163
|
+
|
|
164
|
+
// const migrateTx = new Transaction();
|
|
165
|
+
// migrateTx.moveCall({
|
|
166
|
+
// target: `${newPackageId}::migrate::run`,
|
|
167
|
+
// arguments: [migrateTx.object(worldId), migrateTx.object(adminCap)],
|
|
168
|
+
// });
|
|
169
|
+
|
|
170
|
+
// let newWorldObject = await client.getObject({
|
|
171
|
+
// id: worldId,
|
|
172
|
+
// options: {
|
|
173
|
+
// showContent: true,
|
|
174
|
+
// showDisplay: true,
|
|
175
|
+
// showType: true,
|
|
176
|
+
// showOwner: true,
|
|
177
|
+
// },
|
|
178
|
+
// });
|
|
179
|
+
// let newObjectContent = newWorldObject.data!.content as ObjectContent;
|
|
180
|
+
|
|
181
|
+
// const uniqueSchema: string[] = schemaNames.filter(
|
|
182
|
+
// item => !newObjectContent.fields['schema_names'].includes(item)
|
|
183
|
+
// );
|
|
184
|
+
|
|
185
|
+
// console.log('new schema:', uniqueSchema);
|
|
186
|
+
// let needRegisterSchema = [];
|
|
187
|
+
// for (const newSchema of uniqueSchema) {
|
|
188
|
+
// migrateTx.moveCall({
|
|
189
|
+
// target: `${newPackageId}::${newSchema}_schema::register`,
|
|
190
|
+
// arguments: [
|
|
191
|
+
// migrateTx.object(worldId),
|
|
192
|
+
// migrateTx.object(adminCap),
|
|
193
|
+
// ],
|
|
194
|
+
// });
|
|
195
|
+
// needRegisterSchema.push(`${newSchema}_schema`);
|
|
196
|
+
// }
|
|
197
|
+
// const migrateResult = await client.signAndExecuteTransaction({
|
|
198
|
+
// signer: keypair,
|
|
199
|
+
// transaction: migrateTx,
|
|
200
|
+
// options: {
|
|
201
|
+
// showEffects: true,
|
|
202
|
+
// },
|
|
203
|
+
// });
|
|
204
|
+
|
|
205
|
+
// if (migrateResult.effects?.status.status === 'success') {
|
|
206
|
+
// console.log(
|
|
207
|
+
// chalk.green(
|
|
208
|
+
// `${name} migrate world success, new world version is: ${newObjectContent.fields['version']}, package version is ${newVersion}`
|
|
209
|
+
// )
|
|
210
|
+
// );
|
|
211
|
+
// if (needRegisterSchema.length !== 0) {
|
|
212
|
+
// console.log(
|
|
213
|
+
// chalk.green(
|
|
214
|
+
// `new schema: ${needRegisterSchema.toString()} register success.`
|
|
215
|
+
// )
|
|
216
|
+
// );
|
|
217
|
+
// }
|
|
218
|
+
|
|
219
|
+
// console.log(
|
|
220
|
+
// chalk.blue(
|
|
221
|
+
// `\n${name} world schemas is ${newObjectContent.fields['schema_names']}`
|
|
222
|
+
// )
|
|
223
|
+
// );
|
|
224
|
+
// } else {
|
|
225
|
+
// console.log(
|
|
226
|
+
// chalk.red(
|
|
227
|
+
// `${name} migrate world failed, world version is: ${newObjectContent.fields['version']}, package version is ${newVersion}`
|
|
228
|
+
// )
|
|
229
|
+
// );
|
|
230
|
+
// }
|
|
231
|
+
// } catch (error: any) {
|
|
232
|
+
// console.log(chalk.red('Upgrade failed!'));
|
|
233
|
+
// console.error(error.message);
|
|
234
|
+
|
|
235
|
+
// saveContractData(
|
|
236
|
+
// name,
|
|
237
|
+
// network,
|
|
238
|
+
// oldPackageId,
|
|
239
|
+
// worldId,
|
|
240
|
+
// upgradeCap,
|
|
241
|
+
// adminCap,
|
|
242
|
+
// oldVersion
|
|
243
|
+
// );
|
|
244
|
+
// await updateVersionInFile(projectPath, oldVersion.toString());
|
|
245
|
+
// }
|
|
246
|
+
// }
|
package/src/utils/utils.ts
CHANGED
|
@@ -3,17 +3,18 @@ import { mkdirSync, writeFileSync } from 'fs';
|
|
|
3
3
|
import { dirname } from 'path';
|
|
4
4
|
import { SUI_PRIVATE_KEY_PREFIX } from '@mysten/sui/cryptography';
|
|
5
5
|
import { FsIibError } from './errors';
|
|
6
|
+
export * from './localnode';
|
|
6
7
|
|
|
7
8
|
export type schema = {
|
|
8
|
-
name: string
|
|
9
|
-
objectId: string
|
|
10
|
-
}
|
|
9
|
+
name: string;
|
|
10
|
+
objectId: string;
|
|
11
|
+
};
|
|
11
12
|
|
|
12
13
|
export type DeploymentJsonType = {
|
|
13
14
|
projectName: string;
|
|
14
15
|
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
15
16
|
packageId: string;
|
|
16
|
-
schemas: schema[]
|
|
17
|
+
schemas: schema[];
|
|
17
18
|
upgradeCap: string;
|
|
18
19
|
version: number;
|
|
19
20
|
};
|
|
@@ -112,7 +113,8 @@ export async function getObjectIdBySchemaName(
|
|
|
112
113
|
schemaName: string
|
|
113
114
|
): Promise<string | undefined> {
|
|
114
115
|
const deployment = await getDeploymentJson(projectPath, network);
|
|
115
|
-
return deployment.schemas.find(
|
|
116
|
+
return deployment.schemas.find(schema => schema.name.includes(schemaName))
|
|
117
|
+
?.objectId;
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
export function saveContractData(
|