create-dubhe 0.0.13 → 0.0.14
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/package.json +1 -1
- package/template/101/sui-template/contracts/counter/sources/codegen/errors/counter_error_invalid_increment.move +30 -0
- package/template/101/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move +28 -0
- package/template/101/sui-template/contracts/counter/sources/codegen/schemas/counter.move +13 -13
- package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/metadata.move +102 -0
- package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +114 -0
- package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/system.move +93 -0
- package/template/101/sui-template/contracts/counter/sources/scripts/deploy_hook.move +10 -82
- package/template/101/sui-template/contracts/counter/sources/scripts/migrate.move +1 -2
- package/template/101/sui-template/contracts/counter/sources/systems/counter.move +13 -4
- package/template/101/sui-template/contracts/counter/sources/tests/counter.move +26 -0
- package/template/101/sui-template/contracts/counter/sources/tests/init.move +21 -0
- package/template/101/sui-template/contracts/dubhe-framework/sources/frames/utils/type_info.move +7 -0
- package/template/{nextjs/sui-template/contracts/dubhe-framework/sources/storages/migrate.move → 101/sui-template/contracts/dubhe-framework/sources/storages/migration.move} +3 -3
- package/template/101/sui-template/contracts/dubhe-framework/sources/storages/value.move +1 -1
- package/template/101/sui-template/dubhe.config.ts +23 -10
- package/template/101/sui-template/package.json +2 -2
- package/template/101/sui-template/src/pages/home/index.tsx +1 -1
- package/template/contract/sui-template/contracts/counter/sources/codegen/errors/counter_error_invalid_increment.move +6 -4
- package/template/contract/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move +1 -1
- package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/counter.move +13 -13
- package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/metadata.move +102 -0
- package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +114 -0
- package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/system.move +93 -0
- package/template/contract/sui-template/contracts/counter/sources/scripts/deploy_hook.move +9 -81
- package/template/contract/sui-template/contracts/counter/sources/scripts/migrate.move +1 -1
- package/template/contract/sui-template/contracts/counter/sources/systems/counter.move +7 -7
- package/template/contract/sui-template/contracts/counter/sources/tests/counter.move +26 -0
- package/template/contract/sui-template/contracts/counter/sources/tests/init.move +21 -0
- package/template/contract/sui-template/contracts/dubhe-framework/sources/frames/utils/type_info.move +7 -0
- package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/{migrate.move → migration.move} +3 -3
- package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/value.move +1 -1
- package/template/contract/sui-template/dubhe.config.ts +1 -2
- package/template/contract/sui-template/package.json +2 -2
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/errors/counter_error_invalid_increment.move +30 -0
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move +28 -0
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/counter.move +13 -13
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/metadata.move +102 -0
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +114 -0
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/system.move +93 -0
- package/template/nextjs/sui-template/contracts/counter/sources/scripts/deploy_hook.move +9 -81
- package/template/nextjs/sui-template/contracts/counter/sources/scripts/migrate.move +1 -1
- package/template/nextjs/sui-template/contracts/counter/sources/systems/counter.move +13 -4
- package/template/nextjs/sui-template/contracts/counter/sources/tests/counter.move +26 -0
- package/template/nextjs/sui-template/contracts/counter/sources/tests/init.move +21 -0
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/frames/utils/type_info.move +7 -0
- package/template/{101/sui-template/contracts/dubhe-framework/sources/storages/migrate.move → nextjs/sui-template/contracts/dubhe-framework/sources/storages/migration.move} +3 -3
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/storages/value.move +1 -1
- package/template/nextjs/sui-template/dubhe.config.ts +23 -10
- package/template/nextjs/sui-template/package.json +2 -2
- package/template/nextjs/sui-template/src/pages/home/index.tsx +1 -1
- package/template/101/sui-template/contracts/counter/sources/codegen/dapp_key.move +0 -16
- package/template/101/sui-template/contracts/counter/sources/codegen/schema_hub.move +0 -60
- package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/metadata.move +0 -96
- package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/schema.move +0 -113
- package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/system.move +0 -101
- package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/tests.move +0 -66
- package/template/101/sui-template/contracts/dubhe-framework/sources/core/root/schema.move +0 -33
- package/template/101/sui-template/contracts/dubhe-framework/sources/core/root/system.move +0 -24
- package/template/101/sui-template/contracts/dubhe-framework/sources/core/root/tests.move +0 -39
- package/template/101/sui-template/contracts/dubhe-framework/tests/init.move +0 -6
- package/template/101/sui-template/contracts/dubhe-framework/tests/obelisk_framework_tests.move +0 -19
- package/template/contract/sui-template/contracts/counter/sources/codegen/dapp_key.move +0 -16
- package/template/contract/sui-template/contracts/counter/sources/codegen/schema_hub.move +0 -60
- package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/metadata.move +0 -96
- package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/schema.move +0 -113
- package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/system.move +0 -101
- package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/tests.move +0 -66
- package/template/contract/sui-template/contracts/dubhe-framework/sources/core/root/schema.move +0 -33
- package/template/contract/sui-template/contracts/dubhe-framework/sources/core/root/system.move +0 -24
- package/template/contract/sui-template/contracts/dubhe-framework/sources/core/root/tests.move +0 -39
- package/template/contract/sui-template/contracts/dubhe-framework/tests/init.move +0 -6
- package/template/contract/sui-template/contracts/dubhe-framework/tests/obelisk_framework_tests.move +0 -19
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/dapp_key.move +0 -16
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schema_hub.move +0 -60
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/metadata.move +0 -96
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/schema.move +0 -113
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/system.move +0 -101
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/tests.move +0 -66
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/root/schema.move +0 -33
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/root/system.move +0 -24
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/root/tests.move +0 -39
- package/template/nextjs/sui-template/contracts/dubhe-framework/tests/init.move +0 -6
- package/template/nextjs/sui-template/contracts/dubhe-framework/tests/obelisk_framework_tests.move +0 -19
package/package.json
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright (c) Obelisk Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#[allow(unused_use)]
|
|
4
|
+
|
|
5
|
+
/* Autogenerated file. Do not edit manually. */
|
|
6
|
+
|
|
7
|
+
module counter::counter_error_invalid_increment {
|
|
8
|
+
|
|
9
|
+
#[error]
|
|
10
|
+
|
|
11
|
+
const InvalidIncrement: vector<u8> = b"Number can't be incremented, must be more than 0";
|
|
12
|
+
|
|
13
|
+
/// Get the error message.
|
|
14
|
+
|
|
15
|
+
public fun message(): vector<u8> {
|
|
16
|
+
InvalidIncrement
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// Abort execution with the given error code.
|
|
20
|
+
|
|
21
|
+
public fun emit() {
|
|
22
|
+
abort InvalidIncrement
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// Require that the given condition is true, otherwise abort with the given error code.
|
|
26
|
+
|
|
27
|
+
public fun require(condition: bool) {
|
|
28
|
+
if (!condition) { emit() }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright (c) Obelisk Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#[allow(unused_use)]
|
|
4
|
+
|
|
5
|
+
/* Autogenerated file. Do not edit manually. */
|
|
6
|
+
|
|
7
|
+
module counter::counter_event_increment {
|
|
8
|
+
|
|
9
|
+
use sui::event;
|
|
10
|
+
|
|
11
|
+
use std::ascii::String;
|
|
12
|
+
|
|
13
|
+
public struct IncrementEvent has copy, drop {
|
|
14
|
+
value: u32,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public fun new(value: u32): IncrementEvent {
|
|
18
|
+
IncrementEvent {
|
|
19
|
+
value
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public fun emit(value: u32) {
|
|
24
|
+
event::emit(IncrementEvent {
|
|
25
|
+
value
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Obelisk Labs, Inc.
|
|
2
|
-
// SPDX-License-Identifier:
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
#[allow(unused_use)]
|
|
4
4
|
|
|
5
5
|
/* Autogenerated file. Do not edit manually. */
|
|
@@ -14,11 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
use std::type_name;
|
|
16
16
|
|
|
17
|
-
use dubhe::
|
|
18
|
-
|
|
19
|
-
use dubhe::storage_migrate;
|
|
20
|
-
|
|
21
|
-
use dubhe::dapps_schema::Dapps;
|
|
17
|
+
use dubhe::storage_migration;
|
|
22
18
|
|
|
23
19
|
use dubhe::storage_value::{Self, StorageValue};
|
|
24
20
|
|
|
@@ -26,25 +22,29 @@
|
|
|
26
22
|
|
|
27
23
|
use dubhe::storage_double_map::{Self, StorageDoubleMap};
|
|
28
24
|
|
|
29
|
-
use counter::dapp_key::DappKey;
|
|
30
|
-
|
|
31
25
|
use sui::dynamic_field as df;
|
|
32
26
|
|
|
27
|
+
use sui::sui::SUI;
|
|
28
|
+
|
|
29
|
+
use sui::coin::Coin;
|
|
30
|
+
|
|
31
|
+
use sui::balance::Balance;
|
|
32
|
+
|
|
33
33
|
public struct Counter has key, store {
|
|
34
34
|
id: UID,
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
public fun borrow_value(self: &Counter): &StorageValue<u32> {
|
|
38
|
-
|
|
38
|
+
storage_migration::borrow_field(&self.id, b"value")
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
public(package) fun borrow_mut_value(self: &mut Counter): &mut StorageValue<u32> {
|
|
42
|
-
|
|
42
|
+
storage_migration::borrow_mut_field(&mut self.id, b"value")
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
public(package) fun create(ctx: &mut TxContext): Counter {
|
|
46
46
|
let mut id = object::new(ctx);
|
|
47
|
-
|
|
47
|
+
storage_migration::add_field<StorageValue<u32>>(&mut id, b"value", storage_value::new());
|
|
48
48
|
Counter { id }
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
|
|
53
53
|
// ======================================== View Functions ========================================
|
|
54
54
|
|
|
55
|
-
public fun get_value(self: &Counter):
|
|
56
|
-
self.borrow_value().
|
|
55
|
+
public fun get_value(self: &Counter): &u32 {
|
|
56
|
+
self.borrow_value().borrow()
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// =========================================================================================================
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Copyright (c) Obelisk Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#[allow(unused_use)]
|
|
4
|
+
|
|
5
|
+
/* Autogenerated file. Do not edit manually. */
|
|
6
|
+
|
|
7
|
+
module counter::dapp_metadata {
|
|
8
|
+
|
|
9
|
+
use std::ascii::String;
|
|
10
|
+
|
|
11
|
+
public struct DappMetadata has drop, copy, store {
|
|
12
|
+
name: String,
|
|
13
|
+
description: String,
|
|
14
|
+
icon_url: String,
|
|
15
|
+
website_url: String,
|
|
16
|
+
created_at: u64,
|
|
17
|
+
partners: vector<String>,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public fun new(
|
|
21
|
+
name: String,
|
|
22
|
+
description: String,
|
|
23
|
+
icon_url: String,
|
|
24
|
+
website_url: String,
|
|
25
|
+
created_at: u64,
|
|
26
|
+
partners: vector<String>,
|
|
27
|
+
): DappMetadata {
|
|
28
|
+
DappMetadata {
|
|
29
|
+
name,
|
|
30
|
+
description,
|
|
31
|
+
icon_url,
|
|
32
|
+
website_url,
|
|
33
|
+
created_at,
|
|
34
|
+
partners,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public fun set(
|
|
39
|
+
self: &mut DappMetadata,
|
|
40
|
+
name: String,
|
|
41
|
+
description: String,
|
|
42
|
+
icon_url: String,
|
|
43
|
+
website_url: String,
|
|
44
|
+
created_at: u64,
|
|
45
|
+
partners: vector<String>,
|
|
46
|
+
) {
|
|
47
|
+
self.name = name;
|
|
48
|
+
self.description = description;
|
|
49
|
+
self.icon_url = icon_url;
|
|
50
|
+
self.website_url = website_url;
|
|
51
|
+
self.created_at = created_at;
|
|
52
|
+
self.partners = partners;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public fun set_name(self: &mut DappMetadata, name: String) {
|
|
56
|
+
self.name = name;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public fun set_description(self: &mut DappMetadata, description: String) {
|
|
60
|
+
self.description = description;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public fun set_icon_url(self: &mut DappMetadata, icon_url: String) {
|
|
64
|
+
self.icon_url = icon_url;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public fun set_website_url(self: &mut DappMetadata, website_url: String) {
|
|
68
|
+
self.website_url = website_url;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public fun set_created_at(self: &mut DappMetadata, created_at: u64) {
|
|
72
|
+
self.created_at = created_at;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public fun set_partners(self: &mut DappMetadata, partners: vector<String>) {
|
|
76
|
+
self.partners = partners;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public fun get_name(self: DappMetadata): String {
|
|
80
|
+
self.name
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public fun get_description(self: DappMetadata): String {
|
|
84
|
+
self.description
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public fun get_icon_url(self: DappMetadata): String {
|
|
88
|
+
self.icon_url
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public fun get_website_url(self: DappMetadata): String {
|
|
92
|
+
self.website_url
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public fun get_created_at(self: DappMetadata): u64 {
|
|
96
|
+
self.created_at
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public fun get_partners(self: DappMetadata): vector<String> {
|
|
100
|
+
self.partners
|
|
101
|
+
}
|
|
102
|
+
}
|
package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Copyright (c) Obelisk Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#[allow(unused_use)]
|
|
4
|
+
|
|
5
|
+
/* Autogenerated file. Do not edit manually. */
|
|
6
|
+
|
|
7
|
+
module counter::dapp_schema {
|
|
8
|
+
|
|
9
|
+
use counter::dapp_metadata::DappMetadata;
|
|
10
|
+
|
|
11
|
+
use dubhe::storage_value;
|
|
12
|
+
|
|
13
|
+
use dubhe::storage_value::StorageValue;
|
|
14
|
+
|
|
15
|
+
use dubhe::storage_migration;
|
|
16
|
+
|
|
17
|
+
use sui::transfer::public_share_object;
|
|
18
|
+
|
|
19
|
+
use dubhe::type_info;
|
|
20
|
+
|
|
21
|
+
public struct Dapp has key, store {
|
|
22
|
+
id: UID,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public fun borrow_admin(self: &Dapp): &StorageValue<address> {
|
|
26
|
+
storage_migration::borrow_field(&self.id, b"admin")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public(package) fun borrow_mut_admin(self: &mut Dapp): &mut StorageValue<address> {
|
|
30
|
+
storage_migration::borrow_mut_field(&mut self.id, b"admin")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public fun borrow_package_id(self: &Dapp): &StorageValue<address> {
|
|
34
|
+
storage_migration::borrow_field(&self.id, b"package_id")
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public(package) fun borrow_mut_package_id(self: &mut Dapp): &mut StorageValue<address> {
|
|
38
|
+
storage_migration::borrow_mut_field(&mut self.id, b"package_id")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public fun borrow_version(self: &Dapp): &StorageValue<u32> {
|
|
42
|
+
storage_migration::borrow_field(&self.id, b"version")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public(package) fun borrow_mut_version(self: &mut Dapp): &mut StorageValue<u32> {
|
|
46
|
+
storage_migration::borrow_mut_field(&mut self.id, b"version")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public fun borrow_metadata(self: &Dapp): &StorageValue<DappMetadata> {
|
|
50
|
+
storage_migration::borrow_field(&self.id, b"metadata")
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public(package) fun borrow_mut_metadata(self: &mut Dapp): &mut StorageValue<DappMetadata> {
|
|
54
|
+
storage_migration::borrow_mut_field(&mut self.id, b"metadata")
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public fun borrow_schemas(self: &Dapp): &StorageValue<vector<address>> {
|
|
58
|
+
storage_migration::borrow_field(&self.id, b"schemas")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public(package) fun borrow_mut_schemas(self: &mut Dapp): &mut StorageValue<vector<address>> {
|
|
62
|
+
storage_migration::borrow_mut_field(&mut self.id, b"schemas")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public fun borrow_safe_mode(self: &Dapp): &StorageValue<bool> {
|
|
66
|
+
storage_migration::borrow_field(&self.id, b"safe_mode")
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public(package) fun borrow_mut_safe_mode(self: &mut Dapp): &mut StorageValue<bool> {
|
|
70
|
+
storage_migration::borrow_mut_field(&mut self.id, b"safe_mode")
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public(package) fun create(ctx: &mut TxContext): Dapp {
|
|
74
|
+
let mut id = object::new(ctx);
|
|
75
|
+
storage_migration::add_field<StorageValue<address>>(&mut id, b"admin", storage_value::new());
|
|
76
|
+
storage_migration::add_field<StorageValue<address>>(&mut id, b"package_id", storage_value::new());
|
|
77
|
+
storage_migration::add_field<StorageValue<u32>>(&mut id, b"version", storage_value::new());
|
|
78
|
+
storage_migration::add_field<StorageValue<DappMetadata>>(&mut id, b"metadata", storage_value::new());
|
|
79
|
+
storage_migration::add_field<StorageValue<vector<address>>>(&mut id, b"schemas", storage_value::new());
|
|
80
|
+
storage_migration::add_field<StorageValue<bool>>(&mut id, b"safe_mode", storage_value::new());
|
|
81
|
+
Dapp { id }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public(package) fun upgrade<DappKey: drop>(dapp: &mut Dapp, ctx: &TxContext) {
|
|
85
|
+
assert!(dapp.borrow_metadata().contains(), 0);
|
|
86
|
+
assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
|
|
87
|
+
let new_package_id = type_info::current_package_id<DappKey>();
|
|
88
|
+
dapp.borrow_mut_package_id().set(new_package_id);
|
|
89
|
+
dapp.borrow_mut_version().mutate!(|version| {
|
|
90
|
+
*version = *version + 1;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public(package) fun add_schema<Schema: key + store>(dapp: &mut Dapp, schema: Schema, ctx: &TxContext) {
|
|
95
|
+
assert!(dapp.borrow_metadata().contains(), 0);
|
|
96
|
+
assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
|
|
97
|
+
let schema_id = object::id_address(&schema);
|
|
98
|
+
dapp.borrow_mut_schemas().borrow_mut().push_back(schema_id);
|
|
99
|
+
public_share_object(schema);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#[test_only]
|
|
103
|
+
|
|
104
|
+
public fun create_dapp_for_testing(ctx: &mut TxContext): Dapp {
|
|
105
|
+
create(ctx)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#[test_only]
|
|
109
|
+
|
|
110
|
+
public fun distroy_dapp_for_testing(dapp: Dapp) {
|
|
111
|
+
let Dapp { id } = dapp;
|
|
112
|
+
id.delete();
|
|
113
|
+
}
|
|
114
|
+
}
|
package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/system.move
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
module counter::dapp_system {
|
|
2
|
+
|
|
3
|
+
use std::ascii::String;
|
|
4
|
+
|
|
5
|
+
use std::ascii;
|
|
6
|
+
|
|
7
|
+
use dubhe::type_info;
|
|
8
|
+
|
|
9
|
+
use sui::clock::Clock;
|
|
10
|
+
|
|
11
|
+
use counter::dapp_schema;
|
|
12
|
+
|
|
13
|
+
use counter::dapp_metadata;
|
|
14
|
+
|
|
15
|
+
use counter::dapp_schema::Dapp;
|
|
16
|
+
|
|
17
|
+
public struct DappKey has drop {}
|
|
18
|
+
|
|
19
|
+
public(package) fun new(): DappKey {
|
|
20
|
+
DappKey { }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public(package) fun create(name: String, description: String, clock: &Clock, ctx: &mut TxContext): Dapp {
|
|
24
|
+
let mut dapp = dapp_schema::create(ctx);
|
|
25
|
+
assert!(!dapp.borrow_metadata().contains(), 0);
|
|
26
|
+
dapp.borrow_mut_metadata().set(
|
|
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
|
+
let package_id = type_info::current_package_id<DappKey>();
|
|
37
|
+
dapp.borrow_mut_package_id().set(package_id);
|
|
38
|
+
dapp.borrow_mut_admin().set(ctx.sender());
|
|
39
|
+
dapp.borrow_mut_version().set(1);
|
|
40
|
+
dapp.borrow_mut_safe_mode().set(false);
|
|
41
|
+
dapp.borrow_mut_schemas().set(vector[]);
|
|
42
|
+
dapp
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public entry fun set_metadata(
|
|
46
|
+
dapp: &mut Dapp,
|
|
47
|
+
name: String,
|
|
48
|
+
description: String,
|
|
49
|
+
icon_url: String,
|
|
50
|
+
website_url: String,
|
|
51
|
+
partners: vector<String>,
|
|
52
|
+
ctx: &TxContext,
|
|
53
|
+
) {
|
|
54
|
+
assert!(dapp.borrow_admin().contains(), 0);
|
|
55
|
+
assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
|
|
56
|
+
let created_at = dapp.borrow_mut_metadata().take().get_created_at();
|
|
57
|
+
dapp.borrow_mut_metadata().set(
|
|
58
|
+
dapp_metadata::new(
|
|
59
|
+
name,
|
|
60
|
+
description,
|
|
61
|
+
icon_url,
|
|
62
|
+
website_url,
|
|
63
|
+
created_at,
|
|
64
|
+
partners
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public entry fun transfer_ownership(dapp: &mut Dapp, new_admin: address, ctx: &mut TxContext) {
|
|
70
|
+
assert!(dapp.borrow_admin().contains(), 0);
|
|
71
|
+
assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
|
|
72
|
+
dapp.borrow_mut_admin().set(new_admin);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public entry fun set_safe_mode(dapp: &mut Dapp, safe_mode: bool, ctx: &TxContext) {
|
|
76
|
+
assert!(dapp.borrow_admin().contains(), 0);
|
|
77
|
+
assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
|
|
78
|
+
dapp.borrow_mut_safe_mode().set(safe_mode);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public fun ensure_no_safe_mode(dapp: &Dapp) {
|
|
82
|
+
assert!(!dapp.borrow_safe_mode().get(), 0);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public fun ensure_has_authority(dapp: &Dapp, ctx: &TxContext) {
|
|
86
|
+
assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public fun ensure_has_schema<Schema: key + store>(dapp: &Dapp, schema: &Schema) {
|
|
90
|
+
let schema_id = object::id_address(schema);
|
|
91
|
+
assert!(dapp.borrow_schemas().get().contains(&schema_id), 0);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -1,96 +1,24 @@
|
|
|
1
|
-
#[allow(lint(share_owned))]
|
|
2
|
-
|
|
3
|
-
module counter::deploy_hook {
|
|
4
|
-
|
|
5
|
-
use dubhe::dapps_schema::Dapps;
|
|
6
|
-
|
|
7
|
-
use dubhe::dapps_system;
|
|
8
|
-
|
|
9
|
-
use counter::schema_hub::SchemaHub;
|
|
1
|
+
#[allow(lint(share_owned), unused_let_mut)]module counter::deploy_hook {
|
|
10
2
|
|
|
11
3
|
use std::ascii::string;
|
|
12
4
|
|
|
13
5
|
use sui::clock::Clock;
|
|
14
6
|
|
|
15
|
-
use
|
|
16
|
-
|
|
17
|
-
use sui::coin::Coin;
|
|
18
|
-
|
|
19
|
-
use sui::package::UpgradeCap;
|
|
20
|
-
|
|
21
|
-
use sui::transfer::public_share_object;
|
|
7
|
+
use counter::dapp_system;
|
|
22
8
|
|
|
23
9
|
use counter::counter_schema::Counter;
|
|
24
10
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
#[test_only]
|
|
30
|
-
|
|
31
|
-
use sui::coin;
|
|
32
|
-
|
|
33
|
-
#[test_only]
|
|
34
|
-
|
|
35
|
-
use sui::test_scenario;
|
|
36
|
-
|
|
37
|
-
#[test_only]
|
|
38
|
-
|
|
39
|
-
use sui::package;
|
|
40
|
-
|
|
41
|
-
#[test_only]
|
|
42
|
-
|
|
43
|
-
use counter::schema_hub;
|
|
44
|
-
|
|
45
|
-
#[test_only]
|
|
46
|
-
|
|
47
|
-
use dubhe::dapps_schema;
|
|
48
|
-
|
|
49
|
-
#[test_only]
|
|
50
|
-
|
|
51
|
-
use sui::test_scenario::Scenario;
|
|
52
|
-
|
|
53
|
-
public entry fun run(
|
|
54
|
-
schema_hub: &mut SchemaHub,
|
|
55
|
-
dapps: &mut Dapps,
|
|
56
|
-
cap: &UpgradeCap,
|
|
57
|
-
clock: &Clock,
|
|
58
|
-
coin: Coin<SUI>,
|
|
59
|
-
ctx: &mut TxContext,
|
|
60
|
-
) {
|
|
61
|
-
// Register the dapp to dubhe.
|
|
62
|
-
dapps_system::register(dapps,cap,string(b"counter"),string(b"counter"),clock,coin,ctx);
|
|
11
|
+
public entry fun run(clock: &Clock, ctx: &mut TxContext) {
|
|
12
|
+
// Create a dapp.
|
|
13
|
+
let mut dapp = dapp_system::create(string(b"counter"),string(b"counter contract"), clock , ctx);
|
|
63
14
|
// Create schemas
|
|
64
15
|
let mut counter = counter::counter_schema::create(ctx);
|
|
65
16
|
// Logic that needs to be automated once the contract is deployed
|
|
66
|
-
|
|
67
|
-
counter.borrow_mut_value().set(0);
|
|
68
|
-
|
|
69
|
-
// Authorize schemas and public share objects
|
|
70
|
-
schema_hub.authorize_schema<Counter>();
|
|
71
|
-
public_share_object(counter);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
#[test_only]
|
|
75
|
-
|
|
76
|
-
public fun deploy_hook_for_testing(): (Scenario, SchemaHub, Dapps) {
|
|
77
|
-
let mut scenario = test_scenario::begin(@0xA);
|
|
78
17
|
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
let mut dapps = test_scenario::take_shared<Dapps>(&scenario);
|
|
85
|
-
let mut schema_hub = test_scenario::take_shared<SchemaHub>(&scenario);
|
|
86
|
-
let ctx = test_scenario::ctx(&mut scenario);
|
|
87
|
-
let clock = clock::create_for_testing(ctx);
|
|
88
|
-
let upgrade_cap = package::test_publish(@0x42.to_id(), ctx);
|
|
89
|
-
let coin = coin::mint_for_testing<SUI>(1_000_000_000, ctx);
|
|
90
|
-
run(&mut schema_hub, &mut dapps, &upgrade_cap, &clock, coin, ctx);
|
|
91
|
-
clock::destroy_for_testing(clock);
|
|
92
|
-
upgrade_cap.make_immutable();
|
|
93
|
-
test_scenario::next_tx(&mut scenario,@0xA);
|
|
94
|
-
(scenario, schema_hub, dapps)
|
|
18
|
+
counter.borrow_mut_value().set(0);
|
|
19
|
+
};
|
|
20
|
+
// Authorize schemas and public share objects
|
|
21
|
+
dapp.add_schema<Counter>(counter, ctx);
|
|
22
|
+
sui::transfer::public_share_object(dapp);
|
|
95
23
|
}
|
|
96
24
|
}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
module counter::counter_system {
|
|
2
2
|
use counter::counter_schema::Counter;
|
|
3
|
+
use counter::counter_event_increment;
|
|
4
|
+
use counter::counter_error_invalid_increment;
|
|
3
5
|
|
|
4
|
-
public entry fun inc(counter: &mut Counter) {
|
|
5
|
-
|
|
6
|
+
public entry fun inc(counter: &mut Counter, number: u32) {
|
|
7
|
+
// Check if the increment value is valid.
|
|
8
|
+
counter_error_invalid_increment::require(number > 0 && number < 100);
|
|
9
|
+
counter.borrow_mut_value().mutate!(|value| {
|
|
10
|
+
// Increment the counter value.
|
|
11
|
+
*value = *value + number;
|
|
12
|
+
// Emit an event to notify the increment.
|
|
13
|
+
counter_event_increment::emit(number);
|
|
14
|
+
});
|
|
6
15
|
}
|
|
7
16
|
|
|
8
|
-
public fun get(counter: &Counter): u32 {
|
|
17
|
+
public fun get(counter: &Counter) : u32 {
|
|
9
18
|
counter.borrow_value().get()
|
|
10
19
|
}
|
|
11
|
-
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#[test_only]
|
|
2
|
+
module counter::counter_test {
|
|
3
|
+
use sui::test_scenario;
|
|
4
|
+
use counter::counter_system;
|
|
5
|
+
use counter::counter_schema::Counter;
|
|
6
|
+
use counter::init_test;
|
|
7
|
+
|
|
8
|
+
#[test]
|
|
9
|
+
public fun inc() {
|
|
10
|
+
let (scenario, dapp) = init_test::deploy_dapp_for_testing(@0xA);
|
|
11
|
+
|
|
12
|
+
let mut counter = test_scenario::take_shared<Counter>(&scenario);
|
|
13
|
+
|
|
14
|
+
assert!(counter.borrow_value().get() == 0);
|
|
15
|
+
|
|
16
|
+
counter_system::inc(&mut counter, 10);
|
|
17
|
+
assert!(counter.borrow_value().get() == 10);
|
|
18
|
+
|
|
19
|
+
counter_system::inc(&mut counter, 10);
|
|
20
|
+
assert!(counter.borrow_value().get() == 20);
|
|
21
|
+
|
|
22
|
+
test_scenario::return_shared(counter);
|
|
23
|
+
dapp.distroy_dapp_for_testing();
|
|
24
|
+
scenario.end();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#[test_only]module counter::init_test {
|
|
2
|
+
|
|
3
|
+
use counter::dapp_schema::Dapp;
|
|
4
|
+
|
|
5
|
+
use sui::clock;
|
|
6
|
+
|
|
7
|
+
use sui::test_scenario;
|
|
8
|
+
|
|
9
|
+
use sui::test_scenario::Scenario;
|
|
10
|
+
|
|
11
|
+
public fun deploy_dapp_for_testing(sender: address): (Scenario, Dapp) {
|
|
12
|
+
let mut scenario = test_scenario::begin(sender);
|
|
13
|
+
let ctx = test_scenario::ctx(&mut scenario);
|
|
14
|
+
let clock = clock::create_for_testing(ctx);
|
|
15
|
+
counter::deploy_hook::run(&clock, ctx);
|
|
16
|
+
clock::destroy_for_testing(clock);
|
|
17
|
+
test_scenario::next_tx(&mut scenario,sender);
|
|
18
|
+
let dapp = test_scenario::take_shared<Dapp>(&scenario);
|
|
19
|
+
(scenario, dapp)
|
|
20
|
+
}
|
|
21
|
+
}
|
package/template/101/sui-template/contracts/dubhe-framework/sources/frames/utils/type_info.move
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module dubhe::type_info {
|
|
2
2
|
use std::ascii::String;
|
|
3
3
|
use std::ascii::string;
|
|
4
|
+
use std::type_name;
|
|
4
5
|
use sui::address;
|
|
5
6
|
use std::type_name::TypeName;
|
|
6
7
|
|
|
@@ -26,4 +27,10 @@ module dubhe::type_info {
|
|
|
26
27
|
|
|
27
28
|
(package_id, module_name, struct_name, struct_name_with_type)
|
|
28
29
|
}
|
|
30
|
+
|
|
31
|
+
public fun current_package_id<T>(): address {
|
|
32
|
+
let type_name = type_name::get<T>();
|
|
33
|
+
let (package_id, _, _, _) = parse_type_name(type_name);
|
|
34
|
+
package_id
|
|
35
|
+
}
|
|
29
36
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
module dubhe::
|
|
1
|
+
module dubhe::storage_migration {
|
|
2
2
|
use sui::dynamic_field as df;
|
|
3
3
|
|
|
4
|
-
public fun add_field<StorageType: store>(uid: &mut UID, field_name: vector<u8>,
|
|
5
|
-
df::add(uid, field_name,
|
|
4
|
+
public fun add_field<StorageType: store>(uid: &mut UID, field_name: vector<u8>, storagre_type: StorageType) {
|
|
5
|
+
df::add(uid, field_name, storagre_type);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
public fun borrow_field<StorageType: store>(uid: &UID, field_name: vector<u8>): &StorageType {
|
|
@@ -51,7 +51,7 @@ module dubhe::storage_value {
|
|
|
51
51
|
value
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
///
|
|
54
|
+
/// Put the `value` of the `StorageValue`.
|
|
55
55
|
public fun put<V: store>(self: &mut StorageValue<V>, value: V) {
|
|
56
56
|
assert!(!self.contains(), EValueAlreadyExist);
|
|
57
57
|
self.contents.push_back(Entry { value });
|