@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
package/dist/index.d.ts
CHANGED
|
@@ -17,9 +17,9 @@ declare function formatAndWriteTypescript(output: string, fullOutputPath: string
|
|
|
17
17
|
*/
|
|
18
18
|
declare function posixPath(path: string): string;
|
|
19
19
|
|
|
20
|
-
type BaseType =
|
|
21
|
-
type StorageDataType =
|
|
22
|
-
type StorageMapType =
|
|
20
|
+
type BaseType = 'String' | 'vector<String>' | 'address' | 'bool' | 'u8' | 'u32' | 'u64' | 'u128' | 'vector<address>' | 'vector<bool>' | 'vector<u8>' | 'vector<vector<u8>>' | 'vector<u32>' | 'vector<u64>' | 'vector<u128>' | string;
|
|
21
|
+
type StorageDataType = 'Struct' | 'Enum';
|
|
22
|
+
type StorageMapType = 'Map' | 'Bag' | 'Table';
|
|
23
23
|
type Address = string;
|
|
24
24
|
type Bool = boolean;
|
|
25
25
|
type U8 = number;
|
|
@@ -42,9 +42,8 @@ type DubheConfig = {
|
|
|
42
42
|
name: string;
|
|
43
43
|
description: string;
|
|
44
44
|
schemas: Record<string, SchemaType>;
|
|
45
|
-
migration_enabled: boolean;
|
|
46
45
|
};
|
|
47
|
-
type MoveType =
|
|
46
|
+
type MoveType = 'string' | 'vector<string>' | 'String' | 'vector<String>' | 'address' | 'bool' | 'u8' | 'u32' | 'u64' | 'u128' | 'vector<address>' | 'vector<bool>' | 'vector<u8>' | 'vector<vector<u8>>' | 'vector<u32>' | 'vector<u64>' | 'vector<u128>';
|
|
48
47
|
|
|
49
48
|
declare function schemaGen(config: DubheConfig, srcPrefix?: string, network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet', frameworkId?: string): Promise<void>;
|
|
50
49
|
|
package/dist/index.js
CHANGED
|
@@ -1,68 +1,67 @@
|
|
|
1
|
-
import
|
|
1
|
+
import v from"prettier";import Z from"prettier-plugin-move-js";async function D(e,t){let o;t&&(o=await v.resolveConfig(t));try{return v.format(e,{plugins:[Z],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"),X=M("dubhe:common");b.log=console.debug.bind(console);X.log=console.error.bind(console);var _=b.extend("codegen"),Y=b.extend("codegen");_.log=console.debug.bind(console);Y.log=console.error.bind(console);async function m(e,t,o){let r=await D(e),n=` // Copyright (c) Obelisk Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
#[allow(unused_use)]
|
|
4
4
|
|
|
5
5
|
/* Autogenerated file. Do not edit manually. */
|
|
6
6
|
|
|
7
|
-
`,
|
|
7
|
+
`,s=`#[allow(lint(share_owned))]
|
|
8
8
|
|
|
9
|
-
`,
|
|
10
|
-
\u{1F4C4} Starting Move.toml Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/Move.toml`);let
|
|
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 xe(e,t,o){let r=await T(e);await y.mkdir(j.dirname(t),{recursive:!0}),await y.writeFile(t,r),_(`${o}: ${t}`)}function we(e){return e.replace(/\\/g,"/")}import{existsSync as k}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 W(e){return`(${Object.entries(e).map(([t,o])=>`${o}`)})`}function p(e){return Object.entries(e).map(([t,o])=>`${t}: ${o}`)}function G(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]
|
|
11
11
|
name = "${e.name}"
|
|
12
|
-
version = "0.0
|
|
13
|
-
edition = "2024
|
|
12
|
+
version = "1.0.0"
|
|
13
|
+
edition = "2024"
|
|
14
14
|
|
|
15
15
|
[dependencies]
|
|
16
|
-
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.
|
|
17
|
-
Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "
|
|
16
|
+
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" }
|
|
18
18
|
|
|
19
19
|
[addresses]
|
|
20
20
|
sui = "0x2"
|
|
21
|
-
dubhe = "${r}"
|
|
22
21
|
${e.name} = "0x0"
|
|
23
|
-
`;await m(
|
|
24
|
-
`)}function u(e){return e.split("_").map((t,
|
|
25
|
-
self.${
|
|
22
|
+
`;await m(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 q(e,t){return Object.entries(t).map(([o,r])=>`public(package) fun set_${o}(self: &mut ${e}, ${o}: ${r}) {
|
|
24
|
+
self.${o} = ${o};
|
|
26
25
|
}`).join(`
|
|
27
|
-
`)}function
|
|
28
|
-
${Object.entries(t).map(([
|
|
26
|
+
`)}function J(e,t){return`public(package) fun set(self: &mut ${e}, ${p(t)}) {
|
|
27
|
+
${Object.entries(t).map(([o])=>`self.${o} = ${o};`).join(`
|
|
29
28
|
`)}
|
|
30
|
-
}`}function
|
|
31
|
-
(${
|
|
32
|
-
}`}function
|
|
33
|
-
self.${
|
|
29
|
+
}`}function P(e,t){return`public fun get(self: &${e}): ${W(t)} {
|
|
30
|
+
(${G(t)})
|
|
31
|
+
}`}function ee(e,t){return Object.entries(t).map(([o,r])=>`public fun get_${o}(self: &${e}): ${r} {
|
|
32
|
+
self.${o}
|
|
34
33
|
}`).join(`
|
|
35
|
-
`)}function
|
|
36
|
-
\u{1F4E6} Starting Schema Data Generation...`);for(let
|
|
37
|
-
public enum ${
|
|
38
|
-
${
|
|
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="",c=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}
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
${
|
|
42
|
-
${
|
|
43
|
-
}`).join("")}`:
|
|
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)} {
|
|
44
43
|
use std::ascii::String;
|
|
45
|
-
${
|
|
44
|
+
${c.map(i=>`use ${e}::${r}_${l(i)}::${i};`).join(`
|
|
46
45
|
`)}
|
|
47
46
|
|
|
48
|
-
public struct ${
|
|
49
|
-
${
|
|
47
|
+
public struct ${s.name} has copy, drop , store {
|
|
48
|
+
${p(s.fields)}
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
public fun new(${
|
|
53
|
-
${
|
|
54
|
-
${
|
|
51
|
+
public fun new(${p(s.fields)}): ${s.name} {
|
|
52
|
+
${s.name} {
|
|
53
|
+
${g(s.fields)}
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
${
|
|
59
|
-
${
|
|
60
|
-
${
|
|
61
|
-
${
|
|
62
|
-
}`,await m(
|
|
63
|
-
`)}function
|
|
64
|
-
`):""}async function
|
|
65
|
-
\u{1F528} Starting Schema Structure Generation...`);for(let
|
|
57
|
+
${P(s.name,s.fields)}
|
|
58
|
+
${ee(s.name,s.fields)}
|
|
59
|
+
${q(s.name,s.fields)}
|
|
60
|
+
${J(s.name,s.fields)}
|
|
61
|
+
}`,await m(a,`${o}/contracts/${e}/sources/codegen/schemas/${r}_${l(s.name)}.move`,"formatAndWriteMove")}}}console.log(`\u2705 Schema Data Generation Complete
|
|
62
|
+
`)}function te(e,t,o){return o.data?o.data.map(r=>`use ${e}::${t}_${l(r.name)}::${r.name};`).join(`
|
|
63
|
+
`):""}async function O(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 {
|
|
66
65
|
use std::ascii::String;
|
|
67
66
|
use std::ascii::string;
|
|
68
67
|
use sui::package::UpgradeCap;
|
|
@@ -75,67 +74,72 @@ ${e.name} = "0x0"
|
|
|
75
74
|
use dubhe::storage_double_map::{Self, StorageDoubleMap};
|
|
76
75
|
use ${e}::dapp_key::DappKey;
|
|
77
76
|
use sui::dynamic_field as df;
|
|
78
|
-
${
|
|
77
|
+
${te(e,r,n)}
|
|
79
78
|
|
|
80
|
-
public struct ${u(
|
|
79
|
+
public struct ${u(r)} has key, store {
|
|
81
80
|
id: UID
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
${Object.entries(n.structure).map(([
|
|
85
|
-
storage_migrate::borrow_field(&self.id, b"${
|
|
83
|
+
${Object.entries(n.structure).map(([a,c])=>`public fun borrow_${a}(self: &${u(r)}) : &${c} {
|
|
84
|
+
storage_migrate::borrow_field(&self.id, b"${a}")
|
|
86
85
|
}
|
|
87
86
|
|
|
88
|
-
public(package) fun borrow_mut_${
|
|
89
|
-
storage_migrate::borrow_mut_field(&mut self.id, b"${
|
|
87
|
+
public(package) fun borrow_mut_${a}(self: &mut ${u(r)}): &mut ${c} {
|
|
88
|
+
storage_migrate::borrow_mut_field(&mut self.id, b"${a}")
|
|
90
89
|
}
|
|
91
90
|
`).join("")}
|
|
92
91
|
|
|
93
92
|
|
|
94
|
-
public(package) fun create(ctx: &mut TxContext): ${u(
|
|
93
|
+
public(package) fun create(ctx: &mut TxContext): ${u(r)} {
|
|
95
94
|
let mut id = object::new(ctx);
|
|
96
|
-
${Object.entries(n.structure).map(([
|
|
95
|
+
${Object.entries(n.structure).map(([a,c])=>{let i="";return c.includes("StorageValue")?i="storage_value::new()":c.includes("StorageMap")?i="storage_map::new()":c.includes("StorageDoubleMap")&&(i="storage_double_map::new()"),`storage_migrate::add_field<${c}>(&mut id, b"${a}", ${i});`}).join("")}
|
|
97
96
|
|
|
98
|
-
${u(
|
|
97
|
+
${u(r)} { id }
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
public fun migrate(_${r}: &mut ${u(r)}, _cap: &UpgradeCap) { }
|
|
101
|
+
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
// ======================================== View Functions ========================================
|
|
105
|
-
${Object.entries(n.structure).map(([
|
|
106
|
-
self.borrow_${
|
|
105
|
+
${Object.entries(n.structure).map(([a,c])=>{let i=c.match(/<(.+)>/)[1].split(",").map(Q=>Q.trim()),f=[],$="",h="",x="";return c.includes("StorageValue")?(f=[],$=`${i[0]}`,h="try_get()"):c.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()
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
public fun get_${
|
|
110
|
-
self.borrow_${
|
|
111
|
-
}`):
|
|
112
|
-
self.borrow_${
|
|
109
|
+
public fun get_${a}_values(self: &${u(r)}) : vector<${i[1]}> {
|
|
110
|
+
self.borrow_${a}().values()
|
|
111
|
+
}`):c.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()
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
public fun get_${
|
|
116
|
-
self.borrow_${
|
|
117
|
-
}`),`public fun get_${
|
|
118
|
-
self.borrow_${
|
|
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}
|
|
119
119
|
}
|
|
120
|
-
`+
|
|
120
|
+
`+x}).join("")}
|
|
121
121
|
// =========================================================================================================
|
|
122
122
|
|
|
123
123
|
|
|
124
|
-
}`;await m(
|
|
125
|
-
`)}import{existsSync as
|
|
126
|
-
\u{1F4DD} Starting Deploy Hook Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/
|
|
124
|
+
}`;await m(s,`${o}/contracts/${e}/sources/codegen/schemas/${r}.move`,"formatAndWriteMove")}console.log(`\u2705 Schema Structure Generation Complete
|
|
125
|
+
`)}import{existsSync as U}from"fs";async function z(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`),!U(`${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`)){let o=`module ${e.name}::deploy_hook {
|
|
127
127
|
use dubhe::dapps_schema::Dapps;
|
|
128
128
|
use dubhe::dapps_system;
|
|
129
129
|
use ${e.name}::schema_hub::SchemaHub;
|
|
130
130
|
use std::ascii::string;
|
|
131
131
|
use sui::clock::Clock;
|
|
132
|
+
use sui::sui::SUI;
|
|
133
|
+
use sui::coin::Coin;
|
|
132
134
|
use sui::package::UpgradeCap;
|
|
133
135
|
use sui::transfer::public_share_object;
|
|
134
|
-
${Object.keys(e.schemas).map(
|
|
136
|
+
${Object.keys(e.schemas).map(r=>`use ${e.name}::${r}_schema::${u(r)};`).join(`
|
|
135
137
|
`)}
|
|
136
138
|
#[test_only]
|
|
137
139
|
use sui::clock;
|
|
138
140
|
#[test_only]
|
|
141
|
+
use sui::coin;
|
|
142
|
+
#[test_only]
|
|
139
143
|
use sui::test_scenario;
|
|
140
144
|
#[test_only]
|
|
141
145
|
use sui::package;
|
|
@@ -146,11 +150,11 @@ ${e.name} = "0x0"
|
|
|
146
150
|
#[test_only]
|
|
147
151
|
use sui::test_scenario::Scenario;
|
|
148
152
|
|
|
149
|
-
public entry fun run(schema_hub: &mut SchemaHub, dapps: &mut Dapps, cap: &UpgradeCap, clock: &Clock, ctx: &mut TxContext) {
|
|
153
|
+
public entry fun run(schema_hub: &mut SchemaHub, dapps: &mut Dapps, cap: &UpgradeCap, clock: &Clock, coin: Coin<SUI>, ctx: &mut TxContext) {
|
|
150
154
|
// Register the dapp to dubhe.
|
|
151
|
-
dapps_system::register(dapps,cap,string(b"${e.name}"),string(b"${e.description}"),clock,ctx);
|
|
155
|
+
dapps_system::register(dapps,cap,string(b"${e.name}"),string(b"${e.description}"),clock,coin,ctx);
|
|
152
156
|
// Create schemas
|
|
153
|
-
${Object.keys(e.schemas).map(
|
|
157
|
+
${Object.keys(e.schemas).map(r=>`let ${r} = ${e.name}::${r}_schema::create(ctx);`).join(`
|
|
154
158
|
`)}
|
|
155
159
|
// Logic that needs to be automated once the contract is deployed
|
|
156
160
|
|
|
@@ -159,9 +163,9 @@ ${e.name} = "0x0"
|
|
|
159
163
|
|
|
160
164
|
|
|
161
165
|
// Authorize schemas and public share objects
|
|
162
|
-
${Object.keys(e.schemas).map(
|
|
163
|
-
schema_hub.authorize_schema<${u(
|
|
164
|
-
public_share_object(${
|
|
166
|
+
${Object.keys(e.schemas).map(r=>`
|
|
167
|
+
schema_hub.authorize_schema<${u(r)}>();
|
|
168
|
+
public_share_object(${r});
|
|
165
169
|
`).join(`
|
|
166
170
|
`)}
|
|
167
171
|
}
|
|
@@ -180,7 +184,8 @@ ${e.name} = "0x0"
|
|
|
180
184
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
181
185
|
let clock = clock::create_for_testing(ctx);
|
|
182
186
|
let upgrade_cap = package::test_publish(@0x42.to_id(), ctx);
|
|
183
|
-
|
|
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);
|
|
184
189
|
|
|
185
190
|
clock::destroy_for_testing(clock);
|
|
186
191
|
upgrade_cap.make_immutable();
|
|
@@ -188,16 +193,16 @@ ${e.name} = "0x0"
|
|
|
188
193
|
(scenario, schema_hub, dapps)
|
|
189
194
|
}
|
|
190
195
|
}
|
|
191
|
-
`;await m(
|
|
192
|
-
`)}async function
|
|
196
|
+
`;await m(o,`${t}/contracts/${e.name}/sources/scripts/deploy_hook.move`,"formatAndWriteMove")}console.log(`\u2705 Deploy Hook Generation Complete
|
|
197
|
+
`)}async function E(e,t){if(!U(`${t}/contracts/${e.name}/sources/scripts/migrate.move`)){let o=`module ${e.name}::migrate {
|
|
193
198
|
const ON_CHAIN_VERSION: u32 = 0;
|
|
194
199
|
|
|
195
200
|
public fun on_chain_version(): u32 {
|
|
196
201
|
ON_CHAIN_VERSION
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
|
-
`;await m(
|
|
200
|
-
\u{1F511} Starting DappKey Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/codegen/dapp_key.move`);let
|
|
204
|
+
`;await m(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 {
|
|
201
206
|
/// Authorization token for the app.
|
|
202
207
|
public struct DappKey has drop {}
|
|
203
208
|
|
|
@@ -205,30 +210,30 @@ ${e.name} = "0x0"
|
|
|
205
210
|
DappKey { }
|
|
206
211
|
}
|
|
207
212
|
}
|
|
208
|
-
`;await m(
|
|
209
|
-
`)}function I(e){return e.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"")}async function
|
|
210
|
-
\u{1F4E6} Starting Schema Event Generation...`);for(let
|
|
213
|
+
`;await m(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}_${I(s.name)}_event {
|
|
211
216
|
use sui::event;
|
|
212
217
|
use std::ascii::String;
|
|
213
|
-
public struct ${
|
|
214
|
-
${
|
|
218
|
+
public struct ${s.name}Event has copy, drop {
|
|
219
|
+
${p(s.fields)}
|
|
215
220
|
}
|
|
216
221
|
|
|
217
|
-
public fun new(${
|
|
218
|
-
${
|
|
219
|
-
${
|
|
222
|
+
public fun new(${p(s.fields)}): ${s.name}Event {
|
|
223
|
+
${s.name}Event {
|
|
224
|
+
${g(s.fields)}
|
|
220
225
|
}
|
|
221
226
|
}
|
|
222
227
|
|
|
223
|
-
public fun emit(${
|
|
224
|
-
event::emit(${
|
|
225
|
-
${
|
|
228
|
+
public fun emit(${p(s.fields)}) {
|
|
229
|
+
event::emit(${s.name}Event {
|
|
230
|
+
${g(s.fields)}
|
|
226
231
|
});
|
|
227
|
-
}`;await m(
|
|
228
|
-
`)}import{existsSync as
|
|
229
|
-
\u2699\uFE0F Starting System Generation...`),console.log(" \u251C\u2500 Generating systems"),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/systems`),
|
|
230
|
-
`)}async function
|
|
231
|
-
\u{1F511} Starting DappKey Generation...`),console.log(` \u2514\u2500 Output path: ${t}/contracts/${e.name}/sources/codegen/schema_hub.move`);let
|
|
232
|
+
}`;await m(a,`${o}/contracts/${e}/sources/codegen/events/${r}_${I(s.name)}_event.move`,"formatAndWriteMove")}}}console.log(`\u2705 Schema Event Generation Complete
|
|
233
|
+
`)}import{existsSync as re}from"fs";import oe 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`),re(`${t}/contracts/${e.name}/sources/systems`)||await oe.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 {
|
|
232
237
|
use sui::transfer::public_share_object;
|
|
233
238
|
use sui::dynamic_field as df;
|
|
234
239
|
|
|
@@ -273,9 +278,9 @@ ${e.name} = "0x0"
|
|
|
273
278
|
init(ctx);
|
|
274
279
|
}
|
|
275
280
|
}
|
|
276
|
-
`;await m(
|
|
277
|
-
`)}function
|
|
278
|
-
\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: ${
|
|
279
|
-
`);let
|
|
280
|
-
`)}import{findUp as
|
|
281
|
+
`;await m(o,`${t}/contracts/${e.name}/sources/codegen/schema_hub.move`,"formatAndWriteMove"),console.log(`\u2705 DappKey Generation Complete
|
|
282
|
+
`)}function V(e){switch(e){case"testnet":return"0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6";case"localnet":return"0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6";default:return"0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6"}}async function nt(e,t,o,r){console.log(`
|
|
283
|
+
\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||V(o??"testnet")}
|
|
284
|
+
`);let n=t??process.cwd();r=r||V(o??"testnet"),k(`${n}/contracts/${e.name}`)&&w(`${n}/contracts/${e.name}/sources/codegen`),k(`${n}/contracts/${e.name}/Move.toml`)||await R(e,n,r),k(`${n}/contracts/${e.name}/sources/script/deploy_hook.move`)||await z(e,n),await H(e.name,e.schemas,n),await O(e.name,e.schemas,n),await L(e.name,e.schemas,n),await F(e,n),await B(e,n),await K(e,n),await E(e,n),console.log(`\u2705 Schema Generation Process Complete!
|
|
285
|
+
`)}import{findUp as se}from"find-up";import A from"path";import ne from"esbuild";var S=class extends Error{name="NotInsideProjectError";message="You are not inside a Dubhe project"};import{rmSync as ae}from"fs";import{pathToFileURL as ie}from"url";import ce from"os";var me=["dubhe.config.js","dubhe.config.mjs","dubhe.config.ts","dubhe.config.mts"],C="dubhe.config.example.mjs";async function ft(e){e=await N(e);try{return await ne.build({entryPoints:[e],format:"esm",outfile:C,platform:"node",bundle:!0,packages:"external"}),e=await N(C,!0),(await import(e+`?update=${Date.now()}`)).dubheConfig}finally{ae(C,{force:!0})}}async function N(e,t){return e===void 0?e=await ue():A.isAbsolute(e)||(e=A.join(process.cwd(),e),e=A.normalize(e)),t&&ce.platform()==="win32"?ie(e).href:e}async function ue(){let e=await se(me);if(e===void 0)throw new S;return e}export{m as formatAndWriteMove,xe as formatAndWriteTypescript,D as formatMove,T as formatTypescript,ft as loadConfig,we as posixPath,N as resolveConfigPath,nt as schemaGen};
|
|
281
286
|
//# sourceMappingURL=index.js.map
|