@0xobelisk/sui-common 0.5.20 ā 0.5.22
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/index.d.ts +4 -5
- package/dist/index.js +101 -96
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/codegen/types/index.ts +39 -40
- package/src/codegen/utils/renderMove/generateSchema.ts +82 -84
- package/src/codegen/utils/renderMove/generateScript.ts +13 -8
- package/src/codegen/utils/renderMove/generateToml.ts +4 -5
- package/src/codegen/utils/renderMove/schemaGen.ts +52 -53
|
@@ -20,34 +20,34 @@ export function capitalizeAndRemoveUnderscores(input: string): string {
|
|
|
20
20
|
|
|
21
21
|
export function renderSetAttrsFunc(
|
|
22
22
|
schemaName: string,
|
|
23
|
-
fields: BaseType | Record<string, BaseType
|
|
23
|
+
fields: BaseType | Record<string, BaseType>,
|
|
24
24
|
): string {
|
|
25
25
|
return Object.entries(fields)
|
|
26
26
|
.map(
|
|
27
27
|
([key, type]) =>
|
|
28
28
|
`public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {
|
|
29
29
|
self.${key} = ${key};
|
|
30
|
-
}
|
|
30
|
+
}`,
|
|
31
31
|
)
|
|
32
32
|
.join('\n');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function renderSetFunc(
|
|
36
36
|
schemaName: string,
|
|
37
|
-
fields: Record<string, string
|
|
37
|
+
fields: Record<string, string>,
|
|
38
38
|
): string {
|
|
39
39
|
return `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(
|
|
40
|
-
fields
|
|
40
|
+
fields,
|
|
41
41
|
)}) {
|
|
42
42
|
${Object.entries(fields)
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
.map(([fieldName]) => `self.${fieldName} = ${fieldName};`)
|
|
44
|
+
.join('\n')}
|
|
45
45
|
}`;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export function renderGetAllFunc(
|
|
49
49
|
schemaName: string,
|
|
50
|
-
fields: Record<string, string
|
|
50
|
+
fields: Record<string, string>,
|
|
51
51
|
): string {
|
|
52
52
|
return `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {
|
|
53
53
|
(${getStructAttrsQuery(fields)})
|
|
@@ -56,16 +56,16 @@ export function renderGetAllFunc(
|
|
|
56
56
|
|
|
57
57
|
export function renderGetAttrsFunc(
|
|
58
58
|
schemaName: string,
|
|
59
|
-
fields: BaseType | Record<string, BaseType
|
|
59
|
+
fields: BaseType | Record<string, BaseType>,
|
|
60
60
|
): string {
|
|
61
61
|
return Object.entries(fields)
|
|
62
62
|
.map(
|
|
63
63
|
([
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
key,
|
|
65
|
+
type,
|
|
66
|
+
]) => `public fun get_${key}(self: &${schemaName}): ${type} {
|
|
67
67
|
self.${key}
|
|
68
|
-
}
|
|
68
|
+
}`,
|
|
69
69
|
)
|
|
70
70
|
.join('\n');
|
|
71
71
|
}
|
|
@@ -80,7 +80,7 @@ function convertToSnakeCase(input: string): string {
|
|
|
80
80
|
export async function generateSchemaData(
|
|
81
81
|
projectName: string,
|
|
82
82
|
schemas: Record<string, SchemaType>,
|
|
83
|
-
path: string
|
|
83
|
+
path: string,
|
|
84
84
|
) {
|
|
85
85
|
console.log('\nš¦ Starting Schema Data Generation...');
|
|
86
86
|
for (const schemaName in schemas) {
|
|
@@ -91,7 +91,7 @@ export async function generateSchemaData(
|
|
|
91
91
|
console.log(
|
|
92
92
|
` āā Generating ${item.name} ${
|
|
93
93
|
Array.isArray(item.fields) ? '(enum)' : '(struct)'
|
|
94
|
-
}
|
|
94
|
+
}`,
|
|
95
95
|
);
|
|
96
96
|
let code = '';
|
|
97
97
|
|
|
@@ -101,42 +101,42 @@ export async function generateSchemaData(
|
|
|
101
101
|
|
|
102
102
|
if (Array.isArray(item.fields)) {
|
|
103
103
|
code = `module ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
104
|
-
item.name
|
|
104
|
+
item.name,
|
|
105
105
|
)} {
|
|
106
106
|
public enum ${item.name} has copy, drop , store {
|
|
107
107
|
${item.fields}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
${item.fields
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
.map((field: string) => {
|
|
112
|
+
return `public fun new_${convertToSnakeCase(
|
|
113
|
+
field,
|
|
114
|
+
)}(): ${item.name} {
|
|
115
115
|
${item.name}::${field}
|
|
116
116
|
}`;
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
})
|
|
118
|
+
.join('')}`;
|
|
119
119
|
} else {
|
|
120
120
|
code = `module ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
121
|
-
item.name
|
|
121
|
+
item.name,
|
|
122
122
|
)} {
|
|
123
123
|
use std::ascii::String;
|
|
124
124
|
${enumNames
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
.map(
|
|
126
|
+
name =>
|
|
127
|
+
`use ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
128
|
+
name,
|
|
129
|
+
)}::${name};`,
|
|
130
|
+
)
|
|
131
|
+
.join('\n')}
|
|
132
132
|
|
|
133
133
|
public struct ${item.name} has copy, drop , store {
|
|
134
134
|
${getStructAttrsWithType(item.fields)}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
public fun new(${getStructAttrsWithType(
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
item.fields,
|
|
139
|
+
)}): ${item.name} {
|
|
140
140
|
${item.name} {
|
|
141
141
|
${getStructAttrs(item.fields)}
|
|
142
142
|
}
|
|
@@ -152,9 +152,9 @@ export async function generateSchemaData(
|
|
|
152
152
|
await formatAndWriteMove(
|
|
153
153
|
code,
|
|
154
154
|
`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(
|
|
155
|
-
item.name
|
|
155
|
+
item.name,
|
|
156
156
|
)}.move`,
|
|
157
|
-
'formatAndWriteMove'
|
|
157
|
+
'formatAndWriteMove',
|
|
158
158
|
);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
@@ -165,13 +165,13 @@ export async function generateSchemaData(
|
|
|
165
165
|
function generateImport(
|
|
166
166
|
projectName: string,
|
|
167
167
|
schemaName: string,
|
|
168
|
-
schema: SchemaType
|
|
168
|
+
schema: SchemaType,
|
|
169
169
|
) {
|
|
170
170
|
if (schema.data) {
|
|
171
171
|
return schema.data
|
|
172
172
|
.map(item => {
|
|
173
173
|
return `use ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
174
|
-
item.name
|
|
174
|
+
item.name,
|
|
175
175
|
)}::${item.name};`;
|
|
176
176
|
})
|
|
177
177
|
.join('\n');
|
|
@@ -184,18 +184,17 @@ export async function generateSchemaStructure(
|
|
|
184
184
|
projectName: string,
|
|
185
185
|
schemas: Record<string, SchemaType>,
|
|
186
186
|
path: string,
|
|
187
|
-
migration_enabled: boolean
|
|
188
187
|
) {
|
|
189
188
|
console.log('\nšØ Starting Schema Structure Generation...');
|
|
190
189
|
for (const schemaName in schemas) {
|
|
191
190
|
console.log(` āā Generating schema: ${schemaName}`);
|
|
192
191
|
console.log(
|
|
193
|
-
` āā Output path: ${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move
|
|
192
|
+
` āā Output path: ${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,
|
|
194
193
|
);
|
|
195
194
|
console.log(
|
|
196
195
|
` āā Structure fields: ${
|
|
197
196
|
Object.keys(schemas[schemaName].structure).length
|
|
198
|
-
}
|
|
197
|
+
}`,
|
|
199
198
|
);
|
|
200
199
|
const schema = schemas[schemaName];
|
|
201
200
|
const schemaMoudle = `module ${projectName}::${schemaName}_schema {
|
|
@@ -214,92 +213,91 @@ export async function generateSchemaStructure(
|
|
|
214
213
|
${generateImport(projectName, schemaName, schema)}
|
|
215
214
|
|
|
216
215
|
public struct ${capitalizeAndRemoveUnderscores(
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
schemaName,
|
|
217
|
+
)} has key, store {
|
|
219
218
|
id: UID
|
|
220
219
|
}
|
|
221
220
|
|
|
222
221
|
${Object.entries(schema.structure)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
222
|
+
.map(([key, value]) => {
|
|
223
|
+
return `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(
|
|
224
|
+
schemaName,
|
|
225
|
+
)}) : &${value} {
|
|
227
226
|
storage_migrate::borrow_field(&self.id, b"${key}")
|
|
228
227
|
}
|
|
229
228
|
|
|
230
229
|
public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
schemaName,
|
|
231
|
+
)}): &mut ${value} {
|
|
233
232
|
storage_migrate::borrow_mut_field(&mut self.id, b"${key}")
|
|
234
233
|
}
|
|
235
234
|
`;
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
})
|
|
236
|
+
.join('')}
|
|
238
237
|
|
|
239
238
|
|
|
240
239
|
public(package) fun create(ctx: &mut TxContext): ${capitalizeAndRemoveUnderscores(
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
schemaName,
|
|
241
|
+
)} {
|
|
243
242
|
let mut id = object::new(ctx);
|
|
244
243
|
${Object.entries(schema.structure)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
244
|
+
.map(([key, value]) => {
|
|
245
|
+
let storage_type = '';
|
|
246
|
+
if (value.includes('StorageValue')) {
|
|
247
|
+
storage_type = `storage_value::new()`;
|
|
248
|
+
} else if (value.includes('StorageMap')) {
|
|
249
|
+
storage_type = `storage_map::new()`;
|
|
250
|
+
} else if (
|
|
251
|
+
value.includes('StorageDoubleMap')
|
|
252
|
+
) {
|
|
253
|
+
storage_type = `storage_double_map::new()`;
|
|
254
|
+
}
|
|
255
|
+
return `storage_migrate::add_field<${value}>(&mut id, b"${key}", ${storage_type});`;
|
|
256
|
+
})
|
|
257
|
+
.join('')}
|
|
259
258
|
|
|
260
259
|
${capitalizeAndRemoveUnderscores(schemaName)} { id }
|
|
261
260
|
}
|
|
262
261
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
262
|
+
public fun migrate(_${schemaName}: &mut ${capitalizeAndRemoveUnderscores(schemaName)}, _cap: &UpgradeCap) { }
|
|
263
|
+
|
|
266
264
|
|
|
267
265
|
|
|
268
266
|
// ======================================== View Functions ========================================
|
|
269
267
|
${Object.entries(schema.structure)
|
|
270
268
|
.map(([key, value]) => {
|
|
271
269
|
// @ts-ignore
|
|
272
|
-
let all_types = value.match(/<(.+)>/)[1].split(',').map(type => type.trim())
|
|
273
|
-
let para_key: string[] = []
|
|
274
|
-
let para_value =
|
|
275
|
-
let borrow_key =
|
|
276
|
-
let extra_code =
|
|
270
|
+
let all_types = value.match(/<(.+)>/)[1].split(',').map(type => type.trim());
|
|
271
|
+
let para_key: string[] = [];
|
|
272
|
+
let para_value = '';
|
|
273
|
+
let borrow_key = '';
|
|
274
|
+
let extra_code = '';
|
|
277
275
|
if (value.includes('StorageValue')) {
|
|
278
|
-
para_key = []
|
|
279
|
-
para_value = `${all_types[0]}
|
|
280
|
-
borrow_key = 'try_get()'
|
|
276
|
+
para_key = [];
|
|
277
|
+
para_value = `${all_types[0]}`;
|
|
278
|
+
borrow_key = 'try_get()';
|
|
281
279
|
} else if (value.includes('StorageMap')) {
|
|
282
|
-
para_key = [`key: ${all_types[0]}`]
|
|
283
|
-
para_value = `${all_types[1]}
|
|
284
|
-
borrow_key = 'try_get(key)'
|
|
280
|
+
para_key = [`key: ${all_types[0]}`];
|
|
281
|
+
para_value = `${all_types[1]}`;
|
|
282
|
+
borrow_key = 'try_get(key)';
|
|
285
283
|
extra_code = `public fun get_${key}_keys(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[0]}> {
|
|
286
284
|
self.borrow_${key}().keys()
|
|
287
285
|
}
|
|
288
286
|
|
|
289
287
|
public fun get_${key}_values(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[1]}> {
|
|
290
288
|
self.borrow_${key}().values()
|
|
291
|
-
}
|
|
289
|
+
}`;
|
|
292
290
|
} else if (value.includes('StorageDoubleMap')) {
|
|
293
|
-
para_key = [`key1: ${all_types[0]}`, `key2: ${all_types[1]}`]
|
|
294
|
-
para_value = `${all_types[2]}
|
|
295
|
-
borrow_key = 'try_get(key1, key2)'
|
|
291
|
+
para_key = [`key1: ${all_types[0]}`, `key2: ${all_types[1]}`];
|
|
292
|
+
para_value = `${all_types[2]}`;
|
|
293
|
+
borrow_key = 'try_get(key1, key2)';
|
|
296
294
|
extra_code = `public fun get_${key}_keys(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : (vector<${all_types[0]}>, vector<${all_types[1]}>) {
|
|
297
295
|
self.borrow_${key}().keys()
|
|
298
296
|
}
|
|
299
297
|
|
|
300
298
|
public fun get_${key}_values(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[2]}> {
|
|
301
299
|
self.borrow_${key}().values()
|
|
302
|
-
}
|
|
300
|
+
}`;
|
|
303
301
|
}
|
|
304
302
|
return `public fun get_${key}(self: &${capitalizeAndRemoveUnderscores(schemaName)}, ${para_key}) : Option<${para_value}> {
|
|
305
303
|
self.borrow_${key}().${borrow_key}
|
|
@@ -314,7 +312,7 @@ export async function generateSchemaStructure(
|
|
|
314
312
|
await formatAndWriteMove(
|
|
315
313
|
schemaMoudle,
|
|
316
314
|
`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,
|
|
317
|
-
'formatAndWriteMove'
|
|
315
|
+
'formatAndWriteMove',
|
|
318
316
|
);
|
|
319
317
|
}
|
|
320
318
|
console.log('ā
Schema Structure Generation Complete\n');
|
|
@@ -9,12 +9,12 @@ export async function generateDeployHook(
|
|
|
9
9
|
) {
|
|
10
10
|
console.log('\nš Starting Deploy Hook Generation...');
|
|
11
11
|
console.log(
|
|
12
|
-
` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/
|
|
12
|
+
` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`
|
|
13
13
|
);
|
|
14
14
|
|
|
15
15
|
if (
|
|
16
16
|
!existsSync(
|
|
17
|
-
`${srcPrefix}/contracts/${config.name}/sources/
|
|
17
|
+
`${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`
|
|
18
18
|
)
|
|
19
19
|
) {
|
|
20
20
|
let code = `module ${config.name}::deploy_hook {
|
|
@@ -23,6 +23,8 @@ export async function generateDeployHook(
|
|
|
23
23
|
use ${config.name}::schema_hub::SchemaHub;
|
|
24
24
|
use std::ascii::string;
|
|
25
25
|
use sui::clock::Clock;
|
|
26
|
+
use sui::sui::SUI;
|
|
27
|
+
use sui::coin::Coin;
|
|
26
28
|
use sui::package::UpgradeCap;
|
|
27
29
|
use sui::transfer::public_share_object;
|
|
28
30
|
${Object.keys(config.schemas).map(schemaName => {
|
|
@@ -31,6 +33,8 @@ export async function generateDeployHook(
|
|
|
31
33
|
#[test_only]
|
|
32
34
|
use sui::clock;
|
|
33
35
|
#[test_only]
|
|
36
|
+
use sui::coin;
|
|
37
|
+
#[test_only]
|
|
34
38
|
use sui::test_scenario;
|
|
35
39
|
#[test_only]
|
|
36
40
|
use sui::package;
|
|
@@ -41,9 +45,9 @@ export async function generateDeployHook(
|
|
|
41
45
|
#[test_only]
|
|
42
46
|
use sui::test_scenario::Scenario;
|
|
43
47
|
|
|
44
|
-
public entry fun run(schema_hub: &mut SchemaHub, dapps: &mut Dapps, cap: &UpgradeCap, clock: &Clock, ctx: &mut TxContext) {
|
|
48
|
+
public entry fun run(schema_hub: &mut SchemaHub, dapps: &mut Dapps, cap: &UpgradeCap, clock: &Clock, coin: Coin<SUI>, ctx: &mut TxContext) {
|
|
45
49
|
// Register the dapp to dubhe.
|
|
46
|
-
dapps_system::register(dapps,cap,string(b"${config.name}"),string(b"${config.description}"),clock,ctx);
|
|
50
|
+
dapps_system::register(dapps,cap,string(b"${config.name}"),string(b"${config.description}"),clock,coin,ctx);
|
|
47
51
|
// Create schemas
|
|
48
52
|
${Object.keys(config.schemas).map(schemaName => {
|
|
49
53
|
return `let ${schemaName} = ${config.name}::${schemaName}_schema::create(ctx);`;
|
|
@@ -75,7 +79,8 @@ export async function generateDeployHook(
|
|
|
75
79
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
76
80
|
let clock = clock::create_for_testing(ctx);
|
|
77
81
|
let upgrade_cap = package::test_publish(@0x42.to_id(), ctx);
|
|
78
|
-
|
|
82
|
+
let coin = coin::mint_for_testing<SUI>(1_000_000_000, ctx);
|
|
83
|
+
run(&mut schema_hub, &mut dapps, &upgrade_cap, &clock, coin, ctx);
|
|
79
84
|
|
|
80
85
|
clock::destroy_for_testing(clock);
|
|
81
86
|
upgrade_cap.make_immutable();
|
|
@@ -86,7 +91,7 @@ export async function generateDeployHook(
|
|
|
86
91
|
`;
|
|
87
92
|
await formatAndWriteMove(
|
|
88
93
|
code,
|
|
89
|
-
`${srcPrefix}/contracts/${config.name}/sources/
|
|
94
|
+
`${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`,
|
|
90
95
|
'formatAndWriteMove'
|
|
91
96
|
);
|
|
92
97
|
}
|
|
@@ -96,7 +101,7 @@ export async function generateDeployHook(
|
|
|
96
101
|
export async function generateMigrate(config: DubheConfig, srcPrefix: string) {
|
|
97
102
|
if (
|
|
98
103
|
!existsSync(
|
|
99
|
-
`${srcPrefix}/contracts/${config.name}/sources/
|
|
104
|
+
`${srcPrefix}/contracts/${config.name}/sources/scripts/migrate.move`
|
|
100
105
|
)
|
|
101
106
|
) {
|
|
102
107
|
let code = `module ${config.name}::migrate {
|
|
@@ -109,7 +114,7 @@ export async function generateMigrate(config: DubheConfig, srcPrefix: string) {
|
|
|
109
114
|
`;
|
|
110
115
|
await formatAndWriteMove(
|
|
111
116
|
code,
|
|
112
|
-
`${srcPrefix}/contracts/${config.name}/sources/
|
|
117
|
+
`${srcPrefix}/contracts/${config.name}/sources/scripts/migrate.move`,
|
|
113
118
|
'formatAndWriteMove'
|
|
114
119
|
);
|
|
115
120
|
}
|
|
@@ -13,16 +13,15 @@ export async function generateToml(
|
|
|
13
13
|
|
|
14
14
|
let code = `[package]
|
|
15
15
|
name = "${config.name}"
|
|
16
|
-
version = "0.0
|
|
17
|
-
edition = "2024
|
|
16
|
+
version = "1.0.0"
|
|
17
|
+
edition = "2024"
|
|
18
18
|
|
|
19
19
|
[dependencies]
|
|
20
|
-
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.
|
|
21
|
-
Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "
|
|
20
|
+
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.38.3" }
|
|
21
|
+
Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-testnet-v1.0.0" }
|
|
22
22
|
|
|
23
23
|
[addresses]
|
|
24
24
|
sui = "0x2"
|
|
25
|
-
dubhe = "${frameworkId}"
|
|
26
25
|
${config.name} = "0x0"
|
|
27
26
|
`;
|
|
28
27
|
await formatAndWriteMove(
|
|
@@ -5,72 +5,71 @@ import { generateToml } from './generateToml';
|
|
|
5
5
|
import { generateSchemaData, generateSchemaStructure } from './generateSchema';
|
|
6
6
|
import { generateDeployHook, generateMigrate } from './generateScript';
|
|
7
7
|
import { generateDappKey } from './generateDappKey';
|
|
8
|
-
import {generateSchemaEvent} from
|
|
8
|
+
import { generateSchemaEvent } from './generateEvent';
|
|
9
9
|
import { generateSystem } from './generateSystem';
|
|
10
10
|
import { generateSchemaHub } from './generateSchemaHub';
|
|
11
11
|
|
|
12
12
|
function matchFrameworkId(
|
|
13
|
-
|
|
13
|
+
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
14
14
|
): string {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
switch (network) {
|
|
16
|
+
case 'testnet':
|
|
17
|
+
return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
|
|
18
|
+
case 'localnet':
|
|
19
|
+
return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
|
|
20
|
+
default:
|
|
21
|
+
return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
|
|
22
|
+
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export async function schemaGen(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
config: DubheConfig,
|
|
27
|
+
srcPrefix?: string,
|
|
28
|
+
network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet',
|
|
29
|
+
frameworkId?: string,
|
|
30
30
|
) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
console.log('\nš Starting Schema Generation Process...');
|
|
32
|
+
console.log('š Project Configuration:');
|
|
33
|
+
console.log(` āā Name: ${config.name}`);
|
|
34
|
+
console.log(
|
|
35
|
+
` āā Description: ${config.description || 'No description provided'}`,
|
|
36
|
+
);
|
|
37
|
+
console.log(` āā Network: ${network || 'testnet'}`);
|
|
38
|
+
console.log(
|
|
39
|
+
` āā Framework ID: ${
|
|
40
|
+
frameworkId || matchFrameworkId(network ?? 'testnet')
|
|
41
|
+
}\n`,
|
|
42
|
+
);
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
const path = srcPrefix ?? process.cwd();
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
frameworkId = frameworkId || matchFrameworkId(network ?? 'testnet');
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
if (existsSync(`${path}/contracts/${config.name}`)) {
|
|
49
|
+
deleteFolderRecursive(
|
|
50
|
+
`${path}/contracts/${config.name}/sources/codegen`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {
|
|
55
|
+
await generateToml(config, path, frameworkId);
|
|
56
|
+
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
if (
|
|
59
|
+
!existsSync(
|
|
60
|
+
`${path}/contracts/${config.name}/sources/script/deploy_hook.move`,
|
|
61
|
+
)
|
|
62
|
+
) {
|
|
63
|
+
await generateDeployHook(config, path);
|
|
64
|
+
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
console.log('ā
Schema Generation Process Complete!\n');
|
|
66
|
+
await generateSchemaData(config.name, config.schemas, path);
|
|
67
|
+
await generateSchemaStructure(config.name, config.schemas, path);
|
|
68
|
+
await generateSchemaEvent(config.name, config.schemas, path);
|
|
69
|
+
await generateDappKey(config, path);
|
|
70
|
+
await generateSchemaHub(config, path);
|
|
71
|
+
await generateSystem(config, path);
|
|
72
|
+
await generateMigrate(config, path);
|
|
73
|
+
|
|
74
|
+
console.log('ā
Schema Generation Process Complete!\n');
|
|
76
75
|
}
|