ディレクトリ構成
aptogotchi
├── Move.toml (required)
├── sources\\ (required, stores move modules)
│ └── aptogotchi.move
├── build\\ (generated, build output)
├── scripts\\ (optional, stores move scripts)
│ └── script_batch_create_gotchi.move
├── doc_templates\\ (optional)
|── tests\\ (optional, test mode)
└── examples\\ (optional, test & dev mode)
Move.toml
[package]
name = "aptogotchi"
version = "1.0.0"
upgrade_policy = "compatible"
[addresses]
aptogotchi = "_"
[dependencies]
AptosFramework = {
git = "<https://github.com/aptos-labs/aptos-core.git>",
rev = "main",
subdir = "aptos-move/framework/aptos-framework"
}
AptosTokenObjects = {
git = "<https://github.com/aptos-labs/aptos-core.git>",
rev = "main",
subdir = "aptos-move/framework/aptos-token-objects"
}
# Mock address for unit test.
[dev-addresses]
aptogotchi = "0x123"
upgrade_policy = "immutable”
upgrade_policy = "compatible”
- 既存の構造体はすべて変更できません。
- 制限なく新しい構造体を追加できます。
- すべてのパブリック関数とエントリ関数は、シグネチャ (引数の型、型引数、戻り値の型) を変更できません。ただし、引数名は変更できます。
- 制限なく新しい機能を追加できます。
- 上記のルールに違反する必要がある場合は、モジュールを新しいアドレスに公開する必要があります。
Module
module aptogotchi::main {
struct Config has copy, drop {
admin: address
}
// Init function runs once when the module is published for the first time.
fun init_module(caller: &signer) {
let caller_addr = address_of(caller);
// move_to is a function to move the struct to the global storage
move_to(caller, Config { admin: caller_addr });
}
#[view]
public fun get_admin(): address acquires Config {
// @aptogotchi is the address of the module
let config = borrow_global<Config>(@aptogotchi);
config.admin
}
}