@0xobelisk/sui-common 0.5.9 → 0.5.10
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 +131 -376
- package/dist/index.js.map +1 -1
- package/package.json +11 -7
- package/src/codegen/debug.ts +10 -0
- package/src/codegen/types/index.ts +23 -24
- package/src/codegen/utils/format.ts +4 -7
- package/src/codegen/utils/formatAndWrite.ts +31 -14
- package/src/codegen/utils/index.ts +0 -1
- package/src/codegen/utils/renderMove/common.ts +9 -422
- package/src/codegen/utils/renderMove/generateDappKey.ts +19 -0
- package/src/codegen/utils/renderMove/generateSchema.ts +184 -197
- package/src/codegen/utils/renderMove/generateScript.ts +43 -12
- package/src/codegen/utils/renderMove/generateSystem.ts +8 -38
- package/src/codegen/utils/renderMove/generateToml.ts +4 -5
- package/src/codegen/utils/renderMove/worldgen.ts +15 -17
- package/src/debug.ts +10 -0
- package/src/codegen/utils/renderMove/generateAppKey.ts +0 -24
- package/src/codegen/utils/renderMove/generateEntityKey.ts +0 -52
- package/src/codegen/utils/renderMove/generateEps.ts +0 -159
- package/src/codegen/utils/renderMove/generateInit.ts +0 -45
|
@@ -1,217 +1,204 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
BaseValueType,
|
|
4
|
-
BaseType,
|
|
5
|
-
RenderSchemaOptions,
|
|
6
|
-
MoveType,
|
|
2
|
+
BaseType, SchemaType,
|
|
7
3
|
} from "../../types";
|
|
8
4
|
import { formatAndWriteMove } from "../formatAndWrite";
|
|
9
5
|
import {
|
|
10
|
-
renderKeyName,
|
|
11
|
-
renderSetFunc,
|
|
12
|
-
renderContainFunc,
|
|
13
|
-
renderRemoveFunc,
|
|
14
|
-
renderStruct,
|
|
15
|
-
renderNewStructFunc,
|
|
16
|
-
convertToCamelCase,
|
|
17
|
-
renderSetAttrsFunc,
|
|
18
|
-
renderRegisterFunc,
|
|
19
|
-
renderGetAllFunc,
|
|
20
|
-
renderGetAttrsFunc,
|
|
21
6
|
getStructAttrsWithType,
|
|
22
7
|
getStructAttrs,
|
|
23
|
-
|
|
24
|
-
renderSingleSetFunc,
|
|
25
|
-
renderSingleSetAttrsFunc,
|
|
26
|
-
renderSingleGetAllFunc,
|
|
27
|
-
renderSingleGetAttrsFunc,
|
|
8
|
+
getStructTypes, getStructAttrsQuery,
|
|
28
9
|
} from "./common";
|
|
29
10
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let needImportString = false;
|
|
40
|
-
if (typeof schemaData === "string") {
|
|
41
|
-
realType = schemaData;
|
|
42
|
-
|
|
43
|
-
if (schemaData === "string") {
|
|
44
|
-
valueType = "String";
|
|
45
|
-
needImportString = true;
|
|
46
|
-
} else if (schemaData === "vector<string>") {
|
|
47
|
-
valueType = "vector<String>";
|
|
48
|
-
needImportString = true;
|
|
49
|
-
} else {
|
|
50
|
-
valueType = schemaData;
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
realType = schemaData.valueType;
|
|
54
|
-
|
|
55
|
-
if (typeof schemaData.valueType === "string") {
|
|
56
|
-
if (schemaData.valueType === "string") {
|
|
57
|
-
valueType = "String";
|
|
58
|
-
needImportString = true;
|
|
59
|
-
} else if (schemaData.valueType === "vector<string>") {
|
|
60
|
-
valueType = "vector<String>";
|
|
61
|
-
needImportString = true;
|
|
62
|
-
} else {
|
|
63
|
-
valueType = schemaData.valueType;
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
valueType = { ...schemaData.valueType };
|
|
67
|
-
for (const key in valueType) {
|
|
68
|
-
if (valueType.hasOwnProperty(key)) {
|
|
69
|
-
if (valueType[key] === "string") {
|
|
70
|
-
valueType[key] = "String";
|
|
71
|
-
needImportString = true;
|
|
72
|
-
} else if (valueType[key] === "vector<string>") {
|
|
73
|
-
valueType[key] = "vector<String>";
|
|
74
|
-
needImportString = true;
|
|
75
|
-
|
|
76
|
-
// needImport = "\tuse std::ascii::{String, string};";
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
defaultValue = schemaData.defaultValue;
|
|
82
|
-
ephemeral =
|
|
83
|
-
schemaData.ephemeral !== undefined ? schemaData.ephemeral : false;
|
|
84
|
-
singleton = schemaData.defaultValue !== undefined ? true : false;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
options.push({
|
|
88
|
-
projectName: config.name,
|
|
89
|
-
systems: config.systems,
|
|
90
|
-
schemaName: schemaName,
|
|
91
|
-
structName: convertToCamelCase(schemaName),
|
|
92
|
-
ephemeral,
|
|
93
|
-
singleton,
|
|
94
|
-
valueType,
|
|
95
|
-
realType,
|
|
96
|
-
// structAttrs: [renderKeyName(valueType)],
|
|
97
|
-
// structTypes: [renderStruct(convertToCamelCase(schemaName), valueType)],
|
|
98
|
-
defaultValue,
|
|
99
|
-
needImportString,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
return options;
|
|
11
|
+
function capitalizeAndRemoveUnderscores(input: string): string {
|
|
12
|
+
return input
|
|
13
|
+
.split('_')
|
|
14
|
+
.map((word, index) => {
|
|
15
|
+
return index === 0
|
|
16
|
+
? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
|
17
|
+
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
18
|
+
})
|
|
19
|
+
.join('');
|
|
103
20
|
}
|
|
104
21
|
|
|
105
|
-
export function
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
formatAndWriteMove(
|
|
117
|
-
code,
|
|
118
|
-
`${srcPrefix}/contracts/${option.projectName}/sources/codegen/schemas/${option.schemaName}.move`,
|
|
119
|
-
"formatAndWriteMove"
|
|
120
|
-
);
|
|
121
|
-
}
|
|
22
|
+
export function renderSetAttrsFunc(
|
|
23
|
+
schemaName: string,
|
|
24
|
+
fields: BaseType | Record<string, BaseType>
|
|
25
|
+
): string {
|
|
26
|
+
return Object.entries(fields)
|
|
27
|
+
.map(
|
|
28
|
+
([key, type]) =>
|
|
29
|
+
`public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {
|
|
30
|
+
self.${key} = ${key};
|
|
31
|
+
}`
|
|
32
|
+
).join("\n");
|
|
122
33
|
}
|
|
123
34
|
|
|
124
|
-
function
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
${renderStruct(option.structName, option.valueType, option.ephemeral)}
|
|
134
|
-
\tpublic fun emit_${option.schemaName}(${getStructAttrsWithType(
|
|
135
|
-
option.valueType,
|
|
136
|
-
" "
|
|
137
|
-
)}) {
|
|
138
|
-
\t\tevents::emit_set(SCHEMA_ID, SCHEMA_TYPE, none(), ${option.structName} { ${getStructAttrs(
|
|
139
|
-
option.valueType,
|
|
140
|
-
" "
|
|
141
|
-
)} })
|
|
142
|
-
\t}
|
|
143
|
-
}`;
|
|
35
|
+
export function renderSetFunc(
|
|
36
|
+
schemaName: string,
|
|
37
|
+
fields: Record<string, string>
|
|
38
|
+
): string {
|
|
39
|
+
return `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(fields)}) {
|
|
40
|
+
${Object.entries(fields)
|
|
41
|
+
.map(([fieldName]) => `self.${fieldName} = ${fieldName};`)
|
|
42
|
+
.join('\n')}
|
|
43
|
+
}`;
|
|
144
44
|
}
|
|
145
45
|
|
|
146
|
-
function
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
use obelisk::schema;
|
|
154
|
-
use obelisk::events;
|
|
155
|
-
use obelisk::world::{World, AdminCap};
|
|
156
|
-
|
|
157
|
-
\tconst SCHEMA_ID: vector<u8> = b"${option.schemaName}";
|
|
158
|
-
\tconst SCHEMA_TYPE: u8 = 1;
|
|
159
|
-
|
|
160
|
-
${renderKeyName(option.valueType)}
|
|
161
|
-
${renderStruct(option.structName, option.valueType)}
|
|
162
|
-
${renderNewStructFunc(option.structName, option.valueType)}
|
|
163
|
-
${renderRegisterFuncWithInit(
|
|
164
|
-
option.structName,
|
|
165
|
-
option.realType,
|
|
166
|
-
option.defaultValue!
|
|
167
|
-
)}
|
|
168
|
-
|
|
169
|
-
${renderSingleSetFunc(
|
|
170
|
-
option.structName,
|
|
171
|
-
option.valueType
|
|
172
|
-
)}${renderSingleSetAttrsFunc(option.structName, option.valueType)}
|
|
173
|
-
|
|
174
|
-
${renderSingleGetAllFunc(
|
|
175
|
-
option.structName,
|
|
176
|
-
option.valueType
|
|
177
|
-
)}${renderSingleGetAttrsFunc(option.structName, option.valueType)}
|
|
178
|
-
}
|
|
179
|
-
`;
|
|
46
|
+
export function renderGetAllFunc(
|
|
47
|
+
schemaName: string,
|
|
48
|
+
fields: BaseType | Record<string, BaseType>
|
|
49
|
+
): string {
|
|
50
|
+
return `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {
|
|
51
|
+
(${getStructAttrsQuery(fields, "")})
|
|
52
|
+
}`;
|
|
180
53
|
}
|
|
181
54
|
|
|
182
|
-
function
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
\t/// Entity does not exist
|
|
195
|
-
\tconst EEntityDoesNotExist: u64 = 0;
|
|
196
|
-
|
|
197
|
-
\tconst SCHEMA_ID: vector<u8> = b"${option.schemaName}";
|
|
198
|
-
\tconst SCHEMA_TYPE: u8 = 0;
|
|
55
|
+
export function renderGetAttrsFunc(
|
|
56
|
+
schemaName: string,
|
|
57
|
+
fields: BaseType | Record<string, BaseType>
|
|
58
|
+
): string {
|
|
59
|
+
return Object.entries(fields)
|
|
60
|
+
.map(
|
|
61
|
+
([key, type]) => `public fun get_${key}(self: &${schemaName}): ${type} {
|
|
62
|
+
self.${key}
|
|
63
|
+
}`
|
|
64
|
+
).join("\n");
|
|
65
|
+
}
|
|
199
66
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
67
|
+
function convertToSnakeCase(input: string): string {
|
|
68
|
+
return input
|
|
69
|
+
.replace(/([A-Z])/g, '_$1')
|
|
70
|
+
.toLowerCase()
|
|
71
|
+
.replace(/^_/, '');
|
|
72
|
+
}
|
|
204
73
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
74
|
+
export async function generateSchemaData(projectName: string, schemas: Record<string, SchemaType>, path: string) {
|
|
75
|
+
for (const schemaName in schemas) {
|
|
76
|
+
const schema = schemas[schemaName];
|
|
77
|
+
if (schema.data) {
|
|
78
|
+
for (const item of schema.data) {
|
|
79
|
+
let code = "";
|
|
80
|
+
|
|
81
|
+
const enumNames = schema.data
|
|
82
|
+
.filter(item => Array.isArray(item.fields))
|
|
83
|
+
.map(item => item.name);
|
|
84
|
+
|
|
85
|
+
if (Array.isArray(item.fields)) {
|
|
86
|
+
code = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)} {
|
|
87
|
+
public enum ${item.name} has copy, drop , store {
|
|
88
|
+
${item.fields}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
${item.fields.map((field: string) => {
|
|
92
|
+
return `public fun new_${convertToSnakeCase(field)}(): ${item.name} {
|
|
93
|
+
${item.name}::${field}
|
|
94
|
+
}`
|
|
95
|
+
}).join("")
|
|
96
|
+
}`
|
|
97
|
+
} else {
|
|
98
|
+
code = `module ${projectName}::${schemaName}_${convertToSnakeCase(item.name)} {
|
|
99
|
+
use std::ascii::String;
|
|
100
|
+
${enumNames.map(name => `use ${projectName}::${schemaName}_${convertToSnakeCase(name)}::${name};`).join('\n')}
|
|
101
|
+
|
|
102
|
+
public struct ${item.name} has copy, drop , store {
|
|
103
|
+
${getStructAttrsWithType(item.fields)}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public fun new(${getStructAttrsWithType(item.fields)}): ${item.name} {
|
|
107
|
+
${item.name} {
|
|
108
|
+
${getStructAttrs(item.fields)}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
${renderGetAllFunc(item.name, item.fields)}
|
|
113
|
+
${renderGetAttrsFunc(item.name, item.fields)}
|
|
114
|
+
${renderSetAttrsFunc(item.name, item.fields)}
|
|
115
|
+
${renderSetFunc(item.name, item.fields)}
|
|
116
|
+
}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
await formatAndWriteMove(
|
|
120
|
+
code,
|
|
121
|
+
`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(item.name)}.move`,
|
|
122
|
+
"formatAndWriteMove"
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
215
127
|
}
|
|
216
|
-
|
|
128
|
+
|
|
129
|
+
function generateImport(projectName: string, schemaName: string, schema: SchemaType) {
|
|
130
|
+
if (schema.data) {
|
|
131
|
+
return schema.data.map(item => {
|
|
132
|
+
return `use ${projectName}::${schemaName}_${convertToSnakeCase(item.name)}::${item.name};`
|
|
133
|
+
}).join('\n');
|
|
134
|
+
} else {
|
|
135
|
+
return ""
|
|
136
|
+
}
|
|
217
137
|
}
|
|
138
|
+
|
|
139
|
+
export async function generateSchemaStructure(projectName: string, schemas: Record<string, SchemaType>, path: string) {
|
|
140
|
+
for (const schemaName in schemas) {
|
|
141
|
+
console.log(`Schema: ${schemaName}`);
|
|
142
|
+
const schema = schemas[schemaName];
|
|
143
|
+
const schemaMoudle = `module ${projectName}::${schemaName}_schema {
|
|
144
|
+
use std::ascii::String;
|
|
145
|
+
use std::type_name;
|
|
146
|
+
use sui::transfer::{public_share_object};
|
|
147
|
+
use obelisk::dapps_system;
|
|
148
|
+
use obelisk::dapps_schema::Dapps;
|
|
149
|
+
use obelisk::storage_value::{Self, StorageValue};
|
|
150
|
+
use obelisk::storage_map::{Self, StorageMap};
|
|
151
|
+
use obelisk::storage_double_map::{Self, StorageDoubleMap};
|
|
152
|
+
use ${projectName}::dapp_key::DappKey;
|
|
153
|
+
${generateImport(projectName, schemaName, schema)}
|
|
154
|
+
|
|
155
|
+
public struct ${capitalizeAndRemoveUnderscores(schemaName)} has key, store {
|
|
156
|
+
id: UID,
|
|
157
|
+
${getStructAttrsWithType(schema.structure)}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
${Object.entries(schema.structure).map(([key, value]) => {
|
|
161
|
+
return `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(schemaName)}) : &${value} {
|
|
162
|
+
&self.${key}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(schemaName)}): &mut ${value} {
|
|
166
|
+
&mut self.${key}
|
|
167
|
+
}
|
|
168
|
+
`
|
|
169
|
+
}).join('')}
|
|
170
|
+
|
|
171
|
+
public entry fun register(dapps: &mut Dapps, ctx: &mut TxContext) {
|
|
172
|
+
let package_id = dapps_system::current_package_id<DappKey>();
|
|
173
|
+
assert!(dapps.borrow_metadata().contains_key(package_id), 0);
|
|
174
|
+
assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
|
|
175
|
+
let schema = type_name::get<${capitalizeAndRemoveUnderscores(schemaName)}>().into_string();
|
|
176
|
+
assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);
|
|
177
|
+
|
|
178
|
+
public_share_object(${capitalizeAndRemoveUnderscores(schemaName)} {
|
|
179
|
+
id: object::new(ctx),
|
|
180
|
+
${Object.entries(schema.structure).map(([key, value]) => {
|
|
181
|
+
let storage_type = ""
|
|
182
|
+
if (value.includes("StorageValue")) {
|
|
183
|
+
storage_type = `storage_value::new()`
|
|
184
|
+
} else if (value.includes("StorageMap")) {
|
|
185
|
+
storage_type = `storage_map::new()`
|
|
186
|
+
} else if (value.includes("StorageDoubleMap")) {
|
|
187
|
+
storage_type = `storage_double_map::new()`
|
|
188
|
+
}
|
|
189
|
+
return `${key}: ${storage_type},`
|
|
190
|
+
}).join(' ')
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
dapps_system::add_schema<${capitalizeAndRemoveUnderscores(schemaName)}>(dapps, package_id, ctx);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
}`;
|
|
198
|
+
await formatAndWriteMove(
|
|
199
|
+
schemaMoudle,
|
|
200
|
+
`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,
|
|
201
|
+
"formatAndWriteMove"
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -2,32 +2,63 @@ import { ObeliskConfig } from "../../types";
|
|
|
2
2
|
import { formatAndWriteMove } from "../formatAndWrite";
|
|
3
3
|
import { existsSync } from "fs";
|
|
4
4
|
|
|
5
|
-
export function generateDeployHook(config: ObeliskConfig, srcPrefix: string) {
|
|
5
|
+
export async function generateDeployHook(config: ObeliskConfig, srcPrefix: string) {
|
|
6
6
|
if (
|
|
7
7
|
!existsSync(
|
|
8
8
|
`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`
|
|
9
9
|
)
|
|
10
10
|
) {
|
|
11
11
|
let code = `module ${config.name}::deploy_hook {
|
|
12
|
-
use obelisk::
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
use obelisk::dapps_schema::Dapps;
|
|
13
|
+
use obelisk::dapps_system;
|
|
14
|
+
use ${config.name}::dapp_key::DappKey;
|
|
15
|
+
use std::ascii;
|
|
16
|
+
use sui::clock::Clock;
|
|
17
|
+
#[test_only]
|
|
18
|
+
use obelisk::dapps_schema;
|
|
19
|
+
#[test_only]
|
|
20
|
+
use sui::clock;
|
|
21
|
+
#[test_only]
|
|
22
|
+
use sui::test_scenario;
|
|
23
|
+
#[test_only]
|
|
24
|
+
use sui::test_scenario::Scenario;
|
|
16
25
|
|
|
17
|
-
public entry fun run(
|
|
18
|
-
|
|
26
|
+
public entry fun run(dapps: &mut Dapps, clock: &Clock, ctx: &mut TxContext) {
|
|
27
|
+
// Register the dapp to obelisk.
|
|
28
|
+
dapps_system::register<DappKey>(
|
|
29
|
+
dapps,
|
|
30
|
+
ascii::string(b"${config.name}"),
|
|
31
|
+
ascii::string(b"${config.description}"),
|
|
32
|
+
clock,
|
|
33
|
+
ctx
|
|
34
|
+
);
|
|
35
|
+
${Object.keys(config.schemas).map(schemaName => {
|
|
36
|
+
return `${config.name}::${schemaName}_schema::register(dapps, ctx);`
|
|
37
|
+
}).join("\n")}
|
|
19
38
|
|
|
20
39
|
// Logic that needs to be automated once the contract is deployed
|
|
21
|
-
|
|
40
|
+
|
|
22
41
|
}
|
|
23
42
|
|
|
24
43
|
#[test_only]
|
|
25
|
-
public fun deploy_hook_for_testing(
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
public fun deploy_hook_for_testing(): (Scenario, Dapps) {
|
|
45
|
+
let mut scenario = test_scenario::begin(@0xA);
|
|
46
|
+
{
|
|
47
|
+
let ctx = test_scenario::ctx(&mut scenario);
|
|
48
|
+
dapps_schema::init_dapps_for_testing(ctx);
|
|
49
|
+
test_scenario::next_tx(&mut scenario,@0xA);
|
|
50
|
+
};
|
|
51
|
+
let mut dapps = test_scenario::take_shared<Dapps>(&scenario);
|
|
52
|
+
let ctx = test_scenario::ctx(&mut scenario);
|
|
53
|
+
let clock = clock::create_for_testing(ctx);
|
|
54
|
+
run(&mut dapps, &clock, ctx);
|
|
55
|
+
clock::destroy_for_testing(clock);
|
|
56
|
+
test_scenario::next_tx(&mut scenario,@0xA);
|
|
57
|
+
(scenario, dapps)
|
|
58
|
+
}
|
|
28
59
|
}
|
|
29
60
|
`;
|
|
30
|
-
formatAndWriteMove(
|
|
61
|
+
await formatAndWriteMove(
|
|
31
62
|
code,
|
|
32
63
|
`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`,
|
|
33
64
|
"formatAndWriteMove"
|
|
@@ -2,52 +2,22 @@ import { ObeliskConfig } from "../../types";
|
|
|
2
2
|
import { formatAndWriteMove } from "../formatAndWrite";
|
|
3
3
|
import { existsSync } from "fs";
|
|
4
4
|
|
|
5
|
-
export function
|
|
6
|
-
config.systems.map((systemName) => {
|
|
7
|
-
let code = `module ${config.name}::${systemName} {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
`;
|
|
11
|
-
formatAndWriteMove(
|
|
12
|
-
code,
|
|
13
|
-
`${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`,
|
|
14
|
-
"formatAndWriteMove"
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function generateNewSystem1(
|
|
20
|
-
name: string,
|
|
21
|
-
systemName: string,
|
|
22
|
-
srcPrefix: string
|
|
23
|
-
) {
|
|
24
|
-
let code = `module ${name}::${systemName} {
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
`;
|
|
28
|
-
formatAndWriteMove(
|
|
29
|
-
code,
|
|
30
|
-
`${srcPrefix}/contracts/${name}/sources/system/${systemName}.move`,
|
|
31
|
-
"formatAndWriteMove"
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function generateSystem(config: ObeliskConfig, srcPrefix: string) {
|
|
36
|
-
config.systems.map((systemName) => {
|
|
5
|
+
export async function generateSystem(config: ObeliskConfig, srcPrefix: string) {
|
|
6
|
+
config.systems.map(async (systemName) => {
|
|
37
7
|
if (
|
|
38
8
|
!existsSync(
|
|
39
9
|
`${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`
|
|
40
10
|
)
|
|
41
11
|
) {
|
|
42
|
-
|
|
12
|
+
let code = `module ${config.name}::${systemName}_system {
|
|
43
13
|
|
|
44
14
|
}
|
|
45
15
|
`;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
16
|
+
await formatAndWriteMove(
|
|
17
|
+
code,
|
|
18
|
+
`${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`,
|
|
19
|
+
"formatAndWriteMove"
|
|
20
|
+
);
|
|
51
21
|
}
|
|
52
22
|
});
|
|
53
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ObeliskConfig } from '../../types';
|
|
2
2
|
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
3
|
|
|
4
|
-
export function generateToml(config: ObeliskConfig, srcPrefix: string) {
|
|
4
|
+
export async function generateToml(config: ObeliskConfig, srcPrefix: string) {
|
|
5
5
|
let code = `[package]
|
|
6
6
|
name = "${config.name}"
|
|
7
7
|
version = "0.0.1"
|
|
@@ -9,15 +9,14 @@ edition = "2024.beta"
|
|
|
9
9
|
|
|
10
10
|
[dependencies]
|
|
11
11
|
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.31.1" }
|
|
12
|
-
|
|
13
|
-
Obelisk = { local = "/Volumes/project/obelisk-engine/packages/obelisk-framework" }
|
|
12
|
+
Obelisk = { git = "https://github.com/0xobelisk/obelisk-engine.git", subdir = "packages/obelisk-framework", rev = "main" }
|
|
14
13
|
|
|
15
14
|
[addresses]
|
|
16
15
|
sui = "0x2"
|
|
17
|
-
obelisk = "
|
|
16
|
+
obelisk = "0x3dc2d6239eed38c9798444afbf4bada0998ec98edc365713864405fe64203256"
|
|
18
17
|
${config.name} = "0x0"
|
|
19
18
|
`;
|
|
20
|
-
formatAndWriteMove(
|
|
19
|
+
await formatAndWriteMove(
|
|
21
20
|
code,
|
|
22
21
|
`${srcPrefix}/contracts/${config.name}/Move.toml`,
|
|
23
22
|
'formatAndWriteMove'
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SchemaType, ObeliskConfig } from "../../types";
|
|
2
2
|
import { rmdirSync, existsSync } from "fs";
|
|
3
3
|
import { deleteFolderRecursive } from "./common";
|
|
4
4
|
import { generateSystem } from "./generateSystem";
|
|
5
5
|
import { generateToml } from "./generateToml";
|
|
6
|
-
import {
|
|
7
|
-
import { generateInit } from "./generateInit";
|
|
8
|
-
import { generateEps } from "./generateEps";
|
|
9
|
-
import { generateSchema } from "./generateSchema";
|
|
6
|
+
import {generateSchemaData, generateSchemaStructure} from "./generateSchema";
|
|
10
7
|
import {generateDeployHook, generateMigrate} from "./generateScript";
|
|
11
|
-
import {
|
|
8
|
+
import {generateDappKey} from "./generateDappKey";
|
|
12
9
|
|
|
13
|
-
export function worldgen(config: ObeliskConfig, srcPrefix?: string) {
|
|
10
|
+
export async function worldgen(config: ObeliskConfig, srcPrefix?: string) {
|
|
14
11
|
let path = "";
|
|
15
12
|
if (srcPrefix === undefined) {
|
|
16
13
|
path = process.cwd();
|
|
@@ -20,17 +17,18 @@ export function worldgen(config: ObeliskConfig, srcPrefix?: string) {
|
|
|
20
17
|
|
|
21
18
|
if (existsSync(`${path}/contracts/${config.name}`)) {
|
|
22
19
|
deleteFolderRecursive(`${path}/contracts/${config.name}/sources/codegen`);
|
|
23
|
-
} else {
|
|
24
|
-
generateToml(config, path);
|
|
25
|
-
generateEntityKey(config, path);
|
|
26
20
|
}
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {
|
|
23
|
+
await generateToml(config, path);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!existsSync(`${path}/contracts/${config.name}/sources/script/deploy_hook.move`)) {
|
|
27
|
+
await generateDeployHook(config, path);
|
|
28
|
+
}
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
await generateSystem(config, path);
|
|
31
|
+
await generateSchemaData(config.name, config.schemas, path);
|
|
32
|
+
await generateSchemaStructure(config.name, config.schemas, path);
|
|
33
|
+
await generateDappKey(config, path);
|
|
36
34
|
}
|
package/src/debug.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import createDebug from "debug";
|
|
2
|
+
|
|
3
|
+
export const debug = createDebug("obelisk:common");
|
|
4
|
+
export const error = createDebug("obelisk:common");
|
|
5
|
+
|
|
6
|
+
// Pipe debug output to stdout instead of stderr
|
|
7
|
+
debug.log = console.debug.bind(console);
|
|
8
|
+
|
|
9
|
+
// Pipe error output to stderr
|
|
10
|
+
error.log = console.error.bind(console);
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ObeliskConfig } from "../../types";
|
|
2
|
-
import { formatAndWriteMove } from "../formatAndWrite";
|
|
3
|
-
import {
|
|
4
|
-
getRegisterSchema,
|
|
5
|
-
getUseSchema,
|
|
6
|
-
capitalizeFirstLetter,
|
|
7
|
-
} from "./common";
|
|
8
|
-
|
|
9
|
-
export function generateAppKey(config: ObeliskConfig, srcPrefix: string) {
|
|
10
|
-
let code = `module ${config.name}::app_key {
|
|
11
|
-
/// Authorization token for the app.
|
|
12
|
-
public struct AppKey has drop {}
|
|
13
|
-
|
|
14
|
-
public(package) fun new(): AppKey {
|
|
15
|
-
AppKey { }
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
`;
|
|
19
|
-
formatAndWriteMove(
|
|
20
|
-
code,
|
|
21
|
-
`${srcPrefix}/contracts/${config.name}/sources/codegen/app_key.move`,
|
|
22
|
-
"formatAndWriteMove"
|
|
23
|
-
);
|
|
24
|
-
}
|