create-dubhe 0.0.19 → 0.1.1

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 (59) hide show
  1. package/package.json +1 -1
  2. package/template/{nextjs/sui-template/contracts/counter/sources/codegen/schemas/default → 101/sui-template/contracts/counter/sources/codegen}/dapp/metadata.move +6 -6
  3. package/template/101/sui-template/contracts/counter/sources/codegen/dapp/schema.move +112 -0
  4. package/template/{nextjs/sui-template/contracts/counter/sources/codegen/schemas/default → 101/sui-template/contracts/counter/sources/codegen}/dapp/system.move +17 -17
  5. package/template/101/sui-template/contracts/counter/sources/codegen/{events → data}/increment_event.move +0 -6
  6. package/template/101/sui-template/contracts/counter/sources/codegen/errors.move +16 -0
  7. package/template/101/sui-template/contracts/counter/sources/codegen/events.move +23 -0
  8. package/template/101/sui-template/contracts/counter/sources/codegen/genesis.move +20 -0
  9. package/template/101/sui-template/contracts/counter/sources/codegen/schema.move +54 -0
  10. package/template/101/sui-template/contracts/counter/sources/scripts/deploy_hook.move +12 -22
  11. package/template/101/sui-template/contracts/counter/sources/systems/counter.move +10 -13
  12. package/template/101/sui-template/contracts/counter/sources/tests/counter.move +8 -8
  13. package/template/101/sui-template/contracts/counter/sources/tests/init.move +1 -1
  14. package/template/101/sui-template/contracts/dubhe-framework/sources/events.move +33 -0
  15. package/template/101/sui-template/contracts/dubhe-framework/sources/storages/double_map.move +111 -153
  16. package/template/101/sui-template/contracts/dubhe-framework/sources/storages/map.move +87 -141
  17. package/template/{nextjs/sui-template/contracts/dubhe-framework/sources/storages/migration.move → 101/sui-template/contracts/dubhe-framework/sources/storages/storage.move} +3 -3
  18. package/template/101/sui-template/contracts/dubhe-framework/sources/storages/tests.move +82 -334
  19. package/template/101/sui-template/contracts/dubhe-framework/sources/storages/value.move +77 -83
  20. package/template/101/sui-template/dubhe.config.ts +1 -3
  21. package/template/101/sui-template/package.json +6 -4
  22. package/template/101/sui-template/src/chain/config.ts +2 -4
  23. package/template/101/sui-template/src/pages/home/index.tsx +4 -4
  24. package/template/contract/sui-template/contracts/dubhe-framework/sources/events.move +33 -0
  25. package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/double_map.move +111 -153
  26. package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/map.move +87 -141
  27. package/template/{101/sui-template/contracts/dubhe-framework/sources/storages/migration.move → contract/sui-template/contracts/dubhe-framework/sources/storages/storage.move} +3 -3
  28. package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/tests.move +82 -334
  29. package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/value.move +77 -83
  30. package/template/contract/sui-template/package.json +6 -4
  31. package/template/nextjs/sui-template/contracts/counter/Move.toml +1 -1
  32. package/template/{101/sui-template/contracts/counter/sources/codegen/schemas/default → nextjs/sui-template/contracts/counter/sources/codegen}/dapp/metadata.move +6 -6
  33. package/template/nextjs/sui-template/contracts/counter/sources/codegen/dapp/schema.move +112 -0
  34. package/template/{101/sui-template/contracts/counter/sources/codegen/schemas/default → nextjs/sui-template/contracts/counter/sources/codegen}/dapp/system.move +17 -17
  35. package/template/nextjs/sui-template/contracts/counter/sources/codegen/{events → data}/increment_event.move +0 -6
  36. package/template/nextjs/sui-template/contracts/counter/sources/codegen/errors.move +16 -0
  37. package/template/nextjs/sui-template/contracts/counter/sources/codegen/events.move +23 -0
  38. package/template/nextjs/sui-template/contracts/counter/sources/codegen/genesis.move +20 -0
  39. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schema.move +54 -0
  40. package/template/nextjs/sui-template/contracts/counter/sources/scripts/deploy_hook.move +12 -22
  41. package/template/nextjs/sui-template/contracts/counter/sources/systems/counter.move +10 -13
  42. package/template/nextjs/sui-template/contracts/counter/sources/tests/counter.move +8 -8
  43. package/template/nextjs/sui-template/contracts/counter/sources/tests/init.move +1 -1
  44. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/events.move +33 -0
  45. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/storages/double_map.move +111 -153
  46. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/storages/map.move +87 -141
  47. package/template/{contract/sui-template/contracts/dubhe-framework/sources/storages/migration.move → nextjs/sui-template/contracts/dubhe-framework/sources/storages/storage.move} +3 -3
  48. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/storages/tests.move +82 -334
  49. package/template/nextjs/sui-template/contracts/dubhe-framework/sources/storages/value.move +77 -83
  50. package/template/nextjs/sui-template/dubhe.config.ts +1 -3
  51. package/template/nextjs/sui-template/package.json +7 -5
  52. package/template/nextjs/sui-template/src/chain/config.ts +3 -5
  53. package/template/nextjs/sui-template/src/pages/home/index.tsx +4 -4
  54. package/template/101/sui-template/contracts/counter/sources/codegen/errors/invalid_increment_error.move +0 -30
  55. package/template/101/sui-template/contracts/counter/sources/codegen/schemas/counter.move +0 -60
  56. package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +0 -114
  57. package/template/nextjs/sui-template/contracts/counter/sources/codegen/errors/invalid_increment_error.move +0 -30
  58. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/counter.move +0 -60
  59. package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +0 -114
@@ -10,6 +10,7 @@
10
10
  "upgrade": "pnpm dubhe upgrade --network",
11
11
  "schema:gen": "pnpm dubhe schemagen",
12
12
  "account:gen": "pnpm dubhe generate-key",
13
+ "indexer:sqlite": "pnpm sqlite-indexer --force-regenesis --network",
13
14
  "check-balance": "pnpm dubhe check-balance --network",
14
15
  "config:store": "pnpm dubhe config-store --output-ts-path ./src/chain/config.ts --network",
15
16
  "// Development Environment": "----------------",
@@ -28,11 +29,12 @@
28
29
  "prod:mainnet": "pnpm config:store mainnet && pnpm next"
29
30
  },
30
31
  "dependencies": {
31
- "@0xobelisk/sui-cli": "^1.0.8",
32
- "@0xobelisk/sui-client": "^1.0.3",
33
- "@0xobelisk/sui-common": "^1.0.3",
34
- "@mysten/dapp-kit": "0.14.9",
35
- "@mysten/sui": "1.7.0",
32
+ "@0xobelisk/sui-cli": "^1.1.0",
33
+ "@0xobelisk/sui-client": "^1.1.0",
34
+ "@0xobelisk/sui-common": "^1.1.0",
35
+ "@0xobelisk/sui-indexer": "^1.1.2",
36
+ "@mysten/dapp-kit": "0.14.46",
37
+ "@mysten/sui": "1.19.0",
36
38
  "dotenv": "^16.4.5",
37
39
  "@tanstack/react-query": "^5.17.19",
38
40
  "clsx": "^1.2.1",
@@ -1,7 +1,5 @@
1
1
  type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
2
2
 
3
- export const NETWORK: NetworkType = 'localnet';
4
-
5
- export const PACKAGE_ID = '0xa449868b771214af8bb62414a2e00195664ef295f7fa3f7455aa355eb3e0899e'
6
-
7
- export const Counter_Object_Id = '0x4747e58584beefa3495d8affda4e4cdcadf7064c17fea6a3dceefd8d4ebe9c6c'
3
+ export const NETWORK: NetworkType = 'testnet';
4
+ export const PACKAGE_ID = '0xecf70ffbdc1af4d2b781aec4f5cbb5558c7c559c5f9e52ef4da770d3c2f3ad0d'
5
+ export const SCHEMA_ID = '0x1117240e366ca68db5b0841564313bfba957c6eca365772786d63f4d734ec77f'
@@ -3,7 +3,7 @@ import { useEffect, useState } from 'react';
3
3
  import { useAtom } from 'jotai';
4
4
  import { Value } from '../../jotai';
5
5
  import { useRouter } from 'next/router';
6
- import { Counter_Object_Id, NETWORK, PACKAGE_ID } from '../../chain/config';
6
+ import { SCHEMA_ID, NETWORK, PACKAGE_ID } from '../../chain/config';
7
7
  import { ConnectButton, useCurrentWallet, useSignAndExecuteTransaction, useCurrentAccount } from '@mysten/dapp-kit';
8
8
  import { toast } from 'sonner';
9
9
 
@@ -45,9 +45,9 @@ const Home: React.FC = () => {
45
45
  metadata: metadata,
46
46
  });
47
47
  const tx = new Transaction();
48
- const queryValue = (await dubhe.query.counter_schema.get_value({
48
+ const queryValue = (await dubhe.query.schema.get_value({
49
49
  tx,
50
- params: [tx.object(Counter_Object_Id)],
50
+ params: [tx.object(SCHEMA_ID)],
51
51
  })) as DevInspectResults;
52
52
  console.log('Counter value:', dubhe.view(queryValue)[0]);
53
53
  setValue(dubhe.view(queryValue)[0]);
@@ -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), tx.pure.u32(1)],
88
+ params: [tx.object(SCHEMA_ID), tx.pure.u32(1)],
89
89
  isRaw: true,
90
90
  });
91
91
  await signAndExecuteTransaction(
@@ -1,30 +0,0 @@
1
- // Copyright (c) Obelisk Labs, Inc.
2
- // SPDX-License-Identifier: Apache-2.0
3
- #[allow(unused_use)]
4
-
5
- /* Autogenerated file. Do not edit manually. */
6
-
7
- module counter::invalid_increment_error {
8
-
9
- #[error]
10
-
11
- const InvalidIncrement: vector<u8> = b"Number can't be incremented, must be more than 0";
12
-
13
- /// Get the error message.
14
-
15
- public fun message(): vector<u8> {
16
- InvalidIncrement
17
- }
18
-
19
- /// Abort execution with the given error code.
20
-
21
- public fun emit() {
22
- abort InvalidIncrement
23
- }
24
-
25
- /// Require that the given condition is true, otherwise abort with the given error code.
26
-
27
- public fun require(condition: bool) {
28
- if (!condition) { emit() }
29
- }
30
- }
@@ -1,60 +0,0 @@
1
- // Copyright (c) Obelisk Labs, Inc.
2
- // SPDX-License-Identifier: Apache-2.0
3
- #[allow(unused_use)]
4
-
5
- /* Autogenerated file. Do not edit manually. */
6
-
7
- module counter::counter_schema {
8
-
9
- use std::ascii::String;
10
-
11
- use std::ascii::string;
12
-
13
- use sui::package::UpgradeCap;
14
-
15
- use std::type_name;
16
-
17
- use dubhe::storage_migration;
18
-
19
- use dubhe::storage_value::{Self, StorageValue};
20
-
21
- use dubhe::storage_map::{Self, StorageMap};
22
-
23
- use dubhe::storage_double_map::{Self, StorageDoubleMap};
24
-
25
- use sui::dynamic_field as df;
26
-
27
- use sui::sui::SUI;
28
-
29
- use sui::coin::Coin;
30
-
31
- use sui::balance::Balance;
32
-
33
- public struct Counter has key, store {
34
- id: UID,
35
- }
36
-
37
- public fun borrow_value(self: &Counter): &StorageValue<u32> {
38
- storage_migration::borrow_field(&self.id, b"value")
39
- }
40
-
41
- public(package) fun value(self: &mut Counter): &mut StorageValue<u32> {
42
- storage_migration::borrow_mut_field(&mut self.id, b"value")
43
- }
44
-
45
- public(package) fun create(ctx: &mut TxContext): Counter {
46
- let mut id = object::new(ctx);
47
- storage_migration::add_field<StorageValue<u32>>(&mut id, b"value", storage_value::new());
48
- Counter { id }
49
- }
50
-
51
- public fun migrate(_counter: &mut Counter, _cap: &UpgradeCap) {}
52
-
53
- // ======================================== View Functions ========================================
54
-
55
- public fun get_value(self: &Counter): &u32 {
56
- self.borrow_value().borrow()
57
- }
58
-
59
- // =========================================================================================================
60
- }
@@ -1,114 +0,0 @@
1
- // Copyright (c) Obelisk Labs, Inc.
2
- // SPDX-License-Identifier: Apache-2.0
3
- #[allow(unused_use)]
4
-
5
- /* Autogenerated file. Do not edit manually. */
6
-
7
- module counter::dapp_schema {
8
-
9
- use counter::dapp_metadata::DappMetadata;
10
-
11
- use dubhe::storage_value;
12
-
13
- use dubhe::storage_value::StorageValue;
14
-
15
- use dubhe::storage_migration;
16
-
17
- use sui::transfer::public_share_object;
18
-
19
- use dubhe::type_info;
20
-
21
- public struct Dapp has key, store {
22
- id: UID,
23
- }
24
-
25
- public fun borrow_admin(self: &Dapp): &StorageValue<address> {
26
- storage_migration::borrow_field(&self.id, b"admin")
27
- }
28
-
29
- public(package) fun borrow_mut_admin(self: &mut Dapp): &mut StorageValue<address> {
30
- storage_migration::borrow_mut_field(&mut self.id, b"admin")
31
- }
32
-
33
- public fun borrow_package_id(self: &Dapp): &StorageValue<address> {
34
- storage_migration::borrow_field(&self.id, b"package_id")
35
- }
36
-
37
- public(package) fun borrow_mut_package_id(self: &mut Dapp): &mut StorageValue<address> {
38
- storage_migration::borrow_mut_field(&mut self.id, b"package_id")
39
- }
40
-
41
- public fun borrow_version(self: &Dapp): &StorageValue<u32> {
42
- storage_migration::borrow_field(&self.id, b"version")
43
- }
44
-
45
- public(package) fun borrow_mut_version(self: &mut Dapp): &mut StorageValue<u32> {
46
- storage_migration::borrow_mut_field(&mut self.id, b"version")
47
- }
48
-
49
- public fun borrow_metadata(self: &Dapp): &StorageValue<DappMetadata> {
50
- storage_migration::borrow_field(&self.id, b"metadata")
51
- }
52
-
53
- public(package) fun borrow_mut_metadata(self: &mut Dapp): &mut StorageValue<DappMetadata> {
54
- storage_migration::borrow_mut_field(&mut self.id, b"metadata")
55
- }
56
-
57
- public fun borrow_schemas(self: &Dapp): &StorageValue<vector<address>> {
58
- storage_migration::borrow_field(&self.id, b"schemas")
59
- }
60
-
61
- public(package) fun borrow_mut_schemas(self: &mut Dapp): &mut StorageValue<vector<address>> {
62
- storage_migration::borrow_mut_field(&mut self.id, b"schemas")
63
- }
64
-
65
- public fun borrow_safe_mode(self: &Dapp): &StorageValue<bool> {
66
- storage_migration::borrow_field(&self.id, b"safe_mode")
67
- }
68
-
69
- public(package) fun borrow_mut_safe_mode(self: &mut Dapp): &mut StorageValue<bool> {
70
- storage_migration::borrow_mut_field(&mut self.id, b"safe_mode")
71
- }
72
-
73
- public(package) fun create(ctx: &mut TxContext): Dapp {
74
- let mut id = object::new(ctx);
75
- storage_migration::add_field<StorageValue<address>>(&mut id, b"admin", storage_value::new());
76
- storage_migration::add_field<StorageValue<address>>(&mut id, b"package_id", storage_value::new());
77
- storage_migration::add_field<StorageValue<u32>>(&mut id, b"version", storage_value::new());
78
- storage_migration::add_field<StorageValue<DappMetadata>>(&mut id, b"metadata", storage_value::new());
79
- storage_migration::add_field<StorageValue<vector<address>>>(&mut id, b"schemas", storage_value::new());
80
- storage_migration::add_field<StorageValue<bool>>(&mut id, b"safe_mode", storage_value::new());
81
- Dapp { id }
82
- }
83
-
84
- public(package) fun upgrade<DappKey: drop>(dapp: &mut Dapp, ctx: &TxContext) {
85
- assert!(dapp.borrow_metadata().contains(), 0);
86
- assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
87
- let new_package_id = type_info::current_package_id<DappKey>();
88
- dapp.borrow_mut_package_id().set(new_package_id);
89
- dapp.borrow_mut_version().mutate!(|version| {
90
- *version = *version + 1;
91
- });
92
- }
93
-
94
- public(package) fun add_schema<Schema: key + store>(dapp: &mut Dapp, schema: Schema, ctx: &TxContext) {
95
- assert!(dapp.borrow_metadata().contains(), 0);
96
- assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
97
- let schema_id = object::id_address(&schema);
98
- dapp.borrow_mut_schemas().borrow_mut().push_back(schema_id);
99
- public_share_object(schema);
100
- }
101
-
102
- #[test_only]
103
-
104
- public fun create_dapp_for_testing(ctx: &mut TxContext): Dapp {
105
- create(ctx)
106
- }
107
-
108
- #[test_only]
109
-
110
- public fun distroy_dapp_for_testing(dapp: Dapp) {
111
- let Dapp { id } = dapp;
112
- id.delete();
113
- }
114
- }
@@ -1,30 +0,0 @@
1
- // Copyright (c) Obelisk Labs, Inc.
2
- // SPDX-License-Identifier: Apache-2.0
3
- #[allow(unused_use)]
4
-
5
- /* Autogenerated file. Do not edit manually. */
6
-
7
- module counter::invalid_increment_error {
8
-
9
- #[error]
10
-
11
- const InvalidIncrement: vector<u8> = b"Number can't be incremented, must be more than 0";
12
-
13
- /// Get the error message.
14
-
15
- public fun message(): vector<u8> {
16
- InvalidIncrement
17
- }
18
-
19
- /// Abort execution with the given error code.
20
-
21
- public fun emit() {
22
- abort InvalidIncrement
23
- }
24
-
25
- /// Require that the given condition is true, otherwise abort with the given error code.
26
-
27
- public fun require(condition: bool) {
28
- if (!condition) { emit() }
29
- }
30
- }
@@ -1,60 +0,0 @@
1
- // Copyright (c) Obelisk Labs, Inc.
2
- // SPDX-License-Identifier: Apache-2.0
3
- #[allow(unused_use)]
4
-
5
- /* Autogenerated file. Do not edit manually. */
6
-
7
- module counter::counter_schema {
8
-
9
- use std::ascii::String;
10
-
11
- use std::ascii::string;
12
-
13
- use sui::package::UpgradeCap;
14
-
15
- use std::type_name;
16
-
17
- use dubhe::storage_migration;
18
-
19
- use dubhe::storage_value::{Self, StorageValue};
20
-
21
- use dubhe::storage_map::{Self, StorageMap};
22
-
23
- use dubhe::storage_double_map::{Self, StorageDoubleMap};
24
-
25
- use sui::dynamic_field as df;
26
-
27
- use sui::sui::SUI;
28
-
29
- use sui::coin::Coin;
30
-
31
- use sui::balance::Balance;
32
-
33
- public struct Counter has key, store {
34
- id: UID,
35
- }
36
-
37
- public fun borrow_value(self: &Counter): &StorageValue<u32> {
38
- storage_migration::borrow_field(&self.id, b"value")
39
- }
40
-
41
- public(package) fun value(self: &mut Counter): &mut StorageValue<u32> {
42
- storage_migration::borrow_mut_field(&mut self.id, b"value")
43
- }
44
-
45
- public(package) fun create(ctx: &mut TxContext): Counter {
46
- let mut id = object::new(ctx);
47
- storage_migration::add_field<StorageValue<u32>>(&mut id, b"value", storage_value::new());
48
- Counter { id }
49
- }
50
-
51
- public fun migrate(_counter: &mut Counter, _cap: &UpgradeCap) {}
52
-
53
- // ======================================== View Functions ========================================
54
-
55
- public fun get_value(self: &Counter): &u32 {
56
- self.borrow_value().borrow()
57
- }
58
-
59
- // =========================================================================================================
60
- }
@@ -1,114 +0,0 @@
1
- // Copyright (c) Obelisk Labs, Inc.
2
- // SPDX-License-Identifier: Apache-2.0
3
- #[allow(unused_use)]
4
-
5
- /* Autogenerated file. Do not edit manually. */
6
-
7
- module counter::dapp_schema {
8
-
9
- use counter::dapp_metadata::DappMetadata;
10
-
11
- use dubhe::storage_value;
12
-
13
- use dubhe::storage_value::StorageValue;
14
-
15
- use dubhe::storage_migration;
16
-
17
- use sui::transfer::public_share_object;
18
-
19
- use dubhe::type_info;
20
-
21
- public struct Dapp has key, store {
22
- id: UID,
23
- }
24
-
25
- public fun borrow_admin(self: &Dapp): &StorageValue<address> {
26
- storage_migration::borrow_field(&self.id, b"admin")
27
- }
28
-
29
- public(package) fun borrow_mut_admin(self: &mut Dapp): &mut StorageValue<address> {
30
- storage_migration::borrow_mut_field(&mut self.id, b"admin")
31
- }
32
-
33
- public fun borrow_package_id(self: &Dapp): &StorageValue<address> {
34
- storage_migration::borrow_field(&self.id, b"package_id")
35
- }
36
-
37
- public(package) fun borrow_mut_package_id(self: &mut Dapp): &mut StorageValue<address> {
38
- storage_migration::borrow_mut_field(&mut self.id, b"package_id")
39
- }
40
-
41
- public fun borrow_version(self: &Dapp): &StorageValue<u32> {
42
- storage_migration::borrow_field(&self.id, b"version")
43
- }
44
-
45
- public(package) fun borrow_mut_version(self: &mut Dapp): &mut StorageValue<u32> {
46
- storage_migration::borrow_mut_field(&mut self.id, b"version")
47
- }
48
-
49
- public fun borrow_metadata(self: &Dapp): &StorageValue<DappMetadata> {
50
- storage_migration::borrow_field(&self.id, b"metadata")
51
- }
52
-
53
- public(package) fun borrow_mut_metadata(self: &mut Dapp): &mut StorageValue<DappMetadata> {
54
- storage_migration::borrow_mut_field(&mut self.id, b"metadata")
55
- }
56
-
57
- public fun borrow_schemas(self: &Dapp): &StorageValue<vector<address>> {
58
- storage_migration::borrow_field(&self.id, b"schemas")
59
- }
60
-
61
- public(package) fun borrow_mut_schemas(self: &mut Dapp): &mut StorageValue<vector<address>> {
62
- storage_migration::borrow_mut_field(&mut self.id, b"schemas")
63
- }
64
-
65
- public fun borrow_safe_mode(self: &Dapp): &StorageValue<bool> {
66
- storage_migration::borrow_field(&self.id, b"safe_mode")
67
- }
68
-
69
- public(package) fun borrow_mut_safe_mode(self: &mut Dapp): &mut StorageValue<bool> {
70
- storage_migration::borrow_mut_field(&mut self.id, b"safe_mode")
71
- }
72
-
73
- public(package) fun create(ctx: &mut TxContext): Dapp {
74
- let mut id = object::new(ctx);
75
- storage_migration::add_field<StorageValue<address>>(&mut id, b"admin", storage_value::new());
76
- storage_migration::add_field<StorageValue<address>>(&mut id, b"package_id", storage_value::new());
77
- storage_migration::add_field<StorageValue<u32>>(&mut id, b"version", storage_value::new());
78
- storage_migration::add_field<StorageValue<DappMetadata>>(&mut id, b"metadata", storage_value::new());
79
- storage_migration::add_field<StorageValue<vector<address>>>(&mut id, b"schemas", storage_value::new());
80
- storage_migration::add_field<StorageValue<bool>>(&mut id, b"safe_mode", storage_value::new());
81
- Dapp { id }
82
- }
83
-
84
- public(package) fun upgrade<DappKey: drop>(dapp: &mut Dapp, ctx: &TxContext) {
85
- assert!(dapp.borrow_metadata().contains(), 0);
86
- assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
87
- let new_package_id = type_info::current_package_id<DappKey>();
88
- dapp.borrow_mut_package_id().set(new_package_id);
89
- dapp.borrow_mut_version().mutate!(|version| {
90
- *version = *version + 1;
91
- });
92
- }
93
-
94
- public(package) fun add_schema<Schema: key + store>(dapp: &mut Dapp, schema: Schema, ctx: &TxContext) {
95
- assert!(dapp.borrow_metadata().contains(), 0);
96
- assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
97
- let schema_id = object::id_address(&schema);
98
- dapp.borrow_mut_schemas().borrow_mut().push_back(schema_id);
99
- public_share_object(schema);
100
- }
101
-
102
- #[test_only]
103
-
104
- public fun create_dapp_for_testing(ctx: &mut TxContext): Dapp {
105
- create(ctx)
106
- }
107
-
108
- #[test_only]
109
-
110
- public fun distroy_dapp_for_testing(dapp: Dapp) {
111
- let Dapp { id } = dapp;
112
- id.delete();
113
- }
114
- }