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
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module dubhe::resource_id {
|
|
2
|
-
|
|
3
|
-
public fun encode(type_id: vector<u8>, namespace: vector<u8>, name: vector<u8>) : vector<u8> {
|
|
4
|
-
let mut resource_id: vector<u8> = vector[];
|
|
5
|
-
vector::append(&mut resource_id, type_id);
|
|
6
|
-
vector::append(&mut resource_id, namespace);
|
|
7
|
-
vector::append(&mut resource_id, name);
|
|
8
|
-
resource_id
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public fun offchain_schema() : vector<u8> {
|
|
12
|
-
b"os"
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public fun system() : vector<u8> {
|
|
16
|
-
b"sy"
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public fun namespace() : vector<u8> {
|
|
20
|
-
b"ns"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module dubhe::resource_tyeps {
|
|
2
|
-
|
|
3
|
-
public fun schema() : vector<u8> {
|
|
4
|
-
b"sc"
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
public fun offchain_schema() : vector<u8> {
|
|
8
|
-
b"os"
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public fun system() : vector<u8> {
|
|
12
|
-
b"sy"
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public fun namespace() : vector<u8> {
|
|
16
|
-
b"ns"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module dubhe::schema {
|
|
2
|
-
use std::ascii::{string};
|
|
3
|
-
use sui::bag::{Self};
|
|
4
|
-
use dubhe::world::{World, AdminCap};
|
|
5
|
-
use dubhe::access_control;
|
|
6
|
-
|
|
7
|
-
/// Schema does not exist
|
|
8
|
-
const ESchemaDoesNotExist: u64 = 0;
|
|
9
|
-
/// Schema already exists
|
|
10
|
-
const ESchemaAlreadyExists: u64 = 1;
|
|
11
|
-
/// Not the right admin for this world
|
|
12
|
-
const ENotAdmin: u64 = 2;
|
|
13
|
-
|
|
14
|
-
public fun get<T : store>(world: &World, _dubhe_schema_id: vector<u8>): &T {
|
|
15
|
-
assert!(bag::contains(world.schemas(), _dubhe_schema_id), ESchemaDoesNotExist);
|
|
16
|
-
bag::borrow<vector<u8>, T>(world.schemas(), _dubhe_schema_id)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public fun add<T : store>(_dubhe_world: &mut World, _dubhe_schema_id: vector<u8>, schema: T, admin_cap: &AdminCap){
|
|
20
|
-
assert!(_dubhe_world.admin() == object::id(admin_cap), ENotAdmin);
|
|
21
|
-
assert!(!bag::contains(_dubhe_world.schemas(), _dubhe_schema_id), ESchemaAlreadyExists);
|
|
22
|
-
vector::push_back(_dubhe_world.mut_schema_names(), string(_dubhe_schema_id));
|
|
23
|
-
bag::add<vector<u8>,T>(_dubhe_world.mut_schemas(), _dubhe_schema_id, schema);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public fun contains(_dubhe_world: &mut World, _dubhe_schema_id: vector<u8>): bool {
|
|
27
|
-
bag::contains(_dubhe_world.schemas(), _dubhe_schema_id)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// === Protected features ===
|
|
31
|
-
public fun get_mut<T : store, App: drop>(_: App, world: &mut World, _dubhe_schema_id: vector<u8>): &mut T {
|
|
32
|
-
access_control::assert_app_is_authorized<App>(world);
|
|
33
|
-
assert!(bag::contains(world.schemas(), _dubhe_schema_id), ESchemaDoesNotExist);
|
|
34
|
-
bag::borrow_mut<vector<u8>, T>(world.mut_schemas(), _dubhe_schema_id)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
module dubhe::dapps_system {
|
|
2
|
-
use std::ascii::String;
|
|
3
|
-
use std::ascii;
|
|
4
|
-
use std::type_name;
|
|
5
|
-
use sui::address;
|
|
6
|
-
use dubhe::dapp_metadata;
|
|
7
|
-
use sui::clock::Clock;
|
|
8
|
-
use dubhe::dapps_schema::Dapps;
|
|
9
|
-
|
|
10
|
-
public fun current_package_id<T>(): address {
|
|
11
|
-
let dapp_package_id_string = type_name::get<T>().get_address().into_bytes();
|
|
12
|
-
address::from_ascii_bytes(&dapp_package_id_string)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public entry fun register<T>(
|
|
16
|
-
dapps: &mut Dapps,
|
|
17
|
-
name: String,
|
|
18
|
-
description: String,
|
|
19
|
-
clock: &Clock,
|
|
20
|
-
ctx: &mut TxContext
|
|
21
|
-
) {
|
|
22
|
-
let dapp_package_id = current_package_id<T>();
|
|
23
|
-
assert!(!dapps.borrow_metadata().contains_key(dapp_package_id), 0);
|
|
24
|
-
|
|
25
|
-
dapps.borrow_mut_metadata().set(
|
|
26
|
-
dapp_package_id,
|
|
27
|
-
dapp_metadata::new(
|
|
28
|
-
name,
|
|
29
|
-
description,
|
|
30
|
-
ascii::string(b""),
|
|
31
|
-
ascii::string(b""),
|
|
32
|
-
clock.timestamp_ms(),
|
|
33
|
-
vector[]
|
|
34
|
-
)
|
|
35
|
-
);
|
|
36
|
-
dapps.borrow_mut_admin().set(dapp_package_id, ctx.sender());
|
|
37
|
-
dapps.borrow_mut_version().set(dapp_package_id, 0);
|
|
38
|
-
dapps.borrow_mut_schemas().set(dapp_package_id, vector[]);
|
|
39
|
-
dapps.borrow_mut_safe_mode().set(dapp_package_id, false);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public entry fun set_metadata(
|
|
43
|
-
dapps: &mut Dapps,
|
|
44
|
-
package_id: address,
|
|
45
|
-
clock: &Clock,
|
|
46
|
-
name: String,
|
|
47
|
-
description: String,
|
|
48
|
-
icon_url: String,
|
|
49
|
-
website_url: String,
|
|
50
|
-
partners: vector<String>,
|
|
51
|
-
ctx: &mut TxContext
|
|
52
|
-
) {
|
|
53
|
-
assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
|
|
54
|
-
let created_at = clock.timestamp_ms();
|
|
55
|
-
assert!(dapps.borrow_metadata().contains_key(package_id), 0);
|
|
56
|
-
dapps.borrow_mut_metadata().mutate!(package_id, |metadata| {
|
|
57
|
-
metadata.set(name, description, icon_url, website_url, created_at, partners);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public entry fun add_schema<T>(dapps: &mut Dapps, package_id: address, ctx: &mut TxContext) {
|
|
62
|
-
assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
|
|
63
|
-
let schema = type_name::get<T>().into_string();
|
|
64
|
-
assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);
|
|
65
|
-
dapps.borrow_mut_schemas().mutate!(package_id, |schemas| {
|
|
66
|
-
schemas.push_back(schema);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public entry fun transfer_ownership(
|
|
71
|
-
dapps: &mut Dapps,
|
|
72
|
-
package_id: address,
|
|
73
|
-
new_admin: address,
|
|
74
|
-
ctx: &mut TxContext
|
|
75
|
-
) {
|
|
76
|
-
assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
|
|
77
|
-
dapps.borrow_mut_admin().set(package_id, new_admin);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public fun assert_admin<T: drop>(dapps: &Dapps, ctx: &TxContext) {
|
|
81
|
-
let package_id = current_package_id<T>();
|
|
82
|
-
assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public fun assert_is_safe_mode<T: drop>(dapps: &Dapps) {
|
|
86
|
-
let package_id = current_package_id<T>();
|
|
87
|
-
assert!(!dapps.borrow_safe_mode().get(package_id), 0);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
module dubhe::world {
|
|
2
|
-
use std::ascii::{String};
|
|
3
|
-
use sui::bag::{Self, Bag};
|
|
4
|
-
|
|
5
|
-
public struct AdminCap has key, store {
|
|
6
|
-
id: UID,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public struct World has key, store {
|
|
10
|
-
id: UID,
|
|
11
|
-
/// Name of the world
|
|
12
|
-
name: String,
|
|
13
|
-
/// Description of the world
|
|
14
|
-
description: String,
|
|
15
|
-
/// Schemas of the world
|
|
16
|
-
schemas: Bag,
|
|
17
|
-
/// Schema names of the world
|
|
18
|
-
schema_names: vector<String>,
|
|
19
|
-
/// admin of the world
|
|
20
|
-
admin: ID,
|
|
21
|
-
/// version of the world
|
|
22
|
-
version: u64
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public fun create(name: String, description: String, ctx: &mut TxContext): (World, AdminCap) {
|
|
26
|
-
let admin_cap = AdminCap {
|
|
27
|
-
id: object::new(ctx),
|
|
28
|
-
};
|
|
29
|
-
let world = World {
|
|
30
|
-
id: object::new(ctx),
|
|
31
|
-
name,
|
|
32
|
-
description,
|
|
33
|
-
schemas: bag::new(ctx),
|
|
34
|
-
schema_names: vector::empty(),
|
|
35
|
-
admin: object::id(&admin_cap),
|
|
36
|
-
version: 1,
|
|
37
|
-
};
|
|
38
|
-
(world, admin_cap)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public fun admin(world: &World): ID {
|
|
42
|
-
world.admin
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public fun version(world: &World): u64 {
|
|
46
|
-
world.version
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public fun mut_version(world: &mut World, admin_cap: &AdminCap): &mut u64 {
|
|
50
|
-
assert!(world.admin() == object::id(admin_cap), 0);
|
|
51
|
-
&mut world.version
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public fun info(world: &World): (String, String) {
|
|
55
|
-
(world.name, world.description)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public fun schema_names(world: &World): vector<String> {
|
|
59
|
-
world.schema_names
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public(package) fun mut_schema_names(world: &mut World): &mut vector<String> {
|
|
63
|
-
&mut world.schema_names
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public(package) fun mut_uid(world: &mut World): &mut UID {
|
|
67
|
-
&mut world.id
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public(package) fun uid(world: &World): &UID {
|
|
71
|
-
&world.id
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public(package) fun schemas(world: &World): &Bag {
|
|
75
|
-
&world.schemas
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public(package) fun mut_schemas(world: &mut World): &mut Bag {
|
|
79
|
-
&mut world.schemas
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#[test_only]
|
|
2
|
-
module dubhe::dapps_tests {
|
|
3
|
-
use std::debug;
|
|
4
|
-
use std::type_name;
|
|
5
|
-
use sui::address;
|
|
6
|
-
|
|
7
|
-
public struct USDT has drop {}
|
|
8
|
-
|
|
9
|
-
#[test]
|
|
10
|
-
public fun dapps_register() {
|
|
11
|
-
let name = type_name::get<USDT>().get_address().into_bytes();
|
|
12
|
-
let package_id = address::from_ascii_bytes(&name);
|
|
13
|
-
debug::print(&package_id);
|
|
14
|
-
debug::print(&type_name::get<USDT>().get_module());
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
## Dubhe Framework
|
|
2
|
-
|
|
3
|
-
### Testnet
|
|
4
|
-
```txt
|
|
5
|
-
PackageID: 0xf68ab6ceb5cfce6a73d76e5ef64f28d3cbe684413c80232871b31a9df0e09496
|
|
6
|
-
Version: 1
|
|
7
|
-
Digest: HwpoK2ZUoxsDzFyeszWzdcAm4aLi5g2CxBq3JBodxA16
|
|
8
|
-
Modules: access_control, events, resource_id, resource_tyeps, schema, world
|
|
9
|
-
|
|
10
|
-
ObjectID: 0x9f4cd3e0aa5587b2d9191fa20ea877a0d66c6eb6a4f49ec34328122b29d1d9c6
|
|
11
|
-
ObjectType: 0x2::package::UpgradeCap
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
```shell
|
|
15
|
-
# upgrade
|
|
16
|
-
sui client upgrade --gas-budget 1000000000 --upgrade-capability 0x9f4cd3e0aa5587b2d9191fa20ea877a0d66c6eb6a4f49ec34328122b29d1d9c6
|
|
17
|
-
```
|
|
18
|
-
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
module dubhe::access_control {
|
|
2
|
-
use dubhe::world::{AdminCap, World};
|
|
3
|
-
use sui::dynamic_field as df;
|
|
4
|
-
|
|
5
|
-
const ENotAdmin: u64 = 4;
|
|
6
|
-
const EAppNotAuthorized: u64 = 5;
|
|
7
|
-
|
|
8
|
-
public struct AppKey<phantom App: drop> has copy, store, drop {}
|
|
9
|
-
|
|
10
|
-
/// Authorize an application to access protected features of the World.
|
|
11
|
-
public fun authorize_app<App: drop>(admin_cap: &AdminCap, world: &mut World) {
|
|
12
|
-
assert!(world.admin() == object::id(admin_cap), ENotAdmin);
|
|
13
|
-
df::add(world.mut_uid(), AppKey<App>{}, true);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/// Deauthorize an application by removing its authorization key.
|
|
17
|
-
public fun deauthorize_app<App: drop>(admin_cap: &AdminCap, world: &mut World): bool {
|
|
18
|
-
assert!(world.admin() == object::id(admin_cap), ENotAdmin);
|
|
19
|
-
df::remove(world.mut_uid(), AppKey<App>{})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Check if an application is authorized to access protected features of
|
|
23
|
-
/// the World.
|
|
24
|
-
public fun is_app_authorized<App: drop>(world: &World): bool {
|
|
25
|
-
df::exists_(world.uid(), AppKey<App>{})
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/// Assert that an application is authorized to access protected features of
|
|
29
|
-
/// the World. Aborts with `EAppNotAuthorized` if not.
|
|
30
|
-
public fun assert_app_is_authorized<App: drop>(world: &World) {
|
|
31
|
-
assert!(is_app_authorized<App>(world), EAppNotAuthorized);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module dubhe::events {
|
|
2
|
-
use sui::event;
|
|
3
|
-
|
|
4
|
-
public struct SchemaSetRecord<T: copy + drop> has copy, drop {
|
|
5
|
-
_dubhe_schema_id: vector<u8>,
|
|
6
|
-
_dubhe_schema_type: u8,
|
|
7
|
-
_dubhe_entity_key: Option<address>,
|
|
8
|
-
data: T
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public struct SchemaRemoveRecord has copy, drop {
|
|
12
|
-
_dubhe_schema_id: vector<u8>,
|
|
13
|
-
_dubhe_entity_key: address
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public fun emit_set<T: copy + drop>(_dubhe_schema_id: vector<u8>, _dubhe_schema_type: u8, _dubhe_entity_key: Option<address>, data: T) {
|
|
17
|
-
event::emit(SchemaSetRecord { _dubhe_schema_id, _dubhe_schema_type, _dubhe_entity_key, data})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public fun emit_remove(_dubhe_schema_id: vector<u8>, _dubhe_entity_key: address) {
|
|
21
|
-
event::emit(SchemaRemoveRecord { _dubhe_schema_id, _dubhe_entity_key })
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module dubhe::resource_id {
|
|
2
|
-
|
|
3
|
-
public fun encode(type_id: vector<u8>, namespace: vector<u8>, name: vector<u8>) : vector<u8> {
|
|
4
|
-
let mut resource_id: vector<u8> = vector[];
|
|
5
|
-
vector::append(&mut resource_id, type_id);
|
|
6
|
-
vector::append(&mut resource_id, namespace);
|
|
7
|
-
vector::append(&mut resource_id, name);
|
|
8
|
-
resource_id
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public fun offchain_schema() : vector<u8> {
|
|
12
|
-
b"os"
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public fun system() : vector<u8> {
|
|
16
|
-
b"sy"
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public fun namespace() : vector<u8> {
|
|
20
|
-
b"ns"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module dubhe::resource_tyeps {
|
|
2
|
-
|
|
3
|
-
public fun schema() : vector<u8> {
|
|
4
|
-
b"sc"
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
public fun offchain_schema() : vector<u8> {
|
|
8
|
-
b"os"
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public fun system() : vector<u8> {
|
|
12
|
-
b"sy"
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public fun namespace() : vector<u8> {
|
|
16
|
-
b"ns"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module dubhe::schema {
|
|
2
|
-
use std::ascii::{string};
|
|
3
|
-
use sui::bag::{Self};
|
|
4
|
-
use dubhe::world::{World, AdminCap};
|
|
5
|
-
use dubhe::access_control;
|
|
6
|
-
|
|
7
|
-
/// Schema does not exist
|
|
8
|
-
const ESchemaDoesNotExist: u64 = 0;
|
|
9
|
-
/// Schema already exists
|
|
10
|
-
const ESchemaAlreadyExists: u64 = 1;
|
|
11
|
-
/// Not the right admin for this world
|
|
12
|
-
const ENotAdmin: u64 = 2;
|
|
13
|
-
|
|
14
|
-
public fun get<T : store>(world: &World, _dubhe_schema_id: vector<u8>): &T {
|
|
15
|
-
assert!(bag::contains(world.schemas(), _dubhe_schema_id), ESchemaDoesNotExist);
|
|
16
|
-
bag::borrow<vector<u8>, T>(world.schemas(), _dubhe_schema_id)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public fun add<T : store>(_dubhe_world: &mut World, _dubhe_schema_id: vector<u8>, schema: T, admin_cap: &AdminCap){
|
|
20
|
-
assert!(_dubhe_world.admin() == object::id(admin_cap), ENotAdmin);
|
|
21
|
-
assert!(!bag::contains(_dubhe_world.schemas(), _dubhe_schema_id), ESchemaAlreadyExists);
|
|
22
|
-
vector::push_back(_dubhe_world.mut_schema_names(), string(_dubhe_schema_id));
|
|
23
|
-
bag::add<vector<u8>,T>(_dubhe_world.mut_schemas(), _dubhe_schema_id, schema);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public fun contains(_dubhe_world: &mut World, _dubhe_schema_id: vector<u8>): bool {
|
|
27
|
-
bag::contains(_dubhe_world.schemas(), _dubhe_schema_id)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// === Protected features ===
|
|
31
|
-
public fun get_mut<T : store, App: drop>(_: App, world: &mut World, _dubhe_schema_id: vector<u8>): &mut T {
|
|
32
|
-
access_control::assert_app_is_authorized<App>(world);
|
|
33
|
-
assert!(bag::contains(world.schemas(), _dubhe_schema_id), ESchemaDoesNotExist);
|
|
34
|
-
bag::borrow_mut<vector<u8>, T>(world.mut_schemas(), _dubhe_schema_id)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
module dubhe::dapps_system {
|
|
2
|
-
use std::ascii::String;
|
|
3
|
-
use std::ascii;
|
|
4
|
-
use std::type_name;
|
|
5
|
-
use sui::address;
|
|
6
|
-
use dubhe::dapp_metadata;
|
|
7
|
-
use sui::clock::Clock;
|
|
8
|
-
use dubhe::dapps_schema::Dapps;
|
|
9
|
-
|
|
10
|
-
public fun current_package_id<T>(): address {
|
|
11
|
-
let dapp_package_id_string = type_name::get<T>().get_address().into_bytes();
|
|
12
|
-
address::from_ascii_bytes(&dapp_package_id_string)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public entry fun register<T>(
|
|
16
|
-
dapps: &mut Dapps,
|
|
17
|
-
name: String,
|
|
18
|
-
description: String,
|
|
19
|
-
clock: &Clock,
|
|
20
|
-
ctx: &mut TxContext
|
|
21
|
-
) {
|
|
22
|
-
let dapp_package_id = current_package_id<T>();
|
|
23
|
-
assert!(!dapps.borrow_metadata().contains_key(dapp_package_id), 0);
|
|
24
|
-
|
|
25
|
-
dapps.borrow_mut_metadata().set(
|
|
26
|
-
dapp_package_id,
|
|
27
|
-
dapp_metadata::new(
|
|
28
|
-
name,
|
|
29
|
-
description,
|
|
30
|
-
ascii::string(b""),
|
|
31
|
-
ascii::string(b""),
|
|
32
|
-
clock.timestamp_ms(),
|
|
33
|
-
vector[]
|
|
34
|
-
)
|
|
35
|
-
);
|
|
36
|
-
dapps.borrow_mut_admin().set(dapp_package_id, ctx.sender());
|
|
37
|
-
dapps.borrow_mut_version().set(dapp_package_id, 0);
|
|
38
|
-
dapps.borrow_mut_schemas().set(dapp_package_id, vector[]);
|
|
39
|
-
dapps.borrow_mut_safe_mode().set(dapp_package_id, false);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public entry fun set_metadata(
|
|
43
|
-
dapps: &mut Dapps,
|
|
44
|
-
package_id: address,
|
|
45
|
-
clock: &Clock,
|
|
46
|
-
name: String,
|
|
47
|
-
description: String,
|
|
48
|
-
icon_url: String,
|
|
49
|
-
website_url: String,
|
|
50
|
-
partners: vector<String>,
|
|
51
|
-
ctx: &mut TxContext
|
|
52
|
-
) {
|
|
53
|
-
assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
|
|
54
|
-
let created_at = clock.timestamp_ms();
|
|
55
|
-
assert!(dapps.borrow_metadata().contains_key(package_id), 0);
|
|
56
|
-
dapps.borrow_mut_metadata().mutate!(package_id, |metadata| {
|
|
57
|
-
metadata.set(name, description, icon_url, website_url, created_at, partners);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public entry fun add_schema<T>(dapps: &mut Dapps, package_id: address, ctx: &mut TxContext) {
|
|
62
|
-
assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
|
|
63
|
-
let schema = type_name::get<T>().into_string();
|
|
64
|
-
assert!(!dapps.borrow_schemas().get(package_id).contains(&schema), 0);
|
|
65
|
-
dapps.borrow_mut_schemas().mutate!(package_id, |schemas| {
|
|
66
|
-
schemas.push_back(schema);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public entry fun transfer_ownership(
|
|
71
|
-
dapps: &mut Dapps,
|
|
72
|
-
package_id: address,
|
|
73
|
-
new_admin: address,
|
|
74
|
-
ctx: &mut TxContext
|
|
75
|
-
) {
|
|
76
|
-
assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
|
|
77
|
-
dapps.borrow_mut_admin().set(package_id, new_admin);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public fun assert_admin<T: drop>(dapps: &Dapps, ctx: &TxContext) {
|
|
81
|
-
let package_id = current_package_id<T>();
|
|
82
|
-
assert!(dapps.borrow_admin().get(package_id) == ctx.sender(), 0);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public fun assert_is_safe_mode<T: drop>(dapps: &Dapps) {
|
|
86
|
-
let package_id = current_package_id<T>();
|
|
87
|
-
assert!(!dapps.borrow_safe_mode().get(package_id), 0);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
module dubhe::world {
|
|
2
|
-
use std::ascii::{String};
|
|
3
|
-
use sui::bag::{Self, Bag};
|
|
4
|
-
|
|
5
|
-
public struct AdminCap has key, store {
|
|
6
|
-
id: UID,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public struct World has key, store {
|
|
10
|
-
id: UID,
|
|
11
|
-
/// Name of the world
|
|
12
|
-
name: String,
|
|
13
|
-
/// Description of the world
|
|
14
|
-
description: String,
|
|
15
|
-
/// Schemas of the world
|
|
16
|
-
schemas: Bag,
|
|
17
|
-
/// Schema names of the world
|
|
18
|
-
schema_names: vector<String>,
|
|
19
|
-
/// admin of the world
|
|
20
|
-
admin: ID,
|
|
21
|
-
/// version of the world
|
|
22
|
-
version: u64
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public fun create(name: String, description: String, ctx: &mut TxContext): (World, AdminCap) {
|
|
26
|
-
let admin_cap = AdminCap {
|
|
27
|
-
id: object::new(ctx),
|
|
28
|
-
};
|
|
29
|
-
let world = World {
|
|
30
|
-
id: object::new(ctx),
|
|
31
|
-
name,
|
|
32
|
-
description,
|
|
33
|
-
schemas: bag::new(ctx),
|
|
34
|
-
schema_names: vector::empty(),
|
|
35
|
-
admin: object::id(&admin_cap),
|
|
36
|
-
version: 1,
|
|
37
|
-
};
|
|
38
|
-
(world, admin_cap)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public fun admin(world: &World): ID {
|
|
42
|
-
world.admin
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public fun version(world: &World): u64 {
|
|
46
|
-
world.version
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public fun mut_version(world: &mut World, admin_cap: &AdminCap): &mut u64 {
|
|
50
|
-
assert!(world.admin() == object::id(admin_cap), 0);
|
|
51
|
-
&mut world.version
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public fun info(world: &World): (String, String) {
|
|
55
|
-
(world.name, world.description)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public fun schema_names(world: &World): vector<String> {
|
|
59
|
-
world.schema_names
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public(package) fun mut_schema_names(world: &mut World): &mut vector<String> {
|
|
63
|
-
&mut world.schema_names
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public(package) fun mut_uid(world: &mut World): &mut UID {
|
|
67
|
-
&mut world.id
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public(package) fun uid(world: &World): &UID {
|
|
71
|
-
&world.id
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public(package) fun schemas(world: &World): &Bag {
|
|
75
|
-
&world.schemas
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public(package) fun mut_schemas(world: &mut World): &mut Bag {
|
|
79
|
-
&mut world.schemas
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#[test_only]
|
|
2
|
-
module dubhe::dapps_tests {
|
|
3
|
-
use std::debug;
|
|
4
|
-
use std::type_name;
|
|
5
|
-
use sui::address;
|
|
6
|
-
|
|
7
|
-
public struct USDT has drop {}
|
|
8
|
-
|
|
9
|
-
#[test]
|
|
10
|
-
public fun dapps_register() {
|
|
11
|
-
let name = type_name::get<USDT>().get_address().into_bytes();
|
|
12
|
-
let package_id = address::from_ascii_bytes(&name);
|
|
13
|
-
debug::print(&package_id);
|
|
14
|
-
debug::print(&type_name::get<USDT>().get_module());
|
|
15
|
-
}
|
|
16
|
-
}
|
/package/template/101/sui-template/contracts/counter/sources/{system → systems}/counter.move
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|