create-dubhe 0.0.12 → 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.
Files changed (89) hide show
  1. package/package.json +1 -1
  2. package/template/101/aptos-template/package.json +4 -4
  3. package/template/101/aptos-template/src/pages/home/index.tsx +1 -2
  4. package/template/101/movement-template/package.json +7 -7
  5. package/template/101/movement-template/scripts/checkBalance.ts +2 -2
  6. package/template/101/movement-template/src/pages/home/index.tsx +1 -2
  7. package/template/101/sui-template/contracts/counter/sources/codegen/errors/counter_error_invalid_increment.move +30 -0
  8. package/template/101/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move +28 -0
  9. package/template/101/sui-template/contracts/counter/sources/codegen/schemas/counter.move +13 -13
  10. package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/metadata.move +102 -0
  11. package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +114 -0
  12. package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/system.move +93 -0
  13. package/template/101/sui-template/contracts/counter/sources/scripts/deploy_hook.move +10 -82
  14. package/template/101/sui-template/contracts/counter/sources/scripts/migrate.move +1 -2
  15. package/template/101/sui-template/contracts/counter/sources/systems/counter.move +13 -4
  16. package/template/101/sui-template/contracts/counter/sources/tests/counter.move +26 -0
  17. package/template/101/sui-template/contracts/counter/sources/tests/init.move +21 -0
  18. package/template/101/sui-template/contracts/dubhe-framework/sources/frames/utils/type_info.move +7 -0
  19. package/template/{nextjs/sui-template/contracts/dubhe-framework/sources/storages/migrate.move → 101/sui-template/contracts/dubhe-framework/sources/storages/migration.move} +3 -3
  20. package/template/101/sui-template/contracts/dubhe-framework/sources/storages/value.move +1 -1
  21. package/template/101/sui-template/dubhe.config.ts +23 -10
  22. package/template/101/sui-template/package.json +2 -2
  23. package/template/101/sui-template/src/pages/home/index.tsx +1 -1
  24. package/template/contract/sui-template/contracts/counter/sources/codegen/errors/counter_error_invalid_increment.move +6 -4
  25. package/template/contract/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move +1 -1
  26. package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/counter.move +13 -13
  27. package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/metadata.move +102 -0
  28. package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +114 -0
  29. package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/system.move +93 -0
  30. package/template/contract/sui-template/contracts/counter/sources/scripts/deploy_hook.move +9 -81
  31. package/template/contract/sui-template/contracts/counter/sources/scripts/migrate.move +1 -1
  32. package/template/contract/sui-template/contracts/counter/sources/systems/counter.move +7 -7
  33. package/template/contract/sui-template/contracts/counter/sources/tests/counter.move +26 -0
  34. package/template/contract/sui-template/contracts/counter/sources/tests/init.move +21 -0
  35. package/template/contract/sui-template/contracts/dubhe-framework/sources/frames/utils/type_info.move +7 -0
  36. package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/{migrate.move → migration.move} +3 -3
  37. package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/value.move +1 -1
  38. package/template/contract/sui-template/dubhe.config.ts +1 -2
  39. package/template/contract/sui-template/package.json +2 -2
  40. package/template/nextjs/sui-template/contracts/counter/sources/codegen/errors/counter_error_invalid_increment.move +30 -0
  41. package/template/nextjs/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move +28 -0
  42. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/counter.move +13 -13
  43. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/metadata.move +102 -0
  44. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +114 -0
  45. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/system.move +93 -0
  46. package/template/nextjs/sui-template/contracts/counter/sources/scripts/deploy_hook.move +9 -81
  47. package/template/nextjs/sui-template/contracts/counter/sources/scripts/migrate.move +1 -1
  48. package/template/nextjs/sui-template/contracts/counter/sources/systems/counter.move +13 -4
  49. package/template/nextjs/sui-template/contracts/counter/sources/tests/counter.move +26 -0
  50. package/template/nextjs/sui-template/contracts/counter/sources/tests/init.move +21 -0
  51. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/frames/utils/type_info.move +7 -0
  52. package/template/{101/sui-template/contracts/dubhe-framework/sources/storages/migrate.move → nextjs/sui-template/contracts/dubhe-framework/sources/storages/migration.move} +3 -3
  53. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/storages/value.move +1 -1
  54. package/template/nextjs/sui-template/dubhe.config.ts +23 -10
  55. package/template/nextjs/sui-template/package.json +2 -2
  56. package/template/nextjs/sui-template/src/pages/home/index.tsx +1 -1
  57. package/template/101/sui-template/contracts/counter/sources/codegen/dapp_key.move +0 -16
  58. package/template/101/sui-template/contracts/counter/sources/codegen/schema_hub.move +0 -60
  59. package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/metadata.move +0 -96
  60. package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/schema.move +0 -113
  61. package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/system.move +0 -101
  62. package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/tests.move +0 -66
  63. package/template/101/sui-template/contracts/dubhe-framework/sources/core/root/schema.move +0 -33
  64. package/template/101/sui-template/contracts/dubhe-framework/sources/core/root/system.move +0 -24
  65. package/template/101/sui-template/contracts/dubhe-framework/sources/core/root/tests.move +0 -39
  66. package/template/101/sui-template/contracts/dubhe-framework/tests/init.move +0 -6
  67. package/template/101/sui-template/contracts/dubhe-framework/tests/obelisk_framework_tests.move +0 -19
  68. package/template/contract/sui-template/contracts/counter/sources/codegen/dapp_key.move +0 -16
  69. package/template/contract/sui-template/contracts/counter/sources/codegen/schema_hub.move +0 -60
  70. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/metadata.move +0 -96
  71. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/schema.move +0 -113
  72. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/system.move +0 -101
  73. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/tests.move +0 -66
  74. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/root/schema.move +0 -33
  75. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/root/system.move +0 -24
  76. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/root/tests.move +0 -39
  77. package/template/contract/sui-template/contracts/dubhe-framework/tests/init.move +0 -6
  78. package/template/contract/sui-template/contracts/dubhe-framework/tests/obelisk_framework_tests.move +0 -19
  79. package/template/nextjs/sui-template/contracts/counter/sources/codegen/dapp_key.move +0 -16
  80. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schema_hub.move +0 -60
  81. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/metadata.move +0 -96
  82. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/schema.move +0 -113
  83. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/system.move +0 -101
  84. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/tests.move +0 -66
  85. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/root/schema.move +0 -33
  86. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/root/system.move +0 -24
  87. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/root/tests.move +0 -39
  88. package/template/nextjs/sui-template/contracts/dubhe-framework/tests/init.move +0 -6
  89. package/template/nextjs/sui-template/contracts/dubhe-framework/tests/obelisk_framework_tests.move +0 -19
@@ -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 sui::sui::SUI;
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
- #[test_only]
26
-
27
- use sui::clock;
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
- let ctx = test_scenario::ctx(&mut scenario);
80
- dapps_schema::init_dapps_for_testing(ctx);
81
- schema_hub::init_schema_hub_for_testing(ctx);
82
- test_scenario::next_tx(&mut scenario,@0xA);
18
+ counter.borrow_mut_value().set(0);
83
19
  };
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)
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,6 +1,6 @@
1
1
  module counter::migrate {
2
2
 
3
- const ON_CHAIN_VERSION: u32 = 0;
3
+ const ON_CHAIN_VERSION: u32 = 1;
4
4
 
5
5
  public fun on_chain_version(): u32 {
6
6
  ON_CHAIN_VERSION
@@ -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
- counter.borrow_mut_value().mutate!(|value| *value = *value + 1);
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
+ }
@@ -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::storage_migrate {
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>, storagr_type: StorageType) {
5
- df::add(uid, field_name, storagr_type);
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
- /// Set the `value` of the `StorageValue`.
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 });
@@ -1,14 +1,27 @@
1
1
  import { DubheConfig } from '@0xobelisk/sui-common';
2
2
 
3
3
  export const dubheConfig = {
4
- name: 'counter',
5
- description: 'counter',
6
- systems: ['counter'],
7
- schemas: {
8
- counter: {
9
- structure: {
10
- value: 'StorageValue<u32>',
11
- },
12
- },
13
- },
4
+ name: 'counter',
5
+ description: 'counter contract',
6
+ schemas: {
7
+ counter: {
8
+ structure: {
9
+ value: 'StorageValue<u32>',
10
+ },
11
+ events: [
12
+ {
13
+ name: 'Increment',
14
+ fields: {
15
+ value: 'u32',
16
+ },
17
+ },
18
+ ],
19
+ errors: [
20
+ {
21
+ name: 'InvalidIncrement',
22
+ message: "Number can't be incremented, must be more than 0",
23
+ },
24
+ ]
25
+ },
26
+ },
14
27
  } as DubheConfig;
@@ -25,9 +25,9 @@
25
25
  "prod:testnet": "pnpm config:store testnet && pnpm next"
26
26
  },
27
27
  "dependencies": {
28
- "@0xobelisk/sui-cli": "^0.5.34",
28
+ "@0xobelisk/sui-cli": "^0.5.37",
29
29
  "@0xobelisk/sui-client": "^0.5.30",
30
- "@0xobelisk/sui-common": "^0.5.23",
30
+ "@0xobelisk/sui-common": "^0.5.25",
31
31
  "@mysten/dapp-kit": "0.14.9",
32
32
  "@mysten/sui": "1.7.0",
33
33
  "dotenv": "^16.4.5",
@@ -85,7 +85,7 @@ const Home: React.FC = () => {
85
85
  const tx = new Transaction();
86
86
  await dubhe.tx.counter_system.inc({
87
87
  tx,
88
- params: [tx.object(Counter_Object_Id)],
88
+ params: [tx.object(Counter_Object_Id), tx.pure.u32(1)],
89
89
  isRaw: true,
90
90
  });
91
91
  await signAndExecuteTransaction(
@@ -1,16 +0,0 @@
1
- // Copyright (c) Obelisk Labs, Inc.
2
- // SPDX-License-Identifier: MIT
3
- #[allow(unused_use)]
4
-
5
- /* Autogenerated file. Do not edit manually. */
6
-
7
- module counter::dapp_key {
8
-
9
- /// Authorization token for the app.
10
-
11
- public struct DappKey has drop {}
12
-
13
- public(package) fun new(): DappKey {
14
- DappKey { }
15
- }
16
- }
@@ -1,60 +0,0 @@
1
- // Copyright (c) Obelisk Labs, Inc.
2
- // SPDX-License-Identifier: MIT
3
- #[allow(unused_use)]
4
-
5
- /* Autogenerated file. Do not edit manually. */
6
-
7
- module counter::schema_hub {
8
-
9
- use sui::transfer::public_share_object;
10
-
11
- use sui::dynamic_field as df;
12
-
13
- public struct SchemaHub has key, store {
14
- id: UID,
15
- admin: address,
16
- }
17
-
18
- public struct SchemaTypeWapper<phantom Schema: key + store> has copy, store, drop {}
19
-
20
- /// Authorize an schema to access protected features of the SchemaHub.
21
-
22
- public(package) fun authorize_schema<Schema: key + store>(self: &mut SchemaHub) {
23
- df::add(&mut self.id, SchemaTypeWapper<Schema> {}, true);
24
- }
25
-
26
- /// Deauthorize an schema by removing its authorization key.
27
-
28
- public(package) fun deauthorize_schema<Schema: key + store>(self: &mut SchemaHub) {
29
- df::remove<SchemaTypeWapper<Schema>, bool>(&mut self.id, SchemaTypeWapper<Schema> {});
30
- }
31
-
32
- /// Check if an schema is authorized to access protected features of
33
-
34
- /// the SchemaHub.
35
-
36
- public fun is_schema_authorized<Schema: key + store>(self: &SchemaHub): bool {
37
- df::exists_(&self.id, SchemaTypeWapper<Schema> {})
38
- }
39
-
40
- /// Assert that an schema is authorized to access protected features of
41
-
42
- /// the SchemaHub. Aborts with `EAppNotAuthorized` if not.
43
-
44
- public fun ensure_schema_authorized<Schema: key + store>(self: &SchemaHub) {
45
- assert!(self.is_schema_authorized<Schema>(), 0);
46
- }
47
-
48
- fun init(ctx: &mut TxContext) {
49
- public_share_object(SchemaHub {
50
- id: object::new(ctx),
51
- admin: ctx.sender(),
52
- });
53
- }
54
-
55
- #[test_only]
56
-
57
- public fun init_schema_hub_for_testing(ctx: &mut TxContext) {
58
- init(ctx);
59
- }
60
- }
@@ -1,96 +0,0 @@
1
- module dubhe::dapp_metadata {
2
- use std::ascii::String;
3
-
4
- public struct DappMetadata has drop, copy, store {
5
- name: String,
6
- description: String,
7
- icon_url: String,
8
- website_url: String,
9
- created_at: u64,
10
- partners: vector<String>,
11
- }
12
-
13
- public fun new(
14
- name: String,
15
- description: String,
16
- icon_url: String,
17
- website_url: String,
18
- created_at: u64,
19
- partners: vector<String>,
20
- ): DappMetadata {
21
- DappMetadata {
22
- name,
23
- description,
24
- icon_url,
25
- website_url,
26
- created_at,
27
- partners,
28
- }
29
- }
30
-
31
- public fun set(
32
- self: &mut DappMetadata,
33
- name: String,
34
- description: String,
35
- icon_url: String,
36
- website_url: String,
37
- created_at: u64,
38
- partners: vector<String>,
39
- ) {
40
- self.name = name;
41
- self.description = description;
42
- self.icon_url = icon_url;
43
- self.website_url = website_url;
44
- self.created_at = created_at;
45
- self.partners = partners;
46
- }
47
-
48
- public fun set_name(self: &mut DappMetadata, name: String) {
49
- self.name = name;
50
- }
51
-
52
- public fun set_description(self: &mut DappMetadata, description: String) {
53
- self.description = description;
54
- }
55
-
56
- public fun set_icon_url(self: &mut DappMetadata, icon_url: String) {
57
- self.icon_url = icon_url;
58
- }
59
-
60
- public fun set_website_url(self: &mut DappMetadata, website_url: String) {
61
- self.website_url = website_url;
62
- }
63
-
64
- public fun set_created_at(self: &mut DappMetadata, created_at: u64) {
65
- self.created_at = created_at;
66
- }
67
-
68
- public fun set_partners(self: &mut DappMetadata, partners: vector<String>) {
69
- self.partners = partners;
70
- }
71
-
72
- public fun get_name(self: DappMetadata): String {
73
- self.name
74
- }
75
-
76
- public fun get_description(self: DappMetadata): String {
77
- self.description
78
- }
79
-
80
- public fun get_icon_url(self: DappMetadata): String {
81
- self.icon_url
82
- }
83
-
84
- public fun get_website_url(self: DappMetadata): String {
85
- self.website_url
86
- }
87
-
88
- public fun get_created_at(self: DappMetadata): u64 {
89
- self.created_at
90
- }
91
-
92
- public fun get_partners(self: DappMetadata): vector<String> {
93
- self.partners
94
- }
95
-
96
- }
@@ -1,113 +0,0 @@
1
- module dubhe::dapps_schema {
2
- use std::ascii::String;
3
- use dubhe::storage_value;
4
- use sui::balance::Balance;
5
- use sui::sui::SUI;
6
- use sui::balance;
7
- use dubhe::storage_value::StorageValue;
8
- use dubhe::storage_map;
9
- use sui::transfer::public_share_object;
10
- use dubhe::dapp_metadata::DappMetadata;
11
- use dubhe::storage_map::StorageMap;
12
-
13
- public struct Dapps has key, store {
14
- id: UID,
15
- admin: StorageMap<address, address>,
16
- version: StorageMap<address, u32>,
17
- metadata: StorageMap<address, DappMetadata>,
18
- schemas: StorageMap<address, vector<String>>,
19
- safe_mode: StorageMap<address, bool>,
20
- verified: StorageMap<address, bool>,
21
- reserved: StorageValue<Balance<SUI>>,
22
- reserve_amount: StorageValue<u64>,
23
- }
24
-
25
-
26
- public(package) fun borrow_mut_version(self: &mut Dapps): &mut StorageMap<address, u32> {
27
- &mut self.version
28
- }
29
-
30
- public(package) fun borrow_mut_admin(self: &mut Dapps): &mut StorageMap<address, address> {
31
- &mut self.admin
32
- }
33
-
34
- public(package) fun borrow_mut_metadata(self: &mut Dapps): &mut StorageMap<address, DappMetadata> {
35
- &mut self.metadata
36
- }
37
-
38
- public(package) fun borrow_mut_schemas(self: &mut Dapps): &mut StorageMap<address, vector<String>> {
39
- &mut self.schemas
40
- }
41
-
42
- public(package) fun borrow_mut_safe_mode(self: &mut Dapps): &mut StorageMap<address, bool> {
43
- &mut self.safe_mode
44
- }
45
-
46
- public(package) fun borrow_mut_verified(self: &mut Dapps): &mut StorageMap<address, bool> {
47
- &mut self.verified
48
- }
49
-
50
- public(package) fun borrow_mut_reserved(self: &mut Dapps): &mut StorageValue<Balance<SUI>> {
51
- &mut self.reserved
52
- }
53
-
54
- public(package) fun borrow_mut_reserve_amount(self: &mut Dapps): &mut StorageValue<u64> {
55
- &mut self.reserve_amount
56
- }
57
-
58
- public fun borrow_admin(self: &Dapps): &StorageMap<address, address> {
59
- &self.admin
60
- }
61
-
62
- public fun borrow_version(self: &Dapps): &StorageMap<address, u32> {
63
- &self.version
64
- }
65
-
66
- public fun borrow_metadata(self: &Dapps): &StorageMap<address, DappMetadata> {
67
- &self.metadata
68
- }
69
-
70
- public fun borrow_schemas(self: &Dapps): &StorageMap<address, vector<String>> {
71
- &self.schemas
72
- }
73
-
74
- public fun borrow_safe_mode(self: &Dapps): &StorageMap<address, bool> {
75
- &self.safe_mode
76
- }
77
-
78
- public fun borrow_verified(self: &mut Dapps): &StorageMap<address, bool> {
79
- &self.verified
80
- }
81
-
82
- public fun borrow_reserved(self: &mut Dapps): &StorageValue<Balance<SUI>> {
83
- &self.reserved
84
- }
85
-
86
- public fun borrow_reserve_amount(self: &mut Dapps): &StorageValue<u64> {
87
- &self.reserve_amount
88
- }
89
-
90
- fun init(ctx: &mut TxContext) {
91
- let mut reserved = storage_value::new();
92
- reserved.put(balance::zero());
93
-
94
- let mut reserve_amount = storage_value::new();
95
- reserve_amount.put(1_000_000_000);
96
- public_share_object(Dapps {
97
- id: object::new(ctx),
98
- admin: storage_map::new(),
99
- version: storage_map::new(),
100
- metadata: storage_map::new(),
101
- schemas: storage_map::new(),
102
- safe_mode: storage_map::new(),
103
- verified: storage_map::new(),
104
- reserved,
105
- reserve_amount
106
- });
107
- }
108
-
109
- #[test_only]
110
- public fun init_dapps_for_testing(ctx: &mut TxContext){
111
- init(ctx)
112
- }
113
- }
@@ -1,101 +0,0 @@
1
- module dubhe::dapps_system {
2
- use std::ascii::String;
3
- use std::ascii;
4
- use dubhe::root_schema::Root;
5
- use dubhe::dapp_metadata;
6
- use sui::clock::Clock;
7
- use sui::coin;
8
- use sui::coin::Coin;
9
- use sui::sui::SUI;
10
- use dubhe::dapps_schema::Dapps;
11
- use dubhe::root_system;
12
-
13
- public entry fun register<UpgradeCap: key>(
14
- dapps: &mut Dapps,
15
- upgrade_cap: &UpgradeCap,
16
- name: String,
17
- description: String,
18
- clock: &Clock,
19
- coin: Coin<SUI>,
20
- ctx: &mut TxContext
21
- ) {
22
- let dapp_id = object::id_address<UpgradeCap>(upgrade_cap);
23
- assert!(!dapps.borrow_metadata().contains_key(dapp_id), 0);
24
-
25
- dapps.borrow_mut_metadata().set(
26
- dapp_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_id, ctx.sender());
37
- dapps.borrow_mut_version().set(dapp_id, 1);
38
- dapps.borrow_mut_safe_mode().set(dapp_id, false);
39
-
40
- let reserve_amount = dapps.borrow_reserve_amount().get();
41
- assert!(coin.value() == reserve_amount, 0);
42
- dapps.borrow_mut_reserved().borrow_mut().join(coin.into_balance());
43
- }
44
-
45
- public entry fun unregister<UpgradeCap: key>(
46
- dapps: &mut Dapps,
47
- upgrade_cap: &UpgradeCap,
48
- ctx: &mut TxContext
49
- ) {
50
- let dapp_id = object::id_address<UpgradeCap>(upgrade_cap);
51
- assert!(dapps.borrow_metadata().contains_key(dapp_id), 0);
52
-
53
- dapps.borrow_mut_metadata().remove(dapp_id);
54
- dapps.borrow_mut_admin().remove(dapp_id);
55
- dapps.borrow_mut_version().remove(dapp_id);
56
- dapps.borrow_mut_safe_mode().remove(dapp_id);
57
-
58
- let reserve_amount = dapps.borrow_reserve_amount().get();
59
- let reserve_amount = dapps.borrow_mut_reserved().borrow_mut().split(reserve_amount);
60
- let reserve_amount = coin::from_balance(reserve_amount, ctx);
61
- transfer::public_transfer(reserve_amount, ctx.sender());
62
- }
63
-
64
- public entry fun set_metadata<UpgradeCap: key>(
65
- dapps: &mut Dapps,
66
- upgrade_cap: &UpgradeCap,
67
- name: String,
68
- description: String,
69
- icon_url: String,
70
- website_url: String,
71
- partners: vector<String>
72
- ) {
73
- let dapp_id = object::id_address<UpgradeCap>(upgrade_cap);
74
- assert!(dapps.borrow_metadata().contains_key(dapp_id), 0);
75
- let created_at = dapps.borrow_mut_metadata().take(dapp_id).get_created_at();
76
- dapps.borrow_mut_metadata().set(dapp_id, dapp_metadata::new(name, description, icon_url, website_url, created_at, partners));
77
- }
78
-
79
- public entry fun transfer_ownership<UpgradeCap: key>(
80
- dapps: &mut Dapps,
81
- upgrade_cap: &UpgradeCap,
82
- new_admin: address,
83
- ctx: &mut TxContext
84
- ) {
85
- let dapp_id = object::id_address<UpgradeCap>(upgrade_cap);
86
- assert!(dapps.borrow_admin().get(dapp_id) == ctx.sender(), 0);
87
- dapps.borrow_mut_admin().set(dapp_id, new_admin);
88
- }
89
-
90
- public entry fun add_verification(dapps: &mut Dapps, root: &Root, dapp_id: address, ctx: &mut TxContext) {
91
- root_system::ensure_root(root, ctx);
92
- assert!(dapps.borrow_metadata().contains_key(dapp_id), 0);
93
- dapps.borrow_mut_verified().set(dapp_id, true);
94
- }
95
-
96
- public entry fun remove_verification(dapps: &mut Dapps, root: &Root, dapp_id: address, ctx: &mut TxContext) {
97
- root_system::ensure_root(root, ctx);
98
- assert!(dapps.borrow_metadata().contains_key(dapp_id), 0);
99
- dapps.borrow_mut_verified().remove(dapp_id);
100
- }
101
- }