@0xobelisk/sui-cli 1.0.8 ā 1.0.10
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/dubhe.js +88 -57
- package/dist/dubhe.js.map +1 -1
- package/package.json +7 -4
- package/src/commands/build.ts +51 -45
- package/src/commands/call.ts +1 -1
- package/src/commands/checkBalance.ts +1 -0
- package/src/commands/faucet.ts +1 -2
- package/src/commands/index.ts +2 -0
- package/src/commands/indexer.ts +61 -0
- package/src/commands/publish.ts +1 -0
- package/src/commands/query.ts +1 -9
- package/src/commands/upgrade.ts +1 -0
- package/src/utils/generateAccount.ts +3 -3
- package/src/utils/index.ts +1 -0
- package/src/utils/indexerHandler.ts +232 -0
- package/src/utils/publishHandler.ts +47 -82
- package/src/utils/queryStorage.ts +4 -15
- package/src/utils/startNode.ts +1 -1
- package/src/utils/storeConfig.ts +5 -13
- package/src/utils/upgradeHandler.ts +28 -80
- package/src/utils/utils.ts +10 -36
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import { Dubhe } from '@0xobelisk/sui-client';
|
|
2
|
-
import { Transaction } from '@mysten/sui/transactions';
|
|
3
|
-
import {
|
|
4
|
-
getFullnodeUrl,
|
|
5
|
-
SuiClient,
|
|
6
|
-
SuiTransactionBlockResponse,
|
|
7
|
-
} from '@mysten/sui/client';
|
|
1
|
+
import { Dubhe, Transaction } from '@0xobelisk/sui-client';
|
|
8
2
|
import { execSync } from 'child_process';
|
|
9
3
|
import chalk from 'chalk';
|
|
10
4
|
import { DubheCliError } from './errors';
|
|
11
5
|
import {
|
|
12
6
|
saveContractData,
|
|
13
7
|
validatePrivateKey,
|
|
14
|
-
schema,
|
|
15
8
|
updateDubheDependency,
|
|
16
9
|
switchEnv,
|
|
17
10
|
delay,
|
|
@@ -122,21 +115,21 @@ published-version = "${config.publishedVersion}"
|
|
|
122
115
|
|
|
123
116
|
fs.writeFileSync(envFilePath, newEnvContent, 'utf-8');
|
|
124
117
|
}
|
|
125
|
-
function capitalizeAndRemoveUnderscores(input: string): string {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function getLastSegment(input: string): string {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
118
|
+
// function capitalizeAndRemoveUnderscores(input: string): string {
|
|
119
|
+
// return input
|
|
120
|
+
// .split('_')
|
|
121
|
+
// .map((word, index) => {
|
|
122
|
+
// return index === 0
|
|
123
|
+
// ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
|
124
|
+
// : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
125
|
+
// })
|
|
126
|
+
// .join('');
|
|
127
|
+
// }
|
|
128
|
+
//
|
|
129
|
+
// function getLastSegment(input: string): string {
|
|
130
|
+
// const segments = input.split('::');
|
|
131
|
+
// return segments.length > 0 ? segments[segments.length - 1] : '';
|
|
132
|
+
// }
|
|
140
133
|
|
|
141
134
|
function buildContract(projectPath: string): string[][] {
|
|
142
135
|
let modules: any, dependencies: any;
|
|
@@ -162,14 +155,14 @@ function buildContract(projectPath: string): string[][] {
|
|
|
162
155
|
}
|
|
163
156
|
|
|
164
157
|
async function publishContract(
|
|
165
|
-
client: SuiClient,
|
|
166
158
|
dubhe: Dubhe,
|
|
167
159
|
dubheConfig: DubheConfig,
|
|
168
160
|
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
169
161
|
projectPath: string,
|
|
170
162
|
gasBudget?: number
|
|
171
163
|
) {
|
|
172
|
-
const chainId =
|
|
164
|
+
const chainId =
|
|
165
|
+
await dubhe.suiInteractor.currentClient.getChainIdentifier();
|
|
173
166
|
await removeEnvContent(`${projectPath}/Move.lock`, network);
|
|
174
167
|
console.log('\nš Starting Contract Publication...');
|
|
175
168
|
console.log(` āā Project: ${projectPath}`);
|
|
@@ -177,8 +170,7 @@ async function publishContract(
|
|
|
177
170
|
console.log(` āā ChainId: ${chainId}`);
|
|
178
171
|
console.log(' āā Validating Environment...');
|
|
179
172
|
|
|
180
|
-
|
|
181
|
-
console.log(` āā Account: ${keypair.toSuiAddress()}`);
|
|
173
|
+
console.log(` āā Account: ${dubhe.getAddress()}`);
|
|
182
174
|
|
|
183
175
|
console.log('\nš¦ Building Contract...');
|
|
184
176
|
const [modules, dependencies] = buildContract(projectPath);
|
|
@@ -189,15 +181,11 @@ async function publishContract(
|
|
|
189
181
|
tx.setGasBudget(gasBudget);
|
|
190
182
|
}
|
|
191
183
|
const [upgradeCap] = tx.publish({ modules, dependencies });
|
|
192
|
-
tx.transferObjects([upgradeCap],
|
|
184
|
+
tx.transferObjects([upgradeCap], dubhe.getAddress());
|
|
193
185
|
|
|
194
|
-
let result
|
|
186
|
+
let result;
|
|
195
187
|
try {
|
|
196
|
-
result = await
|
|
197
|
-
signer: keypair,
|
|
198
|
-
transaction: tx,
|
|
199
|
-
options: { showObjectChanges: true },
|
|
200
|
-
});
|
|
188
|
+
result = await dubhe.signAndSendTxn(tx);
|
|
201
189
|
} catch (error: any) {
|
|
202
190
|
console.error(chalk.red(' āā Publication failed'));
|
|
203
191
|
console.error(error.message);
|
|
@@ -212,7 +200,8 @@ async function publishContract(
|
|
|
212
200
|
console.log(' āā Processing publication results...');
|
|
213
201
|
let version = 1;
|
|
214
202
|
let packageId = '';
|
|
215
|
-
let
|
|
203
|
+
let schemaId = '';
|
|
204
|
+
let schemas = dubheConfig.schemas;
|
|
216
205
|
let upgradeCapId = '';
|
|
217
206
|
|
|
218
207
|
result.objectChanges!.map(object => {
|
|
@@ -248,13 +237,9 @@ async function publishContract(
|
|
|
248
237
|
arguments: [deployHookTx.object('0x6')],
|
|
249
238
|
});
|
|
250
239
|
|
|
251
|
-
let deployHookResult
|
|
240
|
+
let deployHookResult;
|
|
252
241
|
try {
|
|
253
|
-
deployHookResult = await
|
|
254
|
-
signer: keypair,
|
|
255
|
-
transaction: deployHookTx,
|
|
256
|
-
options: { showEffects: true, showObjectChanges: true },
|
|
257
|
-
});
|
|
242
|
+
deployHookResult = await dubhe.signAndSendTxn(deployHookTx);
|
|
258
243
|
} catch (error: any) {
|
|
259
244
|
console.error(chalk.red(' āā Deploy hook execution failed'));
|
|
260
245
|
console.error(error.message);
|
|
@@ -267,29 +252,16 @@ async function publishContract(
|
|
|
267
252
|
|
|
268
253
|
console.log('\nš Created Schemas:');
|
|
269
254
|
deployHookResult.objectChanges?.map(object => {
|
|
255
|
+
if (object.type === 'created' && object.objectType.includes('schema::Schema')) {
|
|
256
|
+
schemaId = object.objectId;
|
|
257
|
+
}
|
|
270
258
|
if (
|
|
271
259
|
object.type === 'created' &&
|
|
272
|
-
object.objectType.includes('
|
|
260
|
+
object.objectType.includes('schema') &&
|
|
273
261
|
!object.objectType.includes('dynamic_field')
|
|
274
262
|
) {
|
|
275
263
|
console.log(` āā ${object.objectType}`);
|
|
276
264
|
console.log(` āā ID: ${object.objectId}`);
|
|
277
|
-
|
|
278
|
-
let structure: Record<string, string> = {};
|
|
279
|
-
for (let schemaKey in dubheConfig.schemas) {
|
|
280
|
-
if (
|
|
281
|
-
capitalizeAndRemoveUnderscores(schemaKey) ===
|
|
282
|
-
getLastSegment(object.objectType)
|
|
283
|
-
) {
|
|
284
|
-
structure = dubheConfig.schemas[schemaKey];
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
schemas.push({
|
|
289
|
-
name: object.objectType,
|
|
290
|
-
objectId: object.objectId,
|
|
291
|
-
structure,
|
|
292
|
-
});
|
|
293
265
|
}
|
|
294
266
|
});
|
|
295
267
|
|
|
@@ -297,6 +269,7 @@ async function publishContract(
|
|
|
297
269
|
dubheConfig.name,
|
|
298
270
|
network,
|
|
299
271
|
packageId,
|
|
272
|
+
schemaId,
|
|
300
273
|
upgradeCapId,
|
|
301
274
|
version,
|
|
302
275
|
schemas
|
|
@@ -342,7 +315,6 @@ async function checkDubheFramework(projectPath: string): Promise<boolean> {
|
|
|
342
315
|
}
|
|
343
316
|
|
|
344
317
|
export async function publishDubheFramework(
|
|
345
|
-
client: SuiClient,
|
|
346
318
|
dubhe: Dubhe,
|
|
347
319
|
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
348
320
|
) {
|
|
@@ -354,14 +326,15 @@ export async function publishDubheFramework(
|
|
|
354
326
|
return;
|
|
355
327
|
}
|
|
356
328
|
|
|
357
|
-
const chainId = await client.getChainIdentifier();
|
|
329
|
+
// const chainId = await client.getChainIdentifier();
|
|
330
|
+
const chainId =
|
|
331
|
+
await dubhe.suiInteractor.currentClient.getChainIdentifier();
|
|
358
332
|
await removeEnvContent(`${projectPath}/Move.lock`, network);
|
|
359
333
|
console.log('\nš Starting Contract Publication...');
|
|
360
334
|
console.log(` āā Project: ${projectPath}`);
|
|
361
335
|
console.log(` āā Network: ${network}`);
|
|
362
336
|
|
|
363
|
-
|
|
364
|
-
console.log(` āā Account: ${keypair.toSuiAddress()}`);
|
|
337
|
+
console.log(` āā Account: ${dubhe.getAddress()}`);
|
|
365
338
|
|
|
366
339
|
console.log('\nš¦ Building Contract...');
|
|
367
340
|
const [modules, dependencies] = buildContract(projectPath);
|
|
@@ -369,15 +342,11 @@ export async function publishDubheFramework(
|
|
|
369
342
|
console.log('\nš Publishing Contract...');
|
|
370
343
|
const tx = new Transaction();
|
|
371
344
|
const [upgradeCap] = tx.publish({ modules, dependencies });
|
|
372
|
-
tx.transferObjects([upgradeCap],
|
|
345
|
+
tx.transferObjects([upgradeCap], dubhe.getAddress());
|
|
373
346
|
|
|
374
|
-
let result
|
|
347
|
+
let result;
|
|
375
348
|
try {
|
|
376
|
-
result = await
|
|
377
|
-
signer: keypair,
|
|
378
|
-
transaction: tx,
|
|
379
|
-
options: { showObjectChanges: true },
|
|
380
|
-
});
|
|
349
|
+
result = await dubhe.signAndSendTxn(tx);
|
|
381
350
|
} catch (error: any) {
|
|
382
351
|
console.error(chalk.red(' āā Publication failed'));
|
|
383
352
|
console.error(error.message);
|
|
@@ -391,7 +360,7 @@ export async function publishDubheFramework(
|
|
|
391
360
|
|
|
392
361
|
let version = 1;
|
|
393
362
|
let packageId = '';
|
|
394
|
-
let schemas:
|
|
363
|
+
let schemas: Record<string, string> = {};
|
|
395
364
|
let upgradeCapId = '';
|
|
396
365
|
|
|
397
366
|
result.objectChanges!.map(object => {
|
|
@@ -422,6 +391,7 @@ export async function publishDubheFramework(
|
|
|
422
391
|
'dubhe-framework',
|
|
423
392
|
network,
|
|
424
393
|
packageId,
|
|
394
|
+
'',
|
|
425
395
|
upgradeCapId,
|
|
426
396
|
version,
|
|
427
397
|
schemas
|
|
@@ -450,22 +420,17 @@ in your contracts directory to use the default sui private key.`
|
|
|
450
420
|
throw new DubheCliError(`Please check your privateKey.`);
|
|
451
421
|
}
|
|
452
422
|
|
|
453
|
-
const dubhe = new Dubhe({
|
|
454
|
-
|
|
423
|
+
const dubhe = new Dubhe({
|
|
424
|
+
secretKey: privateKeyFormat,
|
|
425
|
+
networkType: network,
|
|
426
|
+
});
|
|
455
427
|
|
|
456
428
|
if (network === 'localnet') {
|
|
457
|
-
await publishDubheFramework(
|
|
429
|
+
await publishDubheFramework(dubhe, network);
|
|
458
430
|
}
|
|
459
431
|
|
|
460
432
|
const path = process.cwd();
|
|
461
433
|
const projectPath = `${path}/contracts/${dubheConfig.name}`;
|
|
462
|
-
updateDubheDependency(`${projectPath}/Move.toml`, network);
|
|
463
|
-
await publishContract(
|
|
464
|
-
client,
|
|
465
|
-
dubhe,
|
|
466
|
-
dubheConfig,
|
|
467
|
-
network,
|
|
468
|
-
projectPath,
|
|
469
|
-
gasBudget
|
|
470
|
-
);
|
|
434
|
+
await updateDubheDependency(`${projectPath}/Move.toml`, network);
|
|
435
|
+
await publishContract(dubhe, dubheConfig, network, projectPath, gasBudget);
|
|
471
436
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dubhe, loadMetadata } from '@0xobelisk/sui-client';
|
|
2
2
|
import { DubheCliError } from './errors';
|
|
3
|
-
import { validatePrivateKey, getOldPackageId,
|
|
3
|
+
import { validatePrivateKey, getOldPackageId, getSchemaId } from './utils';
|
|
4
4
|
import { DubheConfig } from '@0xobelisk/sui-common';
|
|
5
5
|
import * as fs from 'fs';
|
|
6
6
|
import * as path from 'path';
|
|
@@ -36,7 +36,6 @@ function getExpectedParamsCount(storageType: string): number {
|
|
|
36
36
|
export async function queryStorage({
|
|
37
37
|
dubheConfig,
|
|
38
38
|
schema,
|
|
39
|
-
field,
|
|
40
39
|
params,
|
|
41
40
|
network,
|
|
42
41
|
objectId,
|
|
@@ -45,7 +44,6 @@ export async function queryStorage({
|
|
|
45
44
|
}: {
|
|
46
45
|
dubheConfig: DubheConfig;
|
|
47
46
|
schema: string;
|
|
48
|
-
field: string;
|
|
49
47
|
params?: any[];
|
|
50
48
|
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
51
49
|
objectId?: string;
|
|
@@ -70,7 +68,7 @@ in your contracts directory to use the default sui private key.`
|
|
|
70
68
|
|
|
71
69
|
packageId = packageId || (await getOldPackageId(projectPath, network));
|
|
72
70
|
|
|
73
|
-
objectId = objectId || (await
|
|
71
|
+
objectId = objectId || (await getSchemaId(projectPath, network));
|
|
74
72
|
|
|
75
73
|
let metadata;
|
|
76
74
|
if (metadataFilePath) {
|
|
@@ -92,15 +90,7 @@ in your contracts directory to use the default sui private key.`
|
|
|
92
90
|
);
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
throw new DubheCliError(
|
|
97
|
-
`Field "${field}" not found in schema "${schema}". Available fields: ${Object.keys(
|
|
98
|
-
dubheConfig.schemas[schema]
|
|
99
|
-
).join(', ')}`
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const storageType = dubheConfig.schemas[schema][field];
|
|
93
|
+
const storageType = dubheConfig.schemas[schema];
|
|
104
94
|
|
|
105
95
|
const processedParams = params || [];
|
|
106
96
|
if (!validateParams(storageType, processedParams)) {
|
|
@@ -117,9 +107,8 @@ in your contracts directory to use the default sui private key.`
|
|
|
117
107
|
packageId,
|
|
118
108
|
metadata,
|
|
119
109
|
});
|
|
120
|
-
const result = await dubhe.
|
|
110
|
+
const result = await dubhe.parseState({
|
|
121
111
|
schema,
|
|
122
|
-
field,
|
|
123
112
|
objectId,
|
|
124
113
|
storageType,
|
|
125
114
|
params: processedParams,
|
package/src/utils/startNode.ts
CHANGED
|
@@ -34,7 +34,7 @@ async function printAccounts() {
|
|
|
34
34
|
console.log('==========');
|
|
35
35
|
privateKeys.forEach((privateKey, index) => {
|
|
36
36
|
const dubhe = new Dubhe({ secretKey: privateKey });
|
|
37
|
-
const keypair = dubhe.
|
|
37
|
+
const keypair = dubhe.getSigner();
|
|
38
38
|
spawn(
|
|
39
39
|
'curl',
|
|
40
40
|
[
|
package/src/utils/storeConfig.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fsAsync from 'fs/promises';
|
|
2
2
|
import { mkdirSync, writeFileSync } from 'fs';
|
|
3
3
|
import { dirname } from 'path';
|
|
4
|
-
import { DeploymentJsonType
|
|
4
|
+
import { DeploymentJsonType } from './utils';
|
|
5
5
|
import { DubheConfig } from '@0xobelisk/sui-common';
|
|
6
6
|
|
|
7
7
|
async function getDeploymentJson(
|
|
@@ -24,24 +24,16 @@ async function getDeploymentJson(
|
|
|
24
24
|
function storeConfig(
|
|
25
25
|
network: string,
|
|
26
26
|
packageId: string,
|
|
27
|
-
|
|
27
|
+
schemaId: string,
|
|
28
28
|
outputPath: string
|
|
29
29
|
) {
|
|
30
30
|
let code = `type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
|
|
31
31
|
|
|
32
32
|
export const NETWORK: NetworkType = '${network}';
|
|
33
|
-
|
|
34
33
|
export const PACKAGE_ID = '${packageId}'
|
|
34
|
+
export const SCHEMA_ID = '${schemaId}'
|
|
35
|
+
`
|
|
35
36
|
|
|
36
|
-
${schemas
|
|
37
|
-
.map(
|
|
38
|
-
schema =>
|
|
39
|
-
`export const ${schema.name.split('::')[2]}_Object_Id = '${
|
|
40
|
-
schema.objectId
|
|
41
|
-
}'`
|
|
42
|
-
)
|
|
43
|
-
.join('\n')}
|
|
44
|
-
`;
|
|
45
37
|
// if (outputPath) {
|
|
46
38
|
writeOutput(code, outputPath, 'storeConfig');
|
|
47
39
|
// writeOutput(code, `${path}/src/chain/config.ts`, 'storeConfig');
|
|
@@ -72,7 +64,7 @@ export async function storeConfigHandler(
|
|
|
72
64
|
storeConfig(
|
|
73
65
|
deployment.network,
|
|
74
66
|
deployment.packageId,
|
|
75
|
-
deployment.
|
|
67
|
+
deployment.schemaId,
|
|
76
68
|
outputPath
|
|
77
69
|
);
|
|
78
70
|
}
|
|
@@ -5,59 +5,44 @@ import { execSync } from 'child_process';
|
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import { DubheCliError, UpgradeError } from './errors';
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
getOldPackageId,
|
|
9
|
+
getVersion,
|
|
10
|
+
getUpgradeCap,
|
|
11
|
+
saveContractData,
|
|
12
|
+
validatePrivateKey,
|
|
13
|
+
getOnchainSchemas,
|
|
14
|
+
switchEnv, getSchemaId,
|
|
15
15
|
} from './utils';
|
|
16
16
|
import * as fs from 'fs';
|
|
17
17
|
import * as path from 'path';
|
|
18
18
|
import { DubheConfig } from '@0xobelisk/sui-common';
|
|
19
19
|
|
|
20
|
-
type Field = {
|
|
21
|
-
name: string;
|
|
22
|
-
type: string;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
20
|
type Migration = {
|
|
26
21
|
schemaName: string;
|
|
27
|
-
fields:
|
|
22
|
+
fields: string;
|
|
28
23
|
};
|
|
29
24
|
|
|
30
25
|
function updateMigrateMethod(
|
|
31
26
|
projectPath: string,
|
|
32
27
|
migrations: Migration[]
|
|
33
28
|
): void {
|
|
34
|
-
|
|
35
|
-
let filePath = `${projectPath}/sources/codegen/schemas/${migration.schemaName}.move`;
|
|
29
|
+
let filePath = `${projectPath}/sources/codegen/schema.move`;
|
|
36
30
|
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
37
31
|
const migrateMethodRegex = new RegExp(
|
|
38
|
-
`public fun migrate\\(
|
|
39
|
-
migration.schemaName
|
|
40
|
-
}: &mut ${capitalizeAndRemoveUnderscores(
|
|
41
|
-
migration.schemaName
|
|
42
|
-
)}, _cap: &UpgradeCap\\) {[^}]*}`
|
|
32
|
+
`public fun migrate\\(_schema: &mut Schema, _cap: &UpgradeCap, _ctx: &mut TxContext\\) {[^}]*}`
|
|
43
33
|
);
|
|
44
34
|
const newMigrateMethod = `
|
|
45
|
-
public fun migrate(
|
|
46
|
-
|
|
47
|
-
}: &mut ${capitalizeAndRemoveUnderscores(
|
|
48
|
-
migration.schemaName
|
|
49
|
-
)}, _cap: &UpgradeCap) {
|
|
50
|
-
${migration.fields
|
|
51
|
-
.map(field => {
|
|
35
|
+
public fun migrate(_schema: &mut Schema, _cap: &UpgradeCap, _ctx: &mut TxContext) {
|
|
36
|
+
${migrations.map(migration => {
|
|
52
37
|
let storage_type = '';
|
|
53
|
-
if (
|
|
54
|
-
storage_type = `storage_value::new()`;
|
|
55
|
-
} else if (
|
|
56
|
-
storage_type = `storage_map::new()`;
|
|
57
|
-
} else if (
|
|
58
|
-
storage_type = `storage_double_map::new()`;
|
|
38
|
+
if (migration.fields.includes('StorageValue')) {
|
|
39
|
+
storage_type = `storage_value::new(b"${migration.schemaName}", _ctx)`;
|
|
40
|
+
} else if (migration.fields.includes('StorageMap')) {
|
|
41
|
+
storage_type = `storage_map::new(b"${migration.schemaName}", _ctx)`;
|
|
42
|
+
} else if (migration.fields.includes('StorageDoubleMap')) {
|
|
43
|
+
storage_type = `storage_double_map::new(b"${migration.schemaName}", _ctx)`;
|
|
59
44
|
}
|
|
60
|
-
return `
|
|
45
|
+
return `storage::add_field<${migration.fields}>(&mut _schema.id, b"${migration.schemaName}", ${storage_type});`;
|
|
61
46
|
})
|
|
62
47
|
.join('')}
|
|
63
48
|
}
|
|
@@ -68,23 +53,6 @@ ${migration.fields
|
|
|
68
53
|
newMigrateMethod
|
|
69
54
|
);
|
|
70
55
|
fs.writeFileSync(filePath, updatedContent, 'utf-8');
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function capitalizeAndRemoveUnderscores(input: string): string {
|
|
75
|
-
return input
|
|
76
|
-
.split('_')
|
|
77
|
-
.map((word, index) => {
|
|
78
|
-
return index === 0
|
|
79
|
-
? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
|
80
|
-
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
81
|
-
})
|
|
82
|
-
.join('');
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function getLastSegment(input: string): string {
|
|
86
|
-
const segments = input.split('::');
|
|
87
|
-
return segments.length > 0 ? segments[segments.length - 1] : '';
|
|
88
56
|
}
|
|
89
57
|
|
|
90
58
|
function replaceEnvField(
|
|
@@ -155,7 +123,7 @@ in your contracts directory to use the default sui private key.`
|
|
|
155
123
|
const dubhe = new Dubhe({
|
|
156
124
|
secretKey: privateKeyFormat,
|
|
157
125
|
});
|
|
158
|
-
const keypair = dubhe.
|
|
126
|
+
const keypair = dubhe.getSigner();
|
|
159
127
|
|
|
160
128
|
const client = new SuiClient({
|
|
161
129
|
url: getFullnodeUrl(network),
|
|
@@ -164,6 +132,7 @@ in your contracts directory to use the default sui private key.`
|
|
|
164
132
|
let oldVersion = Number(await getVersion(projectPath, network));
|
|
165
133
|
let oldPackageId = await getOldPackageId(projectPath, network);
|
|
166
134
|
let upgradeCap = await getUpgradeCap(projectPath, network);
|
|
135
|
+
let schemaId = await getSchemaId(projectPath, network);
|
|
167
136
|
|
|
168
137
|
const original_published_id = replaceEnvField(
|
|
169
138
|
`${projectPath}/Move.lock`,
|
|
@@ -174,33 +143,11 @@ in your contracts directory to use the default sui private key.`
|
|
|
174
143
|
|
|
175
144
|
let pendingMigration: Migration[] = [];
|
|
176
145
|
let schemas = await getOnchainSchemas(projectPath, network);
|
|
177
|
-
|
|
178
|
-
schemas.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
) {
|
|
183
|
-
let migrate: Migration = { schemaName: '', fields: [] };
|
|
184
|
-
let fields: Field[] = [];
|
|
185
|
-
let isMigration = false;
|
|
186
|
-
for (const key in config.schemas[schemaKey]) {
|
|
187
|
-
if (!(key in schema.structure)) {
|
|
188
|
-
isMigration = true;
|
|
189
|
-
fields.push({
|
|
190
|
-
name: key,
|
|
191
|
-
type: config.schemas[schemaKey][key],
|
|
192
|
-
});
|
|
193
|
-
schema.structure[key] = config.schemas[schemaKey][key];
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (isMigration) {
|
|
197
|
-
migrate.schemaName = schemaKey;
|
|
198
|
-
migrate.fields = fields;
|
|
199
|
-
pendingMigration.push(migrate);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
}
|
|
146
|
+
Object.entries(config.schemas).forEach(([key, value]) => {
|
|
147
|
+
if (!schemas.hasOwnProperty(key)) {
|
|
148
|
+
pendingMigration.push({ schemaName: key, fields: value });
|
|
149
|
+
}
|
|
150
|
+
});
|
|
204
151
|
|
|
205
152
|
pendingMigration.forEach(migration => {
|
|
206
153
|
console.log(`\nš Starting Migration for ${migration.schemaName}...`);
|
|
@@ -304,9 +251,10 @@ in your contracts directory to use the default sui private key.`
|
|
|
304
251
|
name,
|
|
305
252
|
network,
|
|
306
253
|
newPackageId,
|
|
254
|
+
schemaId,
|
|
307
255
|
upgradeCap,
|
|
308
256
|
oldVersion + 1,
|
|
309
|
-
schemas
|
|
257
|
+
config.schemas
|
|
310
258
|
);
|
|
311
259
|
} catch (error: any) {
|
|
312
260
|
console.log(chalk.red('Upgrade failed!'));
|
package/src/utils/utils.ts
CHANGED
|
@@ -7,19 +7,14 @@ import * as fs from 'fs';
|
|
|
7
7
|
import chalk from 'chalk';
|
|
8
8
|
import { spawn } from 'child_process';
|
|
9
9
|
|
|
10
|
-
export type schema = {
|
|
11
|
-
name: string;
|
|
12
|
-
objectId: string;
|
|
13
|
-
structure: Record<string, string>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
10
|
export type DeploymentJsonType = {
|
|
17
11
|
projectName: string;
|
|
18
12
|
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
19
13
|
packageId: string;
|
|
14
|
+
schemaId: string;
|
|
20
15
|
upgradeCap: string;
|
|
21
16
|
version: number;
|
|
22
|
-
schemas:
|
|
17
|
+
schemas: Record<string, string>;
|
|
23
18
|
};
|
|
24
19
|
|
|
25
20
|
export function validatePrivateKey(privateKey: string): false | string {
|
|
@@ -81,7 +76,7 @@ async function getDeploymentJson(projectPath: string, network: string) {
|
|
|
81
76
|
export async function getOnchainSchemas(
|
|
82
77
|
projectPath: string,
|
|
83
78
|
network: string
|
|
84
|
-
): Promise<
|
|
79
|
+
): Promise<Record<string, string>> {
|
|
85
80
|
const deployment = await getDeploymentJson(projectPath, network);
|
|
86
81
|
return deployment.schemas;
|
|
87
82
|
}
|
|
@@ -110,25 +105,12 @@ export async function getOldPackageId(
|
|
|
110
105
|
return deployment.packageId;
|
|
111
106
|
}
|
|
112
107
|
|
|
113
|
-
export async function
|
|
108
|
+
export async function getSchemaId(
|
|
114
109
|
projectPath: string,
|
|
115
|
-
network: string
|
|
116
|
-
schemaName: string
|
|
110
|
+
network: string
|
|
117
111
|
): Promise<string> {
|
|
118
112
|
const deployment = await getDeploymentJson(projectPath, network);
|
|
119
|
-
|
|
120
|
-
schema.name
|
|
121
|
-
.toLowerCase()
|
|
122
|
-
.endsWith(`::${schemaName.toLowerCase()}_schema::${schemaName}`)
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
if (!schema?.objectId) {
|
|
126
|
-
throw new Error(
|
|
127
|
-
`Schema '${schemaName}' not found in deployment history`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return schema.objectId;
|
|
113
|
+
return deployment.schemaId;
|
|
132
114
|
}
|
|
133
115
|
|
|
134
116
|
export async function getUpgradeCap(
|
|
@@ -139,28 +121,20 @@ export async function getUpgradeCap(
|
|
|
139
121
|
return deployment.upgradeCap;
|
|
140
122
|
}
|
|
141
123
|
|
|
142
|
-
export async function getObjectIdBySchemaName(
|
|
143
|
-
projectPath: string,
|
|
144
|
-
network: string,
|
|
145
|
-
schemaName: string
|
|
146
|
-
): Promise<string | undefined> {
|
|
147
|
-
const deployment = await getDeploymentJson(projectPath, network);
|
|
148
|
-
return deployment.schemas.find(schema => schema.name.includes(schemaName))
|
|
149
|
-
?.objectId;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
124
|
export function saveContractData(
|
|
153
125
|
projectName: string,
|
|
154
126
|
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
155
127
|
packageId: string,
|
|
128
|
+
schemaId: string,
|
|
156
129
|
upgradeCap: string,
|
|
157
130
|
version: number,
|
|
158
|
-
schemas:
|
|
131
|
+
schemas: Record<string, string>
|
|
159
132
|
) {
|
|
160
133
|
const DeploymentData: DeploymentJsonType = {
|
|
161
134
|
projectName,
|
|
162
135
|
network,
|
|
163
136
|
packageId,
|
|
137
|
+
schemaId,
|
|
164
138
|
schemas,
|
|
165
139
|
upgradeCap,
|
|
166
140
|
version,
|
|
@@ -203,7 +177,7 @@ function getDubheDependency(
|
|
|
203
177
|
}
|
|
204
178
|
}
|
|
205
179
|
|
|
206
|
-
export function updateDubheDependency(
|
|
180
|
+
export async function updateDubheDependency(
|
|
207
181
|
filePath: string,
|
|
208
182
|
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
209
183
|
) {
|