@0xobelisk/sui-common 1.1.6 ā 1.1.8
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 +18 -1
- package/dist/index.js +59 -68
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
- package/src/codegen/debug.ts +3 -3
- package/src/codegen/index.ts +2 -2
- package/src/codegen/modules.d.ts +1 -1
- package/src/codegen/types/index.ts +26 -11
- package/src/codegen/utils/config.ts +14 -24
- package/src/codegen/utils/errors.ts +3 -4
- package/src/codegen/utils/format.ts +29 -32
- package/src/codegen/utils/formatAndWrite.ts +22 -19
- package/src/codegen/utils/posixPath.ts +1 -1
- package/src/codegen/utils/renderMove/common.ts +36 -41
- package/src/codegen/utils/renderMove/generateDappKey.ts +12 -15
- package/src/codegen/utils/renderMove/generateDefaultSchema.ts +20 -36
- package/src/codegen/utils/renderMove/generateError.ts +28 -33
- package/src/codegen/utils/renderMove/generateEvent.ts +65 -77
- package/src/codegen/utils/renderMove/generateInit.ts +14 -24
- package/src/codegen/utils/renderMove/generateSchema.ts +160 -197
- package/src/codegen/utils/renderMove/generateSchemaHub.ts +12 -15
- package/src/codegen/utils/renderMove/generateScript.ts +15 -32
- package/src/codegen/utils/renderMove/generateSystem.ts +3 -14
- package/src/codegen/utils/renderMove/generateToml.ts +10 -15
- package/src/codegen/utils/renderMove/schemaGen.ts +39 -47
- package/src/debug.ts +3 -3
- package/src/index.ts +3 -2
- package/src/modules.d.ts +2 -2
- package/src/parseData/index.ts +1 -1
- package/src/parseData/parser/index.ts +42 -42
- package/src/primitives/index.ts +8 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
3
|
-
import { formatMove, formatTypescript } from
|
|
4
|
-
import { debug } from
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { formatMove, formatTypescript } from './format';
|
|
4
|
+
import { debug } from '../debug';
|
|
5
5
|
|
|
6
6
|
export async function formatAndWriteMove(
|
|
7
7
|
output: string,
|
|
@@ -9,27 +9,30 @@ export async function formatAndWriteMove(
|
|
|
9
9
|
logPrefix?: string
|
|
10
10
|
): Promise<void> {
|
|
11
11
|
const formattedOutput = await formatMove(output);
|
|
12
|
-
let schemaPrefix =
|
|
13
|
-
` // Copyright (c) Obelisk Labs, Inc.
|
|
12
|
+
let schemaPrefix = ` // Copyright (c) Obelisk Labs, Inc.
|
|
14
13
|
// SPDX-License-Identifier: Apache-2.0
|
|
15
14
|
#[allow(unused_use)]
|
|
16
15
|
|
|
17
16
|
/* Autogenerated file. Do not edit manually. */
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
`;
|
|
20
19
|
|
|
21
|
-
let initPrefix = `#[test_only]
|
|
20
|
+
let initPrefix = `#[test_only]`;
|
|
22
21
|
|
|
23
|
-
let code = schemaPrefix + formattedOutput
|
|
22
|
+
let code = schemaPrefix + formattedOutput;
|
|
24
23
|
|
|
25
|
-
let deployHookPrefix = `#[allow(lint(share_owned))]
|
|
24
|
+
let deployHookPrefix = `#[allow(lint(share_owned))]`;
|
|
26
25
|
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
code =
|
|
26
|
+
if (
|
|
27
|
+
fullOutputPath.includes('.toml') ||
|
|
28
|
+
fullOutputPath.includes('system') ||
|
|
29
|
+
fullOutputPath.includes('migrate')
|
|
30
|
+
) {
|
|
31
|
+
code = formattedOutput;
|
|
32
|
+
} else if (fullOutputPath.includes('init')) {
|
|
33
|
+
code = initPrefix + formattedOutput;
|
|
34
|
+
} else if (fullOutputPath.includes('genesis')) {
|
|
35
|
+
code = deployHookPrefix + formattedOutput;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
await fs.mkdir(path.dirname(fullOutputPath), { recursive: true });
|
|
@@ -44,9 +47,9 @@ export async function formatAndWriteMove(
|
|
|
44
47
|
* @param logPrefix prefix for debug logs
|
|
45
48
|
*/
|
|
46
49
|
export async function formatAndWriteTypescript(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
output: string,
|
|
51
|
+
fullOutputPath: string,
|
|
52
|
+
logPrefix: string
|
|
50
53
|
): Promise<void> {
|
|
51
54
|
const formattedOutput = await formatTypescript(output);
|
|
52
55
|
|
|
@@ -2,21 +2,21 @@ import { MoveType } from '../../types';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
|
|
4
4
|
export function deleteFolderRecursive(path: string) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
if (fs.existsSync(path)) {
|
|
6
|
+
fs.readdirSync(path).forEach((file) => {
|
|
7
|
+
const curPath = `${path}/${file}`;
|
|
8
|
+
if (fs.lstatSync(curPath).isDirectory()) {
|
|
9
|
+
deleteFolderRecursive(curPath);
|
|
10
|
+
} else {
|
|
11
|
+
fs.unlinkSync(curPath);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
fs.rmdirSync(path);
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export function capitalizeFirstLetter(input: string): string {
|
|
19
|
-
|
|
19
|
+
return input.charAt(0).toUpperCase() + input.slice(1);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -25,17 +25,15 @@ export function capitalizeFirstLetter(input: string): string {
|
|
|
25
25
|
* @param prefixArgs
|
|
26
26
|
* @return [ name, age, birth_time ]
|
|
27
27
|
*/
|
|
28
|
-
export function getStructAttrs(
|
|
29
|
-
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
.map(([key, _]) => `${key}`)
|
|
33
|
-
.join(',');
|
|
28
|
+
export function getStructAttrs(values: Record<string, string> | string): string {
|
|
29
|
+
return Object.entries(values)
|
|
30
|
+
.map(([key, _]) => `${key}`)
|
|
31
|
+
.join(',');
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
function isAddress(str: string): boolean {
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const regex = /^0x[a-fA-F0-9]+$/;
|
|
36
|
+
return regex.test(str);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
/**
|
|
@@ -44,10 +42,8 @@ function isAddress(str: string): boolean {
|
|
|
44
42
|
* @return ( bool , u64 , u64)
|
|
45
43
|
*/
|
|
46
44
|
// export function getStructTypes(values: SchemaType): string {
|
|
47
|
-
export function getStructTypes(
|
|
48
|
-
|
|
49
|
-
): string {
|
|
50
|
-
return `(${Object.entries(values).map(([_, type]) => `${type}`)})`;
|
|
45
|
+
export function getStructTypes(values: Record<string, string>): string {
|
|
46
|
+
return `(${Object.entries(values).map(([_, type]) => `${type}`)})`;
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
/**
|
|
@@ -55,30 +51,29 @@ export function getStructTypes(
|
|
|
55
51
|
* @param values
|
|
56
52
|
* @return Attributes and types of the struct. [ name: string, age: u64 ]
|
|
57
53
|
*/
|
|
58
|
-
export function getStructAttrsWithType(
|
|
59
|
-
|
|
60
|
-
): string[] {
|
|
61
|
-
return Object.entries(values).map(([key, type]) => `${key}: ${type}`);
|
|
54
|
+
export function getStructAttrsWithType(values: Record<string, string>): string[] {
|
|
55
|
+
return Object.entries(values).map(([key, type]) => `${key}: ${type}`);
|
|
62
56
|
}
|
|
63
57
|
|
|
64
58
|
/**
|
|
65
59
|
* @param values
|
|
66
60
|
* @return [ data.name, data.age ]
|
|
67
61
|
*/
|
|
68
|
-
export function getStructAttrsQuery(
|
|
69
|
-
|
|
70
|
-
): string[] {
|
|
71
|
-
return Object.entries(values).map(([key, _]) => `self.${key}`);
|
|
62
|
+
export function getStructAttrsQuery(values: Record<string, string>): string[] {
|
|
63
|
+
return Object.entries(values).map(([key, _]) => `self.${key}`);
|
|
72
64
|
}
|
|
73
65
|
|
|
74
66
|
export function containsString(obj: Record<string, any>, searchString: string): boolean {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
67
|
+
for (const key in obj) {
|
|
68
|
+
if (obj.hasOwnProperty(key)) {
|
|
69
|
+
const value = obj[key];
|
|
70
|
+
if (
|
|
71
|
+
(typeof value === 'string' && value === searchString) ||
|
|
72
|
+
(typeof value === 'string' && value.includes(searchString) && value.includes('>'))
|
|
73
|
+
) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
84
79
|
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { DubheConfig } from '../../types';
|
|
2
2
|
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
3
|
|
|
4
|
-
export async function generateDappKey(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
console.log(
|
|
10
|
-
` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`
|
|
11
|
-
);
|
|
4
|
+
export async function generateDappKey(config: DubheConfig, srcPrefix: string) {
|
|
5
|
+
console.log('\nš Starting DappKey Generation...');
|
|
6
|
+
console.log(
|
|
7
|
+
` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`
|
|
8
|
+
);
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
let code = `module ${config.name}::${config.name}_dapp_key {
|
|
14
11
|
\t/// Authorization token for the app.
|
|
15
12
|
\tpublic struct DappKey has drop {}
|
|
16
13
|
|
|
@@ -19,10 +16,10 @@ export async function generateDappKey(
|
|
|
19
16
|
\t}
|
|
20
17
|
}
|
|
21
18
|
`;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
await formatAndWriteMove(
|
|
20
|
+
code,
|
|
21
|
+
`${srcPrefix}/contracts/${config.name}/sources/codegen/dapp_key.move`,
|
|
22
|
+
'formatAndWriteMove'
|
|
23
|
+
);
|
|
24
|
+
console.log('ā
DappKey Generation Complete\n');
|
|
28
25
|
}
|
|
@@ -3,19 +3,16 @@ import { formatAndWriteMove } from '../formatAndWrite';
|
|
|
3
3
|
import { existsSync } from 'fs';
|
|
4
4
|
import { capitalizeAndRemoveUnderscores } from './generateSchema';
|
|
5
5
|
|
|
6
|
-
export async function generateDefaultSchema(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
)
|
|
10
|
-
await generateDappSchemaMetadata(config, srcPrefix);
|
|
11
|
-
await generateDappSchema(config, srcPrefix);
|
|
12
|
-
await generateDappSystem(config, srcPrefix);
|
|
6
|
+
export async function generateDefaultSchema(config: DubheConfig, srcPrefix: string) {
|
|
7
|
+
await generateDappSchemaMetadata(config, srcPrefix);
|
|
8
|
+
await generateDappSchema(config, srcPrefix);
|
|
9
|
+
await generateDappSystem(config, srcPrefix);
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
async function generateDappSchemaMetadata(config: DubheConfig, srcPrefix: string) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
const path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/metadata.move`;
|
|
14
|
+
if (!existsSync(path)) {
|
|
15
|
+
let code = `module ${config.name}::${config.name}_dapp_metadata {
|
|
19
16
|
use std::ascii::String;
|
|
20
17
|
|
|
21
18
|
public struct DappMetadata has drop, copy, store {
|
|
@@ -112,19 +109,14 @@ async function generateDappSchemaMetadata(config: DubheConfig, srcPrefix: string
|
|
|
112
109
|
|
|
113
110
|
}
|
|
114
111
|
`;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
path,
|
|
118
|
-
'formatAndWriteMove'
|
|
119
|
-
);
|
|
120
|
-
}
|
|
112
|
+
await formatAndWriteMove(code, path, 'formatAndWriteMove');
|
|
113
|
+
}
|
|
121
114
|
}
|
|
122
115
|
|
|
123
|
-
|
|
124
116
|
async function generateDappSchema(config: DubheConfig, srcPrefix: string) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
117
|
+
const path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/schema.move`;
|
|
118
|
+
if (!existsSync(path)) {
|
|
119
|
+
let code = `module ${config.name}::${config.name}_dapp_schema {
|
|
128
120
|
use ${config.name}::${config.name}_dapp_metadata::DappMetadata;
|
|
129
121
|
use dubhe::storage_value;
|
|
130
122
|
use dubhe::storage_value::StorageValue;
|
|
@@ -226,18 +218,14 @@ async function generateDappSchema(config: DubheConfig, srcPrefix: string) {
|
|
|
226
218
|
}
|
|
227
219
|
}
|
|
228
220
|
`;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
path,
|
|
232
|
-
'formatAndWriteMove'
|
|
233
|
-
);
|
|
234
|
-
}
|
|
221
|
+
await formatAndWriteMove(code, path, 'formatAndWriteMove');
|
|
222
|
+
}
|
|
235
223
|
}
|
|
236
224
|
|
|
237
225
|
async function generateDappSystem(config: DubheConfig, srcPrefix: string) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
226
|
+
const path = `${srcPrefix}/contracts/${config.name}/sources/codegen/dapp/system.move`;
|
|
227
|
+
if (!existsSync(path)) {
|
|
228
|
+
let code = `module ${config.name}::${config.name}_dapp_system {
|
|
241
229
|
use std::ascii::String;
|
|
242
230
|
use std::ascii;
|
|
243
231
|
use dubhe::type_info;
|
|
@@ -325,10 +313,6 @@ async function generateDappSystem(config: DubheConfig, srcPrefix: string) {
|
|
|
325
313
|
|
|
326
314
|
|
|
327
315
|
`;
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
'formatAndWriteMove'
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
316
|
+
await formatAndWriteMove(code, path, 'formatAndWriteMove');
|
|
317
|
+
}
|
|
318
|
+
}
|
|
@@ -1,42 +1,37 @@
|
|
|
1
|
-
import {BaseType, ErrorData, SchemaType} from '../../types';
|
|
1
|
+
import { BaseType, ErrorData, SchemaType } from '../../types';
|
|
2
2
|
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
getStructAttrsWithType,
|
|
5
|
+
getStructAttrs,
|
|
6
|
+
getStructTypes,
|
|
7
|
+
getStructAttrsQuery
|
|
8
8
|
} from './common';
|
|
9
9
|
|
|
10
10
|
function convertToSnakeCase(input: string): string {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
return input
|
|
12
|
+
.replace(/([A-Z])/g, '_$1')
|
|
13
|
+
.toLowerCase()
|
|
14
|
+
.replace(/^_/, '');
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export async function generateSchemaError(
|
|
18
|
-
|
|
19
|
-
errors: ErrorData,
|
|
20
|
-
path: string
|
|
21
|
-
) {
|
|
22
|
-
console.log('\nš¦ Starting Schema Error Generation...');
|
|
17
|
+
export async function generateSchemaError(projectName: string, errors: ErrorData, path: string) {
|
|
18
|
+
console.log('\nš¦ Starting Schema Error Generation...');
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
${Object.entries(errors)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const ${name}: vector<u8> = b"${message}";
|
|
30
|
-
public fun ${
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
let code = `module ${projectName}::${projectName}_errors {
|
|
21
|
+
${Object.entries(errors)
|
|
22
|
+
.map(([name, message]) => {
|
|
23
|
+
console.log(` āā ${name}: ${message}`);
|
|
24
|
+
return `#[error]
|
|
25
|
+
const ${name.toUpperCase()}: vector<u8> = b"${message}";
|
|
26
|
+
public fun ${name}_error(condition: bool) { assert!(condition, ${name.toUpperCase()}) }
|
|
27
|
+
`;
|
|
28
|
+
})
|
|
29
|
+
.join('\n')}
|
|
30
|
+
}`;
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
console.log('ā
Schema Error Generation Complete\n');
|
|
42
|
-
}
|
|
32
|
+
await formatAndWriteMove(
|
|
33
|
+
code,
|
|
34
|
+
`${path}/contracts/${projectName}/sources/codegen/errors.move`,
|
|
35
|
+
'formatAndWriteMove'
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -1,110 +1,98 @@
|
|
|
1
|
-
import {BaseType, EventData, SchemaData, SchemaType} from '../../types';
|
|
1
|
+
import { BaseType, EventData, SchemaData, SchemaType } from '../../types';
|
|
2
2
|
import { formatAndWriteMove } from '../formatAndWrite';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
getStructAttrsWithType,
|
|
5
|
+
getStructAttrs,
|
|
6
|
+
getStructTypes,
|
|
7
|
+
getStructAttrsQuery
|
|
8
8
|
} from './common';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
17
|
-
})
|
|
18
|
-
.join('');
|
|
10
|
+
// account_not_found => AccountNotFound,
|
|
11
|
+
function toPascalCase(str: string): string {
|
|
12
|
+
return str
|
|
13
|
+
.split('_')
|
|
14
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
15
|
+
.join('');
|
|
19
16
|
}
|
|
20
17
|
|
|
21
18
|
function convertToSnakeCase(input: string): string {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
return input
|
|
20
|
+
.replace(/([A-Z])/g, '_$1')
|
|
21
|
+
.toLowerCase()
|
|
22
|
+
.replace(/^_/, '');
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
function generateImport(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})
|
|
40
|
-
.join('\n');
|
|
41
|
-
} else {
|
|
42
|
-
return '';
|
|
43
|
-
}
|
|
25
|
+
function generateImport(projectName: string, data: Record<string, SchemaData> | null) {
|
|
26
|
+
if (data != null) {
|
|
27
|
+
const names = Object.keys(data);
|
|
28
|
+
return names
|
|
29
|
+
.map((name) => {
|
|
30
|
+
return `use ${projectName}::${projectName}_${convertToSnakeCase(name)}::${name};`;
|
|
31
|
+
})
|
|
32
|
+
.join('\n');
|
|
33
|
+
} else {
|
|
34
|
+
return '';
|
|
35
|
+
}
|
|
44
36
|
}
|
|
45
37
|
|
|
46
38
|
export async function generateSchemaEvent(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
projectName: string,
|
|
40
|
+
data: Record<string, SchemaData> | null,
|
|
41
|
+
events: Record<string, EventData>,
|
|
42
|
+
path: string
|
|
51
43
|
) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
` āā Generating ${name} event: ${fields}`
|
|
58
|
-
);
|
|
44
|
+
console.log('\nš¦ Starting Schema Event Generation...');
|
|
45
|
+
for (const key of Object.keys(events)) {
|
|
46
|
+
const name = key;
|
|
47
|
+
const fields = events[key];
|
|
48
|
+
console.log(` āā ${name} event: ${JSON.stringify(fields)}`);
|
|
59
49
|
|
|
60
|
-
|
|
50
|
+
let code = `module ${projectName}::${projectName}_${name}_event {
|
|
61
51
|
use sui::event;
|
|
62
52
|
use std::ascii::String;
|
|
63
53
|
${generateImport(projectName, data)}
|
|
64
54
|
|
|
65
|
-
public struct ${name}Event has copy, drop {
|
|
55
|
+
public struct ${toPascalCase(name)}Event has copy, drop {
|
|
66
56
|
${getStructAttrsWithType(fields as Record<string, string>)}
|
|
67
57
|
}
|
|
68
58
|
|
|
69
|
-
public fun new(${getStructAttrsWithType(fields as Record<string, string>)}): ${name}Event {
|
|
70
|
-
${name}Event {
|
|
59
|
+
public fun new(${getStructAttrsWithType(fields as Record<string, string>)}): ${toPascalCase(name)}Event {
|
|
60
|
+
${toPascalCase(name)}Event {
|
|
71
61
|
${getStructAttrs(fields as Record<string, string>)}
|
|
72
62
|
}
|
|
73
63
|
}
|
|
74
64
|
}`;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
);
|
|
82
|
-
}
|
|
65
|
+
await formatAndWriteMove(
|
|
66
|
+
code,
|
|
67
|
+
`${path}/contracts/${projectName}/sources/codegen/data/${name}_event.move`,
|
|
68
|
+
'formatAndWriteMove'
|
|
69
|
+
);
|
|
70
|
+
}
|
|
83
71
|
|
|
84
|
-
|
|
72
|
+
let code = `module ${projectName}::${projectName}_events {
|
|
85
73
|
use std::ascii::{String, string};
|
|
86
74
|
${generateImport(projectName, data)}
|
|
87
|
-
${Object.entries(events)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
use ${projectName}::${projectName}_${
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
75
|
+
${Object.entries(events)
|
|
76
|
+
.map(([name, fields]) => {
|
|
77
|
+
return `
|
|
78
|
+
use ${projectName}::${projectName}_${name}_event::${toPascalCase(name)}Event;
|
|
79
|
+
use ${projectName}::${projectName}_${name}_event;
|
|
80
|
+
public fun ${name}_event(${getStructAttrsWithType(fields as Record<string, string>)}) {
|
|
81
|
+
dubhe::storage_event::emit_set_record<${toPascalCase(name)}Event, ${toPascalCase(name)}Event, ${toPascalCase(name)}Event>(
|
|
82
|
+
string(b"${name}_event"),
|
|
94
83
|
option::none(),
|
|
95
84
|
option::none(),
|
|
96
|
-
option::some(${projectName}_${
|
|
85
|
+
option::some(${projectName}_${name}_event::new(${getStructAttrs(fields as Record<string, string>)}))
|
|
97
86
|
)
|
|
98
87
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
`;
|
|
89
|
+
})
|
|
90
|
+
.join('\n')}
|
|
91
|
+
}`;
|
|
102
92
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
console.log('ā
Schema Event Generation Complete\n');
|
|
110
|
-
}
|
|
93
|
+
await formatAndWriteMove(
|
|
94
|
+
code,
|
|
95
|
+
`${path}/contracts/${projectName}/sources/codegen/events.move`,
|
|
96
|
+
'formatAndWriteMove'
|
|
97
|
+
);
|
|
98
|
+
}
|
|
@@ -3,16 +3,8 @@ import { formatAndWriteMove } from '../formatAndWrite';
|
|
|
3
3
|
import { existsSync } from 'fs';
|
|
4
4
|
import { capitalizeAndRemoveUnderscores } from './generateSchema';
|
|
5
5
|
|
|
6
|
-
export async function generateInit(
|
|
7
|
-
|
|
8
|
-
srcPrefix: string
|
|
9
|
-
) {
|
|
10
|
-
console.log('\nš Starting Init Generation...');
|
|
11
|
-
console.log(
|
|
12
|
-
` āā Output path: ${srcPrefix}/contracts/${config.name}/sources/tests/init.move`
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
let init_test_code = `module ${config.name}::${config.name}_init_test {
|
|
6
|
+
export async function generateInit(config: DubheConfig, srcPrefix: string) {
|
|
7
|
+
let init_test_code = `module ${config.name}::${config.name}_init_test {
|
|
16
8
|
use ${config.name}::${config.name}_dapp_schema::Dapp;
|
|
17
9
|
use sui::clock;
|
|
18
10
|
use sui::test_scenario;
|
|
@@ -30,13 +22,13 @@ export async function generateInit(
|
|
|
30
22
|
}
|
|
31
23
|
}
|
|
32
24
|
`;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
await formatAndWriteMove(
|
|
26
|
+
init_test_code,
|
|
27
|
+
`${srcPrefix}/contracts/${config.name}/sources/tests/init.move`,
|
|
28
|
+
'formatAndWriteMove'
|
|
29
|
+
);
|
|
38
30
|
|
|
39
|
-
|
|
31
|
+
let init_code = `module ${config.name}::${config.name}_genesis {
|
|
40
32
|
use std::ascii::string;
|
|
41
33
|
|
|
42
34
|
use sui::clock::Clock;
|
|
@@ -56,11 +48,9 @@ export async function generateInit(
|
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
50
|
`;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
console.log('ā
Init Generation Complete\n');
|
|
66
|
-
}
|
|
51
|
+
await formatAndWriteMove(
|
|
52
|
+
init_code,
|
|
53
|
+
`${srcPrefix}/contracts/${config.name}/sources/codegen/genesis.move`,
|
|
54
|
+
'formatAndWriteMove'
|
|
55
|
+
);
|
|
56
|
+
}
|