Upgrading the Module
How to upgrade your module?
Aptos์์๋ ์ด๋ฏธ ๋ฐฐํฌ๊ฐ ๋์ด์๋ module์ด๋ผ๋ ์ถ๊ฐ์ ์ธ ์ฝ๋๋ฅผ ์์ฑํ์ฌ ์ ๊ทธ๋ ์ด๋ ํ ์ ์์ต๋๋ค. ์ด๋ฅผ Module Upgrade ๋ผ๊ณ ํ๋ฉฐ ์ด๋ฒ ํํ ๋ฆฌ์ผ์์๋ ๊ธฐ์กด์ ์์ฑ๋ Module์ ์ด์ฉํด ์ ๋ฐ์ดํธ ํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
๋ณธ ํํ ๋ฆฌ์ผ์ ์งํํ๊ธฐ ์ํด์๋ ์ฌ์ฉ์๊ฐ ๋ฐฐํฌํ Fungible Asset Module๊ณผ ๋ฐฐํฌ ํ๊ฒฝ์ด ํ์ํฉ๋๋ค!
๋ฐฐํฌํ ๋ชจ๋์ด ์๋ ๊ฒฝ์ฐ ์๋ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ Nodit Aptos Tutorial์ ๋ฐ๋ผ Message Module์ ๋ฐฐํฌํด ๋ณด์ธ์!
์ด ํํ ๋ฆฌ์ผ์ ํตํด ์๋ ๋ด์ฉ์ ๋ฐฐ์ธ ์ ์์ต๋๋ค!
- Module์ ํจ์๋ฅผ ํธ์ถํ๋ ๋ฐฉ๋ฒ์ ์ ์ ์์ต๋๋ค.
- ์๋ก์ด ํจ์๋ฅผ ์์ฑํ์ฌ Module์์ ์ด์ฉํ๋ ๋ก์ง์ ๋ณ๊ฒฝํ๋ ๋ฐฉ๋ฒ์ ์ ์ ์์ต๋๋ค.
- ์ ์ฒด ํํ ๋ฆฌ์ผ ์ฝ๋๋ ์๋ ๋งํฌ๋ฅผ ํตํด ํ์ธํ ์ ์์ต๋๋ค.
- Nodit Aptos Upgrading the Module ํํ ๋ฆฌ์ผ ์ฝ๋ ํ์ธํ๊ธฐ
Upgrade your Module
Nodit ํํ ๋ฆฌ์ผ์ ํตํด ๋ฐฐํฌํ Message Module์ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
module ownerAddress::message {
use std::signer;
use std::string::{Self,utf8, String};
use std::error;
struct Message has key {
message_counter : u64,
message : String,
}
const ENO_MESSAGE: u64 = 0;
public fun get_message(message_owner : address) : string::String acquires Message {
assert!(exists<Message>(message_owner), error::not_found(ENO_MESSAGE));
borrow_global<Message>(message_owner).message
}
public entry fun set_message(admin: &signer, message : String) acquires Message{
let message_owner_address = signer::address_of(admin);
if (exists<Message>(message_owner_address)) {
let stored_message = borrow_global_mut<Message>(message_owner_address);
stored_message.message = message;
} else {
move_to(admin, Message{
message_counter : 1,
message : message
});
}
}
#[test(account = @ownerAddress)]
public entry fun test_message(account: &signer) acquires Message {
let message = utf8(b"Hello, World!");
set_message(account, message);
let message_owner_address = signer::address_of(account);
let stored_message = get_message(message_owner_address);
assert!(message == stored_message, 0);
}
}
์ฝ๋๋ฅผ ์ดํด๋ณด๋ฉด set_message์์ ๋ก์ง์ด ์ด์ํ ๋ถ๋ถ์ ์ฐพ์ ์ ์์ต๋๋ค. ๋ฐ๋ก ๊ธฐ์กด ๋ฉ์์ง๋ฅผ ์ฌ์ฉ์๊ฐ ์๋ก ์ ๋ ฅํ ๋ฉ์์ง๋ก ๋ณ๊ฒฝํ๋ ๊ฒฝ์ฐ, ๋ฉ์์ง๋ ์ ์์ ์ผ๋ก ๋ณ๊ฒฝ๋๋ message_counter๊ฐ ์ฆ๊ฐํ์ง ์๋๋ค๋ ์ ์ ๋๋ค. ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด Module์ ์ ๋ฐ์ดํธ ํ๋๋ก ํ๊ฒ ์ต๋๋ค.
Step 1. Module์ ํจ์ ๋ณ๊ฒฝ
๊ธฐ์กด์ Module์ ์๋ set_message ํจ์๋ ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ message๋ง ๋ณ๊ฒฝํ๊ณ message_counter๋ ๋ณ๊ฒฝํ์ง ์๋ ๋ก์ง์ด์์ต๋๋ค.
public entry fun set_message(admin: &signer, message : String) acquires Message{
let message_owner_address = signer::address_of(admin);
if (exists<Message>(message_owner_address)) {
let stored_message = borrow_global_mut<Message>(message_owner_address);
stored_message.message = message;
} else {
move_to(admin, Message{
message_counter : 1,
message : message
});
}
}
์ด๋ฌํ ๋ก์ง์ ์์ ํ ์๋ก์ด set_message ํจ์๋ฅผ ์์ฑํฉ๋๋ค. ์ด์ ๋ฉ์์ง๋ฅผ ๋ณ๊ฒฝํ ๋ ๋ง๋ค message_counter ์ญ์ 1 ์ฆ๊ฐํฉ๋๋ค.
public entry fun set_message_with_message_counter(admin: &signer, message : String) acquires Message{
let message_owner_address = signer::address_of(admin);
if (exists<Message>(message_owner_address)) {
let stored_message = borrow_global_mut<Message>(message_owner_address);
// ํ์
stored_message.message_counter = stored_message.message_counter+1;
stored_message.message = message;
} else {
move_to(admin, Message{
message_counter : 1,
message : message
});
}
}
๊ทธ๋ฆฌ๊ณ ์ฌ์ฉ์๊ฐ ํผ์ ์ ๊ฒช์ง ์๋๋ก ๊ธฐ์กด์ set_message ํจ์์ #[deprecated]
์ฝ๋๋ฅผ ์์ฑํ์ฌ ๋ณ๊ฒฝ๋์์์ ์๋ฆฝ๋๋ค.
#[deprecated]
public entry fun set_message(admin: &signer, message : String) acquires Message{
let message_owner_address = signer::address_of(admin);
if (exists<Message>(message_owner_address)) {
let stored_message = borrow_global_mut<Message>(message_owner_address);
stored_message.message = message;
} else {
move_to(admin, Message{
message_counter : 1,
message : message
});
}
}
์ ์ฒด์ ์ธ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
module ownerAddress::message {
use std::signer;
use std::string::{Self,utf8, String};
use std::error;
struct Message has key {
message_counter : u64,
message : String,
}
const ENO_MESSAGE: u64 = 0;
public fun get_message(message_owner : address) : string::String acquires Message {
assert!(exists<Message>(message_owner), error::not_found(ENO_MESSAGE));
borrow_global<Message>(message_owner).message
}
#[deprecated]
public entry fun set_message(admin: &signer, message : String) acquires Message{
let message_owner_address = signer::address_of(admin);
if (exists<Message>(message_owner_address)) {
let stored_message = borrow_global_mut<Message>(message_owner_address);
stored_message.message = message;
} else {
move_to(admin, Message{
message_counter : 1,
message : message
});
}
}
public entry fun set_message_with_message_counter(admin: &signer, message : String) acquires Message{
let message_owner_address = signer::address_of(admin);
if (exists<Message>(message_owner_address)) {
let stored_message = borrow_global_mut<Message>(message_owner_address);
stored_message.message_counter = stored_message.message_counter+1;
stored_message.message = message;
} else {
move_to(admin, Message{
message_counter : 1,
message : message
});
}
}
#[test(account = @ownerAddress)]
public entry fun test_message(account: &signer) acquires Message {
let message = utf8(b"Hello, World!");
set_message_with_counter(account, message);
let message_owner_address = signer::address_of(account);
let stored_message = get_message(message_owner_address);
assert!(message == stored_message, 0);
}
}
Step 2. Compile ๋ฐ ๋ฐฐํฌ
์ฝ๋ ๋ณ๊ฒฝ์ ์๋ฃํ์๋ค๋ฉด ํฐ๋ฏธ๋์ ์๋ ๋ช ๋ น์ด๋ฅผ ์คํํ์ฌ ์ ์์ ์ผ๋ก ์ปดํ์ผ์ด ๋๋์ง ํ์ธํฉ๋๋ค.
$ aptos move compile
์ ์์ ์ผ๋ก ์ปดํ์ผ์ด ์๋ฃ๋๋ฉด ๋ค์๊ณผ ๊ฐ์ ์๋ต์ ๋ฐ์ ์ ์์ต๋๋ค.
Compiling, may take a little while to download git dependencies...
UPDATING GIT DEPENDENCY https://github.com/aptos-labs/aptos-core.git
INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY MoveStdlib
BUILDING myFungibleAsset
{
"Result": [
"<your_account_address>::<your_module_name>"
]
}
์ปดํ์ผ ์๋ฃ ํ ํฐ๋ฏธ๋์ ์๋ ๋ช ๋ น์ด๋ฅผ ์คํํ์ฌ Aptos ๋คํธ์ํฌ์ ๋ณ๊ฒฝ๋ Module์ ๋ฐฐํฌํฉ๋๋ค.
- ๋ฐฐํฌ ์ owner์ Account๊ฐ ๊ธฐ์กด์ owner์ ๋ค๋ฅผ ๊ฒฝ์ฐ ์ ๊ท ๋ชจ๋๋ก ๋ฐฐํฌ๊ฐ ๋ ์ ์์ต๋๋ค.
- ๊ธฐ์กด์ ํจ์๊ฐ ์ง์์ง๊ฑฐ๋ ๋ณ๊ฒฝ๋ ๊ฒฝ์ฐ ๋ฐฐํฌ์ ์คํจํ ์ ์์ต๋๋ค.
- Move.toml, module name ๋ฑ ๊ธฐ์กด ์ค์ ์ด ๋ณ๊ฒฝ๋ ๊ฒฝ์ฐ ๋ฐฐํฌ์ ์คํจํ ์ ์์ต๋๋ค.
$ aptos move publish
์ ์์ ์ผ๋ก ๋ฐฐํฌ๊ฐ ๋์๋ค๋ฉด ์๋์ ๊ฐ์ด ํธ๋์ญ์ ์ ๋ํ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
{
"Result": {
"transaction_hash": "<Your_transaction_hash>",
"gas_used": 165,
"gas_unit_price": 150,
"sender": "<Your_Account_Address>",
"sequence_number": 2,
"success": true,
"timestamp_us": 1720774008922260,
"version": 5066304958,
"vm_status": "Executed successfully"
}
}
Step 3. ๋ณ๊ฒฝ๋ module ํ์ธ
Nodit์์ ์ ๊ณตํ๋ Aptos Node API์ Get account module API๋ฅผ ์ด์ฉํ์ฌ ๋ฐฐํฌ๋ Module์ ABI๋ฅผ ํ์ธํฉ๋๋ค.
curl --request GET \
--url https://aptos-testnet.nodit.io/v1/accounts/<your_account_address>/module/<your_module_name> \
--header 'X-API-KEY: <your X-API-KEY>' \
--header 'accept: application/json'
๋ค์๊ณผ ๊ฐ์ด Module์ ์์ ํ์ฌ ๋ฐฐํฌํ set_message_with_message_counter ํจ์์ ๋ํ ๊ฐ์ ์ฐพ์ ์ ์๋์?
...
{
name:"set_message_with_message_counter"
visibility:"public"
is_entry:true
is_view:false
generic_type_params:[]
params:[
0:"&signer"
1:"0x1::string::String"
]
return:[]
}
...
- ํ์ธ์ด ๋์ง ์๋๋ค๋ฉด ์์ ์ฝ๋์ ๋ค๋ฅธ ๋ถ๋ถ์ด ์๋์ง ํ์ธํด ๋ณด์ธ์.
- ์์ ์ฝ๋์ ์ฐจ์ด๊ฐ ์๋๋ฐ ๋์ง ์๋์? ์ฌ๊ธฐ[QnA ๋งํฌ]๋ฅผ ํด๋ฆญํ์ฌ QnA๋ก ๋จ๊ฒจ์ฃผ์ธ์!
Aptos๋ ๋งค์ฐ ๋น ๋ฅด๊ฒ ์ ๋ฐ์ดํธ ๋๊ณ ์์ต๋๋ค!
Aptos ์ฌ๋จ์์ ๋ฐฐํฌํ SDK ๋ฒ์ ์ ๋ฐ๋ผ ๋ณ๊ฒฝ๋๋ ์ ์ด ์์ ์ ์์ต๋๋ค. Nodit์ ํญ์ ์ด๋ฅผ ํ์ธํ๊ณ ์์ผ๋ ์์ ์ ๋ฐ๋ผ ์ฝ๋ ๋ณ๊ฒฝ์ผ๋ก ์ธํ ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค.
Updated 12 days ago