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.
- package/package.json +1 -1
- package/template/{nextjs/sui-template/contracts/counter/sources/codegen/schemas/default → 101/sui-template/contracts/counter/sources/codegen}/dapp/metadata.move +6 -6
- package/template/101/sui-template/contracts/counter/sources/codegen/dapp/schema.move +112 -0
- package/template/{nextjs/sui-template/contracts/counter/sources/codegen/schemas/default → 101/sui-template/contracts/counter/sources/codegen}/dapp/system.move +17 -17
- package/template/101/sui-template/contracts/counter/sources/codegen/{events → data}/increment_event.move +0 -6
- package/template/101/sui-template/contracts/counter/sources/codegen/errors.move +16 -0
- package/template/101/sui-template/contracts/counter/sources/codegen/events.move +23 -0
- package/template/101/sui-template/contracts/counter/sources/codegen/genesis.move +20 -0
- package/template/101/sui-template/contracts/counter/sources/codegen/schema.move +54 -0
- package/template/101/sui-template/contracts/counter/sources/scripts/deploy_hook.move +12 -22
- package/template/101/sui-template/contracts/counter/sources/systems/counter.move +10 -13
- package/template/101/sui-template/contracts/counter/sources/tests/counter.move +8 -8
- package/template/101/sui-template/contracts/counter/sources/tests/init.move +1 -1
- package/template/101/sui-template/contracts/dubhe-framework/sources/events.move +33 -0
- package/template/101/sui-template/contracts/dubhe-framework/sources/storages/double_map.move +111 -153
- package/template/101/sui-template/contracts/dubhe-framework/sources/storages/map.move +87 -141
- package/template/{nextjs/sui-template/contracts/dubhe-framework/sources/storages/migration.move → 101/sui-template/contracts/dubhe-framework/sources/storages/storage.move} +3 -3
- package/template/101/sui-template/contracts/dubhe-framework/sources/storages/tests.move +82 -334
- package/template/101/sui-template/contracts/dubhe-framework/sources/storages/value.move +77 -83
- package/template/101/sui-template/dubhe.config.ts +1 -3
- package/template/101/sui-template/package.json +6 -4
- package/template/101/sui-template/src/chain/config.ts +2 -4
- package/template/101/sui-template/src/pages/home/index.tsx +4 -4
- package/template/contract/sui-template/contracts/dubhe-framework/sources/events.move +33 -0
- package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/double_map.move +111 -153
- package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/map.move +87 -141
- package/template/{101/sui-template/contracts/dubhe-framework/sources/storages/migration.move → contract/sui-template/contracts/dubhe-framework/sources/storages/storage.move} +3 -3
- package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/tests.move +82 -334
- package/template/contract/sui-template/contracts/dubhe-framework/sources/storages/value.move +77 -83
- package/template/contract/sui-template/package.json +6 -4
- package/template/nextjs/sui-template/contracts/counter/Move.toml +1 -1
- package/template/{101/sui-template/contracts/counter/sources/codegen/schemas/default → nextjs/sui-template/contracts/counter/sources/codegen}/dapp/metadata.move +6 -6
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/dapp/schema.move +112 -0
- package/template/{101/sui-template/contracts/counter/sources/codegen/schemas/default → nextjs/sui-template/contracts/counter/sources/codegen}/dapp/system.move +17 -17
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/{events → data}/increment_event.move +0 -6
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/errors.move +16 -0
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/events.move +23 -0
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/genesis.move +20 -0
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schema.move +54 -0
- package/template/nextjs/sui-template/contracts/counter/sources/scripts/deploy_hook.move +12 -22
- package/template/nextjs/sui-template/contracts/counter/sources/systems/counter.move +10 -13
- package/template/nextjs/sui-template/contracts/counter/sources/tests/counter.move +8 -8
- package/template/nextjs/sui-template/contracts/counter/sources/tests/init.move +1 -1
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/events.move +33 -0
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/storages/double_map.move +111 -153
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/storages/map.move +87 -141
- package/template/{contract/sui-template/contracts/dubhe-framework/sources/storages/migration.move → nextjs/sui-template/contracts/dubhe-framework/sources/storages/storage.move} +3 -3
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/storages/tests.move +82 -334
- package/template/nextjs/sui-template/contracts/dubhe-framework/sources/storages/value.move +77 -83
- package/template/nextjs/sui-template/dubhe.config.ts +1 -3
- package/template/nextjs/sui-template/package.json +7 -5
- package/template/nextjs/sui-template/src/chain/config.ts +3 -5
- package/template/nextjs/sui-template/src/pages/home/index.tsx +4 -4
- package/template/101/sui-template/contracts/counter/sources/codegen/errors/invalid_increment_error.move +0 -30
- package/template/101/sui-template/contracts/counter/sources/codegen/schemas/counter.move +0 -60
- package/template/101/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +0 -114
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/errors/invalid_increment_error.move +0 -30
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/counter.move +0 -60
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +0 -114
package/package.json
CHANGED
|
@@ -76,27 +76,27 @@
|
|
|
76
76
|
self.partners = partners;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
public fun get_name(self: DappMetadata): String {
|
|
79
|
+
public fun get_name(self: &DappMetadata): String {
|
|
80
80
|
self.name
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
public fun get_description(self: DappMetadata): String {
|
|
83
|
+
public fun get_description(self: &DappMetadata): String {
|
|
84
84
|
self.description
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
public fun get_icon_url(self: DappMetadata): String {
|
|
87
|
+
public fun get_icon_url(self: &DappMetadata): String {
|
|
88
88
|
self.icon_url
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
public fun get_website_url(self: DappMetadata): String {
|
|
91
|
+
public fun get_website_url(self: &DappMetadata): String {
|
|
92
92
|
self.website_url
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
public fun get_created_at(self: DappMetadata): u64 {
|
|
95
|
+
public fun get_created_at(self: &DappMetadata): u64 {
|
|
96
96
|
self.created_at
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
public fun get_partners(self: DappMetadata): vector<String> {
|
|
99
|
+
public fun get_partners(self: &DappMetadata): vector<String> {
|
|
100
100
|
self.partners
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
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;
|
|
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::borrow_field(&self.id, b"admin")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public(package) fun admin(self: &mut Dapp): &mut StorageValue<address> {
|
|
30
|
+
storage::borrow_mut_field(&mut self.id, b"admin")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public fun borrow_package_id(self: &Dapp): &StorageValue<address> {
|
|
34
|
+
storage::borrow_field(&self.id, b"package_id")
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public(package) fun package_id(self: &mut Dapp): &mut StorageValue<address> {
|
|
38
|
+
storage::borrow_mut_field(&mut self.id, b"package_id")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public fun borrow_version(self: &Dapp): &StorageValue<u32> {
|
|
42
|
+
storage::borrow_field(&self.id, b"version")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public(package) fun version(self: &mut Dapp): &mut StorageValue<u32> {
|
|
46
|
+
storage::borrow_mut_field(&mut self.id, b"version")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public fun borrow_metadata(self: &Dapp): &StorageValue<DappMetadata> {
|
|
50
|
+
storage::borrow_field(&self.id, b"metadata")
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public(package) fun metadata(self: &mut Dapp): &mut StorageValue<DappMetadata> {
|
|
54
|
+
storage::borrow_mut_field(&mut self.id, b"metadata")
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public fun borrow_safe_mode(self: &Dapp): &StorageValue<bool> {
|
|
58
|
+
storage::borrow_field(&self.id, b"safe_mode")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public(package) fun safe_mode(self: &mut Dapp): &mut StorageValue<bool> {
|
|
62
|
+
storage::borrow_mut_field(&mut self.id, b"safe_mode")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public(package) fun borrow_schemas(self: &Dapp): &StorageValue<vector<address>> {
|
|
66
|
+
storage::borrow_field(&self.id, b"schemas")
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public(package) fun schemas(self: &mut Dapp): &mut StorageValue<vector<address>> {
|
|
70
|
+
storage::borrow_mut_field(&mut self.id, b"schemas")
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public(package) fun create(ctx: &mut TxContext): Dapp {
|
|
74
|
+
let mut id = object::new(ctx);
|
|
75
|
+
storage::add_field<StorageValue<address>>(&mut id, b"admin", storage_value::new(b"admin", ctx));
|
|
76
|
+
storage::add_field<StorageValue<address>>(&mut id, b"package_id", storage_value::new(b"package_id", ctx));
|
|
77
|
+
storage::add_field<StorageValue<u32>>(&mut id, b"version", storage_value::new(b"version", ctx));
|
|
78
|
+
storage::add_field<StorageValue<DappMetadata>>(&mut id, b"metadata", storage_value::new(b"metadata", ctx));
|
|
79
|
+
storage::add_field<StorageValue<bool>>(&mut id, b"safe_mode", storage_value::new(b"safe_mode", ctx));
|
|
80
|
+
storage::add_field<StorageValue<vector<address>>>(&mut id, b"schemas", storage_value::new(b"schemas", ctx));
|
|
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.package_id().set(new_package_id);
|
|
89
|
+
let current_version = dapp.version()[];
|
|
90
|
+
dapp.version().set(current_version + 1);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public(package) fun add_schema<Schema: key + store>(dapp: &mut Dapp, schema: Schema) {
|
|
94
|
+
let mut schemas = dapp.schemas()[];
|
|
95
|
+
schemas.push_back(object::id_address<Schema>(&schema));
|
|
96
|
+
dapp.schemas().set(schemas);
|
|
97
|
+
public_share_object(schema);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#[test_only]
|
|
101
|
+
|
|
102
|
+
public fun create_dapp_for_testing(ctx: &mut TxContext): Dapp {
|
|
103
|
+
create(ctx)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
#[test_only]
|
|
107
|
+
|
|
108
|
+
public fun distroy_dapp_for_testing(dapp: Dapp) {
|
|
109
|
+
let Dapp { id } = dapp;
|
|
110
|
+
id.delete();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -23,7 +23,7 @@ module counter::dapp_system {
|
|
|
23
23
|
public(package) fun create(name: String, description: String, clock: &Clock, ctx: &mut TxContext): Dapp {
|
|
24
24
|
let mut dapp = dapp_schema::create(ctx);
|
|
25
25
|
assert!(!dapp.borrow_metadata().contains(), 0);
|
|
26
|
-
dapp.
|
|
26
|
+
dapp.metadata().set(
|
|
27
27
|
dapp_metadata::new(
|
|
28
28
|
name,
|
|
29
29
|
description,
|
|
@@ -34,11 +34,11 @@ module counter::dapp_system {
|
|
|
34
34
|
)
|
|
35
35
|
);
|
|
36
36
|
let package_id = type_info::current_package_id<DappKey>();
|
|
37
|
-
dapp.
|
|
38
|
-
dapp.
|
|
39
|
-
dapp.
|
|
40
|
-
dapp.
|
|
41
|
-
dapp.
|
|
37
|
+
dapp.package_id().set(package_id);
|
|
38
|
+
dapp.admin().set(ctx.sender());
|
|
39
|
+
dapp.version().set(1);
|
|
40
|
+
dapp.safe_mode().set(false);
|
|
41
|
+
dapp.schemas().set(vector[]);
|
|
42
42
|
dapp
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -51,10 +51,10 @@ module counter::dapp_system {
|
|
|
51
51
|
partners: vector<String>,
|
|
52
52
|
ctx: &TxContext,
|
|
53
53
|
) {
|
|
54
|
-
|
|
55
|
-
assert!(
|
|
56
|
-
let created_at = dapp.
|
|
57
|
-
dapp.
|
|
54
|
+
let admin = dapp.admin().try_get();
|
|
55
|
+
assert!(admin == option::some(ctx.sender()), 0);
|
|
56
|
+
let created_at = dapp.metadata().get().get_created_at();
|
|
57
|
+
dapp.metadata().set(
|
|
58
58
|
dapp_metadata::new(
|
|
59
59
|
name,
|
|
60
60
|
description,
|
|
@@ -67,19 +67,19 @@ module counter::dapp_system {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
public entry fun transfer_ownership(dapp: &mut Dapp, new_admin: address, ctx: &mut TxContext) {
|
|
70
|
-
|
|
71
|
-
assert!(
|
|
72
|
-
dapp.
|
|
70
|
+
let admin = dapp.admin().try_get();
|
|
71
|
+
assert!(admin == option::some(ctx.sender()), 0);
|
|
72
|
+
dapp.admin().set(new_admin);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
public entry fun set_safe_mode(dapp: &mut Dapp, safe_mode: bool, ctx: &TxContext) {
|
|
76
|
-
|
|
77
|
-
assert!(
|
|
78
|
-
dapp.
|
|
76
|
+
let admin = dapp.admin().try_get();
|
|
77
|
+
assert!(admin == option::some(ctx.sender()), 0);
|
|
78
|
+
dapp.safe_mode().set(safe_mode);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
public fun ensure_no_safe_mode(dapp: &Dapp) {
|
|
82
|
-
assert!(!dapp.borrow_safe_mode()
|
|
82
|
+
assert!(!dapp.borrow_safe_mode()[], 0);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
public fun ensure_has_authority(dapp: &Dapp, ctx: &TxContext) {
|
|
@@ -0,0 +1,16 @@
|
|
|
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::errors {
|
|
8
|
+
|
|
9
|
+
#[error]
|
|
10
|
+
|
|
11
|
+
const InvalidIncrement: vector<u8> = b"Number can't be incremented, must be more than 0";
|
|
12
|
+
|
|
13
|
+
public fun invalid_increment_error(condition: bool) {
|
|
14
|
+
assert!(condition, InvalidIncrement)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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::events {
|
|
8
|
+
|
|
9
|
+
use std::ascii::{String, string};
|
|
10
|
+
|
|
11
|
+
use counter::increment_event::IncrementEvent;
|
|
12
|
+
|
|
13
|
+
use counter::increment_event;
|
|
14
|
+
|
|
15
|
+
public fun increment_event(value: u32) {
|
|
16
|
+
dubhe::storage_event::emit_set_record<IncrementEvent, IncrementEvent, IncrementEvent>(
|
|
17
|
+
string(b"increment_event"),
|
|
18
|
+
option::none(),
|
|
19
|
+
option::none(),
|
|
20
|
+
option::some(increment_event::new(value))
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#[allow(lint(share_owned))]module counter::genesis {
|
|
2
|
+
|
|
3
|
+
use std::ascii::string;
|
|
4
|
+
|
|
5
|
+
use sui::clock::Clock;
|
|
6
|
+
|
|
7
|
+
use counter::dapp_system;
|
|
8
|
+
|
|
9
|
+
public entry fun run(clock: &Clock, ctx: &mut TxContext) {
|
|
10
|
+
// Create a dapp.
|
|
11
|
+
let mut dapp = dapp_system::create(string(b"counter"),string(b"counter contract"), clock , ctx);
|
|
12
|
+
// Create schemas
|
|
13
|
+
let mut schema = counter::schema::create(ctx);
|
|
14
|
+
// Logic that needs to be automated once the contract is deployed
|
|
15
|
+
counter::deploy_hook::run(&mut schema, ctx);
|
|
16
|
+
// Authorize schemas and public share objects
|
|
17
|
+
dapp.add_schema(schema);
|
|
18
|
+
sui::transfer::public_share_object(dapp);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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::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;
|
|
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
|
+
public struct Schema has key, store {
|
|
28
|
+
id: UID,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public fun borrow_value(self: &Schema): &StorageValue<u32> {
|
|
32
|
+
storage::borrow_field(&self.id, b"value")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public(package) fun value(self: &mut Schema): &mut StorageValue<u32> {
|
|
36
|
+
storage::borrow_mut_field(&mut self.id, b"value")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public(package) fun create(ctx: &mut TxContext): Schema {
|
|
40
|
+
let mut id = object::new(ctx);
|
|
41
|
+
storage::add_field<StorageValue<u32>>(&mut id, b"value", storage_value::new(b"value", ctx));
|
|
42
|
+
Schema { id }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public fun migrate(_schema: &mut Schema, _cap: &UpgradeCap, _ctx: &mut TxContext) {}
|
|
46
|
+
|
|
47
|
+
// ======================================== View Functions ========================================
|
|
48
|
+
|
|
49
|
+
public fun get_value(self: &Schema): &u32 {
|
|
50
|
+
self.borrow_value().get()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// =========================================================================================================
|
|
54
|
+
}
|
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
use counter::
|
|
10
|
-
|
|
11
|
-
public
|
|
12
|
-
|
|
13
|
-
let mut dapp = dapp_system::create(string(b"counter"),string(b"counter contract"), clock , ctx);
|
|
14
|
-
// Create schemas
|
|
15
|
-
let mut counter = counter::counter_schema::create(ctx);
|
|
16
|
-
// Logic that needs to be automated once the contract is deployed
|
|
17
|
-
{
|
|
18
|
-
counter.value().set(0);
|
|
19
|
-
};
|
|
20
|
-
// Authorize schemas and public share objects
|
|
21
|
-
dapp.add_schema<Counter>(counter, ctx);
|
|
22
|
-
sui::transfer::public_share_object(dapp);
|
|
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::deploy_hook {
|
|
8
|
+
|
|
9
|
+
use counter::schema::Schema;
|
|
10
|
+
|
|
11
|
+
public(package) fun run(_schema: &mut Schema, _ctx: &mut TxContext) {
|
|
12
|
+
_schema.value().set(0);
|
|
23
13
|
}
|
|
24
14
|
}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
module counter::counter_system {
|
|
2
|
-
use counter::
|
|
3
|
-
use counter::increment_event;
|
|
4
|
-
use counter::invalid_increment_error;
|
|
2
|
+
use counter::schema::Schema;
|
|
3
|
+
use counter::events::increment_event;
|
|
4
|
+
use counter::errors::invalid_increment_error;
|
|
5
5
|
|
|
6
|
-
public entry fun inc(
|
|
6
|
+
public entry fun inc(scheam: &mut Schema, number: u32) {
|
|
7
7
|
// Check if the increment value is valid.
|
|
8
|
-
invalid_increment_error
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// Emit an event to notify the increment.
|
|
13
|
-
increment_event::emit(number);
|
|
14
|
-
});
|
|
8
|
+
invalid_increment_error(number > 0 && number < 100);
|
|
9
|
+
let value = scheam.value()[];
|
|
10
|
+
scheam.value().set(value + number);
|
|
11
|
+
increment_event(number);
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
public fun get(
|
|
18
|
-
|
|
14
|
+
public fun get(scheam: &Schema): u32 {
|
|
15
|
+
scheam.borrow_value()[]
|
|
19
16
|
}
|
|
20
17
|
}
|
|
@@ -2,24 +2,24 @@
|
|
|
2
2
|
module counter::counter_test {
|
|
3
3
|
use sui::test_scenario;
|
|
4
4
|
use counter::counter_system;
|
|
5
|
-
use counter::counter_schema::Counter;
|
|
6
5
|
use counter::init_test;
|
|
6
|
+
use counter::schema::Schema;
|
|
7
7
|
|
|
8
8
|
#[test]
|
|
9
9
|
public fun inc() {
|
|
10
10
|
let (scenario, dapp) = init_test::deploy_dapp_for_testing(@0xA);
|
|
11
11
|
|
|
12
|
-
let mut
|
|
12
|
+
let mut schema = test_scenario::take_shared<Schema>(&scenario);
|
|
13
13
|
|
|
14
|
-
assert!(
|
|
14
|
+
assert!(schema.value().get() == 0);
|
|
15
15
|
|
|
16
|
-
counter_system::inc(&mut
|
|
17
|
-
assert!(
|
|
16
|
+
counter_system::inc(&mut schema, 10);
|
|
17
|
+
assert!(schema.value().get() == 10);
|
|
18
18
|
|
|
19
|
-
counter_system::inc(&mut
|
|
20
|
-
assert!(
|
|
19
|
+
counter_system::inc(&mut schema, 10);
|
|
20
|
+
assert!(schema.value().get() == 20);
|
|
21
21
|
|
|
22
|
-
test_scenario::return_shared(
|
|
22
|
+
test_scenario::return_shared(schema);
|
|
23
23
|
dapp.distroy_dapp_for_testing();
|
|
24
24
|
scenario.end();
|
|
25
25
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
let mut scenario = test_scenario::begin(sender);
|
|
13
13
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
14
14
|
let clock = clock::create_for_testing(ctx);
|
|
15
|
-
counter::
|
|
15
|
+
counter::genesis::run(&clock, ctx);
|
|
16
16
|
clock::destroy_for_testing(clock);
|
|
17
17
|
test_scenario::next_tx(&mut scenario,sender);
|
|
18
18
|
let dapp = test_scenario::take_shared<Dapp>(&scenario);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module dubhe::storage_event;
|
|
2
|
+
use std::ascii::String;
|
|
3
|
+
use sui::event;
|
|
4
|
+
|
|
5
|
+
public struct RemoveRecord<K1: copy + drop, K2: copy + drop> has copy, drop {
|
|
6
|
+
name: String,
|
|
7
|
+
key1: Option<K1>,
|
|
8
|
+
key2: Option<K2>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public struct SetRecord<K1: copy + drop, K2: copy + drop, V: copy + drop> has copy, drop {
|
|
12
|
+
name: String,
|
|
13
|
+
key1: Option<K1>,
|
|
14
|
+
key2: Option<K2>,
|
|
15
|
+
value: Option<V>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public fun emit_set_record<K1: copy + drop, K2: copy + drop, V: copy + drop>(name: String, key1: Option<K1>, key2: Option<K2>, value: Option<V>) {
|
|
19
|
+
event::emit(SetRecord {
|
|
20
|
+
name,
|
|
21
|
+
key1,
|
|
22
|
+
key2,
|
|
23
|
+
value
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public fun emit_remove_record<K1: copy + drop, K2: copy + drop>(name: String, key1: Option<K1>, key2: Option<K2>) {
|
|
28
|
+
event::emit(RemoveRecord {
|
|
29
|
+
name,
|
|
30
|
+
key1,
|
|
31
|
+
key2,
|
|
32
|
+
});
|
|
33
|
+
}
|