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.
Files changed (84) hide show
  1. package/package.json +1 -1
  2. package/template/101/sui-template/contracts/counter/sources/codegen/errors/counter_error_invalid_increment.move +30 -0
  3. package/template/101/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move +28 -0
  4. package/template/101/sui-template/contracts/counter/sources/codegen/schemas/counter.move +13 -13
  5. package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/metadata.move +102 -0
  6. package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +114 -0
  7. package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/system.move +93 -0
  8. package/template/101/sui-template/contracts/counter/sources/scripts/deploy_hook.move +10 -82
  9. package/template/101/sui-template/contracts/counter/sources/scripts/migrate.move +1 -2
  10. package/template/101/sui-template/contracts/counter/sources/systems/counter.move +13 -4
  11. package/template/101/sui-template/contracts/counter/sources/tests/counter.move +26 -0
  12. package/template/101/sui-template/contracts/counter/sources/tests/init.move +21 -0
  13. package/template/101/sui-template/contracts/dubhe-framework/sources/frames/utils/type_info.move +7 -0
  14. package/template/{nextjs/sui-template/contracts/dubhe-framework/sources/storages/migrate.move → 101/sui-template/contracts/dubhe-framework/sources/storages/migration.move} +3 -3
  15. package/template/101/sui-template/contracts/dubhe-framework/sources/storages/value.move +1 -1
  16. package/template/101/sui-template/dubhe.config.ts +23 -10
  17. package/template/101/sui-template/package.json +2 -2
  18. package/template/101/sui-template/src/pages/home/index.tsx +1 -1
  19. package/template/contract/sui-template/contracts/counter/sources/codegen/errors/counter_error_invalid_increment.move +6 -4
  20. package/template/contract/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move +1 -1
  21. package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/counter.move +13 -13
  22. package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/metadata.move +102 -0
  23. package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +114 -0
  24. package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/system.move +93 -0
  25. package/template/contract/sui-template/contracts/counter/sources/scripts/deploy_hook.move +9 -81
  26. package/template/contract/sui-template/contracts/counter/sources/scripts/migrate.move +1 -1
  27. package/template/contract/sui-template/contracts/counter/sources/systems/counter.move +7 -7
  28. package/template/contract/sui-template/contracts/counter/sources/tests/counter.move +26 -0
  29. package/template/contract/sui-template/contracts/counter/sources/tests/init.move +21 -0
  30. package/template/contract/sui-template/contracts/dubhe-framework/sources/frames/utils/type_info.move +7 -0
  31. package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/{migrate.move → migration.move} +3 -3
  32. package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/value.move +1 -1
  33. package/template/contract/sui-template/dubhe.config.ts +1 -2
  34. package/template/contract/sui-template/package.json +2 -2
  35. package/template/nextjs/sui-template/contracts/counter/sources/codegen/errors/counter_error_invalid_increment.move +30 -0
  36. package/template/nextjs/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move +28 -0
  37. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/counter.move +13 -13
  38. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/metadata.move +102 -0
  39. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +114 -0
  40. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/system.move +93 -0
  41. package/template/nextjs/sui-template/contracts/counter/sources/scripts/deploy_hook.move +9 -81
  42. package/template/nextjs/sui-template/contracts/counter/sources/scripts/migrate.move +1 -1
  43. package/template/nextjs/sui-template/contracts/counter/sources/systems/counter.move +13 -4
  44. package/template/nextjs/sui-template/contracts/counter/sources/tests/counter.move +26 -0
  45. package/template/nextjs/sui-template/contracts/counter/sources/tests/init.move +21 -0
  46. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/frames/utils/type_info.move +7 -0
  47. package/template/{101/sui-template/contracts/dubhe-framework/sources/storages/migrate.move → nextjs/sui-template/contracts/dubhe-framework/sources/storages/migration.move} +3 -3
  48. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/storages/value.move +1 -1
  49. package/template/nextjs/sui-template/dubhe.config.ts +23 -10
  50. package/template/nextjs/sui-template/package.json +2 -2
  51. package/template/nextjs/sui-template/src/pages/home/index.tsx +1 -1
  52. package/template/101/sui-template/contracts/counter/sources/codegen/dapp_key.move +0 -16
  53. package/template/101/sui-template/contracts/counter/sources/codegen/schema_hub.move +0 -60
  54. package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/metadata.move +0 -96
  55. package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/schema.move +0 -113
  56. package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/system.move +0 -101
  57. package/template/101/sui-template/contracts/dubhe-framework/sources/core/dapps/tests.move +0 -66
  58. package/template/101/sui-template/contracts/dubhe-framework/sources/core/root/schema.move +0 -33
  59. package/template/101/sui-template/contracts/dubhe-framework/sources/core/root/system.move +0 -24
  60. package/template/101/sui-template/contracts/dubhe-framework/sources/core/root/tests.move +0 -39
  61. package/template/101/sui-template/contracts/dubhe-framework/tests/init.move +0 -6
  62. package/template/101/sui-template/contracts/dubhe-framework/tests/obelisk_framework_tests.move +0 -19
  63. package/template/contract/sui-template/contracts/counter/sources/codegen/dapp_key.move +0 -16
  64. package/template/contract/sui-template/contracts/counter/sources/codegen/schema_hub.move +0 -60
  65. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/metadata.move +0 -96
  66. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/schema.move +0 -113
  67. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/system.move +0 -101
  68. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/dapps/tests.move +0 -66
  69. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/root/schema.move +0 -33
  70. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/root/system.move +0 -24
  71. package/template/contract/sui-template/contracts/dubhe-framework/sources/core/root/tests.move +0 -39
  72. package/template/contract/sui-template/contracts/dubhe-framework/tests/init.move +0 -6
  73. package/template/contract/sui-template/contracts/dubhe-framework/tests/obelisk_framework_tests.move +0 -19
  74. package/template/nextjs/sui-template/contracts/counter/sources/codegen/dapp_key.move +0 -16
  75. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schema_hub.move +0 -60
  76. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/metadata.move +0 -96
  77. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/schema.move +0 -113
  78. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/system.move +0 -101
  79. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/dapps/tests.move +0 -66
  80. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/root/schema.move +0 -33
  81. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/root/system.move +0 -24
  82. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/core/root/tests.move +0 -39
  83. package/template/nextjs/sui-template/contracts/dubhe-framework/tests/init.move +0 -6
  84. package/template/nextjs/sui-template/contracts/dubhe-framework/tests/obelisk_framework_tests.move +0 -19
@@ -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
- }
@@ -1,66 +0,0 @@
1
- #[test_only]
2
- module dubhe::dapps_tests {
3
- use dubhe::dapps_schema::Dapps;
4
- use dubhe::dapps_schema;
5
- use dubhe::dapps_system;
6
- use std::ascii::string;
7
- use std::debug;
8
- use sui::clock;
9
- use sui::coin;
10
- use sui::test_scenario;
11
- use sui::package;
12
- use sui::package::UpgradeCap;
13
- use sui::sui::SUI;
14
-
15
- public struct DappKey has drop {}
16
-
17
- #[test]
18
- public fun dapps_register() {
19
- let mut scenario = test_scenario::begin(@0xA);
20
- {
21
- let ctx = test_scenario::ctx(&mut scenario);
22
- dapps_schema::init_dapps_for_testing(ctx);
23
- test_scenario::next_tx(&mut scenario,@0xA);
24
- };
25
-
26
- let mut dapps = test_scenario::take_shared<Dapps>(&scenario);
27
-
28
- let upgrade_cap = package::test_publish(@0x42.to_id(), scenario.ctx());
29
- debug::print(&object::id_address<UpgradeCap>(&upgrade_cap));
30
-
31
- let coin = coin::mint_for_testing<SUI>(1_000_000_000, test_scenario::ctx(&mut scenario));
32
-
33
- let clock = clock::create_for_testing(test_scenario::ctx(&mut scenario));
34
- dapps_system::register<UpgradeCap>(
35
- &mut dapps,
36
- &upgrade_cap,
37
- string(b"DappKey"),
38
- string(b"DappKey"),
39
- &clock,
40
- coin,
41
- test_scenario::ctx(&mut scenario),
42
- );
43
-
44
- test_scenario::next_tx(&mut scenario,@0xA);
45
-
46
- let dapp_id = object::id_address<UpgradeCap>(&upgrade_cap);
47
- assert!(dapps.borrow_version().get(dapp_id) == 1, 0);
48
- assert!(dapps.borrow_metadata().contains_key(dapp_id));
49
- assert!(dapps.borrow_admin().get(dapp_id) == test_scenario::ctx(&mut scenario).sender(), 0);
50
- assert!(dapps.borrow_safe_mode().get(dapp_id) == false, 0);
51
-
52
-
53
- dapps_system::unregister(&mut dapps, &upgrade_cap, test_scenario::ctx(&mut scenario));
54
- test_scenario::next_tx(&mut scenario,@0xA);
55
-
56
- assert!(!dapps.borrow_version().contains_key(dapp_id));
57
- assert!(!dapps.borrow_metadata().contains_key(dapp_id));
58
- assert!(!dapps.borrow_admin().contains_key(dapp_id));
59
- assert!(!dapps.borrow_safe_mode().contains_key(dapp_id));
60
-
61
- clock::destroy_for_testing(clock);
62
- test_scenario::return_shared<Dapps>(dapps);
63
- upgrade_cap.make_immutable();
64
- scenario.end();
65
- }
66
- }
@@ -1,33 +0,0 @@
1
- module dubhe::root_schema {
2
- use dubhe::storage_value;
3
- use dubhe::storage_value::StorageValue;
4
- use sui::transfer::public_share_object;
5
-
6
- public struct Root has key, store {
7
- id: UID,
8
- key: StorageValue<address>,
9
- }
10
-
11
-
12
- public(package) fun borrow_mut_key(self: &mut Root): &mut StorageValue<address> {
13
- &mut self.key
14
- }
15
-
16
- public fun borrow_key(self: &Root): &StorageValue<address> {
17
- &self.key
18
- }
19
-
20
- fun init(ctx: &mut TxContext) {
21
- let mut key = storage_value::new();
22
- key.set(ctx.sender());
23
- public_share_object(Root {
24
- id: object::new(ctx),
25
- key,
26
- });
27
- }
28
-
29
- #[test_only]
30
- public fun init_root_for_testing(ctx: &mut TxContext){
31
- init(ctx)
32
- }
33
- }
@@ -1,24 +0,0 @@
1
- module dubhe::root_system {
2
- use dubhe::root_schema::Root;
3
-
4
- public entry fun set_key(
5
- root: &mut Root,
6
- key: address,
7
- ctx: &mut TxContext
8
- ) {
9
- ensure_root(root, ctx);
10
- root.borrow_mut_key().set(key);
11
- }
12
-
13
- public entry fun remove_key(
14
- root: &mut Root,
15
- ctx: &mut TxContext
16
- ) {
17
- ensure_root(root, ctx);
18
- root.borrow_mut_key().remove();
19
- }
20
-
21
- public fun ensure_root(root: &Root, ctx: &TxContext) {
22
- assert!(root.borrow_key().get() == ctx.sender(), 0);
23
- }
24
- }
@@ -1,39 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
1
- #[test_only]
2
- module dubhe::init_tests {
3
- public fun init_dubhe_for_testing(ctx: &mut TxContext){
4
- dubhe::dapps_schema::init_dapps_for_testing(ctx);
5
- }
6
- }
@@ -1,19 +0,0 @@
1
- /*
2
- #[test_only]
3
- module dubhe_framework::dubhe_framework_tests {
4
- // uncomment this line to import the module
5
- // use dubhe_framework::dubhe_framework;
6
-
7
- const ENotImplemented: u64 = 0;
8
-
9
- #[test]
10
- fun test_dubhe_framework() {
11
- // pass
12
- }
13
-
14
- #[test, expected_failure(abort_code = ::dubhe_framework::dubhe_framework_tests::ENotImplemented)]
15
- fun test_dubhe_framework_fail() {
16
- abort ENotImplemented
17
- }
18
- }
19
- */
@@ -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
- }