@0xobelisk/sui-common 0.5.22 → 0.5.24
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 +7 -2
- package/dist/index.js +415 -191
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/codegen/types/index.ts +6 -0
- package/src/codegen/utils/formatAndWrite.ts +6 -4
- package/src/codegen/utils/renderMove/generateDefaultSchema.ts +327 -0
- package/src/codegen/utils/renderMove/generateError.ts +51 -0
- package/src/codegen/utils/renderMove/generateEvent.ts +3 -3
- package/src/codegen/utils/renderMove/generateInit.ts +40 -0
- package/src/codegen/utils/renderMove/generateSchema.ts +18 -14
- package/src/codegen/utils/renderMove/generateScript.ts +78 -82
- package/src/codegen/utils/renderMove/generateToml.ts +1 -2
- package/src/codegen/utils/renderMove/schemaGen.ts +9 -25
|
@@ -3,6 +3,20 @@ import { formatAndWriteMove } from '../formatAndWrite';
|
|
|
3
3
|
import { existsSync } from 'fs';
|
|
4
4
|
import { capitalizeAndRemoveUnderscores } from './generateSchema';
|
|
5
5
|
|
|
6
|
+
import { readFileSync } from 'fs';
|
|
7
|
+
|
|
8
|
+
export function extractLogicAndAuthorizationContent(filePath: string): string {
|
|
9
|
+
const fileContent = readFileSync(filePath, 'utf-8');
|
|
10
|
+
const logicAndAuthRegex = /\/\/ Logic that needs to be automated once the contract is deployed\s*\{([\s\S]*?)\}\s*;\s*\/\/ Authorize schemas and public share objects/;
|
|
11
|
+
const match = fileContent.match(logicAndAuthRegex);
|
|
12
|
+
|
|
13
|
+
if (match) {
|
|
14
|
+
return match[1].trim();
|
|
15
|
+
} else {
|
|
16
|
+
throw new Error('Logic and authorization block not found in the file.');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
6
20
|
export async function generateDeployHook(
|
|
7
21
|
config: DubheConfig,
|
|
8
22
|
srcPrefix: string
|
|
@@ -12,89 +26,71 @@ export async function generateDeployHook(
|
|
|
12
26
|
` └─ Output path: ${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`
|
|
13
27
|
);
|
|
14
28
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
#[test_only]
|
|
34
|
-
use sui::clock;
|
|
35
|
-
#[test_only]
|
|
36
|
-
use sui::coin;
|
|
37
|
-
#[test_only]
|
|
38
|
-
use sui::test_scenario;
|
|
39
|
-
#[test_only]
|
|
40
|
-
use sui::package;
|
|
41
|
-
#[test_only]
|
|
42
|
-
use ${config.name}::schema_hub;
|
|
43
|
-
#[test_only]
|
|
44
|
-
use dubhe::dapps_schema;
|
|
45
|
-
#[test_only]
|
|
46
|
-
use sui::test_scenario::Scenario;
|
|
47
|
-
|
|
48
|
-
public entry fun run(schema_hub: &mut SchemaHub, dapps: &mut Dapps, cap: &UpgradeCap, clock: &Clock, coin: Coin<SUI>, ctx: &mut TxContext) {
|
|
49
|
-
// Register the dapp to dubhe.
|
|
50
|
-
dapps_system::register(dapps,cap,string(b"${config.name}"),string(b"${config.description}"),clock,coin,ctx);
|
|
51
|
-
// Create schemas
|
|
52
|
-
${Object.keys(config.schemas).map(schemaName => {
|
|
53
|
-
return `let ${schemaName} = ${config.name}::${schemaName}_schema::create(ctx);`;
|
|
54
|
-
}).join('\n')}
|
|
55
|
-
// Logic that needs to be automated once the contract is deployed
|
|
56
|
-
${`\n`}
|
|
57
|
-
${`\n`}
|
|
58
|
-
|
|
59
|
-
// Authorize schemas and public share objects
|
|
60
|
-
${Object.keys(config.schemas).map(schemaName => {
|
|
61
|
-
return `
|
|
62
|
-
schema_hub.authorize_schema<${capitalizeAndRemoveUnderscores(schemaName)}>();
|
|
63
|
-
public_share_object(${schemaName});
|
|
64
|
-
`;
|
|
29
|
+
const schemas = Object.keys(config.schemas).map(schemaName => { return `_${schemaName}: &mut ${capitalizeAndRemoveUnderscores(schemaName)}`}).join(',')
|
|
30
|
+
const importSchemas = Object.keys(config.schemas).map(schemaName => { return `use ${config.name}::${schemaName}_schema::${capitalizeAndRemoveUnderscores(schemaName)};`}).join('\n')
|
|
31
|
+
const path = `${srcPrefix}/contracts/${config.name}/sources/scripts/deploy_hook.move`;
|
|
32
|
+
let code = '';
|
|
33
|
+
if (!existsSync(path)) {
|
|
34
|
+
code = `module ${config.name}::deploy_hook {
|
|
35
|
+
use std::ascii::string;
|
|
36
|
+
use sui::clock::Clock;
|
|
37
|
+
use ${config.name}::dapp_system;
|
|
38
|
+
${importSchemas}
|
|
39
|
+
public entry fun run(clock: &Clock, ctx: &mut TxContext) {
|
|
40
|
+
// Create a dapp.
|
|
41
|
+
let mut dapp = dapp_system::create(string(b"${config.name}"),string(b"${config.description}"), clock , ctx);
|
|
42
|
+
|
|
43
|
+
// Create schemas
|
|
44
|
+
${Object.keys(config.schemas).map(schemaName => {
|
|
45
|
+
return `let mut ${schemaName} = ${config.name}::${schemaName}_schema::create(ctx);`;
|
|
65
46
|
}).join('\n')}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
47
|
+
// Logic that needs to be automated once the contract is deployed
|
|
48
|
+
{
|
|
49
|
+
};
|
|
50
|
+
// Authorize schemas and public share objects
|
|
51
|
+
${Object.keys(config.schemas).map(schemaName => {
|
|
52
|
+
return `
|
|
53
|
+
dapp.add_schema<${capitalizeAndRemoveUnderscores(schemaName)}>(${schemaName}, ctx);
|
|
54
|
+
`;
|
|
55
|
+
}).join('\n')}
|
|
56
|
+
sui::transfer::public_share_object(dapp);
|
|
57
|
+
}
|
|
58
|
+
}` } else {
|
|
59
|
+
const content = extractLogicAndAuthorizationContent(path);
|
|
60
|
+
code = `module ${config.name}::deploy_hook {
|
|
61
|
+
use std::ascii::string;
|
|
62
|
+
use sui::clock::Clock;
|
|
63
|
+
use merak::dapp_system;
|
|
64
|
+
${importSchemas}
|
|
65
|
+
public entry fun run(clock: &Clock, ctx: &mut TxContext) {
|
|
66
|
+
// Create a dapp.
|
|
67
|
+
let mut dapp = dapp_system::create(string(b"${config.name}"),string(b"${config.description}"), clock , ctx);
|
|
68
|
+
|
|
69
|
+
// Create schemas
|
|
70
|
+
${Object.keys(config.schemas).map(schemaName => {
|
|
71
|
+
return `let mut ${schemaName} = ${config.name}::${schemaName}_schema::create(ctx);`;
|
|
72
|
+
}).join('\n')}
|
|
73
|
+
// Logic that needs to be automated once the contract is deployed
|
|
74
|
+
|
|
75
|
+
{
|
|
76
|
+
${content}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Authorize schemas and public share objects
|
|
80
|
+
${Object.keys(config.schemas).map(schemaName => {
|
|
81
|
+
return `
|
|
82
|
+
dapp.add_schema<${capitalizeAndRemoveUnderscores(schemaName)}>(${schemaName}, ctx);
|
|
83
|
+
`;
|
|
84
|
+
}).join('\n')}
|
|
85
|
+
sui::transfer::public_share_object(dapp);
|
|
86
|
+
}
|
|
87
|
+
}`
|
|
97
88
|
}
|
|
89
|
+
await formatAndWriteMove(
|
|
90
|
+
code,
|
|
91
|
+
path,
|
|
92
|
+
'formatAndWriteMove'
|
|
93
|
+
);
|
|
98
94
|
console.log('✅ Deploy Hook Generation Complete\n');
|
|
99
95
|
}
|
|
100
96
|
|
|
@@ -105,7 +101,7 @@ export async function generateMigrate(config: DubheConfig, srcPrefix: string) {
|
|
|
105
101
|
)
|
|
106
102
|
) {
|
|
107
103
|
let code = `module ${config.name}::migrate {
|
|
108
|
-
const ON_CHAIN_VERSION: u32 =
|
|
104
|
+
const ON_CHAIN_VERSION: u32 = 1;
|
|
109
105
|
|
|
110
106
|
public fun on_chain_version(): u32 {
|
|
111
107
|
ON_CHAIN_VERSION
|
|
@@ -4,7 +4,6 @@ import { formatAndWriteMove } from '../formatAndWrite';
|
|
|
4
4
|
export async function generateToml(
|
|
5
5
|
config: DubheConfig,
|
|
6
6
|
srcPrefix: string,
|
|
7
|
-
frameworkId: string
|
|
8
7
|
) {
|
|
9
8
|
console.log('\n📄 Starting Move.toml Generation...');
|
|
10
9
|
console.log(
|
|
@@ -18,7 +17,7 @@ edition = "2024"
|
|
|
18
17
|
|
|
19
18
|
[dependencies]
|
|
20
19
|
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.38.3" }
|
|
21
|
-
Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-testnet-v1.
|
|
20
|
+
Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "dubhe-testnet-v1.1.0" }
|
|
22
21
|
|
|
23
22
|
[addresses]
|
|
24
23
|
sui = "0x2"
|
|
@@ -8,25 +8,14 @@ import { generateDappKey } from './generateDappKey';
|
|
|
8
8
|
import { generateSchemaEvent } from './generateEvent';
|
|
9
9
|
import { generateSystem } from './generateSystem';
|
|
10
10
|
import { generateSchemaHub } from './generateSchemaHub';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
): string {
|
|
15
|
-
switch (network) {
|
|
16
|
-
case 'testnet':
|
|
17
|
-
return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
|
|
18
|
-
case 'localnet':
|
|
19
|
-
return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
|
|
20
|
-
default:
|
|
21
|
-
return '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
|
|
22
|
-
}
|
|
23
|
-
}
|
|
11
|
+
import { generateSchemaError } from './generateError';
|
|
12
|
+
import {generateDefaultSchema} from "./generateDefaultSchema";
|
|
13
|
+
import {generateInit} from "./generateInit";
|
|
24
14
|
|
|
25
15
|
export async function schemaGen(
|
|
26
16
|
config: DubheConfig,
|
|
27
17
|
srcPrefix?: string,
|
|
28
|
-
network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
29
|
-
frameworkId?: string,
|
|
18
|
+
network?: 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
30
19
|
) {
|
|
31
20
|
console.log('\n🚀 Starting Schema Generation Process...');
|
|
32
21
|
console.log('📋 Project Configuration:');
|
|
@@ -35,16 +24,9 @@ export async function schemaGen(
|
|
|
35
24
|
` ├─ Description: ${config.description || 'No description provided'}`,
|
|
36
25
|
);
|
|
37
26
|
console.log(` ├─ Network: ${network || 'testnet'}`);
|
|
38
|
-
console.log(
|
|
39
|
-
` └─ Framework ID: ${
|
|
40
|
-
frameworkId || matchFrameworkId(network ?? 'testnet')
|
|
41
|
-
}\n`,
|
|
42
|
-
);
|
|
43
27
|
|
|
44
28
|
const path = srcPrefix ?? process.cwd();
|
|
45
29
|
|
|
46
|
-
frameworkId = frameworkId || matchFrameworkId(network ?? 'testnet');
|
|
47
|
-
|
|
48
30
|
if (existsSync(`${path}/contracts/${config.name}`)) {
|
|
49
31
|
deleteFolderRecursive(
|
|
50
32
|
`${path}/contracts/${config.name}/sources/codegen`,
|
|
@@ -52,7 +34,7 @@ export async function schemaGen(
|
|
|
52
34
|
}
|
|
53
35
|
|
|
54
36
|
if (!existsSync(`${path}/contracts/${config.name}/Move.toml`)) {
|
|
55
|
-
await generateToml(config, path
|
|
37
|
+
await generateToml(config, path);
|
|
56
38
|
}
|
|
57
39
|
|
|
58
40
|
if (
|
|
@@ -66,8 +48,10 @@ export async function schemaGen(
|
|
|
66
48
|
await generateSchemaData(config.name, config.schemas, path);
|
|
67
49
|
await generateSchemaStructure(config.name, config.schemas, path);
|
|
68
50
|
await generateSchemaEvent(config.name, config.schemas, path);
|
|
69
|
-
await
|
|
70
|
-
|
|
51
|
+
await generateSchemaError(config.name, config.schemas, path);
|
|
52
|
+
|
|
53
|
+
await generateDefaultSchema(config, path);
|
|
54
|
+
await generateInit(config, path);
|
|
71
55
|
await generateSystem(config, path);
|
|
72
56
|
await generateMigrate(config, path);
|
|
73
57
|
|