@0xobelisk/sui-common 0.5.19 → 0.5.21

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.
@@ -7,7 +7,7 @@ import {
7
7
  getStructAttrsQuery,
8
8
  } from './common';
9
9
 
10
- function capitalizeAndRemoveUnderscores(input: string): string {
10
+ export function capitalizeAndRemoveUnderscores(input: string): string {
11
11
  return input
12
12
  .split('_')
13
13
  .map((word, index) => {
@@ -20,34 +20,34 @@ 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
- .map(([fieldName]) => `self.${fieldName} = ${fieldName};`)
44
- .join('\n')}
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
- key,
65
- type,
66
- ]) => `public fun get_${key}(self: &${schemaName}): ${type} {
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
- .map((field: string) => {
112
- return `public fun new_${convertToSnakeCase(
113
- field
114
- )}(): ${item.name} {
111
+ .map((field: string) => {
112
+ return `public fun new_${convertToSnakeCase(
113
+ field,
114
+ )}(): ${item.name} {
115
115
  ${item.name}::${field}
116
116
  }`;
117
- })
118
- .join('')}`;
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
- .map(
126
- name =>
127
- `use ${projectName}::${schemaName}_${convertToSnakeCase(
128
- name
129
- )}::${name};`
130
- )
131
- .join('\n')}
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
- item.fields
139
- )}): ${item.name} {
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');
@@ -183,128 +183,124 @@ function generateImport(
183
183
  export async function generateSchemaStructure(
184
184
  projectName: string,
185
185
  schemas: Record<string, SchemaType>,
186
- path: string
186
+ path: string,
187
187
  ) {
188
188
  console.log('\nšŸ”Ø Starting Schema Structure Generation...');
189
189
  for (const schemaName in schemas) {
190
190
  console.log(` ā”œā”€ Generating schema: ${schemaName}`);
191
191
  console.log(
192
- ` ā”œā”€ Output path: ${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`
192
+ ` ā”œā”€ Output path: ${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,
193
193
  );
194
194
  console.log(
195
195
  ` └─ Structure fields: ${
196
196
  Object.keys(schemas[schemaName].structure).length
197
- }`
197
+ }`,
198
198
  );
199
199
  const schema = schemas[schemaName];
200
200
  const schemaMoudle = `module ${projectName}::${schemaName}_schema {
201
201
  use std::ascii::String;
202
+ use std::ascii::string;
203
+ use sui::package::UpgradeCap;
202
204
  use std::type_name;
203
205
  use dubhe::dapps_system;
206
+ use dubhe::storage_migrate;
204
207
  use dubhe::dapps_schema::Dapps;
205
208
  use dubhe::storage_value::{Self, StorageValue};
206
209
  use dubhe::storage_map::{Self, StorageMap};
207
210
  use dubhe::storage_double_map::{Self, StorageDoubleMap};
208
211
  use ${projectName}::dapp_key::DappKey;
212
+ use sui::dynamic_field as df;
209
213
  ${generateImport(projectName, schemaName, schema)}
210
214
 
211
215
  public struct ${capitalizeAndRemoveUnderscores(
212
- schemaName
213
- )} has key, store {
214
- id: UID,
215
- ${getStructAttrsWithType(schema.structure)}
216
- }
216
+ schemaName,
217
+ )} has key, store {
218
+ id: UID
219
+ }
217
220
 
218
221
  ${Object.entries(schema.structure)
219
- .map(([key, value]) => {
220
- return `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(
221
- schemaName
222
- )}) : &${value} {
223
- &self.${key}
222
+ .map(([key, value]) => {
223
+ return `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(
224
+ schemaName,
225
+ )}) : &${value} {
226
+ storage_migrate::borrow_field(&self.id, b"${key}")
224
227
  }
225
228
 
226
229
  public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(
227
- schemaName
228
- )}): &mut ${value} {
229
- &mut self.${key}
230
+ schemaName,
231
+ )}): &mut ${value} {
232
+ storage_migrate::borrow_mut_field(&mut self.id, b"${key}")
230
233
  }
231
234
  `;
232
- })
233
- .join('')}
235
+ })
236
+ .join('')}
234
237
 
235
238
 
236
- public fun register(dapps: &mut Dapps, ctx: &mut TxContext): ${capitalizeAndRemoveUnderscores(
237
- schemaName
238
- )} {
239
- let package_id = dapps_system::current_package_id<DappKey>();
240
- assert!(dapps.borrow_metadata().contains_key(package_id), 0);
241
- assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
242
- let schema = type_name::get<${capitalizeAndRemoveUnderscores(
243
- schemaName
244
- )}>().into_string();
245
- assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);
246
- dapps_system::add_schema<${capitalizeAndRemoveUnderscores(
247
- schemaName
248
- )}>(dapps, package_id, ctx);
249
- ${capitalizeAndRemoveUnderscores(schemaName)} {
250
- id: object::new(ctx),
251
- ${Object.entries(schema.structure)
252
- .map(([key, value]) => {
253
- let storage_type = '';
254
- if (value.includes('StorageValue')) {
255
- storage_type = `storage_value::new()`;
256
- } else if (value.includes('StorageMap')) {
257
- storage_type = `storage_map::new()`;
258
- } else if (
259
- value.includes('StorageDoubleMap')
260
- ) {
261
- storage_type = `storage_double_map::new()`;
262
- }
263
- return `${key}: ${storage_type},`;
264
- })
265
- .join(' ')}
266
- }
239
+ public(package) fun create(ctx: &mut TxContext): ${capitalizeAndRemoveUnderscores(
240
+ schemaName,
241
+ )} {
242
+ let mut id = object::new(ctx);
243
+ ${Object.entries(schema.structure)
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('')}
258
+
259
+ ${capitalizeAndRemoveUnderscores(schemaName)} { id }
267
260
  }
268
261
 
262
+ public fun migrate(_${schemaName}: &mut ${capitalizeAndRemoveUnderscores(schemaName)}, _cap: &UpgradeCap) { }
263
+
269
264
 
265
+
270
266
  // ======================================== View Functions ========================================
271
267
  ${Object.entries(schema.structure)
272
268
  .map(([key, value]) => {
273
269
  // @ts-ignore
274
- let all_types = value.match(/<(.+)>/)[1].split(',').map(type => type.trim())
275
- let para_key: string[] = []
276
- let para_value = ""
277
- let borrow_key = ""
278
- 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 = '';
279
275
  if (value.includes('StorageValue')) {
280
- para_key = []
281
- para_value = `${all_types[0]}`
282
- borrow_key = 'try_get()'
276
+ para_key = [];
277
+ para_value = `${all_types[0]}`;
278
+ borrow_key = 'try_get()';
283
279
  } else if (value.includes('StorageMap')) {
284
- para_key = [`key: ${all_types[0]}`]
285
- para_value = `${all_types[1]}`
286
- borrow_key = 'try_get(key)'
280
+ para_key = [`key: ${all_types[0]}`];
281
+ para_value = `${all_types[1]}`;
282
+ borrow_key = 'try_get(key)';
287
283
  extra_code = `public fun get_${key}_keys(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[0]}> {
288
- self.${key}.keys()
284
+ self.borrow_${key}().keys()
289
285
  }
290
286
 
291
287
  public fun get_${key}_values(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[1]}> {
292
- self.${key}.values()
293
- }`
288
+ self.borrow_${key}().values()
289
+ }`;
294
290
  } else if (value.includes('StorageDoubleMap')) {
295
- para_key = [`key1: ${all_types[0]}`, `key2: ${all_types[1]}`]
296
- para_value = `${all_types[2]}`
297
- 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)';
298
294
  extra_code = `public fun get_${key}_keys(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : (vector<${all_types[0]}>, vector<${all_types[1]}>) {
299
- self.${key}.keys()
295
+ self.borrow_${key}().keys()
300
296
  }
301
297
 
302
298
  public fun get_${key}_values(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : vector<${all_types[2]}> {
303
- self.${key}.values()
304
- }`
299
+ self.borrow_${key}().values()
300
+ }`;
305
301
  }
306
302
  return `public fun get_${key}(self: &${capitalizeAndRemoveUnderscores(schemaName)}, ${para_key}) : Option<${para_value}> {
307
- self.${key}.${borrow_key}
303
+ self.borrow_${key}().${borrow_key}
308
304
  }
309
305
  ` + extra_code;
310
306
  })
@@ -316,7 +312,7 @@ export async function generateSchemaStructure(
316
312
  await formatAndWriteMove(
317
313
  schemaMoudle,
318
314
  `${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,
319
- 'formatAndWriteMove'
315
+ 'formatAndWriteMove',
320
316
  );
321
317
  }
322
318
  console.log('āœ… Schema Structure Generation Complete\n');
@@ -0,0 +1,65 @@
1
+ import { DubheConfig } from '../../types';
2
+ import { formatAndWriteMove } from '../formatAndWrite';
3
+
4
+ export async function generateSchemaHub(
5
+ config: DubheConfig,
6
+ srcPrefix: string
7
+ ) {
8
+ console.log('\nšŸ”‘ Starting DappKey Generation...');
9
+ console.log(
10
+ ` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/schema_hub.move`
11
+ );
12
+
13
+ let code = `module ${config.name}::schema_hub {
14
+ use sui::transfer::public_share_object;
15
+ use sui::dynamic_field as df;
16
+
17
+ public struct SchemaHub has key, store {
18
+ id: UID,
19
+ admin: address,
20
+ }
21
+
22
+ public struct SchemaTypeWapper<phantom Schema: key + store> has copy, store, drop {}
23
+
24
+ /// Authorize an schema to access protected features of the SchemaHub.
25
+ public(package) fun authorize_schema<Schema: key + store>(self: &mut SchemaHub) {
26
+ df::add(&mut self.id, SchemaTypeWapper<Schema> {}, true);
27
+ }
28
+
29
+ /// Deauthorize an schema by removing its authorization key.
30
+ public(package) fun deauthorize_schema<Schema: key + store>(self: &mut SchemaHub) {
31
+ df::remove<SchemaTypeWapper<Schema>, bool>(&mut self.id, SchemaTypeWapper<Schema> {});
32
+ }
33
+
34
+ /// Check if an schema is authorized to access protected features of
35
+ /// the SchemaHub.
36
+ public fun is_schema_authorized<Schema: key + store>(self: &SchemaHub): bool {
37
+ df::exists_(&self.id, SchemaTypeWapper<Schema> {})
38
+ }
39
+
40
+ /// Assert that an schema is authorized to access protected features of
41
+ /// the SchemaHub. Aborts with \`EAppNotAuthorized\` if not.
42
+ public fun ensure_schema_authorized<Schema: key + store>(self: &SchemaHub) {
43
+ assert!(self.is_schema_authorized<Schema>(), 0);
44
+ }
45
+
46
+ fun init(ctx: &mut TxContext) {
47
+ public_share_object(SchemaHub {
48
+ id: object::new(ctx),
49
+ admin: ctx.sender(),
50
+ });
51
+ }
52
+
53
+ #[test_only]
54
+ public fun init_schema_hub_for_testing(ctx: &mut TxContext) {
55
+ init(ctx);
56
+ }
57
+ }
58
+ `;
59
+ await formatAndWriteMove(
60
+ code,
61
+ `${srcPrefix}/contracts/${config.name}/sources/codegen/schema_hub.move`,
62
+ 'formatAndWriteMove'
63
+ );
64
+ console.log('āœ… DappKey Generation Complete\n');
65
+ }
@@ -1,6 +1,7 @@
1
1
  import { DubheConfig } from '../../types';
2
2
  import { formatAndWriteMove } from '../formatAndWrite';
3
3
  import { existsSync } from 'fs';
4
+ import { capitalizeAndRemoveUnderscores } from './generateSchema';
4
5
 
5
6
  export async function generateDeployHook(
6
7
  config: DubheConfig,
@@ -19,59 +20,67 @@ export async function generateDeployHook(
19
20
  let code = `module ${config.name}::deploy_hook {
20
21
  use dubhe::dapps_schema::Dapps;
21
22
  use dubhe::dapps_system;
22
- use ${config.name}::dapp_key::DappKey;
23
- use std::ascii;
23
+ use ${config.name}::schema_hub::SchemaHub;
24
+ use std::ascii::string;
24
25
  use sui::clock::Clock;
26
+ use sui::package::UpgradeCap;
25
27
  use sui::transfer::public_share_object;
26
- #[test_only]
27
- use dubhe::dapps_schema;
28
+ ${Object.keys(config.schemas).map(schemaName => {
29
+ return `use ${config.name}::${schemaName}_schema::${capitalizeAndRemoveUnderscores(schemaName)};`}).join('\n')
30
+ }
28
31
  #[test_only]
29
32
  use sui::clock;
30
33
  #[test_only]
31
34
  use sui::test_scenario;
32
35
  #[test_only]
36
+ use sui::package;
37
+ #[test_only]
38
+ use ${config.name}::schema_hub;
39
+ #[test_only]
40
+ use dubhe::dapps_schema;
41
+ #[test_only]
33
42
  use sui::test_scenario::Scenario;
34
43
 
35
- public entry fun run(dapps: &mut Dapps, clock: &Clock, ctx: &mut TxContext) {
44
+ public entry fun run(schema_hub: &mut SchemaHub, dapps: &mut Dapps, cap: &UpgradeCap, clock: &Clock, ctx: &mut TxContext) {
36
45
  // Register the dapp to dubhe.
37
- dapps_system::register<DappKey>(
38
- dapps,
39
- ascii::string(b"${config.name}"),
40
- ascii::string(b"${config.description}"),
41
- clock,
42
- ctx
43
- );
44
- ${Object.keys(config.schemas)
45
- .map(schemaName => {
46
- return `let ${schemaName} = ${config.name}::${schemaName}_schema::register(dapps, ctx);`;
47
- })
48
- .join('\n')}
46
+ dapps_system::register(dapps,cap,string(b"${config.name}"),string(b"${config.description}"),clock,ctx);
47
+ // Create schemas
48
+ ${Object.keys(config.schemas).map(schemaName => {
49
+ return `let ${schemaName} = ${config.name}::${schemaName}_schema::create(ctx);`;
50
+ }).join('\n')}
49
51
  // Logic that needs to be automated once the contract is deployed
50
-
51
-
52
- // Share the dapp object with the public
53
- ${Object.keys(config.schemas)
54
- .map(schemaName => {
55
- return `public_share_object(${schemaName});`;
56
- })
57
- .join('\n')}
52
+ ${`\n`}
53
+ ${`\n`}
54
+
55
+ // Authorize schemas and public share objects
56
+ ${Object.keys(config.schemas).map(schemaName => {
57
+ return `
58
+ schema_hub.authorize_schema<${capitalizeAndRemoveUnderscores(schemaName)}>();
59
+ public_share_object(${schemaName});
60
+ `;
61
+ }).join('\n')}
58
62
  }
59
63
 
60
64
  #[test_only]
61
- public fun deploy_hook_for_testing(): (Scenario, Dapps) {
62
- let mut scenario = test_scenario::begin(@0xA);
63
- {
65
+ public fun deploy_hook_for_testing(): (Scenario, SchemaHub, Dapps) {
66
+ let mut scenario = test_scenario::begin(@0xA);
67
+ {
64
68
  let ctx = test_scenario::ctx(&mut scenario);
65
69
  dapps_schema::init_dapps_for_testing(ctx);
70
+ schema_hub::init_schema_hub_for_testing(ctx);
66
71
  test_scenario::next_tx(&mut scenario,@0xA);
67
72
  };
68
- let mut dapps = test_scenario::take_shared<Dapps>(&scenario);
69
- let ctx = test_scenario::ctx(&mut scenario);
70
- let clock = clock::create_for_testing(ctx);
71
- run(&mut dapps, &clock, ctx);
72
- clock::destroy_for_testing(clock);
73
- test_scenario::next_tx(&mut scenario,@0xA);
74
- (scenario, dapps)
73
+ let mut dapps = test_scenario::take_shared<Dapps>(&scenario);
74
+ let mut schema_hub = test_scenario::take_shared<SchemaHub>(&scenario);
75
+ let ctx = test_scenario::ctx(&mut scenario);
76
+ let clock = clock::create_for_testing(ctx);
77
+ let upgrade_cap = package::test_publish(@0x42.to_id(), ctx);
78
+ run(&mut schema_hub, &mut dapps, &upgrade_cap, &clock, ctx);
79
+
80
+ clock::destroy_for_testing(clock);
81
+ upgrade_cap.make_immutable();
82
+ test_scenario::next_tx(&mut scenario,@0xA);
83
+ (scenario, schema_hub, dapps)
75
84
  }
76
85
  }
77
86
  `;
@@ -84,33 +93,21 @@ export async function generateDeployHook(
84
93
  console.log('āœ… Deploy Hook Generation Complete\n');
85
94
  }
86
95
 
87
- export function generateMigrate(config: DubheConfig, srcPrefix: string) {
96
+ export async function generateMigrate(config: DubheConfig, srcPrefix: string) {
88
97
  if (
89
98
  !existsSync(
90
99
  `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`
91
100
  )
92
101
  ) {
93
102
  let code = `module ${config.name}::migrate {
94
- use dubhe::world::{World, AdminCap};
95
-
96
- /// Not the right admin for this world
97
- const ENotAdmin: u64 = 0;
98
- const EWrongVersion: u64 = 1;
99
- const ENotUpgrade: u64 = 2;
100
- const VERSION: u64 = 1;
103
+ const ON_CHAIN_VERSION: u32 = 0;
101
104
 
102
- public entry fun run(world: &mut World, admin_cap: &AdminCap) {
103
- assert!(world.admin() == object::id(admin_cap), ENotAdmin);
104
- assert!(world.version() < VERSION, ENotUpgrade);
105
- *dubhe::world::mut_version(world, admin_cap) = VERSION;
106
- }
107
-
108
- public fun assert_version(world: &World){
109
- assert!(world.version() == VERSION, EWrongVersion);
105
+ public fun on_chain_version(): u32 {
106
+ ON_CHAIN_VERSION
110
107
  }
111
108
  }
112
109
  `;
113
- formatAndWriteMove(
110
+ await formatAndWriteMove(
114
111
  code,
115
112
  `${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`,
116
113
  'formatAndWriteMove'
@@ -1,30 +1,22 @@
1
1
  import { DubheConfig } from '../../types';
2
2
  import { formatAndWriteMove } from '../formatAndWrite';
3
3
  import { existsSync } from 'fs';
4
+ import fs from 'node:fs/promises';
5
+ import path from 'node:path';
4
6
 
5
7
  export async function generateSystem(config: DubheConfig, srcPrefix: string) {
6
8
  console.log('\nāš™ļø Starting System Generation...');
7
- config.systems.map(async systemName => {
8
- console.log(` ā”œā”€ Generating system: ${systemName}`);
9
+ console.log(` ā”œā”€ Generating systems`);
9
10
  console.log(
10
- ` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`
11
+ ` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/systems`
11
12
  );
12
13
 
13
14
  if (
14
15
  !existsSync(
15
- `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`
16
+ `${srcPrefix}/contracts/${config.name}/sources/systems`
16
17
  )
17
18
  ) {
18
- let code = `module ${config.name}::${systemName}_system {
19
-
20
- }
21
- `;
22
- await formatAndWriteMove(
23
- code,
24
- `${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`,
25
- 'formatAndWriteMove'
26
- );
19
+ await fs.mkdir(`${srcPrefix}/contracts/${config.name}/sources/systems`, { recursive: true })
27
20
  }
28
- });
29
21
  console.log('āœ… System Generation Complete\n');
30
22
  }
@@ -18,7 +18,7 @@ edition = "2024.beta"
18
18
 
19
19
  [dependencies]
20
20
  Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.36.2" }
21
- Dubhe = { git = "https://github.com/0xobelisk/dubhe.git", subdir = "packages/dubhe-framework", rev = "main" }
21
+ Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "release-dubhe-v1.0.0-rc1" }
22
22
 
23
23
  [addresses]
24
24
  sui = "0x2"