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.
Files changed (157) hide show
  1. package/dist/index.mjs +44 -42
  2. package/package.json +1 -1
  3. package/template/101/rooch-template/.dockerignore +7 -0
  4. package/template/101/rooch-template/.eslintrc.json +3 -0
  5. package/template/101/rooch-template/.prettierrc +8 -0
  6. package/template/101/rooch-template/Dockerfile +52 -0
  7. package/template/101/rooch-template/LICENSE +674 -0
  8. package/template/101/rooch-template/README.md +14 -0
  9. package/template/101/rooch-template/contracts/counter/Move.toml +14 -0
  10. package/template/101/rooch-template/contracts/counter/sources/counter.move +48 -0
  11. package/template/101/rooch-template/dubhe.config.ts +14 -0
  12. package/template/101/rooch-template/jest.config.ts +17 -0
  13. package/template/101/rooch-template/next-env.d.ts +5 -0
  14. package/template/101/rooch-template/next-i18next.config.js +6 -0
  15. package/template/101/rooch-template/next.config.js +15 -0
  16. package/template/101/rooch-template/package.json +72 -0
  17. package/template/101/rooch-template/postcss.config.js +6 -0
  18. package/template/101/rooch-template/public/discord.svg +9 -0
  19. package/template/101/rooch-template/public/fail.svg +12 -0
  20. package/template/101/rooch-template/public/favicon.ico +0 -0
  21. package/template/101/rooch-template/public/locales/de/common.json +8 -0
  22. package/template/101/rooch-template/public/locales/de/footer.json +3 -0
  23. package/template/101/rooch-template/public/locales/de/second-page.json +5 -0
  24. package/template/101/rooch-template/public/locales/en/common.json +8 -0
  25. package/template/101/rooch-template/public/locales/en/footer.json +3 -0
  26. package/template/101/rooch-template/public/locales/en/second-page.json +5 -0
  27. package/template/101/rooch-template/public/locales/zn/common.json +8 -0
  28. package/template/101/rooch-template/public/locales/zn/footer.json +3 -0
  29. package/template/101/rooch-template/public/locales/zn/second-page.json +5 -0
  30. package/template/101/rooch-template/public/logo.svg +1 -0
  31. package/template/101/rooch-template/public/medium.svg +9 -0
  32. package/template/101/rooch-template/public/successful.svg +11 -0
  33. package/template/101/rooch-template/public/telegram.svg +9 -0
  34. package/template/101/rooch-template/public/twitter.svg +9 -0
  35. package/template/101/rooch-template/scripts/checkBalance.ts +37 -0
  36. package/template/101/rooch-template/scripts/generateAccount.ts +55 -0
  37. package/template/101/rooch-template/scripts/storeConfig.ts +52 -0
  38. package/template/101/rooch-template/scripts/waitNode.ts +9 -0
  39. package/template/101/rooch-template/src/chain/config.ts +5 -0
  40. package/template/101/rooch-template/src/css/font-awesome.css +2337 -0
  41. package/template/101/rooch-template/src/css/font-awesome.min.css +4 -0
  42. package/template/101/rooch-template/src/fonts/FontAwesome.otf +0 -0
  43. package/template/101/rooch-template/src/fonts/fontawesome-webfont.eot +0 -0
  44. package/template/101/rooch-template/src/fonts/fontawesome-webfont.svg +2671 -0
  45. package/template/101/rooch-template/src/fonts/fontawesome-webfont.ttf +0 -0
  46. package/template/101/rooch-template/src/fonts/fontawesome-webfont.woff +0 -0
  47. package/template/101/rooch-template/src/fonts/fontawesome-webfont.woff2 +0 -0
  48. package/template/101/rooch-template/src/jotai/index.tsx +12 -0
  49. package/template/101/rooch-template/src/pages/_app.tsx +9 -0
  50. package/template/101/rooch-template/src/pages/home/index.tsx +82 -0
  51. package/template/101/rooch-template/src/pages/index.tsx +14 -0
  52. package/template/101/rooch-template/tailwind.config.js +56 -0
  53. package/template/101/rooch-template/tsconfig.json +25 -0
  54. package/template/101/sui-template/contracts/counter/Move.toml +3 -3
  55. package/template/101/sui-template/contracts/counter/sources/codegen/schema_hub.move +60 -0
  56. package/template/101/sui-template/contracts/counter/sources/codegen/schemas/counter.move +17 -15
  57. package/template/101/sui-template/contracts/counter/sources/script/deploy_hook.move +37 -19
  58. package/template/101/sui-template/contracts/counter/sources/script/migrate.move +8 -0
  59. package/template/101/sui-template/localnet/dubhe-framework/Move.toml +6 -16
  60. 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
  61. package/template/101/sui-template/localnet/dubhe-framework/sources/core/dapps/system.move +75 -0
  62. package/template/101/sui-template/localnet/dubhe-framework/sources/core/dapps/tests.move +52 -0
  63. package/template/101/sui-template/localnet/dubhe-framework/sources/core/root/schema.move +33 -0
  64. package/template/101/sui-template/localnet/dubhe-framework/sources/core/root/system.move +24 -0
  65. package/template/101/sui-template/localnet/dubhe-framework/sources/core/root/tests.move +39 -0
  66. package/template/101/sui-template/localnet/dubhe-framework/sources/frames/utils/type_info.move +29 -0
  67. package/template/101/sui-template/localnet/dubhe-framework/sources/storages/double_map.move +0 -3
  68. package/template/101/sui-template/localnet/dubhe-framework/sources/storages/map.move +0 -3
  69. package/template/101/sui-template/localnet/dubhe-framework/sources/storages/migrate.move +19 -0
  70. package/template/101/sui-template/localnet/dubhe-framework/sources/storages/value.move +0 -3
  71. package/template/101/sui-template/package.json +19 -27
  72. package/template/101/sui-template/scripts/deployment/testnet/deploy.ts +2 -2
  73. package/template/101/sui-template/src/chain/config.ts +3 -3
  74. package/template/cocos/sui-template/assets/lib/dubhe.js +21 -1
  75. package/template/cocos/sui-template/contracts/counter/Move.toml +1 -1
  76. package/template/cocos/sui-template/package.json +3 -3
  77. package/template/contract/sui-template/contracts/counter/Move.toml +13 -0
  78. package/template/contract/sui-template/contracts/counter/sources/codegen/dapp_key.move +16 -0
  79. package/template/contract/sui-template/contracts/counter/sources/codegen/schema_hub.move +60 -0
  80. package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/counter.move +60 -0
  81. package/template/contract/sui-template/contracts/counter/sources/script/deploy_hook.move +85 -0
  82. package/template/contract/sui-template/contracts/counter/sources/script/migrate.move +8 -0
  83. package/template/contract/sui-template/dubhe.config.ts +14 -0
  84. package/template/contract/sui-template/localnet/dubhe-framework/Move.toml +29 -0
  85. 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
  86. package/template/contract/sui-template/localnet/dubhe-framework/sources/core/dapps/system.move +75 -0
  87. package/template/contract/sui-template/localnet/dubhe-framework/sources/core/dapps/tests.move +52 -0
  88. package/template/contract/sui-template/localnet/dubhe-framework/sources/core/root/schema.move +33 -0
  89. package/template/contract/sui-template/localnet/dubhe-framework/sources/core/root/system.move +24 -0
  90. package/template/contract/sui-template/localnet/dubhe-framework/sources/core/root/tests.move +39 -0
  91. package/template/contract/sui-template/localnet/dubhe-framework/sources/frames/utils/type_info.move +29 -0
  92. package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/double_map.move +153 -0
  93. package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/map.move +156 -0
  94. package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/migrate.move +19 -0
  95. package/template/contract/sui-template/localnet/dubhe-framework/sources/storages/value.move +97 -0
  96. package/template/contract/sui-template/localnet/dubhe-framework/tests/init.move +6 -0
  97. package/template/contract/sui-template/localnet/dubhe-framework/tests/obelisk_framework_tests.move +19 -0
  98. package/template/contract/sui-template/package.json +28 -0
  99. package/template/contract/sui-template/scripts/checkBalance.ts +40 -0
  100. package/template/contract/sui-template/scripts/deployment/common.ts +45 -0
  101. package/template/contract/sui-template/scripts/deployment/localnet/deploy.ts +42 -0
  102. package/template/contract/sui-template/scripts/deployment/testnet/deploy.ts +48 -0
  103. package/template/contract/sui-template/scripts/deployment/types.ts +13 -0
  104. package/template/contract/sui-template/scripts/framework/common.ts +17 -0
  105. package/template/contract/sui-template/scripts/framework/deploy.ts +199 -0
  106. package/template/contract/sui-template/scripts/framework/parse-history.ts +76 -0
  107. package/template/contract/sui-template/scripts/framework/types.ts +8 -0
  108. package/template/contract/sui-template/scripts/generateAccount.ts +37 -0
  109. package/template/contract/sui-template/tsconfig.json +35 -0
  110. package/template/nextjs/sui-template/contracts/counter/Move.toml +3 -3
  111. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schema_hub.move +60 -0
  112. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/counter.move +17 -15
  113. package/template/nextjs/sui-template/contracts/counter/sources/script/deploy_hook.move +37 -19
  114. package/template/nextjs/sui-template/contracts/counter/sources/script/migrate.move +8 -0
  115. package/template/nextjs/sui-template/contracts/counter/sources/systems/counter.move +11 -0
  116. package/template/nextjs/sui-template/dubhe.config.ts +2 -2
  117. package/template/nextjs/sui-template/localnet/dubhe-framework/Move.toml +6 -16
  118. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/metadata.move +96 -0
  119. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/schema.move +83 -0
  120. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/system.move +75 -0
  121. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/dapps/tests.move +52 -0
  122. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/root/schema.move +33 -0
  123. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/root/system.move +24 -0
  124. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/core/root/tests.move +39 -0
  125. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/frames/utils/type_info.move +29 -0
  126. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/double_map.move +0 -3
  127. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/map.move +0 -3
  128. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/migrate.move +19 -0
  129. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/tests.move +398 -0
  130. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/storages/value.move +0 -3
  131. package/template/nextjs/sui-template/package.json +19 -27
  132. package/template/nextjs/sui-template/scripts/deployment/testnet/deploy.ts +2 -2
  133. package/template/nextjs/sui-template/src/chain/config.ts +2 -2
  134. package/template/101/sui-template/localnet/dubhe-framework/README.md +0 -18
  135. package/template/101/sui-template/localnet/dubhe-framework/sources/access_control.move +0 -35
  136. package/template/101/sui-template/localnet/dubhe-framework/sources/events.move +0 -23
  137. package/template/101/sui-template/localnet/dubhe-framework/sources/resource_id.move +0 -22
  138. package/template/101/sui-template/localnet/dubhe-framework/sources/resource_types.move +0 -18
  139. package/template/101/sui-template/localnet/dubhe-framework/sources/schema.move +0 -36
  140. package/template/101/sui-template/localnet/dubhe-framework/sources/systems/dapps.move +0 -90
  141. package/template/101/sui-template/localnet/dubhe-framework/sources/world.move +0 -81
  142. package/template/101/sui-template/localnet/dubhe-framework/tests/dapp.move +0 -16
  143. package/template/nextjs/sui-template/localnet/dubhe-framework/README.md +0 -18
  144. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/access_control.move +0 -35
  145. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/events.move +0 -23
  146. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/resource_id.move +0 -22
  147. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/resource_types.move +0 -18
  148. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/schema.move +0 -36
  149. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/systems/dapps.move +0 -90
  150. package/template/nextjs/sui-template/localnet/dubhe-framework/sources/world.move +0 -81
  151. package/template/nextjs/sui-template/localnet/dubhe-framework/tests/dapp.move +0 -16
  152. /package/template/101/sui-template/contracts/counter/sources/{system → systems}/counter.move +0 -0
  153. /package/template/101/sui-template/localnet/dubhe-framework/sources/{schemas → core}/dapps/metadata.move +0 -0
  154. /package/template/101/sui-template/localnet/dubhe-framework/{tests/storage.move → sources/storages/tests.move} +0 -0
  155. /package/template/{nextjs/sui-template/contracts/counter/sources/system → contract/sui-template/contracts/counter/sources/systems}/counter.move +0 -0
  156. /package/template/{nextjs/sui-template/localnet/dubhe-framework/sources/schemas → contract/sui-template/localnet/dubhe-framework/sources/core}/dapps/metadata.move +0 -0
  157. /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,39 @@
1
+ #[test_only]
2
+ module dubhe::root_tests {
3
+ use dubhe::root_schema::Root;
4
+ use dubhe::root_schema;
5
+ use dubhe::root_system;
6
+ use sui::test_scenario;
7
+
8
+ public struct USDT has drop {}
9
+
10
+ #[test]
11
+ public fun root_key() {
12
+ let mut scenario = test_scenario::begin(@0xA);
13
+ {
14
+ let ctx = test_scenario::ctx(&mut scenario);
15
+ root_schema::init_root_for_testing(ctx);
16
+ test_scenario::next_tx(&mut scenario,@0xA);
17
+ };
18
+
19
+ let mut root = test_scenario::take_shared<Root>(&scenario);
20
+ assert!(root.borrow_key().get() == @0xA, 0);
21
+
22
+ {
23
+ let ctx = test_scenario::ctx(&mut scenario);
24
+ root_system::set_key(&mut root, @0xB, ctx);
25
+ test_scenario::next_tx(&mut scenario,@0xB);
26
+ };
27
+ assert!(root.borrow_key().get() == @0xB, 0);
28
+
29
+ {
30
+ let ctx = test_scenario::ctx(&mut scenario);
31
+ root_system::remove_key(&mut root, ctx);
32
+ test_scenario::next_tx(&mut scenario,@0xC);
33
+ };
34
+ assert!(root.borrow_key().try_get() == option::none<address>(), 0);
35
+
36
+ test_scenario::return_shared<Root>(root);
37
+ scenario.end();
38
+ }
39
+ }
@@ -0,0 +1,29 @@
1
+ module dubhe::type_info {
2
+ use std::ascii::String;
3
+ use std::ascii::string;
4
+ use sui::address;
5
+ use std::type_name::TypeName;
6
+
7
+ public fun parse_type_name(type_name: TypeName): (address, String, String, String) {
8
+ let pending_parse_str = type_name.into_string();
9
+ let delimiter = string(b"::");
10
+
11
+ // TBD: this can probably be hard-coded as all hex addrs are 64 bytes
12
+ let package_delimiter_index = pending_parse_str.index_of(&delimiter);
13
+ let package_addr = pending_parse_str.substring(0, package_delimiter_index);
14
+ let package_id = address::from_ascii_bytes(package_addr.as_bytes());
15
+
16
+ let tail = pending_parse_str.substring(package_delimiter_index + 2, pending_parse_str.length());
17
+
18
+ let module_delimiter_index = tail.index_of(&delimiter);
19
+ let module_name = tail.substring(0, module_delimiter_index);
20
+
21
+ let struct_name_with_type = tail.substring(module_delimiter_index + 2, tail.length());
22
+
23
+ let delimiter = string(b"<");
24
+ let struct_name_delimiter_index = struct_name_with_type.index_of(&delimiter);
25
+ let struct_name = struct_name_with_type.substring(0, struct_name_delimiter_index);
26
+
27
+ (package_id, module_name, struct_name, struct_name_with_type)
28
+ }
29
+ }
@@ -1,6 +1,3 @@
1
- // Copyright (c) Mysten Labs, Inc.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
1
  #[allow(unused_variable)]
5
2
  module dubhe::storage_double_map {
6
3
 
@@ -1,6 +1,3 @@
1
- // Copyright (c) Mysten Labs, Inc.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
1
  #[allow(unused_variable)]
5
2
  module dubhe::storage_map {
6
3
 
@@ -0,0 +1,19 @@
1
+ module dubhe::storage_migrate {
2
+ use sui::dynamic_field as df;
3
+
4
+ public fun add_field<StorageType: store>(uid: &mut UID, field_name: vector<u8>, storagr_type: StorageType) {
5
+ df::add(uid, field_name, storagr_type);
6
+ }
7
+
8
+ public fun borrow_field<StorageType: store>(uid: &UID, field_name: vector<u8>): &StorageType {
9
+ df::borrow(uid, field_name)
10
+ }
11
+
12
+ public fun borrow_mut_field<StorageType: store>(uid: &mut UID, field_name: vector<u8>): &mut StorageType {
13
+ df::borrow_mut(uid, field_name)
14
+ }
15
+
16
+ public fun field_exists(uid: &UID, field_name: vector<u8>): bool {
17
+ df::exists_(uid, field_name)
18
+ }
19
+ }
@@ -0,0 +1,398 @@
1
+ #[test_only]
2
+ module dubhe::storage_tests {
3
+ use dubhe::storage_double_map::StorageDoubleMap;
4
+ use dubhe::storage_map::StorageMap;
5
+ use dubhe::storage_double_map;
6
+ use dubhe::storage_map;
7
+ use dubhe::storage_value::StorageValue;
8
+ use sui::test_scenario;
9
+ use sui::transfer::public_share_object;
10
+ use dubhe::storage_value;
11
+
12
+ public struct TestValue has drop, copy, store {
13
+ value: u64,
14
+ }
15
+
16
+ public struct TestStoreValue has store {
17
+ value: u64,
18
+ }
19
+
20
+ /// Destroy a TestStoreValue`.
21
+ public fun destroy_value(value: TestStoreValue) {
22
+ let TestStoreValue { value: _ } = value;
23
+ }
24
+
25
+ public struct TestObject has key, store {
26
+ id: UID,
27
+ value: StorageValue<TestValue>,
28
+ immutable_value: StorageValue<TestStoreValue>,
29
+ map: StorageMap<u32, TestValue>,
30
+ immutable_map: StorageMap<u32, TestStoreValue>,
31
+ double_map: StorageDoubleMap<u32, u32, TestValue>,
32
+ immutable_double_map: StorageDoubleMap<u32, u32, TestStoreValue>,
33
+ }
34
+
35
+ public fun value(self: &mut TestObject): &mut StorageValue<TestValue> {
36
+ &mut self.value
37
+ }
38
+
39
+
40
+ #[test]
41
+ public fun test_double_map() {
42
+ let mut scenario = test_scenario::begin(@0x0001);
43
+ let ctx = test_scenario::ctx(&mut scenario);
44
+
45
+ let mut double_map = storage_double_map::new();
46
+
47
+ double_map.insert(0, 0, TestValue { value: 0 });
48
+ double_map.insert(0, 1, TestValue { value: 1 });
49
+ double_map.insert(0, 2, TestValue { value: 2 });
50
+
51
+ assert!(double_map.contains_key(0, 0));
52
+ assert!(double_map.contains_key(0, 1));
53
+ assert!(double_map.contains_key(0, 2));
54
+ let (keys1, keys2) = double_map.keys();
55
+ assert!(keys1 == vector[0, 0, 0], 0);
56
+ assert!(keys2 == vector[0, 1, 2], 0);
57
+ assert!(double_map.values() == vector[TestValue { value: 0 }, TestValue { value: 1 }, TestValue { value: 2 }]);
58
+ assert!(double_map.length() == 3);
59
+ assert!(double_map.borrow(0, 0).value == 0);
60
+ assert!(double_map.borrow(0, 1).value == 1);
61
+ assert!(double_map.borrow_mut(0, 2).value == 2);
62
+ assert!(double_map.get(0, 0).value == 0);
63
+ assert!(double_map.get(0, 1).value == 1);
64
+ assert!(double_map.get(0, 2).value == 2);
65
+ assert!(double_map.try_get(0, 0) == option::some(TestValue { value: 0 }));
66
+ assert!(double_map.try_get(0, 1) == option::some(TestValue { value: 1 }));
67
+ assert!(double_map.try_get(0, 2) == option::some(TestValue { value: 2 }));
68
+ assert!(double_map.try_get(0, 3) == option::none());
69
+
70
+ double_map.take(0, 1);
71
+
72
+ assert!(double_map.contains_key(0, 0));
73
+ assert!(!double_map.contains_key(0, 1));
74
+ assert!(double_map.contains_key(0, 2));
75
+ let (keys1, keys2) = double_map.keys();
76
+ assert!(keys1 == vector[0, 0]);
77
+ assert!(keys2 == vector[0, 2]);
78
+ assert!(double_map.values() == vector[TestValue { value: 0 }, TestValue { value: 2 }]);
79
+ assert!(double_map.length() == 2);
80
+ assert!(double_map.borrow(0, 0).value == 0);
81
+ assert!(double_map.borrow_mut(0, 2).value == 2);
82
+
83
+ double_map.mutate!(0, 0, |value| {
84
+ *value = TestValue { value: 2 };
85
+ });
86
+
87
+ assert!(double_map.contains_key(0, 0));
88
+ assert!(!double_map.contains_key(0, 1));
89
+ assert!(double_map.contains_key(0, 2));
90
+ let (keys1, keys2) = double_map.keys();
91
+ assert!(keys1 == vector[0, 0]);
92
+ assert!(keys2 == vector[0, 2]);
93
+ assert!(double_map.values() == vector[TestValue { value: 2 }, TestValue { value: 2 }]);
94
+ assert!(double_map.length() == 2);
95
+ assert!(double_map.borrow(0, 0).value == 2);
96
+ assert!(double_map.borrow_mut(0, 2).value == 2);
97
+
98
+ double_map.remove(0, 0);
99
+ assert!(!double_map.contains_key(0,0));
100
+ assert!(double_map.length() == 1);
101
+ let (keys1, keys2) = double_map.keys();
102
+ assert!(keys1 == vector[0]);
103
+ assert!(keys2 == vector[2]);
104
+ assert!(double_map.values() == vector[TestValue { value: 2 }]);
105
+
106
+ double_map.remove(0,3);
107
+ assert!(double_map.length() == 1);
108
+ let (keys1, keys2) = double_map.keys();
109
+ assert!(keys1 == vector[0]);
110
+ assert!(keys2 == vector[2]);
111
+ assert!(double_map.values() == vector[TestValue { value: 2 }]);
112
+
113
+ double_map.set(0,3, TestValue { value: 0 });
114
+ assert!(double_map.contains_key(0,3));
115
+ assert!(double_map.length() == 2);
116
+ let (keys1, keys2) = double_map.keys();
117
+ assert!(keys1 == vector[0, 0]);
118
+ assert!(keys2 == vector[2, 3]);
119
+ assert!(double_map.values() == vector[TestValue { value: 2 }, TestValue { value: 0 }]);
120
+ assert!(double_map.get(0,3).value == 0);
121
+
122
+ double_map.set(0,3, TestValue { value: 3 });
123
+ assert!(double_map.contains_key(0,3));
124
+ assert!(double_map.length() == 2);
125
+ let (keys1, keys2) = double_map.keys();
126
+ assert!(keys1 == vector[0, 0]);
127
+ assert!(keys2 == vector[2, 3]);
128
+ assert!(double_map.values() == vector[TestValue { value: 2 }, TestValue { value: 3 }]);
129
+ assert!(double_map.get(0,3).value == 3);
130
+
131
+ public_share_object(TestObject {
132
+ id: object::new(ctx),
133
+ value: storage_value::new(),
134
+ immutable_value: storage_value::new(),
135
+ map: storage_map::new(),
136
+ immutable_map: storage_map::new(),
137
+ double_map,
138
+ immutable_double_map: storage_double_map::new(),
139
+ });
140
+
141
+ scenario.end();
142
+ }
143
+
144
+ #[test]
145
+ public fun test_value() {
146
+ let mut scenario = test_scenario::begin(@0x0001);
147
+ let ctx = test_scenario::ctx(&mut scenario);
148
+
149
+ let mut value = storage_value::new();
150
+ value.set(TestValue { value: 1 });
151
+ assert!(value.get() == TestValue { value: 1 });
152
+ assert!(*value.borrow() == TestValue { value: 1 });
153
+ assert!(*value.borrow_mut() == TestValue { value: 1 });
154
+
155
+ value.set(TestValue { value: 2 });
156
+ assert!(value.get() == TestValue { value: 2 });
157
+
158
+ value.mutate!(|value| {
159
+ *value = TestValue { value: 3 };
160
+ });
161
+ assert!(value.get() == TestValue { value: 3 });
162
+
163
+ value.set(TestValue { value: 4 });
164
+ assert!(value.get() == TestValue { value: 4 });
165
+
166
+
167
+ let mut immutable_value = storage_value::new();
168
+ immutable_value.put(TestStoreValue { value: 1 });
169
+ assert!(immutable_value.borrow().value == 1);
170
+
171
+ immutable_value.mutate!(|store_value| {
172
+ store_value.value = 2;
173
+ });
174
+ assert!(immutable_value.borrow().value == 2);
175
+ assert!(immutable_value.borrow_mut().value == 2);
176
+
177
+ immutable_value.mutate!(|store_value| {
178
+ store_value.value = 3;
179
+ });
180
+ assert!(immutable_value.borrow().value == 3);
181
+ assert!(immutable_value.borrow_mut().value == 3);
182
+
183
+ public_share_object(TestObject {
184
+ id: object::new(ctx),
185
+ value,
186
+ immutable_value,
187
+ map: storage_map::new(),
188
+ immutable_map: storage_map::new(),
189
+ double_map: storage_double_map::new(),
190
+ immutable_double_map: storage_double_map::new(),
191
+ });
192
+
193
+ scenario.end();
194
+ }
195
+
196
+ #[test]
197
+ public fun test_map() {
198
+ let mut scenario = test_scenario::begin(@0x0001);
199
+ let ctx = test_scenario::ctx(&mut scenario);
200
+
201
+ let mut map = storage_map::new();
202
+ map.insert(0, TestValue { value: 0 });
203
+ map.insert(1, TestValue { value: 1 });
204
+ map.insert(2, TestValue { value: 2 });
205
+
206
+ assert!(map.contains_key(0));
207
+ assert!(map.contains_key(1));
208
+ assert!(map.contains_key(2));
209
+ assert!(map.keys() == vector[0, 1, 2]);
210
+ assert!(map.values() == vector[TestValue { value: 0 }, TestValue { value: 1 }, TestValue { value: 2 }]);
211
+ assert!(map.length() == 3);
212
+ assert!(map.borrow(0).value == 0);
213
+ assert!(map.borrow(1).value == 1);
214
+ assert!(map.borrow_mut(2).value == 2);
215
+ assert!(map.get(0).value == 0);
216
+ assert!(map.get(1).value == 1);
217
+ assert!(map.get(2).value == 2);
218
+ assert!(map.try_get(0) == option::some(TestValue { value: 0 }));
219
+ assert!(map.try_get(1) == option::some(TestValue { value: 1 }));
220
+ assert!(map.try_get(2) == option::some(TestValue { value: 2 }));
221
+ assert!(map.try_get(3) == option::none());
222
+
223
+ map.take(1);
224
+
225
+ assert!(map.contains_key(0));
226
+ assert!(!map.contains_key(1));
227
+ assert!(map.contains_key(2));
228
+ assert!(map.keys() == vector[0, 2]);
229
+ assert!(map.values() == vector[TestValue { value: 0 }, TestValue { value: 2 }]);
230
+ assert!(map.length() == 2);
231
+ assert!(map.borrow(0).value == 0);
232
+ assert!(map.borrow_mut(2).value == 2);
233
+
234
+
235
+ map.mutate!(0, |store_value| {
236
+ store_value.value = 2;
237
+ });
238
+ assert!(map.contains_key(0));
239
+ assert!(!map.contains_key(1));
240
+ assert!(map.contains_key(2));
241
+ assert!(map.keys() == vector[0, 2]);
242
+ assert!(map.values() == vector[TestValue { value: 2 }, TestValue { value: 2 }]);
243
+ assert!(map.length() == 2);
244
+ assert!(map.borrow(0).value == 2);
245
+ assert!(map.borrow_mut(2).value == 2);
246
+
247
+ map.remove(0);
248
+ assert!(!map.contains_key(0));
249
+ assert!(map.length() == 1);
250
+ assert!(map.keys() == vector[2]);
251
+ assert!(map.values() == vector[TestValue { value: 2 }]);
252
+
253
+ map.remove(3);
254
+ assert!(map.length() == 1);
255
+ assert!(map.keys() == vector[2]);
256
+ assert!(map.values() == vector[TestValue { value: 2 }]);
257
+
258
+ map.set(3, TestValue { value: 0 });
259
+ assert!(map.contains_key(3));
260
+ assert!(map.length() == 2);
261
+ assert!(map.keys() == vector[2, 3]);
262
+ assert!(map.values() == vector[TestValue { value: 2 }, TestValue { value: 0 }]);
263
+ assert!(map.get(3).value == 0);
264
+
265
+ map.set(3, TestValue { value: 3 });
266
+ assert!(map.contains_key(3));
267
+ assert!(map.length() == 2);
268
+ assert!(map.keys() == vector[2, 3]);
269
+ assert!(map.values() == vector[TestValue { value: 2 }, TestValue { value: 3 }]);
270
+ assert!(map.get(3).value == 3);
271
+
272
+ public_share_object(TestObject {
273
+ id: object::new(ctx),
274
+ value: storage_value::new(),
275
+ immutable_value: storage_value::new(),
276
+ map,
277
+ immutable_map: storage_map::new(),
278
+ double_map: storage_double_map::new(),
279
+ immutable_double_map: storage_double_map::new(),
280
+ });
281
+
282
+ scenario.end();
283
+ }
284
+
285
+ #[test]
286
+ public fun test_immutable_map() {
287
+ let mut scenario = test_scenario::begin(@0x0001);
288
+ let ctx = test_scenario::ctx(&mut scenario);
289
+
290
+ let mut immutable_map = storage_map::new();
291
+ immutable_map.insert(0, TestStoreValue { value: 0 });
292
+ immutable_map.insert(1, TestStoreValue { value: 1 });
293
+ immutable_map.insert(2, TestStoreValue { value: 2 });
294
+
295
+ assert!(immutable_map.contains_key(0));
296
+ assert!(immutable_map.contains_key(1));
297
+ assert!(immutable_map.contains_key(2));
298
+ assert!(immutable_map.keys() == vector[0, 1, 2]);
299
+ assert!(immutable_map.length() == 3);
300
+ assert!(immutable_map.borrow(0).value == 0);
301
+ assert!(immutable_map.borrow(1).value == 1);
302
+ assert!(immutable_map.borrow_mut(2).value == 2);
303
+
304
+ let detele_store_value = immutable_map.take(1);
305
+ destroy_value(detele_store_value);
306
+ assert!(immutable_map.contains_key(0));
307
+ assert!(!immutable_map.contains_key(1));
308
+ assert!(immutable_map.contains_key(2));
309
+ assert!(immutable_map.keys() == vector[0, 2]);
310
+ assert!(immutable_map.length() == 2);
311
+ assert!(immutable_map.borrow(0).value == 0);
312
+ assert!(immutable_map.borrow_mut(2).value == 2);
313
+
314
+
315
+ immutable_map.mutate!(0, |store_value| {
316
+ store_value.value = 2;
317
+ });
318
+ assert!(immutable_map.contains_key(0));
319
+ assert!(!immutable_map.contains_key(1));
320
+ assert!(immutable_map.contains_key(2));
321
+ assert!(immutable_map.keys() == vector[0, 2]);
322
+ assert!(immutable_map.length() == 2);
323
+ assert!(immutable_map.borrow(0).value == 2);
324
+ assert!(immutable_map.borrow_mut(2).value == 2);
325
+
326
+ public_share_object(TestObject {
327
+ id: object::new(ctx),
328
+ value: storage_value::new(),
329
+ immutable_value: storage_value::new(),
330
+ map: storage_map::new(),
331
+ immutable_map,
332
+ double_map: storage_double_map::new(),
333
+ immutable_double_map: storage_double_map::new(),
334
+ });
335
+
336
+ scenario.end();
337
+ }
338
+
339
+ // #[test]
340
+ // public fun test_immutable_map2() {
341
+ // let mut scenario = test_scenario::begin(@0x0001);
342
+ // let ctx = test_scenario::ctx(&mut scenario);
343
+ //
344
+ // let mut immutable_map = storage_immutable_map::new(ctx);
345
+ // immutable_map.set(0, TestValue { value: 1 });
346
+ //
347
+ // // immutable_map.mutate!(|store_value| {
348
+ // // store_value.value = 2;
349
+ // // });
350
+ // // assert!(immutable_map.get().value == 2);
351
+ // // assert!(immutable_map.borrow_mut().value == 2);
352
+ // //
353
+ // // immutable_map.mutate!(|store_value| {
354
+ // // store_value.value = 3;
355
+ // // });
356
+ // // assert!(immutable_map.get().value == 3);
357
+ // // assert!(immutable_map.borrow_mut().value == 3);
358
+ //
359
+ // public_share_object(TestObject2 {
360
+ // id: object::new(ctx),
361
+ // value: storage_value::new(TestValue { value: 1 }),
362
+ // immutable_value: storage_value::new(TestStoreValue { value: 1 }),
363
+ // immutable_map,
364
+ // });
365
+ //
366
+ // scenario.end();
367
+ // }
368
+
369
+ // #[test]
370
+ // public fun test_object() {
371
+ // let sender = @0x0001;
372
+ // let mut scenario_val = test_scenario::begin(sender);
373
+ // let scenario = &mut scenario_val;
374
+ //
375
+ // let obj = TestObject {
376
+ // id: object::new(test_scenario::ctx(scenario)),
377
+ // value: storage_value::empty(),
378
+ // };
379
+ // public_share_object(obj);
380
+ //
381
+ // test_scenario::next_tx(scenario, sender);
382
+ //
383
+ // let mut obj = test_scenario::take_shared<TestObject>(scenario);
384
+ //
385
+ // obj.value.set(TestValue { value: 1 });
386
+ // assert!(obj.value.contains());
387
+ // assert!(!obj.value.is_empty());
388
+ // assert!(obj.value.get() == TestValue { value: 1 });
389
+ //
390
+ // obj.value.set(TestValue { value: 2 });
391
+ // assert!(obj.value.contains());
392
+ // assert!(!obj.value.is_empty());
393
+ // assert!(obj.value.get() == TestValue { value: 2 });
394
+ //
395
+ // test_scenario::return_shared<TestObject>(obj);
396
+ // test_scenario::end(scenario_val);
397
+ // }
398
+ }
@@ -1,6 +1,3 @@
1
- // Copyright (c) Mysten Labs, Inc.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
1
  module dubhe::storage_value {
5
2
 
6
3
  /// This key does not exist in the map
@@ -5,39 +5,31 @@
5
5
  "author": "team@0xobelisk.com",
6
6
  "license": "MIT",
7
7
  "scripts": {
8
- "// Development Environment": "----------------",
9
- "dev": "pnpm dev:localnet",
10
- "dev:localnet": "pnpm localnet:setup && pnpm next",
11
- "dev:testnet": "pnpm testnet:setup && pnpm next",
12
- "// Production Environment": "----------------",
13
- "prod:localnet": "pnpm config:store localnet && pnpm next",
14
- "prod:testnet": "pnpm config:store testnet && pnpm next",
15
- "// Local Network": "----------------",
16
- "localnet:setup": "pnpm localnet:start && pnpm localnet:wait && pnpm localnet:account && pnpm localnet:faucet && pnpm localnet:deploy",
17
- "localnet:start": "pnpm dubhe localnode start -b",
18
- "localnet:restart": "pnpm dubhe localnode restart -b",
19
- "localnet:stop": "pnpm dubhe localnode stop",
20
- "localnet:status": "pnpm dubhe localnode status",
21
- "localnet:wait": "NODE_NO_WARNINGS=1 ts-node scripts/waitNode.ts",
22
- "localnet:account": "NODE_NO_WARNINGS=1 ts-node scripts/generateAccount.ts",
23
- "localnet:faucet": "pnpm dubhe faucet --network localnet",
24
- "localnet:deploy": "NODE_NO_WARNINGS=1 ts-node scripts/deployment/localnet/deploy.ts",
25
- "// Test Network": "----------------",
26
- "testnet:setup": "pnpm testnet:account && pnpm testnet:check-balance && pnpm testnet:deploy",
27
- "testnet:account": "NODE_NO_WARNINGS=1 ts-node scripts/generateAccount.ts",
28
- "testnet:check-balance": "NODE_NO_WARNINGS=1 ts-node scripts/checkBalance.ts testnet",
29
- "testnet:faucet": "pnpm dubhe faucet --network testnet",
30
- "testnet:deploy": "NODE_NO_WARNINGS=1 ts-node scripts/deployment/testnet/deploy.ts",
31
8
  "// Utility Commands": "----------------",
32
9
  "schema:gen": "pnpm dubhe schemagen --configPath ./dubhe.config.ts",
10
+ "account:gen": "NODE_NO_WARNINGS=1 ts-node scripts/generateAccount.ts",
33
11
  "config:store": "ts-node scripts/storeConfig.ts",
12
+ "start:localnet": "pnpm dubhe localnode start",
13
+ "faucet": "pnpm dubhe faucet --network",
14
+ "check-balance": "NODE_NO_WARNINGS=1 ts-node scripts/checkBalance.ts",
15
+ "deploy:localnet": "NODE_NO_WARNINGS=1 ts-node scripts/deployment/localnet/deploy.ts",
16
+ "deploy:testnet": "NODE_NO_WARNINGS=1 ts-node scripts/deployment/testnet/deploy.ts",
17
+ "// Development Environment": "----------------",
18
+ "dev": "pnpm dev:localnet",
19
+ "dev:localnet": "pnpm setup:localnet && pnpm next",
20
+ "dev:testnet": "pnpm setup:testnet && pnpm next",
21
+ "setup:localnet": "pnpm account:gen && pnpm faucet localnet && pnpm deploy:localnet",
22
+ "setup:testnet": "pnpm account:gen && pnpm check-balance testnet && pnpm deploy:testnet",
34
23
  "build": "next build",
35
- "start": "next start"
24
+ "start": "next start",
25
+ "// Production Environment": "----------------",
26
+ "prod:localnet": "pnpm config:store localnet && pnpm next",
27
+ "prod:testnet": "pnpm config:store testnet && pnpm next"
36
28
  },
37
29
  "dependencies": {
38
- "@0xobelisk/sui-cli": "^0.5.23",
39
- "@0xobelisk/sui-client": "^0.5.27",
40
- "@0xobelisk/sui-common": "^0.5.19",
30
+ "@0xobelisk/sui-cli": "^0.5.25",
31
+ "@0xobelisk/sui-client": "v0.5.28",
32
+ "@0xobelisk/sui-common": "^0.5.21",
41
33
  "@mysten/dapp-kit": "0.14.9",
42
34
  "@mysten/sui": "1.7.0",
43
35
  "dotenv": "^16.4.5",
@@ -4,7 +4,7 @@ import { dubheConfig } from '../../../dubhe.config';
4
4
  import fs from 'fs/promises';
5
5
  import path from 'path';
6
6
 
7
- const TESTNET_FRAMEWORK_ID = '0x1736475f476c5dec96f33c03c778843f572239d3a887d795eef66d2836484c28';
7
+ const TESTNET_FRAMEWORK_ID = '0x417ad1864a56a29ad0b5aaddd2e11bac1eeab6a68883ef53184a4cc5c293fec6';
8
8
 
9
9
  async function updateDubheMoveToml(projectName: string) {
10
10
  try {
@@ -14,7 +14,7 @@ async function updateDubheMoveToml(projectName: string) {
14
14
 
15
15
  content = content.replace(
16
16
  /Dubhe = \{[^}]+\}/,
17
- `Dubhe = { git = "https://github.com/0xobelisk/dubhe.git", subdir = "packages/dubhe-framework", rev = "main" }`,
17
+ `Dubhe = { git = "https://github.com/0xobelisk/dubhe-framework.git", rev = "release-dubhe-v1.0.0-rc1" }`,
18
18
  );
19
19
 
20
20
  content = content.replace(/^dubhe\s+=\s+"0x[0-9a-fA-F]+"/m, `dubhe = "${TESTNET_FRAMEWORK_ID}"`);
@@ -2,6 +2,6 @@ type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
2
2
 
3
3
  export const NETWORK: NetworkType = 'testnet';
4
4
 
5
- export const PACKAGE_ID = '0xde82669197017965ce955ea7a5bb67750218523ca5f942f395b45610a1ec82d0'
5
+ export const PACKAGE_ID = '0x7dea0ab27de6a4c85ddd1cdede7dd0d1a8e5aa77d3c0e9c9268e8a1eb97e73bc'
6
6
 
7
- export const Counter_Object_Id = '0x88b0fcdec5a83cdebb308cbc8e721b146938273bcb439917674155c25ef9e895'
7
+ export const Counter_Object_Id = '0x5a1b868e71da437ba1eabfe7c7d6ee6ba45de5934bf6d36ff321105b6be8a099'
@@ -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
- }