create-dubhe 0.0.4 → 0.0.5
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.mjs +44 -42
- package/package.json +1 -1
- package/template/101/rooch-template/.dockerignore +7 -0
- package/template/101/rooch-template/.eslintrc.json +3 -0
- package/template/101/rooch-template/.prettierrc +8 -0
- package/template/101/rooch-template/Dockerfile +52 -0
- package/template/101/rooch-template/LICENSE +674 -0
- package/template/101/rooch-template/README.md +14 -0
- package/template/101/rooch-template/contracts/counter/Move.toml +14 -0
- package/template/101/rooch-template/contracts/counter/sources/counter.move +48 -0
- package/template/101/rooch-template/dubhe.config.ts +14 -0
- package/template/101/rooch-template/jest.config.ts +17 -0
- package/template/101/rooch-template/next-env.d.ts +5 -0
- package/template/101/rooch-template/next-i18next.config.js +6 -0
- package/template/101/rooch-template/next.config.js +15 -0
- package/template/101/rooch-template/package.json +72 -0
- package/template/101/rooch-template/postcss.config.js +6 -0
- package/template/101/rooch-template/public/discord.svg +9 -0
- package/template/101/rooch-template/public/fail.svg +12 -0
- package/template/101/rooch-template/public/favicon.ico +0 -0
- package/template/101/rooch-template/public/locales/de/common.json +8 -0
- package/template/101/rooch-template/public/locales/de/footer.json +3 -0
- package/template/101/rooch-template/public/locales/de/second-page.json +5 -0
- package/template/101/rooch-template/public/locales/en/common.json +8 -0
- package/template/101/rooch-template/public/locales/en/footer.json +3 -0
- package/template/101/rooch-template/public/locales/en/second-page.json +5 -0
- package/template/101/rooch-template/public/locales/zn/common.json +8 -0
- package/template/101/rooch-template/public/locales/zn/footer.json +3 -0
- package/template/101/rooch-template/public/locales/zn/second-page.json +5 -0
- package/template/101/rooch-template/public/logo.svg +1 -0
- package/template/101/rooch-template/public/medium.svg +9 -0
- package/template/101/rooch-template/public/successful.svg +11 -0
- package/template/101/rooch-template/public/telegram.svg +9 -0
- package/template/101/rooch-template/public/twitter.svg +9 -0
- package/template/101/rooch-template/scripts/checkBalance.ts +37 -0
- package/template/101/rooch-template/scripts/generateAccount.ts +55 -0
- package/template/101/rooch-template/scripts/storeConfig.ts +52 -0
- package/template/101/rooch-template/scripts/waitNode.ts +9 -0
- package/template/101/rooch-template/src/chain/config.ts +5 -0
- package/template/101/rooch-template/src/css/font-awesome.css +2337 -0
- package/template/101/rooch-template/src/css/font-awesome.min.css +4 -0
- package/template/101/rooch-template/src/fonts/FontAwesome.otf +0 -0
- package/template/101/rooch-template/src/fonts/fontawesome-webfont.eot +0 -0
- package/template/101/rooch-template/src/fonts/fontawesome-webfont.svg +2671 -0
- package/template/101/rooch-template/src/fonts/fontawesome-webfont.ttf +0 -0
- package/template/101/rooch-template/src/fonts/fontawesome-webfont.woff +0 -0
- package/template/101/rooch-template/src/fonts/fontawesome-webfont.woff2 +0 -0
- package/template/101/rooch-template/src/jotai/index.tsx +12 -0
- package/template/101/rooch-template/src/pages/_app.tsx +9 -0
- package/template/101/rooch-template/src/pages/home/index.tsx +82 -0
- package/template/101/rooch-template/src/pages/index.tsx +14 -0
- package/template/101/rooch-template/tailwind.config.js +56 -0
- package/template/101/rooch-template/tsconfig.json +25 -0
- package/template/101/sui-template/contracts/counter/Move.toml +3 -3
- package/template/101/sui-template/contracts/counter/sources/codegen/schema_hub.move +60 -0
- package/template/101/sui-template/contracts/counter/sources/codegen/schemas/counter.move +17 -15
- package/template/101/sui-template/contracts/counter/sources/script/deploy_hook.move +37 -19
- package/template/101/sui-template/contracts/counter/sources/script/migrate.move +8 -0
- package/template/101/sui-template/localnet/dubhe-framework/Move.toml +6 -16
- package/template/{nextjs/sui-template/localnet/dubhe-framework/sources/schemas/dapps/dapps.move → 101/sui-template/localnet/dubhe-framework/sources/core/dapps/schema.move} +12 -2
- package/template/101/sui-template/localnet/dubhe-framework/sources/core/dapps/system.move +75 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/core/dapps/tests.move +52 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/core/root/schema.move +33 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/core/root/system.move +24 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/core/root/tests.move +39 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/frames/utils/type_info.move +29 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/storages/double_map.move +0 -3
- package/template/101/sui-template/localnet/dubhe-framework/sources/storages/map.move +0 -3
- package/template/101/sui-template/localnet/dubhe-framework/sources/storages/migrate.move +19 -0
- package/template/101/sui-template/localnet/dubhe-framework/sources/storages/value.move +0 -3
- package/template/101/sui-template/package.json +19 -27
- package/template/101/sui-template/scripts/deployment/testnet/deploy.ts +2 -2
- package/template/101/sui-template/src/chain/config.ts +3 -3
- package/template/cocos/sui-template/assets/lib/dubhe.js +21 -1
- package/template/cocos/sui-template/contracts/counter/Move.toml +1 -1
- package/template/cocos/sui-template/package.json +3 -3
- package/template/contract/sui-template/contracts/counter/Move.toml +13 -0
- package/template/contract/sui-template/contracts/counter/sources/codegen/dapp_key.move +16 -0
- package/template/contract/sui-template/contracts/counter/sources/codegen/schema_hub.move +60 -0
- package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/counter.move +60 -0
- package/template/contract/sui-template/contracts/counter/sources/script/deploy_hook.move +85 -0
- package/template/contract/sui-template/contracts/counter/sources/script/migrate.move +8 -0
- package/template/contract/sui-template/dubhe.config.ts +14 -0
- package/template/contract/sui-template/localnet/dubhe-framework/Move.toml +29 -0
- package/template/{101/sui-template/localnet/dubhe-framework/sources/schemas/dapps/dapps.move → contract/sui-template/localnet/dubhe-framework/sources/core/dapps/schema.move} +12 -2
- package/template/contract/sui-template/localnet/dubhe-framework/sources/core/dapps/system.move +75 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/core/dapps/tests.move +52 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/core/root/schema.move +33 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/core/root/system.move +24 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/core/root/tests.move +39 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/frames/utils/type_info.move +29 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/double_map.move +153 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/map.move +156 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/migrate.move +19 -0
- package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/value.move +97 -0
- package/template/contract/sui-template/localnet/dubhe-framework/tests/init.move +6 -0
- package/template/contract/sui-template/localnet/dubhe-framework/tests/obelisk_framework_tests.move +19 -0
- package/template/contract/sui-template/package.json +28 -0
- package/template/contract/sui-template/scripts/checkBalance.ts +40 -0
- package/template/contract/sui-template/scripts/deployment/common.ts +45 -0
- package/template/contract/sui-template/scripts/deployment/localnet/deploy.ts +42 -0
- package/template/contract/sui-template/scripts/deployment/testnet/deploy.ts +48 -0
- package/template/contract/sui-template/scripts/deployment/types.ts +13 -0
- package/template/contract/sui-template/scripts/framework/common.ts +17 -0
- package/template/contract/sui-template/scripts/framework/deploy.ts +199 -0
- package/template/contract/sui-template/scripts/framework/parse-history.ts +76 -0
- package/template/contract/sui-template/scripts/framework/types.ts +8 -0
- package/template/contract/sui-template/scripts/generateAccount.ts +37 -0
- package/template/contract/sui-template/tsconfig.json +35 -0
- package/template/nextjs/sui-template/contracts/counter/Move.toml +3 -3
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schema_hub.move +60 -0
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/counter.move +17 -15
- package/template/nextjs/sui-template/contracts/counter/sources/script/deploy_hook.move +37 -19
- package/template/nextjs/sui-template/contracts/counter/sources/script/migrate.move +8 -0
- package/template/nextjs/sui-template/contracts/counter/sources/systems/counter.move +11 -0
- package/template/nextjs/sui-template/dubhe.config.ts +2 -2
- package/template/nextjs/sui-template/localnet/dubhe-framework/Move.toml +6 -16
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/metadata.move +96 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/schema.move +83 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/system.move +75 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/tests.move +52 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/root/schema.move +33 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/root/system.move +24 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/root/tests.move +39 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/frames/utils/type_info.move +29 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/double_map.move +0 -3
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/map.move +0 -3
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/migrate.move +19 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/tests.move +398 -0
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/value.move +0 -3
- package/template/nextjs/sui-template/package.json +19 -27
- package/template/nextjs/sui-template/scripts/deployment/testnet/deploy.ts +2 -2
- package/template/nextjs/sui-template/src/chain/config.ts +2 -2
- package/template/101/sui-template/localnet/dubhe-framework/README.md +0 -18
- package/template/101/sui-template/localnet/dubhe-framework/sources/access_control.move +0 -35
- package/template/101/sui-template/localnet/dubhe-framework/sources/events.move +0 -23
- package/template/101/sui-template/localnet/dubhe-framework/sources/resource_id.move +0 -22
- package/template/101/sui-template/localnet/dubhe-framework/sources/resource_types.move +0 -18
- package/template/101/sui-template/localnet/dubhe-framework/sources/schema.move +0 -36
- package/template/101/sui-template/localnet/dubhe-framework/sources/systems/dapps.move +0 -90
- package/template/101/sui-template/localnet/dubhe-framework/sources/world.move +0 -81
- package/template/101/sui-template/localnet/dubhe-framework/tests/dapp.move +0 -16
- package/template/nextjs/sui-template/localnet/dubhe-framework/README.md +0 -18
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/access_control.move +0 -35
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/events.move +0 -23
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/resource_id.move +0 -22
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/resource_types.move +0 -18
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/schema.move +0 -36
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/systems/dapps.move +0 -90
- package/template/nextjs/sui-template/localnet/dubhe-framework/sources/world.move +0 -81
- package/template/nextjs/sui-template/localnet/dubhe-framework/tests/dapp.move +0 -16
- /package/template/101/sui-template/contracts/counter/sources/{system → systems}/counter.move +0 -0
- /package/template/101/sui-template/localnet/dubhe-framework/sources/{schemas → core}/dapps/metadata.move +0 -0
- /package/template/101/sui-template/localnet/dubhe-framework/{tests/storage.move → sources/storages/tests.move} +0 -0
- /package/template/{nextjs/sui-template/contracts/counter/sources/system → contract/sui-template/contracts/counter/sources/systems}/counter.move +0 -0
- /package/template/{nextjs/sui-template/localnet/dubhe-framework/sources/schemas → contract/sui-template/localnet/dubhe-framework/sources/core}/dapps/metadata.move +0 -0
- /package/template/{nextjs/sui-template/localnet/dubhe-framework/tests/storage.move → contract/sui-template/localnet/dubhe-framework/sources/storages/tests.move} +0 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { atom } from 'jotai';
|
|
2
|
+
|
|
3
|
+
const SellPopUpBoxState = atom(false);
|
|
4
|
+
const SellState = atom({
|
|
5
|
+
type: '',
|
|
6
|
+
hash: '',
|
|
7
|
+
state: false,
|
|
8
|
+
});
|
|
9
|
+
const OpenBoxState = atom(false);
|
|
10
|
+
const Value = atom('');
|
|
11
|
+
|
|
12
|
+
export { SellPopUpBoxState, SellState, OpenBoxState, Value };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { loadMetadata, Dubhe, Transaction } from '@0xobelisk/rooch-client';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { useAtom } from 'jotai';
|
|
4
|
+
import { Value } from '../../jotai';
|
|
5
|
+
import { useRouter } from 'next/router';
|
|
6
|
+
import { NETWORK, PACKAGE_ID } from '../../chain/config';
|
|
7
|
+
import { PRIVATEKEY } from '../../chain/key';
|
|
8
|
+
|
|
9
|
+
const Home = () => {
|
|
10
|
+
const router = useRouter();
|
|
11
|
+
const [value, setValue] = useAtom(Value);
|
|
12
|
+
const [loading, setLoading] = useState(false);
|
|
13
|
+
|
|
14
|
+
const query_counter_value = async () => {
|
|
15
|
+
const metadata = await loadMetadata(NETWORK, PACKAGE_ID, ['counter']);
|
|
16
|
+
const dubhe = new Dubhe({
|
|
17
|
+
networkType: NETWORK,
|
|
18
|
+
packageId: PACKAGE_ID,
|
|
19
|
+
metadata: metadata,
|
|
20
|
+
});
|
|
21
|
+
const query_value = await dubhe.query.counter.value();
|
|
22
|
+
|
|
23
|
+
if (query_value.return_values) {
|
|
24
|
+
console.log(query_value.return_values[0].decoded_value);
|
|
25
|
+
setValue(query_value.return_values[0].decoded_value.toString());
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const counter = async () => {
|
|
30
|
+
setLoading(true);
|
|
31
|
+
try {
|
|
32
|
+
const metadata = await loadMetadata(NETWORK, PACKAGE_ID, ['counter']);
|
|
33
|
+
const dubhe = new Dubhe({
|
|
34
|
+
networkType: NETWORK,
|
|
35
|
+
packageId: PACKAGE_ID,
|
|
36
|
+
metadata: metadata,
|
|
37
|
+
secretKey: PRIVATEKEY,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const tx = new Transaction();
|
|
41
|
+
const response = await dubhe.tx.counter.increase(tx);
|
|
42
|
+
console.log(response.execution_info.tx_hash, response.execution_info.status.type);
|
|
43
|
+
if (response.execution_info.status.type == 'executed') {
|
|
44
|
+
setTimeout(async () => {
|
|
45
|
+
await query_counter_value();
|
|
46
|
+
setLoading(false);
|
|
47
|
+
}, 200);
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
setLoading(false);
|
|
51
|
+
console.error(error);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (router.isReady) {
|
|
57
|
+
query_counter_value();
|
|
58
|
+
}
|
|
59
|
+
}, [router.isReady]);
|
|
60
|
+
return (
|
|
61
|
+
<div className="max-w-7xl mx-auto text-center py-12 px-4 sm:px-6 lg:py-16 lg:px-8 flex-6">
|
|
62
|
+
<div className="flex flex-col gap-6 mt-12">
|
|
63
|
+
<div className="flex flex-col gap-4">
|
|
64
|
+
You account already have some sui from testnet
|
|
65
|
+
<div className="flex flex-col gap-6 text-2xl text-green-600 mt-6 ">Counter: {value}</div>
|
|
66
|
+
<div className="flex flex-col gap-6">
|
|
67
|
+
<button
|
|
68
|
+
type="button"
|
|
69
|
+
className="mx-auto px-5 py-3 border border-transparent text-base font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700"
|
|
70
|
+
onClick={() => counter()}
|
|
71
|
+
disabled={loading}
|
|
72
|
+
>
|
|
73
|
+
{loading ? 'Processing...' : 'Increment'}
|
|
74
|
+
</button>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default Home;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const defaultTheme = require('tailwindcss/defaultTheme')
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
|
|
5
|
+
content: ['./src/**/*.{js,ts,jsx,tsx}'],
|
|
6
|
+
darkMode: 'media', // or 'media' or 'class'
|
|
7
|
+
theme: {
|
|
8
|
+
extend: {
|
|
9
|
+
spacing: {
|
|
10
|
+
"70":"17rem",
|
|
11
|
+
'78':'18rem',
|
|
12
|
+
'82': '20rem',
|
|
13
|
+
'90': '22rem',
|
|
14
|
+
'93': '23rem',
|
|
15
|
+
'97': '25rem',
|
|
16
|
+
'98': '27rem',
|
|
17
|
+
'99': "30rem",
|
|
18
|
+
"new":"34rem",
|
|
19
|
+
"new-1":"39rem",
|
|
20
|
+
"100":"43rem",
|
|
21
|
+
"105":"46rem",
|
|
22
|
+
"106":"48rem",
|
|
23
|
+
},
|
|
24
|
+
colors: {
|
|
25
|
+
transparent: 'transparent',
|
|
26
|
+
current: 'currentColor',
|
|
27
|
+
custom:{
|
|
28
|
+
DEFAULT:'#8861D1',
|
|
29
|
+
light:"#8861D1",
|
|
30
|
+
dark:"#8861D1",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
},
|
|
34
|
+
screens: {
|
|
35
|
+
'3xl': '1700px',
|
|
36
|
+
},
|
|
37
|
+
fontFamily: {
|
|
38
|
+
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
},
|
|
46
|
+
plugins: [
|
|
47
|
+
|
|
48
|
+
require('@tailwindcss/line-clamp'),
|
|
49
|
+
require('tailwind-scrollbar'),
|
|
50
|
+
],
|
|
51
|
+
variants: {
|
|
52
|
+
scrollbar: ['rounded']
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ts-node": {
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "CommonJS"
|
|
5
|
+
}
|
|
6
|
+
},
|
|
7
|
+
"compilerOptions": {
|
|
8
|
+
"target": "es6",
|
|
9
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
10
|
+
"allowJs": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"strict": false,
|
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"module": "esnext",
|
|
17
|
+
"moduleResolution": "node",
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"jsx": "preserve",
|
|
21
|
+
"incremental": true
|
|
22
|
+
},
|
|
23
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
|
|
24
|
+
"exclude": ["node_modules"]
|
|
25
|
+
}
|
|
@@ -5,9 +5,9 @@ edition = "2024.beta"
|
|
|
5
5
|
|
|
6
6
|
[dependencies]
|
|
7
7
|
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.36.2" }
|
|
8
|
-
Dubhe = {
|
|
8
|
+
Dubhe = { local = "../../localnet/dubhe-framework" }
|
|
9
9
|
|
|
10
10
|
[addresses]
|
|
11
11
|
sui = "0x2"
|
|
12
|
-
dubhe = "
|
|
13
|
-
counter = "0x0"
|
|
12
|
+
dubhe = "0xe2793ee7dd5f05c73969577b0074f29aae3f70ab33c57dd42681ca29196e6a04"
|
|
13
|
+
counter = "0x0"
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright (c) Obelisk Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
#[allow(unused_use)]
|
|
4
|
+
|
|
5
|
+
/* Autogenerated file. Do not edit manually. */
|
|
6
|
+
|
|
7
|
+
module counter::schema_hub {
|
|
8
|
+
|
|
9
|
+
use sui::transfer::public_share_object;
|
|
10
|
+
|
|
11
|
+
use sui::dynamic_field as df;
|
|
12
|
+
|
|
13
|
+
public struct SchemaHub has key, store {
|
|
14
|
+
id: UID,
|
|
15
|
+
admin: address,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public struct SchemaTypeWapper<phantom Schema: key + store> has copy, store, drop {}
|
|
19
|
+
|
|
20
|
+
/// Authorize an schema to access protected features of the SchemaHub.
|
|
21
|
+
|
|
22
|
+
public(package) fun authorize_schema<Schema: key + store>(self: &mut SchemaHub) {
|
|
23
|
+
df::add(&mut self.id, SchemaTypeWapper<Schema> {}, true);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/// Deauthorize an schema by removing its authorization key.
|
|
27
|
+
|
|
28
|
+
public(package) fun deauthorize_schema<Schema: key + store>(self: &mut SchemaHub) {
|
|
29
|
+
df::remove<SchemaTypeWapper<Schema>, bool>(&mut self.id, SchemaTypeWapper<Schema> {});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// Check if an schema is authorized to access protected features of
|
|
33
|
+
|
|
34
|
+
/// the SchemaHub.
|
|
35
|
+
|
|
36
|
+
public fun is_schema_authorized<Schema: key + store>(self: &SchemaHub): bool {
|
|
37
|
+
df::exists_(&self.id, SchemaTypeWapper<Schema> {})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// Assert that an schema is authorized to access protected features of
|
|
41
|
+
|
|
42
|
+
/// the SchemaHub. Aborts with `EAppNotAuthorized` if not.
|
|
43
|
+
|
|
44
|
+
public fun ensure_schema_authorized<Schema: key + store>(self: &SchemaHub) {
|
|
45
|
+
assert!(self.is_schema_authorized<Schema>(), 0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fun init(ctx: &mut TxContext) {
|
|
49
|
+
public_share_object(SchemaHub {
|
|
50
|
+
id: object::new(ctx),
|
|
51
|
+
admin: ctx.sender(),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#[test_only]
|
|
56
|
+
|
|
57
|
+
public fun init_schema_hub_for_testing(ctx: &mut TxContext) {
|
|
58
|
+
init(ctx);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -8,10 +8,16 @@
|
|
|
8
8
|
|
|
9
9
|
use std::ascii::String;
|
|
10
10
|
|
|
11
|
+
use std::ascii::string;
|
|
12
|
+
|
|
13
|
+
use sui::package::UpgradeCap;
|
|
14
|
+
|
|
11
15
|
use std::type_name;
|
|
12
16
|
|
|
13
17
|
use dubhe::dapps_system;
|
|
14
18
|
|
|
19
|
+
use dubhe::storage_migrate;
|
|
20
|
+
|
|
15
21
|
use dubhe::dapps_schema::Dapps;
|
|
16
22
|
|
|
17
23
|
use dubhe::storage_value::{Self, StorageValue};
|
|
@@ -22,36 +28,32 @@
|
|
|
22
28
|
|
|
23
29
|
use counter::dapp_key::DappKey;
|
|
24
30
|
|
|
31
|
+
use sui::dynamic_field as df;
|
|
32
|
+
|
|
25
33
|
public struct Counter has key, store {
|
|
26
34
|
id: UID,
|
|
27
|
-
value: StorageValue<u32>,
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
public fun borrow_value(self: &Counter): &StorageValue<u32> {
|
|
31
|
-
&self.value
|
|
38
|
+
storage_migrate::borrow_field(&self.id, b"value")
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
public(package) fun borrow_mut_value(self: &mut Counter): &mut StorageValue<u32> {
|
|
35
|
-
&mut self.value
|
|
42
|
+
storage_migrate::borrow_mut_field(&mut self.id, b"value")
|
|
36
43
|
}
|
|
37
44
|
|
|
38
|
-
public fun
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
let schema = type_name::get<Counter>().into_string();
|
|
43
|
-
assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);
|
|
44
|
-
dapps_system::add_schema<Counter>(dapps, package_id, ctx);
|
|
45
|
-
Counter {
|
|
46
|
-
id: object::new(ctx),
|
|
47
|
-
value: storage_value::new(),
|
|
48
|
-
}
|
|
45
|
+
public(package) fun create(ctx: &mut TxContext): Counter {
|
|
46
|
+
let mut id = object::new(ctx);
|
|
47
|
+
storage_migrate::add_field<StorageValue<u32>>(&mut id, b"value", storage_value::new());
|
|
48
|
+
Counter { id }
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
public fun migrate(_counter: &mut Counter, _cap: &UpgradeCap) {}
|
|
52
|
+
|
|
51
53
|
// ======================================== View Functions ========================================
|
|
52
54
|
|
|
53
55
|
public fun get_value(self: &Counter): Option<u32> {
|
|
54
|
-
self.
|
|
56
|
+
self.borrow_value().try_get()
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
// =========================================================================================================
|
|
@@ -6,17 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
use dubhe::dapps_system;
|
|
8
8
|
|
|
9
|
-
use counter::
|
|
9
|
+
use counter::schema_hub::SchemaHub;
|
|
10
10
|
|
|
11
|
-
use std::ascii;
|
|
11
|
+
use std::ascii::string;
|
|
12
12
|
|
|
13
13
|
use sui::clock::Clock;
|
|
14
14
|
|
|
15
|
-
use sui::
|
|
15
|
+
use sui::package::UpgradeCap;
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
use sui::transfer::public_share_object;
|
|
18
18
|
|
|
19
|
-
use
|
|
19
|
+
use counter::counter_schema::Counter;
|
|
20
20
|
|
|
21
21
|
#[test_only]
|
|
22
22
|
|
|
@@ -28,40 +28,58 @@
|
|
|
28
28
|
|
|
29
29
|
#[test_only]
|
|
30
30
|
|
|
31
|
+
use sui::package;
|
|
32
|
+
|
|
33
|
+
#[test_only]
|
|
34
|
+
|
|
35
|
+
use counter::schema_hub;
|
|
36
|
+
|
|
37
|
+
#[test_only]
|
|
38
|
+
|
|
39
|
+
use dubhe::dapps_schema;
|
|
40
|
+
|
|
41
|
+
#[test_only]
|
|
42
|
+
|
|
31
43
|
use sui::test_scenario::Scenario;
|
|
32
44
|
|
|
33
|
-
public entry fun run(
|
|
45
|
+
public entry fun run(
|
|
46
|
+
schema_hub: &mut SchemaHub,
|
|
47
|
+
dapps: &mut Dapps,
|
|
48
|
+
cap: &UpgradeCap,
|
|
49
|
+
clock: &Clock,
|
|
50
|
+
ctx: &mut TxContext,
|
|
51
|
+
) {
|
|
34
52
|
// Register the dapp to dubhe.
|
|
35
|
-
dapps_system::register
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
ascii::string(b"counter"),
|
|
39
|
-
clock,
|
|
40
|
-
ctx
|
|
41
|
-
);
|
|
42
|
-
let mut counter = counter::counter_schema::register(dapps, ctx);
|
|
53
|
+
dapps_system::register(dapps,cap,string(b"counter"),string(b"counter"),clock,ctx);
|
|
54
|
+
// Create schemas
|
|
55
|
+
let mut counter = counter::counter_schema::create(ctx);
|
|
43
56
|
// Logic that needs to be automated once the contract is deployed
|
|
44
|
-
counter.borrow_mut_value().set(0);
|
|
45
57
|
|
|
46
|
-
|
|
58
|
+
counter.borrow_mut_value().set(0);
|
|
59
|
+
// Authorize schemas and public share objects
|
|
60
|
+
schema_hub.authorize_schema<Counter>();
|
|
47
61
|
public_share_object(counter);
|
|
48
62
|
}
|
|
49
63
|
|
|
50
64
|
#[test_only]
|
|
51
65
|
|
|
52
|
-
public fun deploy_hook_for_testing(): (Scenario, Dapps) {
|
|
66
|
+
public fun deploy_hook_for_testing(): (Scenario, SchemaHub, Dapps) {
|
|
53
67
|
let mut scenario = test_scenario::begin(@0xA);
|
|
54
68
|
{
|
|
55
69
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
56
70
|
dapps_schema::init_dapps_for_testing(ctx);
|
|
71
|
+
schema_hub::init_schema_hub_for_testing(ctx);
|
|
57
72
|
test_scenario::next_tx(&mut scenario,@0xA);
|
|
58
73
|
};
|
|
59
74
|
let mut dapps = test_scenario::take_shared<Dapps>(&scenario);
|
|
75
|
+
let mut schema_hub = test_scenario::take_shared<SchemaHub>(&scenario);
|
|
60
76
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
61
77
|
let clock = clock::create_for_testing(ctx);
|
|
62
|
-
|
|
78
|
+
let upgrade_cap = package::test_publish(@0x42.to_id(), ctx);
|
|
79
|
+
run(&mut schema_hub, &mut dapps, &upgrade_cap, &clock, ctx);
|
|
63
80
|
clock::destroy_for_testing(clock);
|
|
81
|
+
upgrade_cap.make_immutable();
|
|
64
82
|
test_scenario::next_tx(&mut scenario,@0xA);
|
|
65
|
-
(scenario, dapps)
|
|
83
|
+
(scenario, schema_hub, dapps)
|
|
66
84
|
}
|
|
67
85
|
}
|
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "Dubhe"
|
|
3
|
-
edition = "2024.alpha"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
edition = "2024.alpha"
|
|
4
|
+
version = "1.0.0"
|
|
5
|
+
published-at = "0xe2793ee7dd5f05c73969577b0074f29aae3f70ab33c57dd42681ca29196e6a04"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
authors = ["Obelisk Labs"]
|
|
7
8
|
|
|
8
9
|
[dependencies]
|
|
9
10
|
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.36.2" }
|
|
10
11
|
|
|
11
|
-
# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
|
|
12
|
-
# Revision can be a branch, a tag, and a commit hash.
|
|
13
|
-
# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" }
|
|
14
|
-
|
|
15
|
-
# For local dependencies use `local = path`. Path is relative to the package root
|
|
16
|
-
# Local = { local = "../path/to" }
|
|
17
|
-
|
|
18
|
-
# To resolve a version conflict and force a specific version for dependency
|
|
19
|
-
# override use `override = true`
|
|
20
|
-
# Override = { local = "../conflicting/version", override = true }
|
|
21
|
-
|
|
22
12
|
[addresses]
|
|
23
|
-
dubhe = "
|
|
13
|
+
dubhe = "0xe2793ee7dd5f05c73969577b0074f29aae3f70ab33c57dd42681ca29196e6a04"
|
|
24
14
|
#dubhe = "0x0"
|
|
25
15
|
|
|
26
16
|
# Named addresses will be accessible in Move as `@name`. They're also exported:
|
|
@@ -11,7 +11,8 @@ module dubhe::dapps_schema {
|
|
|
11
11
|
version: StorageMap<address, u32>,
|
|
12
12
|
metadata: StorageMap<address, DappMetadata>,
|
|
13
13
|
schemas: StorageMap<address, vector<String>>,
|
|
14
|
-
safe_mode: StorageMap<address, bool
|
|
14
|
+
safe_mode: StorageMap<address, bool>,
|
|
15
|
+
verified: StorageMap<address, bool>
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
|
|
@@ -35,6 +36,10 @@ module dubhe::dapps_schema {
|
|
|
35
36
|
&mut self.safe_mode
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
public(package) fun borrow_mut_verified(self: &mut Dapps): &mut StorageMap<address, bool> {
|
|
40
|
+
&mut self.verified
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
public fun borrow_admin(self: &Dapps): &StorageMap<address, address> {
|
|
39
44
|
&self.admin
|
|
40
45
|
}
|
|
@@ -55,6 +60,10 @@ module dubhe::dapps_schema {
|
|
|
55
60
|
&self.safe_mode
|
|
56
61
|
}
|
|
57
62
|
|
|
63
|
+
public fun borrow_verified(self: &mut Dapps): &StorageMap<address, bool> {
|
|
64
|
+
&self.verified
|
|
65
|
+
}
|
|
66
|
+
|
|
58
67
|
fun init(ctx: &mut TxContext) {
|
|
59
68
|
public_share_object(Dapps {
|
|
60
69
|
id: object::new(ctx),
|
|
@@ -62,7 +71,8 @@ module dubhe::dapps_schema {
|
|
|
62
71
|
version: storage_map::new(),
|
|
63
72
|
metadata: storage_map::new(),
|
|
64
73
|
schemas: storage_map::new(),
|
|
65
|
-
safe_mode: storage_map::new()
|
|
74
|
+
safe_mode: storage_map::new(),
|
|
75
|
+
verified: storage_map::new(),
|
|
66
76
|
});
|
|
67
77
|
}
|
|
68
78
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
module dubhe::dapps_system {
|
|
2
|
+
use std::ascii::String;
|
|
3
|
+
use std::ascii;
|
|
4
|
+
use dubhe::root_schema::Root;
|
|
5
|
+
use dubhe::dapp_metadata;
|
|
6
|
+
use sui::clock::Clock;
|
|
7
|
+
use dubhe::dapps_schema::Dapps;
|
|
8
|
+
use dubhe::root_system;
|
|
9
|
+
|
|
10
|
+
public entry fun register<UpgradeCap: key>(
|
|
11
|
+
dapps: &mut Dapps,
|
|
12
|
+
upgrade_cap: &UpgradeCap,
|
|
13
|
+
name: String,
|
|
14
|
+
description: String,
|
|
15
|
+
clock: &Clock,
|
|
16
|
+
ctx: &mut TxContext
|
|
17
|
+
) {
|
|
18
|
+
|
|
19
|
+
let dapp_id = object::id_address<UpgradeCap>(upgrade_cap);
|
|
20
|
+
assert!(!dapps.borrow_metadata().contains_key(dapp_id), 0);
|
|
21
|
+
|
|
22
|
+
dapps.borrow_mut_metadata().set(
|
|
23
|
+
dapp_id,
|
|
24
|
+
dapp_metadata::new(
|
|
25
|
+
name,
|
|
26
|
+
description,
|
|
27
|
+
ascii::string(b""),
|
|
28
|
+
ascii::string(b""),
|
|
29
|
+
clock.timestamp_ms(),
|
|
30
|
+
vector[]
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
dapps.borrow_mut_admin().set(dapp_id, ctx.sender());
|
|
34
|
+
dapps.borrow_mut_version().set(dapp_id, 0);
|
|
35
|
+
dapps.borrow_mut_safe_mode().set(dapp_id, false);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public entry fun set_metadata<UpgradeCap: key>(
|
|
39
|
+
dapps: &mut Dapps,
|
|
40
|
+
upgrade_cap: &UpgradeCap,
|
|
41
|
+
name: String,
|
|
42
|
+
description: String,
|
|
43
|
+
icon_url: String,
|
|
44
|
+
website_url: String,
|
|
45
|
+
partners: vector<String>
|
|
46
|
+
) {
|
|
47
|
+
let dapp_id = object::id_address<UpgradeCap>(upgrade_cap);
|
|
48
|
+
assert!(dapps.borrow_metadata().contains_key(dapp_id), 0);
|
|
49
|
+
let created_at = dapps.borrow_mut_metadata().take(dapp_id).get_created_at();
|
|
50
|
+
dapps.borrow_mut_metadata().set(dapp_id, dapp_metadata::new(name, description, icon_url, website_url, created_at, partners));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public entry fun transfer_ownership<UpgradeCap: key>(
|
|
54
|
+
dapps: &mut Dapps,
|
|
55
|
+
upgrade_cap: &UpgradeCap,
|
|
56
|
+
new_admin: address,
|
|
57
|
+
ctx: &mut TxContext
|
|
58
|
+
) {
|
|
59
|
+
let dapp_id = object::id_address<UpgradeCap>(upgrade_cap);
|
|
60
|
+
assert!(dapps.borrow_admin().get(dapp_id) == ctx.sender(), 0);
|
|
61
|
+
dapps.borrow_mut_admin().set(dapp_id, new_admin);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public entry fun add_verification(dapps: &mut Dapps, root: &Root, dapp_id: address, ctx: &mut TxContext) {
|
|
65
|
+
root_system::ensure_root(root, ctx);
|
|
66
|
+
assert!(dapps.borrow_metadata().contains_key(dapp_id), 0);
|
|
67
|
+
dapps.borrow_mut_verified().set(dapp_id, true);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public entry fun remove_verification(dapps: &mut Dapps, root: &Root, dapp_id: address, ctx: &mut TxContext) {
|
|
71
|
+
root_system::ensure_root(root, ctx);
|
|
72
|
+
assert!(dapps.borrow_metadata().contains_key(dapp_id), 0);
|
|
73
|
+
dapps.borrow_mut_verified().remove(dapp_id);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#[test_only]
|
|
2
|
+
module dubhe::dapps_tests {
|
|
3
|
+
use dubhe::dapps_schema::Dapps;
|
|
4
|
+
use dubhe::dapps_schema;
|
|
5
|
+
use dubhe::dapps_system;
|
|
6
|
+
use std::ascii::string;
|
|
7
|
+
use std::debug;
|
|
8
|
+
use sui::clock;
|
|
9
|
+
use sui::test_scenario;
|
|
10
|
+
use sui::package;
|
|
11
|
+
use sui::package::UpgradeCap;
|
|
12
|
+
|
|
13
|
+
public struct DappKey has drop {}
|
|
14
|
+
|
|
15
|
+
#[test]
|
|
16
|
+
public fun dapps_register() {
|
|
17
|
+
let mut scenario = test_scenario::begin(@0xA);
|
|
18
|
+
{
|
|
19
|
+
let ctx = test_scenario::ctx(&mut scenario);
|
|
20
|
+
dapps_schema::init_dapps_for_testing(ctx);
|
|
21
|
+
test_scenario::next_tx(&mut scenario,@0xA);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
let mut dapps = test_scenario::take_shared<Dapps>(&scenario);
|
|
25
|
+
|
|
26
|
+
let upgrade_cap = package::test_publish(@0x42.to_id(), scenario.ctx());
|
|
27
|
+
debug::print(&object::id_address<UpgradeCap>(&upgrade_cap));
|
|
28
|
+
|
|
29
|
+
let clock = clock::create_for_testing(test_scenario::ctx(&mut scenario));
|
|
30
|
+
dapps_system::register<UpgradeCap>(
|
|
31
|
+
&mut dapps,
|
|
32
|
+
&upgrade_cap,
|
|
33
|
+
string(b"DappKey"),
|
|
34
|
+
string(b"DappKey"),
|
|
35
|
+
&clock,
|
|
36
|
+
test_scenario::ctx(&mut scenario)
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
test_scenario::next_tx(&mut scenario,@0xA);
|
|
40
|
+
|
|
41
|
+
let dapp_id = object::id_address<UpgradeCap>(&upgrade_cap);
|
|
42
|
+
assert!(dapps.borrow_version().get(dapp_id) == 0, 0);
|
|
43
|
+
assert!(dapps.borrow_metadata().contains_key(dapp_id));
|
|
44
|
+
assert!(dapps.borrow_admin().get(dapp_id) == test_scenario::ctx(&mut scenario).sender(), 0);
|
|
45
|
+
assert!(dapps.borrow_safe_mode().get(dapp_id) == false, 0);
|
|
46
|
+
|
|
47
|
+
clock::destroy_for_testing(clock);
|
|
48
|
+
test_scenario::return_shared<Dapps>(dapps);
|
|
49
|
+
upgrade_cap.make_immutable();
|
|
50
|
+
scenario.end();
|
|
51
|
+
}
|
|
52
|
+
}
|