@0xobelisk/sui-common 0.5.23 → 0.5.25

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.js CHANGED
@@ -1,295 +1,510 @@
1
- import v from"prettier";import X from"prettier-plugin-move-js";async function D(e,t){let o;t&&(o=await v.resolveConfig(t));try{return v.format(e,{plugins:[X],parser:"move-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...o})}catch(r){let n;return r instanceof Error?n=r.message:n=r,console.log(`Error during output formatting: ${n}`),e}}async function T(e){return v.format(e,{parser:"typescript"})}import y from"node:fs/promises";import j from"node:path";import M from"debug";var b=M("dubhe:common"),Y=M("dubhe:common");b.log=console.debug.bind(console);Y.log=console.error.bind(console);var _=b.extend("codegen"),J=b.extend("codegen");_.log=console.debug.bind(console);J.log=console.error.bind(console);async function c(e,t,o){let r=await D(e),n=` // Copyright (c) Obelisk Labs, Inc.
2
- // SPDX-License-Identifier: MIT
1
+ import v from"prettier";import X from"prettier-plugin-move-js";async function M(e,t){let a;t&&(a=await v.resolveConfig(t));try{return v.format(e,{plugins:[X],parser:"move-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...a})}catch(r){let c;return r instanceof Error?c=r.message:c=r,console.log(`Error during output formatting: ${c}`),e}}async function T(e){return v.format(e,{parser:"typescript"})}import S from"node:fs/promises";import R from"node:path";import j from"debug";var $=j("dubhe:common"),Y=j("dubhe:common");$.log=console.debug.bind(console);Y.log=console.error.bind(console);var h=$.extend("codegen"),J=$.extend("codegen");h.log=console.debug.bind(console);J.log=console.error.bind(console);async function p(e,t,a){let r=await M(e),c=` // Copyright (c) Obelisk Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
3
  #[allow(unused_use)]
4
4
 
5
5
  /* Autogenerated file. Do not edit manually. */
6
6
 
7
- `,s=`#[allow(lint(share_owned))]
8
-
9
- `,a=n+r;t.includes(".toml")||t.includes("system")||t.includes("migrate")?a=r:t.includes("deploy_hook")&&(a=s+r),await y.mkdir(j.dirname(t),{recursive:!0}),await y.writeFile(t,a),_(`${o}: ${t}`)}async function we(e,t,o){let r=await T(e);await y.mkdir(j.dirname(t),{recursive:!0}),await y.writeFile(t,r),_(`${o}: ${t}`)}function ke(e){return e.replace(/\\/g,"/")}import{existsSync as A}from"fs";import d from"fs";function w(e){d.existsSync(e)&&(d.readdirSync(e).forEach(t=>{let o=`${e}/${t}`;d.lstatSync(o).isDirectory()?w(o):d.unlinkSync(o)}),d.rmdirSync(e))}function g(e){return Object.entries(e).map(([t,o])=>`${t}`).join(",")}function G(e){return`(${Object.entries(e).map(([t,o])=>`${o}`)})`}function p(e){return Object.entries(e).map(([t,o])=>`${t}: ${o}`)}function W(e){return Object.entries(e).map(([t,o])=>`self.${t}`)}async function R(e,t,o){console.log(`
10
- \u{1F4C4} Starting Move.toml Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/Move.toml`);let r=`[package]
7
+ `,o="#[test_only]",s=c+r,n="#[allow(lint(share_owned), unused_let_mut)]";t.includes(".toml")||t.includes("system")||t.includes("migrate")?s=r:t.includes("init")?s=o+r:t.includes("deploy_hook")&&(s=n+r),await S.mkdir(R.dirname(t),{recursive:!0}),await S.writeFile(t,s),h(`${a}: ${t}`)}async function Me(e,t,a){let r=await T(e);await S.mkdir(R.dirname(t),{recursive:!0}),await S.writeFile(t,r),h(`${a}: ${t}`)}function je(e){return e.replace(/\\/g,"/")}import{existsSync as k}from"fs";import l from"fs";function x(e){l.existsSync(e)&&(l.readdirSync(e).forEach(t=>{let a=`${e}/${t}`;l.lstatSync(a).isDirectory()?x(a):l.unlinkSync(a)}),l.rmdirSync(e))}function g(e){return Object.entries(e).map(([t,a])=>`${t}`).join(",")}function G(e){return`(${Object.entries(e).map(([t,a])=>`${a}`)})`}function u(e){return Object.entries(e).map(([t,a])=>`${t}: ${a}`)}function W(e){return Object.entries(e).map(([t,a])=>`self.${t}`)}async function V(e,t){console.log(`
8
+ \u{1F4C4} Starting Move.toml Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/Move.toml`);let a=`[package]
11
9
  name = "${e.name}"
12
10
  version = "1.0.0"
13
11
  edition = "2024"
14
12
 
15
13
  [dependencies]
16
14
  Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.38.3" }
17
- Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-testnet-v1.0.0" }
15
+ Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-testnet-v1.1.0" }
18
16
 
19
17
  [addresses]
20
18
  sui = "0x2"
21
19
  ${e.name} = "0x0"
22
- `;await c(r,`${t}/contracts/${e.name}/Move.toml`,"formatAndWriteMove"),console.log(`\u2705 Move.toml Generation Complete
23
- `)}function u(e){return e.split("_").map((t,o)=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}function P(e,t){return Object.entries(t).map(([o,r])=>`public(package) fun set_${o}(self: &mut ${e}, ${o}: ${r}) {
24
- self.${o} = ${o};
20
+ `;await p(a,`${t}/contracts/${e.name}/Move.toml`,"formatAndWriteMove"),console.log(`\u2705 Move.toml Generation Complete
21
+ `)}function m(e){return e.split("_").map((t,a)=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}function P(e,t){return Object.entries(t).map(([a,r])=>`public(package) fun set_${a}(self: &mut ${e}, ${a}: ${r}) {
22
+ self.${a} = ${a};
25
23
  }`).join(`
26
- `)}function ee(e,t){return`public(package) fun set(self: &mut ${e}, ${p(t)}) {
27
- ${Object.entries(t).map(([o])=>`self.${o} = ${o};`).join(`
24
+ `)}function ee(e,t){return`public(package) fun set(self: &mut ${e}, ${u(t)}) {
25
+ ${Object.entries(t).map(([a])=>`self.${a} = ${a};`).join(`
28
26
  `)}
29
27
  }`}function te(e,t){return`public fun get(self: &${e}): ${G(t)} {
30
28
  (${W(t)})
31
- }`}function re(e,t){return Object.entries(t).map(([o,r])=>`public fun get_${o}(self: &${e}): ${r} {
32
- self.${o}
29
+ }`}function re(e,t){return Object.entries(t).map(([a,r])=>`public fun get_${a}(self: &${e}): ${r} {
30
+ self.${a}
33
31
  }`).join(`
34
- `)}function l(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function H(e,t,o){console.log(`
35
- \u{1F4E6} Starting Schema Data Generation...`);for(let r in t){let n=t[r];if(n.data){console.log(` \u251C\u2500 Processing schema: ${r}`);for(let s of n.data){console.log(` \u2514\u2500 Generating ${s.name} ${Array.isArray(s.fields)?"(enum)":"(struct)"}`);let a="",m=n.data.filter(i=>Array.isArray(i.fields)).map(i=>i.name);Array.isArray(s.fields)?a=`module ${e}::${r}_${l(s.name)} {
36
- public enum ${s.name} has copy, drop , store {
37
- ${s.fields}
32
+ `)}function d(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function E(e,t,a){console.log(`
33
+ \u{1F4E6} Starting Schema Data Generation...`);for(let r in t){let c=t[r];if(c.data){console.log(` \u251C\u2500 Processing schema: ${r}`);for(let o of c.data){console.log(` \u2514\u2500 Generating ${o.name} ${Array.isArray(o.fields)?"(enum)":"(struct)"}`);let s="",n=c.data.filter(i=>Array.isArray(i.fields)).map(i=>i.name);Array.isArray(o.fields)?s=`module ${e}::${r}_${d(o.name)} {
34
+ public enum ${o.name} has copy, drop , store {
35
+ ${o.fields}
38
36
  }
39
37
 
40
- ${s.fields.map(i=>`public fun new_${l(i)}(): ${s.name} {
41
- ${s.name}::${i}
42
- }`).join("")}`:a=`module ${e}::${r}_${l(s.name)} {
38
+ ${o.fields.map(i=>`public fun new_${d(i)}(): ${o.name} {
39
+ ${o.name}::${i}
40
+ }`).join("")}`:s=`module ${e}::${r}_${d(o.name)} {
43
41
  use std::ascii::String;
44
- ${m.map(i=>`use ${e}::${r}_${l(i)}::${i};`).join(`
42
+ ${n.map(i=>`use ${e}::${r}_${d(i)}::${i};`).join(`
45
43
  `)}
46
44
 
47
- public struct ${s.name} has copy, drop , store {
48
- ${p(s.fields)}
45
+ public struct ${o.name} has copy, drop , store {
46
+ ${u(o.fields)}
49
47
  }
50
48
 
51
- public fun new(${p(s.fields)}): ${s.name} {
52
- ${s.name} {
53
- ${g(s.fields)}
49
+ public fun new(${u(o.fields)}): ${o.name} {
50
+ ${o.name} {
51
+ ${g(o.fields)}
54
52
  }
55
53
  }
56
54
 
57
- ${te(s.name,s.fields)}
58
- ${re(s.name,s.fields)}
59
- ${P(s.name,s.fields)}
60
- ${ee(s.name,s.fields)}
61
- }`,await c(a,`${o}/contracts/${e}/sources/codegen/schemas/${r}_${l(s.name)}.move`,"formatAndWriteMove")}}}console.log(`\u2705 Schema Data Generation Complete
62
- `)}function oe(e,t,o){return o.data?o.data.map(r=>`use ${e}::${t}_${l(r.name)}::${r.name};`).join(`
63
- `):""}async function E(e,t,o){console.log(`
64
- \u{1F528} Starting Schema Structure Generation...`);for(let r in t){console.log(` \u251C\u2500 Generating schema: ${r}`),console.log(` \u251C\u2500 Output path: ${o}/contracts/${e}/sources/codegen/schemas/${r}.move`),console.log(` \u2514\u2500 Structure fields: ${Object.keys(t[r].structure).length}`);let n=t[r],s=`module ${e}::${r}_schema {
55
+ ${te(o.name,o.fields)}
56
+ ${re(o.name,o.fields)}
57
+ ${P(o.name,o.fields)}
58
+ ${ee(o.name,o.fields)}
59
+ }`,await p(s,`${a}/contracts/${e}/sources/codegen/schemas/${r}_${d(o.name)}.move`,"formatAndWriteMove")}}}console.log(`\u2705 Schema Data Generation Complete
60
+ `)}function ae(e,t,a){return a.data?a.data.map(r=>`use ${e}::${t}_${d(r.name)}::${r.name};`).join(`
61
+ `):""}async function O(e,t,a){console.log(`
62
+ \u{1F528} Starting Schema Structure Generation...`);for(let r in t){console.log(` \u251C\u2500 Generating schema: ${r}`),console.log(` \u251C\u2500 Output path: ${a}/contracts/${e}/sources/codegen/schemas/${r}.move`),console.log(` \u2514\u2500 Structure fields: ${Object.keys(t[r].structure).length}`);let c=t[r],o=`module ${e}::${r}_schema {
65
63
  use std::ascii::String;
66
64
  use std::ascii::string;
67
65
  use sui::package::UpgradeCap;
68
- use std::type_name;
69
- use dubhe::dapps_system;
70
- use dubhe::storage_migrate;
71
- use dubhe::dapps_schema::Dapps;
66
+ use std::type_name;
67
+ use dubhe::storage_migration;
72
68
  use dubhe::storage_value::{Self, StorageValue};
73
69
  use dubhe::storage_map::{Self, StorageMap};
74
70
  use dubhe::storage_double_map::{Self, StorageDoubleMap};
75
- use ${e}::dapp_key::DappKey;
76
71
  use sui::dynamic_field as df;
77
- ${oe(e,r,n)}
72
+ use sui::sui::SUI;
73
+ use sui::coin::Coin;
74
+ use sui::balance::Balance;
75
+ ${ae(e,r,c)}
78
76
 
79
- public struct ${u(r)} has key, store {
77
+ public struct ${m(r)} has key, store {
80
78
  id: UID
81
79
  }
82
80
 
83
- ${Object.entries(n.structure).map(([a,m])=>`public fun borrow_${a}(self: &${u(r)}) : &${m} {
84
- storage_migrate::borrow_field(&self.id, b"${a}")
81
+ ${Object.entries(c.structure).map(([s,n])=>`public fun borrow_${s}(self: &${m(r)}) : &${n} {
82
+ storage_migration::borrow_field(&self.id, b"${s}")
85
83
  }
86
84
 
87
- public(package) fun borrow_mut_${a}(self: &mut ${u(r)}): &mut ${m} {
88
- storage_migrate::borrow_mut_field(&mut self.id, b"${a}")
85
+ public(package) fun borrow_mut_${s}(self: &mut ${m(r)}): &mut ${n} {
86
+ storage_migration::borrow_mut_field(&mut self.id, b"${s}")
89
87
  }
90
88
  `).join("")}
91
89
 
92
90
 
93
- public(package) fun create(ctx: &mut TxContext): ${u(r)} {
91
+ public(package) fun create(ctx: &mut TxContext): ${m(r)} {
94
92
  let mut id = object::new(ctx);
95
- ${Object.entries(n.structure).map(([a,m])=>{let i="";return m.includes("StorageValue")?i="storage_value::new()":m.includes("StorageMap")?i="storage_map::new()":m.includes("StorageDoubleMap")&&(i="storage_double_map::new()"),`storage_migrate::add_field<${m}>(&mut id, b"${a}", ${i});`}).join("")}
93
+ ${Object.entries(c.structure).map(([s,n])=>{let i="";return n.includes("StorageValue")?i="storage_value::new()":n.includes("StorageMap")?i="storage_map::new()":n.includes("StorageDoubleMap")&&(i="storage_double_map::new()"),`storage_migration::add_field<${n}>(&mut id, b"${s}", ${i});`}).join("")}
96
94
 
97
- ${u(r)} { id }
95
+ ${m(r)} { id }
98
96
  }
99
97
 
100
- public fun migrate(_${r}: &mut ${u(r)}, _cap: &UpgradeCap) { }
98
+ public fun migrate(_${r}: &mut ${m(r)}, _cap: &UpgradeCap) { }
101
99
 
102
100
 
103
101
 
104
102
  // ======================================== View Functions ========================================
105
- ${Object.entries(n.structure).map(([a,m])=>{let i=m.match(/<(.+)>/)[1].split(",").map(q=>q.trim()),f=[],$="",h="",x="";return m.includes("StorageValue")?(f=[],$=`${i[0]}`,h="try_get()"):m.includes("StorageMap")?(f=[`key: ${i[0]}`],$=`${i[1]}`,h="try_get(key)",x=`public fun get_${a}_keys(self: &${u(r)}) : vector<${i[0]}> {
106
- self.borrow_${a}().keys()
103
+ ${Object.entries(c.structure).map(([s,n])=>{let i=n.match(/<(.+)>/)[1].split(",").map(N=>N.trim()),f=[],_="",b="",y="";return n.includes("StorageValue")?(f=[],_=`${i[0]}`,b="borrow()"):n.includes("StorageMap")?(f=[`key: ${i[0]}`],_=`${i[1]}`,b="borrow(key)",!n.includes("Balance")&&!n.includes("Coin")&&(y=`public fun get_${s}_keys(self: &${m(r)}) : vector<${i[0]}> {
104
+ self.borrow_${s}().keys()
107
105
  }
108
106
 
109
- public fun get_${a}_values(self: &${u(r)}) : vector<${i[1]}> {
110
- self.borrow_${a}().values()
111
- }`):m.includes("StorageDoubleMap")&&(f=[`key1: ${i[0]}`,`key2: ${i[1]}`],$=`${i[2]}`,h="try_get(key1, key2)",x=`public fun get_${a}_keys(self: &${u(r)}) : (vector<${i[0]}>, vector<${i[1]}>) {
112
- self.borrow_${a}().keys()
107
+ public fun get_${s}_values(self: &${m(r)}) : vector<${i[1]}> {
108
+ self.borrow_${s}().values()
109
+ }`)):n.includes("StorageDoubleMap")&&(f=[`key1: ${i[0]}`,`key2: ${i[1]}`],_=`${i[2]}`,b="borrow(key1, key2)",!n.includes("Balance")&&!n.includes("Coin")&&(y=`public fun get_${s}_keys(self: &${m(r)}) : (vector<${i[0]}>, vector<${i[1]}>) {
110
+ self.borrow_${s}().keys()
113
111
  }
114
112
 
115
- public fun get_${a}_values(self: &${u(r)}) : vector<${i[2]}> {
116
- self.borrow_${a}().values()
117
- }`),`public fun get_${a}(self: &${u(r)}, ${f}) : Option<${$}> {
118
- self.borrow_${a}().${h}
113
+ public fun get_${s}_values(self: &${m(r)}) : vector<${i[2]}> {
114
+ self.borrow_${s}().values()
115
+ }`)),`public fun get_${s}(self: &${m(r)}, ${f}) : &${_} {
116
+ self.borrow_${s}().${b}
119
117
  }
120
- `+x}).join("")}
118
+ `+y}).join("")}
121
119
  // =========================================================================================================
122
120
 
123
121
 
124
- }`;await c(s,`${o}/contracts/${e}/sources/codegen/schemas/${r}.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Structure Generation Complete
125
- `)}import{existsSync as O}from"fs";async function U(e,t){if(console.log(`
126
- \u{1F4DD} Starting Deploy Hook Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`),!O(`${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`)){let o=`module ${e.name}::deploy_hook {
127
- use dubhe::dapps_schema::Dapps;
128
- use dubhe::dapps_system;
129
- use ${e.name}::schema_hub::SchemaHub;
130
- use std::ascii::string;
131
- use sui::clock::Clock;
132
- use sui::sui::SUI;
133
- use sui::coin::Coin;
134
- use sui::package::UpgradeCap;
135
- use sui::transfer::public_share_object;
136
- ${Object.keys(e.schemas).map(r=>`use ${e.name}::${r}_schema::${u(r)};`).join(`
122
+ }`;await p(o,`${a}/contracts/${e}/sources/codegen/schemas/${r}.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Structure Generation Complete
123
+ `)}import{existsSync as U}from"fs";import{readFileSync as oe}from"fs";function se(e){let t=oe(e,"utf-8"),a=/\/\/ Logic that needs to be automated once the contract is deployed\s*\{([\s\S]*?)\}\s*;\s*\/\/ Authorize schemas and public share objects/,r=t.match(a);if(r)return r[1].trim();throw new Error("Logic and authorization block not found in the file.")}async function L(e,t){console.log(`
124
+ \u{1F4DD} Starting Deploy Hook Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`);let a=Object.keys(e.schemas).map(s=>`_${s}: &mut ${m(s)}`).join(","),r=Object.keys(e.schemas).map(s=>`use ${e.name}::${s}_schema::${m(s)};`).join(`
125
+ `),c=`${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`,o="";if(!U(c))o=`module ${e.name}::deploy_hook {
126
+ use std::ascii::string;
127
+ use sui::clock::Clock;
128
+ use ${e.name}::dapp_system;
129
+ ${r}
130
+ public entry fun run(clock: &Clock, ctx: &mut TxContext) {
131
+ // Create a dapp.
132
+ let mut dapp = dapp_system::create(string(b"${e.name}"),string(b"${e.description}"), clock , ctx);
133
+
134
+ // Create schemas
135
+ ${Object.keys(e.schemas).map(s=>`let mut ${s} = ${e.name}::${s}_schema::create(ctx);`).join(`
137
136
  `)}
138
- #[test_only]
139
- use sui::clock;
140
- #[test_only]
141
- use sui::coin;
142
- #[test_only]
143
- use sui::test_scenario;
144
- #[test_only]
145
- use sui::package;
146
- #[test_only]
147
- use ${e.name}::schema_hub;
148
- #[test_only]
149
- use dubhe::dapps_schema;
150
- #[test_only]
151
- use sui::test_scenario::Scenario;
152
-
153
- public entry fun run(schema_hub: &mut SchemaHub, dapps: &mut Dapps, cap: &UpgradeCap, clock: &Clock, coin: Coin<SUI>, ctx: &mut TxContext) {
154
- // Register the dapp to dubhe.
155
- dapps_system::register(dapps,cap,string(b"${e.name}"),string(b"${e.description}"),clock,coin,ctx);
156
- // Create schemas
157
- ${Object.keys(e.schemas).map(r=>`let ${r} = ${e.name}::${r}_schema::create(ctx);`).join(`
137
+ // Logic that needs to be automated once the contract is deployed
138
+ {
139
+ };
140
+ // Authorize schemas and public share objects
141
+ ${Object.keys(e.schemas).map(s=>`
142
+ dapp.add_schema<${m(s)}>(${s}, ctx);
143
+ `).join(`
158
144
  `)}
159
- // Logic that needs to be automated once the contract is deployed
160
-
161
-
162
-
163
-
164
-
165
- // Authorize schemas and public share objects
166
- ${Object.keys(e.schemas).map(r=>`
167
- schema_hub.authorize_schema<${u(r)}>();
168
- public_share_object(${r});
169
- `).join(`
145
+ sui::transfer::public_share_object(dapp);
146
+ }
147
+ }`;else{let s=se(c);o=`module ${e.name}::deploy_hook {
148
+ use std::ascii::string;
149
+ use sui::clock::Clock;
150
+ use ${e.name}::dapp_system;
151
+ ${r}
152
+ public entry fun run(clock: &Clock, ctx: &mut TxContext) {
153
+ // Create a dapp.
154
+ let mut dapp = dapp_system::create(string(b"${e.name}"),string(b"${e.description}"), clock , ctx);
155
+
156
+ // Create schemas
157
+ ${Object.keys(e.schemas).map(n=>`let mut ${n} = ${e.name}::${n}_schema::create(ctx);`).join(`
170
158
  `)}
171
- }
172
-
173
- #[test_only]
174
- public fun deploy_hook_for_testing(): (Scenario, SchemaHub, Dapps) {
175
- let mut scenario = test_scenario::begin(@0xA);
176
- {
177
- let ctx = test_scenario::ctx(&mut scenario);
178
- dapps_schema::init_dapps_for_testing(ctx);
179
- schema_hub::init_schema_hub_for_testing(ctx);
180
- test_scenario::next_tx(&mut scenario,@0xA);
181
- };
182
- let mut dapps = test_scenario::take_shared<Dapps>(&scenario);
183
- let mut schema_hub = test_scenario::take_shared<SchemaHub>(&scenario);
184
- let ctx = test_scenario::ctx(&mut scenario);
185
- let clock = clock::create_for_testing(ctx);
186
- let upgrade_cap = package::test_publish(@0x42.to_id(), ctx);
187
- let coin = coin::mint_for_testing<SUI>(1_000_000_000, ctx);
188
- run(&mut schema_hub, &mut dapps, &upgrade_cap, &clock, coin, ctx);
189
-
190
- clock::destroy_for_testing(clock);
191
- upgrade_cap.make_immutable();
192
- test_scenario::next_tx(&mut scenario,@0xA);
193
- (scenario, schema_hub, dapps)
194
- }
195
- }
196
- `;await c(o,`${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`,"formatAndWriteMove")}console.log(`\u2705 Deploy Hook Generation Complete
197
- `)}async function z(e,t){if(!O(`${t}/contracts/${e.name}/sources/scripts/migrate.move`)){let o=`module ${e.name}::migrate {
198
- const ON_CHAIN_VERSION: u32 = 0;
159
+ // Logic that needs to be automated once the contract is deployed
160
+
161
+ {
162
+ ${s}
163
+ };
164
+
165
+ // Authorize schemas and public share objects
166
+ ${Object.keys(e.schemas).map(n=>`
167
+ dapp.add_schema<${m(n)}>(${n}, ctx);
168
+ `).join(`
169
+ `)}
170
+ sui::transfer::public_share_object(dapp);
171
+ }
172
+ }`}await p(o,c,"formatAndWriteMove"),console.log(`\u2705 Deploy Hook Generation Complete
173
+ `)}async function F(e,t){if(!U(`${t}/contracts/${e.name}/sources/scripts/migrate.move`)){let a=`module ${e.name}::migrate {
174
+ const ON_CHAIN_VERSION: u32 = 1;
199
175
 
200
176
  public fun on_chain_version(): u32 {
201
177
  ON_CHAIN_VERSION
202
178
  }
203
179
  }
204
- `;await c(o,`${t}/contracts/${e.name}/sources/scripts/migrate.move`,"formatAndWriteMove")}}async function F(e,t){console.log(`
205
- \u{1F511} Starting DappKey Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/codegen/dapp_key.move`);let o=`module ${e.name}::dapp_key {
206
- /// Authorization token for the app.
207
- public struct DappKey has drop {}
208
-
209
- public(package) fun new(): DappKey {
210
- DappKey { }
211
- }
212
- }
213
- `;await c(o,`${t}/contracts/${e.name}/sources/codegen/dapp_key.move`,"formatAndWriteMove"),console.log(`\u2705 DappKey Generation Complete
214
- `)}function I(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function L(e,t,o){console.log(`
215
- \u{1F4E6} Starting Schema Event Generation...`);for(let r in t){let n=t[r];if(n.events){console.log(` \u251C\u2500 Processing schema: ${r}`);for(let s of n.events){console.log(` \u2514\u2500 Generating ${s.name} ${Array.isArray(s.fields)?"(enum)":"(struct)"}`);let a=`module ${e}::${r}_event_${I(s.name)} {
180
+ `;await p(a,`${t}/contracts/${e.name}/sources/scripts/migrate.move`,"formatAndWriteMove")}}function I(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function z(e,t,a){console.log(`
181
+ \u{1F4E6} Starting Schema Event Generation...`);for(let r in t){let c=t[r];if(c.events){console.log(` \u251C\u2500 Processing schema: ${r}`);for(let o of c.events){console.log(` \u2514\u2500 Generating ${o.name} ${Array.isArray(o.fields)?"(enum)":"(struct)"}`);let s=`module ${e}::${r}_event_${I(o.name)} {
216
182
  use sui::event;
217
183
  use std::ascii::String;
218
- public struct ${s.name}Event has copy, drop {
219
- ${p(s.fields)}
184
+ public struct ${o.name}Event has copy, drop {
185
+ ${u(o.fields)}
220
186
  }
221
187
 
222
- public fun new(${p(s.fields)}): ${s.name}Event {
223
- ${s.name}Event {
224
- ${g(s.fields)}
188
+ public fun new(${u(o.fields)}): ${o.name}Event {
189
+ ${o.name}Event {
190
+ ${g(o.fields)}
225
191
  }
226
192
  }
227
193
 
228
- public fun emit(${p(s.fields)}) {
229
- event::emit(${s.name}Event {
230
- ${g(s.fields)}
194
+ public fun emit(${u(o.fields)}) {
195
+ event::emit(${o.name}Event {
196
+ ${g(o.fields)}
231
197
  });
232
- }`;await c(a,`${o}/contracts/${e}/sources/codegen/events/${r}_event_${I(s.name)}.move`,"formatAndWriteMove")}}}console.log(`\u2705 Schema Event Generation Complete
233
- `)}import{existsSync as se}from"fs";import ne from"node:fs/promises";async function K(e,t){console.log(`
234
- \u2699\uFE0F Starting System Generation...`),console.log(" \u251C\u2500 Generating systems"),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/systems`),se(`${t}/contracts/${e.name}/sources/systems`)||await ne.mkdir(`${t}/contracts/${e.name}/sources/systems`,{recursive:!0}),console.log(`\u2705 System Generation Complete
235
- `)}async function B(e,t){console.log(`
236
- \u{1F511} Starting DappKey Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/codegen/schema_hub.move`);let o=`module ${e.name}::schema_hub {
198
+ }`;await p(s,`${a}/contracts/${e}/sources/codegen/events/${r}_event_${I(o.name)}.move`,"formatAndWriteMove")}}}console.log(`\u2705 Schema Event Generation Complete
199
+ `)}import{existsSync as ne}from"fs";import ie from"node:fs/promises";async function B(e,t){console.log(`
200
+ \u2699\uFE0F Starting System Generation...`),console.log(" \u251C\u2500 Generating systems"),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/systems`),ne(`${t}/contracts/${e.name}/sources/systems`)||await ie.mkdir(`${t}/contracts/${e.name}/sources/systems`,{recursive:!0}),console.log(`\u2705 System Generation Complete
201
+ `)}function H(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function K(e,t,a){console.log(`
202
+ \u{1F4E6} Starting Schema Error Generation...`);for(let r in t){let c=t[r];if(c.errors){console.log(` \u251C\u2500 Processing schema: ${r}`);for(let o of c.errors){console.log(` \u2514\u2500 Generating ${o.name} message: ${o.message}`);let s=`module ${e}::${r}_error_${H(o.name)} {
203
+ #[error]
204
+ const ${o.name}: vector<u8> = b"${o.message}";
205
+ /// Get the error message.
206
+ public fun message(): vector<u8> { ${o.name} }
207
+ /// Abort execution with the given error code.
208
+ public fun emit() { abort ${o.name} }
209
+ /// Require that the given condition is true, otherwise abort with the given error code.
210
+ public fun require(condition: bool) { if (!condition) { emit() } }`;await p(s,`${a}/contracts/${e}/sources/codegen/errors/${r}_error_${H(o.name)}.move`,"formatAndWriteMove")}}}console.log(`\u2705 Schema Error Generation Complete
211
+ `)}import{existsSync as D}from"fs";async function Q(e,t){await ce(e,t),await pe(e,t),await me(e,t)}async function ce(e,t){let a=`${t}/contracts/${e.name}/sources/codegen/schemas/default/dapp/metadata.move`;if(!D(a)){let r=`module ${e.name}::dapp_metadata {
212
+ use std::ascii::String;
213
+
214
+ public struct DappMetadata has drop, copy, store {
215
+ name: String,
216
+ description: String,
217
+ icon_url: String,
218
+ website_url: String,
219
+ created_at: u64,
220
+ partners: vector<String>,
221
+ }
222
+
223
+ public fun new(
224
+ name: String,
225
+ description: String,
226
+ icon_url: String,
227
+ website_url: String,
228
+ created_at: u64,
229
+ partners: vector<String>,
230
+ ): DappMetadata {
231
+ DappMetadata {
232
+ name,
233
+ description,
234
+ icon_url,
235
+ website_url,
236
+ created_at,
237
+ partners,
238
+ }
239
+ }
240
+
241
+ public fun set(
242
+ self: &mut DappMetadata,
243
+ name: String,
244
+ description: String,
245
+ icon_url: String,
246
+ website_url: String,
247
+ created_at: u64,
248
+ partners: vector<String>,
249
+ ) {
250
+ self.name = name;
251
+ self.description = description;
252
+ self.icon_url = icon_url;
253
+ self.website_url = website_url;
254
+ self.created_at = created_at;
255
+ self.partners = partners;
256
+ }
257
+
258
+ public fun set_name(self: &mut DappMetadata, name: String) {
259
+ self.name = name;
260
+ }
261
+
262
+ public fun set_description(self: &mut DappMetadata, description: String) {
263
+ self.description = description;
264
+ }
265
+
266
+ public fun set_icon_url(self: &mut DappMetadata, icon_url: String) {
267
+ self.icon_url = icon_url;
268
+ }
269
+
270
+ public fun set_website_url(self: &mut DappMetadata, website_url: String) {
271
+ self.website_url = website_url;
272
+ }
273
+
274
+ public fun set_created_at(self: &mut DappMetadata, created_at: u64) {
275
+ self.created_at = created_at;
276
+ }
277
+
278
+ public fun set_partners(self: &mut DappMetadata, partners: vector<String>) {
279
+ self.partners = partners;
280
+ }
281
+
282
+ public fun get_name(self: DappMetadata): String {
283
+ self.name
284
+ }
285
+
286
+ public fun get_description(self: DappMetadata): String {
287
+ self.description
288
+ }
289
+
290
+ public fun get_icon_url(self: DappMetadata): String {
291
+ self.icon_url
292
+ }
293
+
294
+ public fun get_website_url(self: DappMetadata): String {
295
+ self.website_url
296
+ }
297
+
298
+ public fun get_created_at(self: DappMetadata): u64 {
299
+ self.created_at
300
+ }
301
+
302
+ public fun get_partners(self: DappMetadata): vector<String> {
303
+ self.partners
304
+ }
305
+
306
+ }
307
+ `;await p(r,a,"formatAndWriteMove")}}async function pe(e,t){let a=`${t}/contracts/${e.name}/sources/codegen/schemas/default/dapp/schema.move`;if(!D(a)){let r=`module ${e.name}::dapp_schema {
308
+ use ${e.name}::dapp_metadata::DappMetadata;
309
+ use dubhe::storage_value;
310
+ use dubhe::storage_value::StorageValue;
311
+ use dubhe::storage_migration;
237
312
  use sui::transfer::public_share_object;
238
- use sui::dynamic_field as df;
313
+ use dubhe::type_info;
239
314
 
240
- public struct SchemaHub has key, store {
241
- id: UID,
242
- admin: address,
315
+ public struct Dapp has key, store { id: UID }
316
+
317
+ public fun borrow_admin(self: &Dapp): &StorageValue<address> {
318
+ storage_migration::borrow_field(&self.id, b"admin")
243
319
  }
244
-
245
- public struct SchemaTypeWapper<phantom Schema: key + store> has copy, store, drop {}
246
320
 
247
- /// Authorize an schema to access protected features of the SchemaHub.
248
- public(package) fun authorize_schema<Schema: key + store>(self: &mut SchemaHub) {
249
- df::add(&mut self.id, SchemaTypeWapper<Schema> {}, true);
321
+ public(package) fun borrow_mut_admin(self: &mut Dapp): &mut StorageValue<address> {
322
+ storage_migration::borrow_mut_field(&mut self.id, b"admin")
250
323
  }
251
324
 
252
- /// Deauthorize an schema by removing its authorization key.
253
- public(package) fun deauthorize_schema<Schema: key + store>(self: &mut SchemaHub) {
254
- df::remove<SchemaTypeWapper<Schema>, bool>(&mut self.id, SchemaTypeWapper<Schema> {});
325
+ public fun borrow_package_id(self: &Dapp): &StorageValue<address> {
326
+ storage_migration::borrow_field(&self.id, b"package_id")
255
327
  }
256
328
 
257
- /// Check if an schema is authorized to access protected features of
258
- /// the SchemaHub.
259
- public fun is_schema_authorized<Schema: key + store>(self: &SchemaHub): bool {
260
- df::exists_(&self.id, SchemaTypeWapper<Schema> {})
329
+ public(package) fun borrow_mut_package_id(self: &mut Dapp): &mut StorageValue<address> {
330
+ storage_migration::borrow_mut_field(&mut self.id, b"package_id")
261
331
  }
262
332
 
263
- /// Assert that an schema is authorized to access protected features of
264
- /// the SchemaHub. Aborts with \`EAppNotAuthorized\` if not.
265
- public fun ensure_schema_authorized<Schema: key + store>(self: &SchemaHub) {
266
- assert!(self.is_schema_authorized<Schema>(), 0);
333
+ public fun borrow_version(self: &Dapp): &StorageValue<u32> {
334
+ storage_migration::borrow_field(&self.id, b"version")
267
335
  }
268
336
 
269
- fun init(ctx: &mut TxContext) {
270
- public_share_object(SchemaHub {
271
- id: object::new(ctx),
272
- admin: ctx.sender(),
337
+ public(package) fun borrow_mut_version(self: &mut Dapp): &mut StorageValue<u32> {
338
+ storage_migration::borrow_mut_field(&mut self.id, b"version")
339
+ }
340
+
341
+ public fun borrow_metadata(self: &Dapp): &StorageValue<DappMetadata> {
342
+ storage_migration::borrow_field(&self.id, b"metadata")
343
+ }
344
+
345
+ public(package) fun borrow_mut_metadata(self: &mut Dapp): &mut StorageValue<DappMetadata> {
346
+ storage_migration::borrow_mut_field(&mut self.id, b"metadata")
347
+ }
348
+
349
+ public fun borrow_schemas(self: &Dapp): &StorageValue<vector<address>> {
350
+ storage_migration::borrow_field(&self.id, b"schemas")
351
+ }
352
+
353
+ public(package) fun borrow_mut_schemas(self: &mut Dapp): &mut StorageValue<vector<address>> {
354
+ storage_migration::borrow_mut_field(&mut self.id, b"schemas")
355
+ }
356
+
357
+ public fun borrow_safe_mode(self: &Dapp): &StorageValue<bool> {
358
+ storage_migration::borrow_field(&self.id, b"safe_mode")
359
+ }
360
+
361
+ public(package) fun borrow_mut_safe_mode(self: &mut Dapp): &mut StorageValue<bool> {
362
+ storage_migration::borrow_mut_field(&mut self.id, b"safe_mode")
363
+ }
364
+
365
+ public(package) fun create(ctx: &mut TxContext): Dapp {
366
+ let mut id = object::new(ctx);
367
+ storage_migration::add_field<StorageValue<address>>(&mut id, b"admin", storage_value::new());
368
+ storage_migration::add_field<StorageValue<address>>(&mut id, b"package_id", storage_value::new());
369
+ storage_migration::add_field<StorageValue<u32>>(&mut id, b"version", storage_value::new());
370
+ storage_migration::add_field<StorageValue<DappMetadata>>(&mut id, b"metadata", storage_value::new());
371
+ storage_migration::add_field<StorageValue<vector<address>>>(&mut id, b"schemas", storage_value::new());
372
+ storage_migration::add_field<StorageValue<bool>>(&mut id, b"safe_mode", storage_value::new());
373
+ Dapp { id }
374
+ }
375
+
376
+ public(package) fun upgrade<DappKey: drop>(dapp: &mut Dapp, ctx: &TxContext) {
377
+ assert!(dapp.borrow_metadata().contains(), 0);
378
+ assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
379
+
380
+ let new_package_id = type_info::current_package_id<DappKey>();
381
+ dapp.borrow_mut_package_id().set(new_package_id);
382
+ dapp.borrow_mut_version().mutate!(|version| {
383
+ *version = *version + 1;
273
384
  });
274
385
  }
275
386
 
387
+ public(package) fun add_schema<Schema: key + store>(dapp: &mut Dapp, schema: Schema, ctx: &TxContext) {
388
+ assert!(dapp.borrow_metadata().contains(), 0);
389
+ assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
390
+
391
+ let schema_id = object::id_address(&schema);
392
+ dapp.borrow_mut_schemas().borrow_mut().push_back(schema_id);
393
+ public_share_object(schema);
394
+ }
395
+
276
396
  #[test_only]
277
- public fun init_schema_hub_for_testing(ctx: &mut TxContext) {
278
- init(ctx);
397
+ public fun create_dapp_for_testing(ctx: &mut TxContext): Dapp {
398
+ create(ctx)
399
+ }
400
+
401
+ #[test_only]
402
+ public fun distroy_dapp_for_testing(dapp: Dapp) {
403
+ let Dapp { id } = dapp;
404
+ id.delete();
279
405
  }
280
406
  }
281
- `;await c(o,`${t}/contracts/${e.name}/sources/codegen/schema_hub.move`,"formatAndWriteMove"),console.log(`\u2705 DappKey Generation Complete
282
- `)}function V(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function N(e,t,o){console.log(`
283
- \u{1F4E6} Starting Schema Error Generation...`);for(let r in t){let n=t[r];if(n.errors){console.log(` \u251C\u2500 Processing schema: ${r}`);for(let s of n.errors){console.log(` \u2514\u2500 Generating ${s.name} code: ${s.code}`);let a=`module ${e}::${r}_error_${V(s.name)} {
284
- const ${s.name}: u64 = ${s.code};
285
- /// Get the error code.
286
- public fun code(): u64 { ${s.name} }
287
- /// Abort execution with the given error code.
288
- public fun emit() { abort ${s.name} }
289
- /// Require that the given condition is true, otherwise abort with the given error code.
290
- public fun require(condition: bool) { if (!condition) { emit() } }`;await c(a,`${o}/contracts/${e}/sources/codegen/errors/${r}_error_${V(s.name)}.move`,"formatAndWriteMove")}}}console.log(`\u2705 Schema Error Generation Complete
291
- `)}function Q(e){switch(e){case"testnet":return"0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6";case"localnet":return"0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6";default:return"0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6"}}async function ut(e,t,o,r){console.log(`
292
- \u{1F680} Starting Schema Generation Process...`),console.log("\u{1F4CB} Project Configuration:"),console.log(` \u251C\u2500 Name: ${e.name}`),console.log(` \u251C\u2500 Description: ${e.description||"No description provided"}`),console.log(` \u251C\u2500 Network: ${o||"testnet"}`),console.log(` \u2514\u2500 Framework ID: ${r||Q(o??"testnet")}
293
- `);let n=t??process.cwd();r=r||Q(o??"testnet"),A(`${n}/contracts/${e.name}`)&&w(`${n}/contracts/${e.name}/sources/codegen`),A(`${n}/contracts/${e.name}/Move.toml`)||await R(e,n,r),A(`${n}/contracts/${e.name}/sources/script/deploy_hook.move`)||await U(e,n),await H(e.name,e.schemas,n),await E(e.name,e.schemas,n),await L(e.name,e.schemas,n),await N(e.name,e.schemas,n),await F(e,n),await B(e,n),await K(e,n),await z(e,n),console.log(`\u2705 Schema Generation Process Complete!
294
- `)}import{findUp as ae}from"find-up";import k from"path";import ie from"esbuild";var S=class extends Error{name="NotInsideProjectError";message="You are not inside a Dubhe project"};import{rmSync as ce}from"fs";import{pathToFileURL as me}from"url";import ue from"os";var pe=["dubhe.config.js","dubhe.config.mjs","dubhe.config.ts","dubhe.config.mts"],C="dubhe.config.example.mjs";async function yt(e){e=await Z(e);try{return await ie.build({entryPoints:[e],format:"esm",outfile:C,platform:"node",bundle:!0,packages:"external"}),e=await Z(C,!0),(await import(e+`?update=${Date.now()}`)).dubheConfig}finally{ce(C,{force:!0})}}async function Z(e,t){return e===void 0?e=await le():k.isAbsolute(e)||(e=k.join(process.cwd(),e),e=k.normalize(e)),t&&ue.platform()==="win32"?me(e).href:e}async function le(){let e=await ae(pe);if(e===void 0)throw new S;return e}export{c as formatAndWriteMove,we as formatAndWriteTypescript,D as formatMove,T as formatTypescript,yt as loadConfig,ke as posixPath,Z as resolveConfigPath,ut as schemaGen};
407
+ `;await p(r,a,"formatAndWriteMove")}}async function me(e,t){let a=`${t}/contracts/${e.name}/sources/codegen/schemas/default/dapp/system.move`;if(!D(a)){let r=`module ${e.name}::dapp_system {
408
+ use std::ascii::String;
409
+ use std::ascii;
410
+ use dubhe::type_info;
411
+ use sui::clock::Clock;
412
+ use ${e.name}::dapp_schema;
413
+ use ${e.name}::dapp_metadata;
414
+ use ${e.name}::dapp_schema::Dapp;
415
+
416
+ public struct DappKey has drop {}
417
+
418
+ public(package) fun new(): DappKey {
419
+ DappKey { }
420
+ }
421
+
422
+ public(package) fun create(name: String, description: String, clock: &Clock, ctx: &mut TxContext): Dapp {
423
+ let mut dapp = dapp_schema::create(ctx);
424
+ assert!(!dapp.borrow_metadata().contains(), 0);
425
+ dapp.borrow_mut_metadata().set(
426
+ dapp_metadata::new(
427
+ name,
428
+ description,
429
+ ascii::string(b""),
430
+ ascii::string(b""),
431
+ clock.timestamp_ms(),
432
+ vector[]
433
+ )
434
+ );
435
+ let package_id = type_info::current_package_id<DappKey>();
436
+ dapp.borrow_mut_package_id().set(package_id);
437
+ dapp.borrow_mut_admin().set(ctx.sender());
438
+ dapp.borrow_mut_version().set(1);
439
+ dapp.borrow_mut_safe_mode().set(false);
440
+ dapp.borrow_mut_schemas().set(vector[]);
441
+ dapp
442
+ }
443
+
444
+ public entry fun set_metadata(dapp: &mut Dapp, name: String, description: String, icon_url: String, website_url: String, partners: vector<String>, ctx: &TxContext) {
445
+ assert!(dapp.borrow_admin().contains(), 0);
446
+ assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
447
+ let created_at = dapp.borrow_mut_metadata().take().get_created_at();
448
+ dapp.borrow_mut_metadata().set(
449
+ dapp_metadata::new(
450
+ name,
451
+ description,
452
+ icon_url,
453
+ website_url,
454
+ created_at,
455
+ partners
456
+ )
457
+ );
458
+ }
459
+
460
+ public entry fun transfer_ownership(dapp: &mut Dapp, new_admin: address, ctx: &mut TxContext) {
461
+ assert!(dapp.borrow_admin().contains(), 0);
462
+ assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
463
+
464
+ dapp.borrow_mut_admin().set(new_admin);
465
+ }
466
+
467
+ public entry fun set_safe_mode(dapp: &mut Dapp, safe_mode: bool, ctx: &TxContext) {
468
+ assert!(dapp.borrow_admin().contains(), 0);
469
+ assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
470
+
471
+ dapp.borrow_mut_safe_mode().set(safe_mode);
472
+ }
473
+
474
+ public fun ensure_no_safe_mode(dapp: &Dapp) {
475
+ assert!(!dapp.borrow_safe_mode().get(), 0);
476
+ }
477
+
478
+ public fun ensure_has_authority(dapp: &Dapp, ctx: &TxContext) {
479
+ assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
480
+ }
481
+
482
+ public fun ensure_has_schema<Schema: key + store>(dapp: &Dapp, schema: &Schema) {
483
+ let schema_id = object::id_address(schema);
484
+ assert!(dapp.borrow_schemas().get().contains(&schema_id), 0);
485
+ }
486
+ }
487
+
488
+ `;await p(r,a,"formatAndWriteMove")}}async function Z(e,t){console.log(`
489
+ \u{1F4DD} Starting Init Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/tests/init.move`);let a=`module ${e.name}::init_test {
490
+ use ${e.name}::dapp_schema::Dapp;
491
+ use sui::clock;
492
+ use sui::test_scenario;
493
+ use sui::test_scenario::Scenario;
494
+
495
+ public fun deploy_dapp_for_testing(sender: address): (Scenario, Dapp) {
496
+ let mut scenario = test_scenario::begin(sender);
497
+ let ctx = test_scenario::ctx(&mut scenario);
498
+ let clock = clock::create_for_testing(ctx);
499
+ ${e.name}::deploy_hook::run(&clock, ctx);
500
+ clock::destroy_for_testing(clock);
501
+ test_scenario::next_tx(&mut scenario,sender);
502
+ let dapp = test_scenario::take_shared<Dapp>(&scenario);
503
+ (scenario, dapp)
504
+ }
505
+ }
506
+ `;await p(a,`${t}/contracts/${e.name}/sources/tests/init.move`,"formatAndWriteMove"),console.log(`\u2705 Deploy Hook Generation Complete
507
+ `)}async function bt(e,t,a){console.log(`
508
+ \u{1F680} Starting Schema Generation Process...`),console.log("\u{1F4CB} Project Configuration:"),console.log(` \u251C\u2500 Name: ${e.name}`),console.log(` \u251C\u2500 Description: ${e.description||"No description provided"}`),console.log(` \u251C\u2500 Network: ${a||"testnet"}`);let r=t??process.cwd();k(`${r}/contracts/${e.name}`)&&x(`${r}/contracts/${e.name}/sources/codegen`),k(`${r}/contracts/${e.name}/Move.toml`)||await V(e,r),k(`${r}/contracts/${e.name}/sources/script/deploy_hook.move`)||await L(e,r),await E(e.name,e.schemas,r),await O(e.name,e.schemas,r),await z(e.name,e.schemas,r),await K(e.name,e.schemas,r),await Q(e,r),await Z(e,r),await B(e,r),await F(e,r),console.log(`\u2705 Schema Generation Process Complete!
509
+ `)}import{findUp as ue}from"find-up";import C from"path";import de from"esbuild";var w=class extends Error{name="NotInsideProjectError";message="You are not inside a Dubhe project"};import{rmSync as le}from"fs";import{pathToFileURL as ge}from"url";import fe from"os";var _e=["dubhe.config.js","dubhe.config.mjs","dubhe.config.ts","dubhe.config.mts"],A="dubhe.config.example.mjs";async function Ct(e){e=await q(e);try{return await de.build({entryPoints:[e],format:"esm",outfile:A,platform:"node",bundle:!0,packages:"external"}),e=await q(A,!0),(await import(e+`?update=${Date.now()}`)).dubheConfig}finally{le(A,{force:!0})}}async function q(e,t){return e===void 0?e=await be():C.isAbsolute(e)||(e=C.join(process.cwd(),e),e=C.normalize(e)),t&&fe.platform()==="win32"?ge(e).href:e}async function be(){let e=await ue(_e);if(e===void 0)throw new w;return e}export{p as formatAndWriteMove,Me as formatAndWriteTypescript,M as formatMove,T as formatTypescript,Ct as loadConfig,je as posixPath,q as resolveConfigPath,bt as schemaGen};
295
510
  //# sourceMappingURL=index.js.map