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
|
@@ -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
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module counter::counter_system {
|
|
2
|
+
use counter::counter_schema::Counter;
|
|
3
|
+
|
|
4
|
+
public entry fun inc(counter: &mut Counter) {
|
|
5
|
+
counter.borrow_mut_value().mutate!(|value| *value = *value + 1);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
public fun get(counter: &Counter): u32 {
|
|
9
|
+
counter.borrow_value().get()
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -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 = "0xbaa3c172e1409fbbd8cd5da701166f8df4db725ee791de21d7b45f330b8b2568"
|
|
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 = "0xbaa3c172e1409fbbd8cd5da701166f8df4db725ee791de21d7b45f330b8b2568"
|
|
24
14
|
#dubhe = "0x0"
|
|
25
15
|
|
|
26
16
|
# Named addresses will be accessible in Move as `@name`. They're also exported:
|
package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/metadata.move
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
module dubhe::dapp_metadata {
|
|
2
|
+
use std::ascii::String;
|
|
3
|
+
|
|
4
|
+
public struct DappMetadata has drop, copy, store {
|
|
5
|
+
name: String,
|
|
6
|
+
description: String,
|
|
7
|
+
icon_url: String,
|
|
8
|
+
website_url: String,
|
|
9
|
+
created_at: u64,
|
|
10
|
+
partners: vector<String>,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public fun new(
|
|
14
|
+
name: String,
|
|
15
|
+
description: String,
|
|
16
|
+
icon_url: String,
|
|
17
|
+
website_url: String,
|
|
18
|
+
created_at: u64,
|
|
19
|
+
partners: vector<String>,
|
|
20
|
+
): DappMetadata {
|
|
21
|
+
DappMetadata {
|
|
22
|
+
name,
|
|
23
|
+
description,
|
|
24
|
+
icon_url,
|
|
25
|
+
website_url,
|
|
26
|
+
created_at,
|
|
27
|
+
partners,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public fun set(
|
|
32
|
+
self: &mut DappMetadata,
|
|
33
|
+
name: String,
|
|
34
|
+
description: String,
|
|
35
|
+
icon_url: String,
|
|
36
|
+
website_url: String,
|
|
37
|
+
created_at: u64,
|
|
38
|
+
partners: vector<String>,
|
|
39
|
+
) {
|
|
40
|
+
self.name = name;
|
|
41
|
+
self.description = description;
|
|
42
|
+
self.icon_url = icon_url;
|
|
43
|
+
self.website_url = website_url;
|
|
44
|
+
self.created_at = created_at;
|
|
45
|
+
self.partners = partners;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public fun set_name(self: &mut DappMetadata, name: String) {
|
|
49
|
+
self.name = name;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public fun set_description(self: &mut DappMetadata, description: String) {
|
|
53
|
+
self.description = description;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public fun set_icon_url(self: &mut DappMetadata, icon_url: String) {
|
|
57
|
+
self.icon_url = icon_url;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public fun set_website_url(self: &mut DappMetadata, website_url: String) {
|
|
61
|
+
self.website_url = website_url;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public fun set_created_at(self: &mut DappMetadata, created_at: u64) {
|
|
65
|
+
self.created_at = created_at;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public fun set_partners(self: &mut DappMetadata, partners: vector<String>) {
|
|
69
|
+
self.partners = partners;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public fun get_name(self: DappMetadata): String {
|
|
73
|
+
self.name
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public fun get_description(self: DappMetadata): String {
|
|
77
|
+
self.description
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public fun get_icon_url(self: DappMetadata): String {
|
|
81
|
+
self.icon_url
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public fun get_website_url(self: DappMetadata): String {
|
|
85
|
+
self.website_url
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public fun get_created_at(self: DappMetadata): u64 {
|
|
89
|
+
self.created_at
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public fun get_partners(self: DappMetadata): vector<String> {
|
|
93
|
+
self.partners
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module dubhe::dapps_schema {
|
|
2
|
+
use std::ascii::String;
|
|
3
|
+
use dubhe::storage_map;
|
|
4
|
+
use sui::transfer::public_share_object;
|
|
5
|
+
use dubhe::dapp_metadata::DappMetadata;
|
|
6
|
+
use dubhe::storage_map::StorageMap;
|
|
7
|
+
|
|
8
|
+
public struct Dapps has key, store {
|
|
9
|
+
id: UID,
|
|
10
|
+
admin: StorageMap<address, address>,
|
|
11
|
+
version: StorageMap<address, u32>,
|
|
12
|
+
metadata: StorageMap<address, DappMetadata>,
|
|
13
|
+
schemas: StorageMap<address, vector<String>>,
|
|
14
|
+
safe_mode: StorageMap<address, bool>,
|
|
15
|
+
verified: StorageMap<address, bool>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
public(package) fun borrow_mut_version(self: &mut Dapps): &mut StorageMap<address, u32> {
|
|
20
|
+
&mut self.version
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public(package) fun borrow_mut_admin(self: &mut Dapps): &mut StorageMap<address, address> {
|
|
24
|
+
&mut self.admin
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public(package) fun borrow_mut_metadata(self: &mut Dapps): &mut StorageMap<address, DappMetadata> {
|
|
28
|
+
&mut self.metadata
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public(package) fun borrow_mut_schemas(self: &mut Dapps): &mut StorageMap<address, vector<String>> {
|
|
32
|
+
&mut self.schemas
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public(package) fun borrow_mut_safe_mode(self: &mut Dapps): &mut StorageMap<address, bool> {
|
|
36
|
+
&mut self.safe_mode
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public(package) fun borrow_mut_verified(self: &mut Dapps): &mut StorageMap<address, bool> {
|
|
40
|
+
&mut self.verified
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public fun borrow_admin(self: &Dapps): &StorageMap<address, address> {
|
|
44
|
+
&self.admin
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public fun borrow_version(self: &Dapps): &StorageMap<address, u32> {
|
|
48
|
+
&self.version
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public fun borrow_metadata(self: &Dapps): &StorageMap<address, DappMetadata> {
|
|
52
|
+
&self.metadata
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public fun borrow_schemas(self: &Dapps): &StorageMap<address, vector<String>> {
|
|
56
|
+
&self.schemas
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public fun borrow_safe_mode(self: &Dapps): &StorageMap<address, bool> {
|
|
60
|
+
&self.safe_mode
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public fun borrow_verified(self: &mut Dapps): &StorageMap<address, bool> {
|
|
64
|
+
&self.verified
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fun init(ctx: &mut TxContext) {
|
|
68
|
+
public_share_object(Dapps {
|
|
69
|
+
id: object::new(ctx),
|
|
70
|
+
admin: storage_map::new(),
|
|
71
|
+
version: storage_map::new(),
|
|
72
|
+
metadata: storage_map::new(),
|
|
73
|
+
schemas: storage_map::new(),
|
|
74
|
+
safe_mode: storage_map::new(),
|
|
75
|
+
verified: storage_map::new(),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
#[test_only]
|
|
80
|
+
public fun init_dapps_for_testing(ctx: &mut TxContext){
|
|
81
|
+
init(ctx)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module dubhe::root_schema {
|
|
2
|
+
use dubhe::storage_value;
|
|
3
|
+
use dubhe::storage_value::StorageValue;
|
|
4
|
+
use sui::transfer::public_share_object;
|
|
5
|
+
|
|
6
|
+
public struct Root has key, store {
|
|
7
|
+
id: UID,
|
|
8
|
+
key: StorageValue<address>,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
public(package) fun borrow_mut_key(self: &mut Root): &mut StorageValue<address> {
|
|
13
|
+
&mut self.key
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public fun borrow_key(self: &Root): &StorageValue<address> {
|
|
17
|
+
&self.key
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fun init(ctx: &mut TxContext) {
|
|
21
|
+
let mut key = storage_value::new();
|
|
22
|
+
key.set(ctx.sender());
|
|
23
|
+
public_share_object(Root {
|
|
24
|
+
id: object::new(ctx),
|
|
25
|
+
key,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#[test_only]
|
|
30
|
+
public fun init_root_for_testing(ctx: &mut TxContext){
|
|
31
|
+
init(ctx)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module dubhe::root_system {
|
|
2
|
+
use dubhe::root_schema::Root;
|
|
3
|
+
|
|
4
|
+
public entry fun set_key(
|
|
5
|
+
root: &mut Root,
|
|
6
|
+
key: address,
|
|
7
|
+
ctx: &mut TxContext
|
|
8
|
+
) {
|
|
9
|
+
ensure_root(root, ctx);
|
|
10
|
+
root.borrow_mut_key().set(key);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public entry fun remove_key(
|
|
14
|
+
root: &mut Root,
|
|
15
|
+
ctx: &mut TxContext
|
|
16
|
+
) {
|
|
17
|
+
ensure_root(root, ctx);
|
|
18
|
+
root.borrow_mut_key().remove();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public fun ensure_root(root: &Root, ctx: &TxContext) {
|
|
22
|
+
assert!(root.borrow_key().get() == ctx.sender(), 0);
|
|
23
|
+
}
|
|
24
|
+
}
|