@0xobelisk/sui-common 0.5.18 → 0.5.20

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.
@@ -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"
@@ -1,22 +1,24 @@
1
1
  import { SchemaType, DubheConfig } from '../../types';
2
2
  import { rmdirSync, existsSync } from 'fs';
3
3
  import { deleteFolderRecursive } from './common';
4
- import { generateSystem } from './generateSystem';
5
4
  import { generateToml } from './generateToml';
6
5
  import { generateSchemaData, generateSchemaStructure } from './generateSchema';
7
6
  import { generateDeployHook, generateMigrate } from './generateScript';
8
7
  import { generateDappKey } from './generateDappKey';
8
+ import {generateSchemaEvent} from "./generateEvent";
9
+ import { generateSystem } from './generateSystem';
10
+ import { generateSchemaHub } from './generateSchemaHub';
9
11
 
10
12
  function matchFrameworkId(
11
13
  network: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
12
14
  ): string {
13
15
  switch (network) {
14
16
  case 'testnet':
15
- return '0x1736475f476c5dec96f33c03c778843f572239d3a887d795eef66d2836484c28';
17
+ return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
16
18
  case 'localnet':
17
- return '0x1736475f476c5dec96f33c03c778843f572239d3a887d795eef66d2836484c28';
19
+ return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
18
20
  default:
19
- return '0x1736475f476c5dec96f33c03c778843f572239d3a887d795eef66d2836484c28';
21
+ return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
20
22
  }
21
23
  }
22
24
 
@@ -61,9 +63,14 @@ export async function schemaGen(
61
63
  await generateDeployHook(config, path);
62
64
  }
63
65
 
64
- await generateSystem(config, path);
65
66
  await generateSchemaData(config.name, config.schemas, path);
66
- await generateSchemaStructure(config.name, config.schemas, path);
67
+ await generateSchemaStructure(config.name, config.schemas, path, config.migration_enabled);
68
+ await generateSchemaEvent(config.name, config.schemas, path);
67
69
  await generateDappKey(config, path);
70
+ await generateSchemaHub(config, path);
71
+ await generateSystem(config, path);
72
+ if (config.migration_enabled) {
73
+ await generateMigrate(config, path);
74
+ }
68
75
  console.log('✅ Schema Generation Process Complete!\n');
69
76
  }