create-dubhe 0.0.16 → 0.0.18
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/101/sui-template/contracts/counter/sources/codegen/errors/{counter_error_invalid_increment.move → invalid_increment_error.move} +1 -1
- package/template/{nextjs/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move → 101/sui-template/contracts/counter/sources/codegen/events/increment_event.move} +1 -1
- package/template/101/sui-template/contracts/counter/sources/codegen/schemas/counter.move +1 -1
- package/template/101/sui-template/contracts/counter/sources/scripts/deploy_hook.move +2 -2
- package/template/101/sui-template/contracts/counter/sources/systems/counter.move +8 -8
- package/template/101/sui-template/dubhe.config.ts +7 -17
- package/template/101/sui-template/package.json +3 -3
- package/template/contract/sui-template/dubhe.config.ts +3 -23
- package/template/contract/sui-template/package.json +4 -3
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/errors/{counter_error_invalid_increment.move → invalid_increment_error.move} +1 -1
- package/template/{101/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move → nextjs/sui-template/contracts/counter/sources/codegen/events/increment_event.move} +1 -1
- package/template/nextjs/sui-template/contracts/counter/sources/codegen/schemas/counter.move +1 -1
- package/template/nextjs/sui-template/contracts/counter/sources/scripts/deploy_hook.move +2 -2
- package/template/nextjs/sui-template/contracts/counter/sources/systems/counter.move +8 -8
- package/template/nextjs/sui-template/dubhe.config.ts +7 -17
- package/template/nextjs/sui-template/package.json +4 -4
- package/template/contract/sui-template/contracts/counter/Move.toml +0 -12
- package/template/contract/sui-template/contracts/counter/sources/codegen/errors/counter_error_invalid_increment.move +0 -30
- package/template/contract/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move +0 -28
- package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/counter.move +0 -60
- package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/metadata.move +0 -102
- package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/schema.move +0 -114
- package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/default/dapp/system.move +0 -93
- package/template/contract/sui-template/contracts/counter/sources/scripts/deploy_hook.move +0 -24
- package/template/contract/sui-template/contracts/counter/sources/scripts/migrate.move +0 -8
- package/template/contract/sui-template/contracts/counter/sources/systems/counter.move +0 -20
- package/template/contract/sui-template/contracts/counter/sources/tests/counter.move +0 -26
- package/template/contract/sui-template/contracts/counter/sources/tests/init.move +0 -21
package/package.json
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
storage_migration::borrow_field(&self.id, b"value")
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
public(package) fun
|
|
41
|
+
public(package) fun value(self: &mut Counter): &mut StorageValue<u32> {
|
|
42
42
|
storage_migration::borrow_mut_field(&mut self.id, b"value")
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
let mut counter = counter::counter_schema::create(ctx);
|
|
16
16
|
// Logic that needs to be automated once the contract is deployed
|
|
17
17
|
{
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
counter.value().set(0);
|
|
19
|
+
};
|
|
20
20
|
// Authorize schemas and public share objects
|
|
21
21
|
dapp.add_schema<Counter>(counter, ctx);
|
|
22
22
|
sui::transfer::public_share_object(dapp);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
module counter::counter_system {
|
|
2
2
|
use counter::counter_schema::Counter;
|
|
3
|
-
use counter::
|
|
4
|
-
use counter::
|
|
3
|
+
use counter::increment_event;
|
|
4
|
+
use counter::invalid_increment_error;
|
|
5
5
|
|
|
6
6
|
public entry fun inc(counter: &mut Counter, number: u32) {
|
|
7
7
|
// Check if the increment value is valid.
|
|
8
|
-
|
|
9
|
-
counter.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
invalid_increment_error::require(number > 0 && number < 100);
|
|
9
|
+
counter.value().mutate!(|value| {
|
|
10
|
+
// Increment the counter value.
|
|
11
|
+
*value = *value + number;
|
|
12
|
+
// Emit an event to notify the increment.
|
|
13
|
+
increment_event::emit(number);
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -5,23 +5,13 @@ export const dubheConfig = {
|
|
|
5
5
|
description: 'counter contract',
|
|
6
6
|
schemas: {
|
|
7
7
|
counter: {
|
|
8
|
-
|
|
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
|
-
]
|
|
8
|
+
value: 'StorageValue<u32>',
|
|
25
9
|
},
|
|
26
10
|
},
|
|
11
|
+
events: {
|
|
12
|
+
Increment: { value: 'u32' },
|
|
13
|
+
},
|
|
14
|
+
errors: {
|
|
15
|
+
InvalidIncrement: "Number can't be incremented, must be more than 0",
|
|
16
|
+
}
|
|
27
17
|
} as DubheConfig;
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"prod:mainnet": "pnpm config:store mainnet && pnpm next"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@0xobelisk/sui-cli": "^1.0.
|
|
32
|
-
"@0xobelisk/sui-client": "^1.0.
|
|
33
|
-
"@0xobelisk/sui-common": "^1.0.
|
|
31
|
+
"@0xobelisk/sui-cli": "^1.0.6",
|
|
32
|
+
"@0xobelisk/sui-client": "^1.0.3",
|
|
33
|
+
"@0xobelisk/sui-common": "^1.0.3",
|
|
34
34
|
"@mysten/sui": "1.7.0",
|
|
35
35
|
"clsx": "^1.2.1",
|
|
36
36
|
"dotenv": "^16.4.5",
|
|
@@ -1,27 +1,7 @@
|
|
|
1
1
|
import { DubheConfig } from '@0xobelisk/sui-common';
|
|
2
2
|
|
|
3
3
|
export const dubheConfig = {
|
|
4
|
-
name: '
|
|
5
|
-
description: '
|
|
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
|
-
},
|
|
4
|
+
name: 'template',
|
|
5
|
+
description: 'template',
|
|
6
|
+
schemas: {},
|
|
27
7
|
} as DubheConfig;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"name": "dubhe-contract-template",
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"description": "Simple starter template",
|
|
5
|
+
"license": "Apache-2.0",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"// Utility Commands": "----------------",
|
|
7
8
|
"start:localnet": "pnpm dubhe node",
|
|
@@ -13,9 +14,9 @@
|
|
|
13
14
|
"check-balance": "pnpm dubhe check-balance --network"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
|
-
"@0xobelisk/sui-cli": "^1.0.
|
|
17
|
-
"@0xobelisk/sui-client": "^1.0.
|
|
18
|
-
"@0xobelisk/sui-common": "^1.0.
|
|
17
|
+
"@0xobelisk/sui-cli": "^1.0.6",
|
|
18
|
+
"@0xobelisk/sui-client": "^1.0.3",
|
|
19
|
+
"@0xobelisk/sui-common": "^1.0.3",
|
|
19
20
|
"dotenv": "^16.4.5",
|
|
20
21
|
"chalk": "^4.1.2"
|
|
21
22
|
},
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
storage_migration::borrow_field(&self.id, b"value")
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
public(package) fun
|
|
41
|
+
public(package) fun value(self: &mut Counter): &mut StorageValue<u32> {
|
|
42
42
|
storage_migration::borrow_mut_field(&mut self.id, b"value")
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
let mut counter = counter::counter_schema::create(ctx);
|
|
16
16
|
// Logic that needs to be automated once the contract is deployed
|
|
17
17
|
{
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
counter.value().set(0);
|
|
19
|
+
};
|
|
20
20
|
// Authorize schemas and public share objects
|
|
21
21
|
dapp.add_schema<Counter>(counter, ctx);
|
|
22
22
|
sui::transfer::public_share_object(dapp);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
module counter::counter_system {
|
|
2
2
|
use counter::counter_schema::Counter;
|
|
3
|
-
use counter::
|
|
4
|
-
use counter::
|
|
3
|
+
use counter::increment_event;
|
|
4
|
+
use counter::invalid_increment_error;
|
|
5
5
|
|
|
6
6
|
public entry fun inc(counter: &mut Counter, number: u32) {
|
|
7
7
|
// Check if the increment value is valid.
|
|
8
|
-
|
|
9
|
-
counter.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
invalid_increment_error::require(number > 0 && number < 100);
|
|
9
|
+
counter.value().mutate!(|value| {
|
|
10
|
+
// Increment the counter value.
|
|
11
|
+
*value = *value + number;
|
|
12
|
+
// Emit an event to notify the increment.
|
|
13
|
+
increment_event::emit(number);
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -5,23 +5,13 @@ export const dubheConfig = {
|
|
|
5
5
|
description: 'counter contract',
|
|
6
6
|
schemas: {
|
|
7
7
|
counter: {
|
|
8
|
-
|
|
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
|
-
]
|
|
8
|
+
value: 'StorageValue<u32>',
|
|
25
9
|
},
|
|
26
10
|
},
|
|
11
|
+
events: {
|
|
12
|
+
Increment: { value: 'u32' },
|
|
13
|
+
},
|
|
14
|
+
errors: {
|
|
15
|
+
InvalidIncrement: "Number can't be incremented, must be more than 0",
|
|
16
|
+
}
|
|
27
17
|
} as DubheConfig;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"deploy": "pnpm dubhe publish --network",
|
|
10
10
|
"upgrade": "pnpm dubhe upgrade --network",
|
|
11
11
|
"schema:gen": "pnpm dubhe schemagen",
|
|
12
|
-
"account:gen": "pnpm dubhe generate-key
|
|
12
|
+
"account:gen": "pnpm dubhe generate-key",
|
|
13
13
|
"check-balance": "pnpm dubhe check-balance --network",
|
|
14
14
|
"config:store": "pnpm dubhe config-store --output-ts-path ./src/chain/config.ts --network",
|
|
15
15
|
"// Development Environment": "----------------",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"prod:mainnet": "pnpm config:store mainnet && pnpm next"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@0xobelisk/sui-cli": "^1.0.
|
|
32
|
-
"@0xobelisk/sui-client": "^1.0.
|
|
33
|
-
"@0xobelisk/sui-common": "^1.0.
|
|
31
|
+
"@0xobelisk/sui-cli": "^1.0.6",
|
|
32
|
+
"@0xobelisk/sui-client": "^1.0.3",
|
|
33
|
+
"@0xobelisk/sui-common": "^1.0.3",
|
|
34
34
|
"@mysten/dapp-kit": "0.14.9",
|
|
35
35
|
"@mysten/sui": "1.7.0",
|
|
36
36
|
"dotenv": "^16.4.5",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "counter"
|
|
3
|
-
version = "1.0.0"
|
|
4
|
-
edition = "2024"
|
|
5
|
-
|
|
6
|
-
[dependencies]
|
|
7
|
-
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.38.3" }
|
|
8
|
-
Dubhe = { local = "../dubhe-framework" }
|
|
9
|
-
|
|
10
|
-
[addresses]
|
|
11
|
-
sui = "0x2"
|
|
12
|
-
counter = "0x0"
|
|
@@ -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::counter_error_invalid_increment {
|
|
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,28 +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_event_increment {
|
|
8
|
-
|
|
9
|
-
use sui::event;
|
|
10
|
-
|
|
11
|
-
use std::ascii::String;
|
|
12
|
-
|
|
13
|
-
public struct IncrementEvent has copy, drop {
|
|
14
|
-
value: u32,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public fun new(value: u32): IncrementEvent {
|
|
18
|
-
IncrementEvent {
|
|
19
|
-
value
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public fun emit(value: u32) {
|
|
24
|
-
event::emit(IncrementEvent {
|
|
25
|
-
value
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
package/template/contract/sui-template/contracts/counter/sources/codegen/schemas/counter.move
DELETED
|
@@ -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 borrow_mut_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,102 +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_metadata {
|
|
8
|
-
|
|
9
|
-
use std::ascii::String;
|
|
10
|
-
|
|
11
|
-
public struct DappMetadata has drop, copy, store {
|
|
12
|
-
name: String,
|
|
13
|
-
description: String,
|
|
14
|
-
icon_url: String,
|
|
15
|
-
website_url: String,
|
|
16
|
-
created_at: u64,
|
|
17
|
-
partners: vector<String>,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public fun new(
|
|
21
|
-
name: String,
|
|
22
|
-
description: String,
|
|
23
|
-
icon_url: String,
|
|
24
|
-
website_url: String,
|
|
25
|
-
created_at: u64,
|
|
26
|
-
partners: vector<String>,
|
|
27
|
-
): DappMetadata {
|
|
28
|
-
DappMetadata {
|
|
29
|
-
name,
|
|
30
|
-
description,
|
|
31
|
-
icon_url,
|
|
32
|
-
website_url,
|
|
33
|
-
created_at,
|
|
34
|
-
partners,
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public fun set(
|
|
39
|
-
self: &mut DappMetadata,
|
|
40
|
-
name: String,
|
|
41
|
-
description: String,
|
|
42
|
-
icon_url: String,
|
|
43
|
-
website_url: String,
|
|
44
|
-
created_at: u64,
|
|
45
|
-
partners: vector<String>,
|
|
46
|
-
) {
|
|
47
|
-
self.name = name;
|
|
48
|
-
self.description = description;
|
|
49
|
-
self.icon_url = icon_url;
|
|
50
|
-
self.website_url = website_url;
|
|
51
|
-
self.created_at = created_at;
|
|
52
|
-
self.partners = partners;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public fun set_name(self: &mut DappMetadata, name: String) {
|
|
56
|
-
self.name = name;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public fun set_description(self: &mut DappMetadata, description: String) {
|
|
60
|
-
self.description = description;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public fun set_icon_url(self: &mut DappMetadata, icon_url: String) {
|
|
64
|
-
self.icon_url = icon_url;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public fun set_website_url(self: &mut DappMetadata, website_url: String) {
|
|
68
|
-
self.website_url = website_url;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public fun set_created_at(self: &mut DappMetadata, created_at: u64) {
|
|
72
|
-
self.created_at = created_at;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public fun set_partners(self: &mut DappMetadata, partners: vector<String>) {
|
|
76
|
-
self.partners = partners;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public fun get_name(self: DappMetadata): String {
|
|
80
|
-
self.name
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public fun get_description(self: DappMetadata): String {
|
|
84
|
-
self.description
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public fun get_icon_url(self: DappMetadata): String {
|
|
88
|
-
self.icon_url
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public fun get_website_url(self: DappMetadata): String {
|
|
92
|
-
self.website_url
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public fun get_created_at(self: DappMetadata): u64 {
|
|
96
|
-
self.created_at
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
public fun get_partners(self: DappMetadata): vector<String> {
|
|
100
|
-
self.partners
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -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,93 +0,0 @@
|
|
|
1
|
-
module counter::dapp_system {
|
|
2
|
-
|
|
3
|
-
use std::ascii::String;
|
|
4
|
-
|
|
5
|
-
use std::ascii;
|
|
6
|
-
|
|
7
|
-
use dubhe::type_info;
|
|
8
|
-
|
|
9
|
-
use sui::clock::Clock;
|
|
10
|
-
|
|
11
|
-
use counter::dapp_schema;
|
|
12
|
-
|
|
13
|
-
use counter::dapp_metadata;
|
|
14
|
-
|
|
15
|
-
use counter::dapp_schema::Dapp;
|
|
16
|
-
|
|
17
|
-
public struct DappKey has drop {}
|
|
18
|
-
|
|
19
|
-
public(package) fun new(): DappKey {
|
|
20
|
-
DappKey { }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public(package) fun create(name: String, description: String, clock: &Clock, ctx: &mut TxContext): Dapp {
|
|
24
|
-
let mut dapp = dapp_schema::create(ctx);
|
|
25
|
-
assert!(!dapp.borrow_metadata().contains(), 0);
|
|
26
|
-
dapp.borrow_mut_metadata().set(
|
|
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
|
-
let package_id = type_info::current_package_id<DappKey>();
|
|
37
|
-
dapp.borrow_mut_package_id().set(package_id);
|
|
38
|
-
dapp.borrow_mut_admin().set(ctx.sender());
|
|
39
|
-
dapp.borrow_mut_version().set(1);
|
|
40
|
-
dapp.borrow_mut_safe_mode().set(false);
|
|
41
|
-
dapp.borrow_mut_schemas().set(vector[]);
|
|
42
|
-
dapp
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public entry fun set_metadata(
|
|
46
|
-
dapp: &mut Dapp,
|
|
47
|
-
name: String,
|
|
48
|
-
description: String,
|
|
49
|
-
icon_url: String,
|
|
50
|
-
website_url: String,
|
|
51
|
-
partners: vector<String>,
|
|
52
|
-
ctx: &TxContext,
|
|
53
|
-
) {
|
|
54
|
-
assert!(dapp.borrow_admin().contains(), 0);
|
|
55
|
-
assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
|
|
56
|
-
let created_at = dapp.borrow_mut_metadata().take().get_created_at();
|
|
57
|
-
dapp.borrow_mut_metadata().set(
|
|
58
|
-
dapp_metadata::new(
|
|
59
|
-
name,
|
|
60
|
-
description,
|
|
61
|
-
icon_url,
|
|
62
|
-
website_url,
|
|
63
|
-
created_at,
|
|
64
|
-
partners
|
|
65
|
-
)
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public entry fun transfer_ownership(dapp: &mut Dapp, new_admin: address, ctx: &mut TxContext) {
|
|
70
|
-
assert!(dapp.borrow_admin().contains(), 0);
|
|
71
|
-
assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
|
|
72
|
-
dapp.borrow_mut_admin().set(new_admin);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public entry fun set_safe_mode(dapp: &mut Dapp, safe_mode: bool, ctx: &TxContext) {
|
|
76
|
-
assert!(dapp.borrow_admin().contains(), 0);
|
|
77
|
-
assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
|
|
78
|
-
dapp.borrow_mut_safe_mode().set(safe_mode);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public fun ensure_no_safe_mode(dapp: &Dapp) {
|
|
82
|
-
assert!(!dapp.borrow_safe_mode().get(), 0);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public fun ensure_has_authority(dapp: &Dapp, ctx: &TxContext) {
|
|
86
|
-
assert!(dapp.borrow_admin().get() == ctx.sender(), 0);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public fun ensure_has_schema<Schema: key + store>(dapp: &Dapp, schema: &Schema) {
|
|
90
|
-
let schema_id = object::id_address(schema);
|
|
91
|
-
assert!(dapp.borrow_schemas().get().contains(&schema_id), 0);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
#[allow(lint(share_owned), unused_let_mut)]module counter::deploy_hook {
|
|
2
|
-
|
|
3
|
-
use std::ascii::string;
|
|
4
|
-
|
|
5
|
-
use sui::clock::Clock;
|
|
6
|
-
|
|
7
|
-
use counter::dapp_system;
|
|
8
|
-
|
|
9
|
-
use counter::counter_schema::Counter;
|
|
10
|
-
|
|
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);
|
|
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.borrow_mut_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);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
module counter::counter_system {
|
|
2
|
-
use counter::counter_schema::Counter;
|
|
3
|
-
use counter::counter_event_increment;
|
|
4
|
-
use counter::counter_error_invalid_increment;
|
|
5
|
-
|
|
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
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public fun get(counter: &Counter) : u32 {
|
|
18
|
-
counter.borrow_value().get()
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|