@0xobelisk/sui-common 0.5.14 ā 0.5.16
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 +2 -2
- package/dist/index.js +70 -51
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/codegen/utils/formatAndWrite.ts +10 -3
- package/src/codegen/utils/index.ts +5 -5
- package/src/codegen/utils/renderMove/common.ts +32 -32
- package/src/codegen/utils/renderMove/generateDappKey.ts +23 -14
- package/src/codegen/utils/renderMove/generateSchema.ts +189 -117
- package/src/codegen/utils/renderMove/generateScript.ts +50 -33
- package/src/codegen/utils/renderMove/generateSystem.ts +24 -17
- package/src/codegen/utils/renderMove/generateToml.ts +13 -3
- package/src/codegen/utils/renderMove/schemaGen.ts +69 -0
- package/src/codegen/utils/renderMove/worldgen.ts +0 -34
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
import { ObeliskConfig } from
|
|
2
|
-
import { formatAndWriteMove } from
|
|
1
|
+
import { ObeliskConfig } from '../../types';
|
|
2
|
+
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
3
|
|
|
4
|
-
export async function generateDappKey(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export async function generateDappKey(
|
|
5
|
+
config: ObeliskConfig,
|
|
6
|
+
srcPrefix: string
|
|
7
|
+
) {
|
|
8
|
+
console.log('\nš Starting DappKey Generation...');
|
|
9
|
+
console.log(
|
|
10
|
+
` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`
|
|
11
|
+
);
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
let code = `module ${config.name}::dapp_key {
|
|
14
|
+
\t/// Authorization token for the app.
|
|
15
|
+
\tpublic struct DappKey has drop {}
|
|
16
|
+
|
|
17
|
+
\tpublic(package) fun new(): DappKey {
|
|
18
|
+
\t\tDappKey { }
|
|
19
|
+
\t}
|
|
12
20
|
}
|
|
13
21
|
`;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
await formatAndWriteMove(
|
|
23
|
+
code,
|
|
24
|
+
`${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,
|
|
25
|
+
'formatAndWriteMove'
|
|
26
|
+
);
|
|
27
|
+
console.log('ā
DappKey Generation Complete\n');
|
|
19
28
|
}
|
|
@@ -1,109 +1,142 @@
|
|
|
1
|
+
import { BaseType, SchemaType } from '../../types';
|
|
2
|
+
import { formatAndWriteMove } from '../formatAndWrite';
|
|
1
3
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
getStructAttrs,
|
|
8
|
-
getStructTypes, getStructAttrsQuery,
|
|
9
|
-
} from "./common";
|
|
4
|
+
getStructAttrsWithType,
|
|
5
|
+
getStructAttrs,
|
|
6
|
+
getStructTypes,
|
|
7
|
+
getStructAttrsQuery,
|
|
8
|
+
} from './common';
|
|
10
9
|
|
|
11
10
|
function capitalizeAndRemoveUnderscores(input: string): string {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
return input
|
|
12
|
+
.split('_')
|
|
13
|
+
.map((word, index) => {
|
|
14
|
+
return index === 0
|
|
15
|
+
? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
|
16
|
+
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
17
|
+
})
|
|
18
|
+
.join('');
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
export function renderSetAttrsFunc(
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
schemaName: string,
|
|
23
|
+
fields: BaseType | Record<string, BaseType>
|
|
25
24
|
): string {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
return Object.entries(fields)
|
|
26
|
+
.map(
|
|
27
|
+
([key, type]) =>
|
|
28
|
+
`public(package) fun set_${key}(self: &mut ${schemaName}, ${key}: ${type}) {
|
|
30
29
|
self.${key} = ${key};
|
|
31
30
|
}`
|
|
32
|
-
|
|
31
|
+
)
|
|
32
|
+
.join('\n');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function renderSetFunc(
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
schemaName: string,
|
|
37
|
+
fields: Record<string, string>
|
|
38
38
|
): string {
|
|
39
|
-
|
|
39
|
+
return `public(package) fun set(self: &mut ${schemaName}, ${getStructAttrsWithType(
|
|
40
|
+
fields
|
|
41
|
+
)}) {
|
|
40
42
|
${Object.entries(fields)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
.map(([fieldName]) => `self.${fieldName} = ${fieldName};`)
|
|
44
|
+
.join('\n')}
|
|
43
45
|
}`;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
export function renderGetAllFunc(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
schemaName: string,
|
|
50
|
+
fields: BaseType | Record<string, BaseType>
|
|
49
51
|
): string {
|
|
50
|
-
|
|
51
|
-
(${getStructAttrsQuery(fields,
|
|
52
|
+
return `public fun get(self: &${schemaName}): ${getStructTypes(fields)} {
|
|
53
|
+
(${getStructAttrsQuery(fields, '')})
|
|
52
54
|
}`;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
export function renderGetAttrsFunc(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
schemaName: string,
|
|
59
|
+
fields: BaseType | Record<string, BaseType>
|
|
58
60
|
): string {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
return Object.entries(fields)
|
|
62
|
+
.map(
|
|
63
|
+
([
|
|
64
|
+
key,
|
|
65
|
+
type,
|
|
66
|
+
]) => `public fun get_${key}(self: &${schemaName}): ${type} {
|
|
62
67
|
self.${key}
|
|
63
68
|
}`
|
|
64
|
-
|
|
69
|
+
)
|
|
70
|
+
.join('\n');
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
function convertToSnakeCase(input: string): string {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
return input
|
|
75
|
+
.replace(/([A-Z])/g, '_$1')
|
|
76
|
+
.toLowerCase()
|
|
77
|
+
.replace(/^_/, '');
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
export async function generateSchemaData(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
export async function generateSchemaData(
|
|
81
|
+
projectName: string,
|
|
82
|
+
schemas: Record<string, SchemaType>,
|
|
83
|
+
path: string
|
|
84
|
+
) {
|
|
85
|
+
console.log('\nš¦ Starting Schema Data Generation...');
|
|
86
|
+
for (const schemaName in schemas) {
|
|
87
|
+
const schema = schemas[schemaName];
|
|
88
|
+
if (schema.data) {
|
|
89
|
+
console.log(` āā Processing schema: ${schemaName}`);
|
|
90
|
+
for (const item of schema.data) {
|
|
91
|
+
console.log(
|
|
92
|
+
` āā Generating ${item.name} ${
|
|
93
|
+
Array.isArray(item.fields) ? '(enum)' : '(struct)'
|
|
94
|
+
}`
|
|
95
|
+
);
|
|
96
|
+
let code = '';
|
|
80
97
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
98
|
+
const enumNames = schema.data
|
|
99
|
+
.filter(item => Array.isArray(item.fields))
|
|
100
|
+
.map(item => item.name);
|
|
84
101
|
|
|
85
|
-
|
|
86
|
-
|
|
102
|
+
if (Array.isArray(item.fields)) {
|
|
103
|
+
code = `module ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
104
|
+
item.name
|
|
105
|
+
)} {
|
|
87
106
|
public enum ${item.name} has copy, drop , store {
|
|
88
107
|
${item.fields}
|
|
89
108
|
}
|
|
90
109
|
|
|
91
|
-
${item.fields
|
|
92
|
-
|
|
110
|
+
${item.fields
|
|
111
|
+
.map((field: string) => {
|
|
112
|
+
return `public fun new_${convertToSnakeCase(
|
|
113
|
+
field
|
|
114
|
+
)}(): ${item.name} {
|
|
93
115
|
${item.name}::${field}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
116
|
+
}`;
|
|
117
|
+
})
|
|
118
|
+
.join('')}`;
|
|
119
|
+
} else {
|
|
120
|
+
code = `module ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
121
|
+
item.name
|
|
122
|
+
)} {
|
|
99
123
|
use std::ascii::String;
|
|
100
|
-
${enumNames
|
|
124
|
+
${enumNames
|
|
125
|
+
.map(
|
|
126
|
+
name =>
|
|
127
|
+
`use ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
128
|
+
name
|
|
129
|
+
)}::${name};`
|
|
130
|
+
)
|
|
131
|
+
.join('\n')}
|
|
101
132
|
|
|
102
133
|
public struct ${item.name} has copy, drop , store {
|
|
103
134
|
${getStructAttrsWithType(item.fields)}
|
|
104
135
|
}
|
|
105
136
|
|
|
106
|
-
public fun new(${getStructAttrsWithType(
|
|
137
|
+
public fun new(${getStructAttrsWithType(
|
|
138
|
+
item.fields
|
|
139
|
+
)}): ${item.name} {
|
|
107
140
|
${item.name} {
|
|
108
141
|
${getStructAttrs(item.fields)}
|
|
109
142
|
}
|
|
@@ -114,36 +147,59 @@ export async function generateSchemaData(projectName: string, schemas: Record<st
|
|
|
114
147
|
${renderSetAttrsFunc(item.name, item.fields)}
|
|
115
148
|
${renderSetFunc(item.name, item.fields)}
|
|
116
149
|
}`;
|
|
117
|
-
|
|
150
|
+
}
|
|
118
151
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
152
|
+
await formatAndWriteMove(
|
|
153
|
+
code,
|
|
154
|
+
`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}_${convertToSnakeCase(
|
|
155
|
+
item.name
|
|
156
|
+
)}.move`,
|
|
157
|
+
'formatAndWriteMove'
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
console.log('ā
Schema Data Generation Complete\n');
|
|
127
163
|
}
|
|
128
164
|
|
|
129
|
-
function generateImport(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
165
|
+
function generateImport(
|
|
166
|
+
projectName: string,
|
|
167
|
+
schemaName: string,
|
|
168
|
+
schema: SchemaType
|
|
169
|
+
) {
|
|
170
|
+
if (schema.data) {
|
|
171
|
+
return schema.data
|
|
172
|
+
.map(item => {
|
|
173
|
+
return `use ${projectName}::${schemaName}_${convertToSnakeCase(
|
|
174
|
+
item.name
|
|
175
|
+
)}::${item.name};`;
|
|
176
|
+
})
|
|
177
|
+
.join('\n');
|
|
178
|
+
} else {
|
|
179
|
+
return '';
|
|
180
|
+
}
|
|
137
181
|
}
|
|
138
182
|
|
|
139
|
-
export async function generateSchemaStructure(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
183
|
+
export async function generateSchemaStructure(
|
|
184
|
+
projectName: string,
|
|
185
|
+
schemas: Record<string, SchemaType>,
|
|
186
|
+
path: string
|
|
187
|
+
) {
|
|
188
|
+
console.log('\nšØ Starting Schema Structure Generation...');
|
|
189
|
+
for (const schemaName in schemas) {
|
|
190
|
+
console.log(` āā Generating schema: ${schemaName}`);
|
|
191
|
+
console.log(
|
|
192
|
+
` āā Output path: ${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`
|
|
193
|
+
);
|
|
194
|
+
console.log(
|
|
195
|
+
` āā Structure fields: ${
|
|
196
|
+
Object.keys(schemas[schemaName].structure).length
|
|
197
|
+
}`
|
|
198
|
+
);
|
|
199
|
+
const schema = schemas[schemaName];
|
|
200
|
+
const schemaMoudle = `module ${projectName}::${schemaName}_schema {
|
|
144
201
|
use std::ascii::String;
|
|
145
202
|
use std::type_name;
|
|
146
|
-
use sui::transfer::{public_share_object};
|
|
147
203
|
use obelisk::dapps_system;
|
|
148
204
|
use obelisk::dapps_schema::Dapps;
|
|
149
205
|
use obelisk::storage_value::{Self, StorageValue};
|
|
@@ -152,53 +208,69 @@ export async function generateSchemaStructure(projectName: string, schemas: Reco
|
|
|
152
208
|
use ${projectName}::dapp_key::DappKey;
|
|
153
209
|
${generateImport(projectName, schemaName, schema)}
|
|
154
210
|
|
|
155
|
-
public struct ${capitalizeAndRemoveUnderscores(
|
|
211
|
+
public struct ${capitalizeAndRemoveUnderscores(
|
|
212
|
+
schemaName
|
|
213
|
+
)} has key, store {
|
|
156
214
|
id: UID,
|
|
157
215
|
${getStructAttrsWithType(schema.structure)}
|
|
158
216
|
}
|
|
159
217
|
|
|
160
|
-
${Object.entries(schema.structure)
|
|
161
|
-
|
|
218
|
+
${Object.entries(schema.structure)
|
|
219
|
+
.map(([key, value]) => {
|
|
220
|
+
return `public fun borrow_${key}(self: &${capitalizeAndRemoveUnderscores(
|
|
221
|
+
schemaName
|
|
222
|
+
)}) : &${value} {
|
|
162
223
|
&self.${key}
|
|
163
224
|
}
|
|
164
225
|
|
|
165
|
-
public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(
|
|
226
|
+
public(package) fun borrow_mut_${key}(self: &mut ${capitalizeAndRemoveUnderscores(
|
|
227
|
+
schemaName
|
|
228
|
+
)}): &mut ${value} {
|
|
166
229
|
&mut self.${key}
|
|
167
230
|
}
|
|
168
|
-
|
|
169
|
-
|
|
231
|
+
`;
|
|
232
|
+
})
|
|
233
|
+
.join('')}
|
|
170
234
|
|
|
171
|
-
public
|
|
235
|
+
public fun register(dapps: &mut Dapps, ctx: &mut TxContext): ${capitalizeAndRemoveUnderscores(
|
|
236
|
+
schemaName
|
|
237
|
+
)} {
|
|
172
238
|
let package_id = dapps_system::current_package_id<DappKey>();
|
|
173
239
|
assert!(dapps.borrow_metadata().contains_key(package_id), 0);
|
|
174
240
|
assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
|
|
175
|
-
let schema = type_name::get<${capitalizeAndRemoveUnderscores(
|
|
241
|
+
let schema = type_name::get<${capitalizeAndRemoveUnderscores(
|
|
242
|
+
schemaName
|
|
243
|
+
)}>().into_string();
|
|
176
244
|
assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);
|
|
177
|
-
|
|
178
|
-
|
|
245
|
+
dapps_system::add_schema<${capitalizeAndRemoveUnderscores(
|
|
246
|
+
schemaName
|
|
247
|
+
)}>(dapps, package_id, ctx);
|
|
248
|
+
${capitalizeAndRemoveUnderscores(schemaName)} {
|
|
179
249
|
id: object::new(ctx),
|
|
180
|
-
${Object.entries(schema.structure)
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
250
|
+
${Object.entries(schema.structure)
|
|
251
|
+
.map(([key, value]) => {
|
|
252
|
+
let storage_type = '';
|
|
253
|
+
if (value.includes('StorageValue')) {
|
|
254
|
+
storage_type = `storage_value::new()`;
|
|
255
|
+
} else if (value.includes('StorageMap')) {
|
|
256
|
+
storage_type = `storage_map::new()`;
|
|
257
|
+
} else if (
|
|
258
|
+
value.includes('StorageDoubleMap')
|
|
259
|
+
) {
|
|
260
|
+
storage_type = `storage_double_map::new()`;
|
|
261
|
+
}
|
|
262
|
+
return `${key}: ${storage_type},`;
|
|
263
|
+
})
|
|
264
|
+
.join(' ')}
|
|
265
|
+
}
|
|
195
266
|
}
|
|
196
267
|
|
|
197
268
|
}`;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
269
|
+
await formatAndWriteMove(
|
|
270
|
+
schemaMoudle,
|
|
271
|
+
`${path}/contracts/${projectName}/sources/codegen/schemas/${schemaName}.move`,
|
|
272
|
+
'formatAndWriteMove'
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
console.log('ā
Schema Structure Generation Complete\n');
|
|
276
|
+
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
import { ObeliskConfig } from
|
|
2
|
-
import { formatAndWriteMove } from
|
|
3
|
-
import { existsSync } from
|
|
1
|
+
import { ObeliskConfig } from '../../types';
|
|
2
|
+
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
4
|
|
|
5
|
-
export async function generateDeployHook(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
export async function generateDeployHook(
|
|
6
|
+
config: ObeliskConfig,
|
|
7
|
+
srcPrefix: string
|
|
8
|
+
) {
|
|
9
|
+
console.log('\nš Starting Deploy Hook Generation...');
|
|
10
|
+
console.log(
|
|
11
|
+
` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
if (
|
|
15
|
+
!existsSync(
|
|
16
|
+
`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`
|
|
17
|
+
)
|
|
18
|
+
) {
|
|
19
|
+
let code = `module ${config.name}::deploy_hook {
|
|
12
20
|
use obelisk::dapps_schema::Dapps;
|
|
13
21
|
use obelisk::dapps_system;
|
|
14
22
|
use ${config.name}::dapp_key::DappKey;
|
|
15
23
|
use std::ascii;
|
|
16
24
|
use sui::clock::Clock;
|
|
25
|
+
use sui::transfer::public_share_object;
|
|
17
26
|
#[test_only]
|
|
18
27
|
use obelisk::dapps_schema;
|
|
19
28
|
#[test_only]
|
|
@@ -32,12 +41,20 @@ export async function generateDeployHook(config: ObeliskConfig, srcPrefix: strin
|
|
|
32
41
|
clock,
|
|
33
42
|
ctx
|
|
34
43
|
);
|
|
35
|
-
${Object.keys(config.schemas)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
${Object.keys(config.schemas)
|
|
45
|
+
.map(schemaName => {
|
|
46
|
+
return `let ${schemaName} = ${config.name}::${schemaName}_schema::register(dapps, ctx);`;
|
|
47
|
+
})
|
|
48
|
+
.join('\n')}
|
|
39
49
|
// Logic that needs to be automated once the contract is deployed
|
|
40
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')}
|
|
41
58
|
}
|
|
42
59
|
|
|
43
60
|
#[test_only]
|
|
@@ -58,21 +75,22 @@ export async function generateDeployHook(config: ObeliskConfig, srcPrefix: strin
|
|
|
58
75
|
}
|
|
59
76
|
}
|
|
60
77
|
`;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
78
|
+
await formatAndWriteMove(
|
|
79
|
+
code,
|
|
80
|
+
`${srcPrefix}/contracts/${config.name}/sources/script/deploy_hook.move`,
|
|
81
|
+
'formatAndWriteMove'
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
console.log('ā
Deploy Hook Generation Complete\n');
|
|
67
85
|
}
|
|
68
86
|
|
|
69
87
|
export function generateMigrate(config: ObeliskConfig, srcPrefix: string) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
if (
|
|
89
|
+
!existsSync(
|
|
90
|
+
`${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`
|
|
91
|
+
)
|
|
92
|
+
) {
|
|
93
|
+
let code = `module ${config.name}::migrate {
|
|
76
94
|
use obelisk::world::{World, AdminCap};
|
|
77
95
|
|
|
78
96
|
/// Not the right admin for this world
|
|
@@ -92,11 +110,10 @@ export function generateMigrate(config: ObeliskConfig, srcPrefix: string) {
|
|
|
92
110
|
}
|
|
93
111
|
}
|
|
94
112
|
`;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
113
|
+
formatAndWriteMove(
|
|
114
|
+
code,
|
|
115
|
+
`${srcPrefix}/contracts/${config.name}/sources/script/migrate.move`,
|
|
116
|
+
'formatAndWriteMove'
|
|
117
|
+
);
|
|
118
|
+
}
|
|
101
119
|
}
|
|
102
|
-
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import { ObeliskConfig } from
|
|
2
|
-
import { formatAndWriteMove } from
|
|
3
|
-
import { existsSync } from
|
|
1
|
+
import { ObeliskConfig } from '../../types';
|
|
2
|
+
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
4
|
|
|
5
5
|
export async function generateSystem(config: ObeliskConfig, srcPrefix: string) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
console.log('\nāļø Starting System Generation...');
|
|
7
|
+
config.systems.map(async systemName => {
|
|
8
|
+
console.log(` āā Generating system: ${systemName}`);
|
|
9
|
+
console.log(
|
|
10
|
+
` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
if (
|
|
14
|
+
!existsSync(
|
|
15
|
+
`${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`
|
|
16
|
+
)
|
|
17
|
+
) {
|
|
18
|
+
let code = `module ${config.name}::${systemName}_system {
|
|
13
19
|
|
|
14
20
|
}
|
|
15
21
|
`;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
await formatAndWriteMove(
|
|
23
|
+
code,
|
|
24
|
+
`${srcPrefix}/contracts/${config.name}/sources/system/${systemName}.move`,
|
|
25
|
+
'formatAndWriteMove'
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
console.log('ā
System Generation Complete\n');
|
|
23
30
|
}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { ObeliskConfig } from '../../types';
|
|
2
2
|
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
3
|
|
|
4
|
-
export async function generateToml(
|
|
4
|
+
export async function generateToml(
|
|
5
|
+
config: ObeliskConfig,
|
|
6
|
+
srcPrefix: string,
|
|
7
|
+
frameworkId: string
|
|
8
|
+
) {
|
|
9
|
+
console.log('\nš Starting Move.toml Generation...');
|
|
10
|
+
console.log(
|
|
11
|
+
` āā Output path: ${srcPrefix}/contracts/${config.name}/Move.toml`
|
|
12
|
+
);
|
|
13
|
+
|
|
5
14
|
let code = `[package]
|
|
6
15
|
name = "${config.name}"
|
|
7
16
|
version = "0.0.1"
|
|
@@ -12,8 +21,8 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram
|
|
|
12
21
|
Obelisk = { git = "https://github.com/0xobelisk/obelisk-engine.git", subdir = "packages/obelisk-framework", rev = "main" }
|
|
13
22
|
|
|
14
23
|
[addresses]
|
|
15
|
-
sui =
|
|
16
|
-
obelisk =
|
|
24
|
+
sui = "0x2"
|
|
25
|
+
obelisk = "${frameworkId}"
|
|
17
26
|
${config.name} = "0x0"
|
|
18
27
|
`;
|
|
19
28
|
await formatAndWriteMove(
|
|
@@ -21,4 +30,5 @@ ${config.name} = "0x0"
|
|
|
21
30
|
`${srcPrefix}/contracts/${config.name}/Move.toml`,
|
|
22
31
|
'formatAndWriteMove'
|
|
23
32
|
);
|
|
33
|
+
console.log('ā
Move.toml Generation Complete\n');
|
|
24
34
|
}
|