Skip to content

Commit

Permalink
完成task5和笔记
Browse files Browse the repository at this point in the history
  • Loading branch information
Ch1hiro4002 committed Nov 22, 2024
1 parent 513b50a commit 03855aa
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 6 deletions.
Binary file added mover/Ch1hiro/co-learn-2411/images/07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mover/Ch1hiro/co-learn-2411/images/08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions mover/Ch1hiro/co-learn-2411/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

- [x] 第一周:![学习记录截图](./images/03.png)
- [x] 第二周:![学习记录截图](./images/05.png)
- [] 第三周:![学习记录截图](./images/你的图片地址)
- [x] 第三周:![学习记录截图](./images/07.png)
- [] 第四周:![学习记录截图](./images/你的图片地址)

## 参加直播答疑

- [x] 第一周:![学习记录截图](./images/04.png)
- [x] 第二周:![学习记录截图](./images/06.png)
- [] 第三周:![学习记录截图](./images/你的图片地址)
- [x] 第三周:![学习记录截图](./images/08.png)
- [] 第四周:![学习记录截图](./images/你的图片地址)

## 群里分享学习笔记
Expand All @@ -34,7 +34,7 @@

- [x] 第一篇笔记【https://learnblockchain.cn/article/9832】
- [x] 第二篇笔记【https://learnblockchain.cn/article/9916】
- [] 第三篇笔记【学习笔记链接
- [x] 第三篇笔记【https://learnblockchain.cn/article/10010
- [] 第四篇笔记【学习笔记链接】

## 在HOH社区公众号发布自己的技术文章
Expand Down
43 changes: 43 additions & 0 deletions mover/Ch1hiro/code/task5/ch1hiro/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "47A34D68338E0923BF11A14349A8841445F79341A900C8A30148FB158C50862E"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"
dependencies = [
{ id = "Sui", name = "Sui" },
{ id = "mycoin", name = "mycoin" },
]

[[move.package]]
id = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/move-stdlib" }

[[move.package]]
id = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/mainnet", subdir = "crates/sui-framework/packages/sui-framework" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
]

[[move.package]]
id = "mycoin"
source = { local = "../../02_coin/mycoin" }

dependencies = [
{ id = "Sui", name = "Sui" },
]

[move.toolchain-version]
compiler-version = "1.38.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0xd80653d568c836a17a5bef6802bc109512fdc653c93ceb4399c9d557d83c872b"
latest-published-id = "0xd80653d568c836a17a5bef6802bc109512fdc653c93ceb4399c9d557d83c872b"
published-version = "1"
38 changes: 38 additions & 0 deletions mover/Ch1hiro/code/task5/ch1hiro/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "ch1hiro"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
# license = "" # e.g., "MIT", "GPL", "Apache 2.0"
# authors = ["..."] # e.g., ["Joe Smith ([email protected])", "John Snow ([email protected])"]

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" }
mycoin = { local = "../../02_coin/mycoin" }

# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
# Revision can be a branch, a tag, and a commit hash.
# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" }

# For local dependencies use `local = path`. Path is relative to the package root
# Local = { local = "../path/to" }

# To resolve a version conflict and force a specific version for dependency
# override use `override = true`
# Override = { local = "../conflicting/version", override = true }

[addresses]
ch1hiro = "0x0"

# Named addresses will be accessible in Move as `@name`. They're also exported:
# for example, `std = "0x1"` is exported by the Standard Library.
# alice = "0xA11CE"

[dev-dependencies]
# The dev-dependencies section allows overriding dependencies for `--test` and
# `--dev` modes. You can introduce test-only dependencies here.
# Local = { local = "../path/to/dev-build" }

[dev-addresses]
# The dev-addresses section allows overwriting named addresses for the `--test`
# and `--dev` modes.
# alice = "0xB0B"

78 changes: 78 additions & 0 deletions mover/Ch1hiro/code/task5/ch1hiro/sources/ch1hiro.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
module ch1hiro::ch1hiro {
use sui::balance;
use sui::balance::Balance;
use sui::coin;
use sui::coin::{Coin, into_balance, from_balance};
use sui::transfer::public_transfer;
use sui::tx_context::sender;
use mycoin::mycoin::MYCOIN;
use mycoin::faucetcoin::FAUCETCOIN;

// 创建银行
public struct Bank has key {
id: UID,
hiro: Balance<MYCOIN>,
fct: Balance<FAUCETCOIN>
}

// 创建管理员权限
public struct AdminCap has key {
id: UID,
}

// 实例化对象
fun init(ctx: &mut TxContext) {
let bank = Bank {
id: object::new(ctx),
hiro: balance::zero<MYCOIN>(),
fct: balance::zero<FAUCETCOIN>(),
};

transfer::share_object(bank);

let admincap = AdminCap {
id: object::new(ctx),
};

transfer::transfer(admincap, sender(ctx));
}

// 将 hiro 转换为 balance 存入银行
public entry fun deposit_hiro(bank: &mut Bank, hiro: Coin<MYCOIN>) {
let hiro_balance = into_balance(hiro);
balance::join(&mut bank.hiro, hiro_balance);
}

// 将 fct 转换为 balance 存入银行
public entry fun deposit_fct(bank: &mut Bank, fct: Coin<FAUCETCOIN>) {
let fct_balance = into_balance(fct);
balance::join(&mut bank.fct, fct_balance);
}

// 将 hiro 转为 coin 并取出
public entry fun withdrawal_hiro(bank: &mut Bank, amt: u64, ctx: &mut TxContext) {
let hiro_balance = balance::split(&mut bank.hiro, amt);
let hiro_coin = from_balance(hiro_balance, ctx);
public_transfer(hiro_coin, sender(ctx));
}

// 1 hiro == 10 fct
public entry fun swap_hiro_fct(bank: &mut Bank, hiro: Coin<MYCOIN>, ctx: &mut TxContext) {
let amt = coin::value(&hiro);
balance::join(&mut bank.hiro, into_balance(hiro));
let amt_fct = amt * 100 / 10;
let fct_balance = balance::split(&mut bank.fct, amt_fct);
let fct_coin = from_balance(fct_balance, ctx);
public_transfer(fct_coin, sender(ctx));
}

public entry fun swap_fct_hiro(bank: &mut Bank, fct: Coin<FAUCETCOIN>, ctx: &mut TxContext) {
let amt = coin::value(&fct);
balance::join(&mut bank.fct, into_balance(fct));
let amt_hiro = amt * 10 / 100;
let hiro_balance = balance::split(&mut bank.hiro, amt_hiro);
let hiro_coin = from_balance(hiro_balance, ctx);
public_transfer(hiro_coin, sender(ctx));
}
}

6 changes: 3 additions & 3 deletions mover/Ch1hiro/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
- [x] play game hash:9T1jyEu5bKYLoXgofMd9cvTxtB3zjaTtCgWiWjtCW9xk

## 05 Move Swap
- [] swap package id :
- [] call swap CoinA-> CoinB hash :
- [] call swap CoinB-> CoinA hash :
- [x] swap package id : 0xd80653d568c836a17a5bef6802bc109512fdc653c93ceb4399c9d557d83c872b
- [x] call swap CoinA-> CoinB hash : 3KsbGtGDst7qV7i4YBjcKu7TkdLDXMECxvvxDBvHxsQB
- [x] call swap CoinB-> CoinA hash : BhYxRmP98LAWuALRb6vvsHh3oDhAQNT9NokGVnL1XvBV

## 06 Dapp-kit SDK PTB
- [] save hash :
Expand Down

0 comments on commit 03855aa

Please sign in to comment.