From ac11a6b0cf06147eb7b12252ac346fca5dc0a15d Mon Sep 17 00:00:00 2001 From: uvd <386180127@qq.com> Date: Wed, 27 Nov 2024 17:09:58 +0800 Subject: [PATCH] Revert "task4+task5" --- letsmove | 1 - mover/Ming-XX/readme.md | 14 +++---- mover/Ming-XX/task4/my_game.move | 65 ----------------------------- mover/Ming-XX/task5/my_swap.move | 71 -------------------------------- 4 files changed, 7 insertions(+), 144 deletions(-) delete mode 160000 letsmove delete mode 100644 mover/Ming-XX/task4/my_game.move delete mode 100644 mover/Ming-XX/task5/my_swap.move diff --git a/letsmove b/letsmove deleted file mode 160000 index 1b5554cfc..000000000 --- a/letsmove +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1b5554cfc3fd1f07a423e8f2fe53a80a352d54fa diff --git a/mover/Ming-XX/readme.md b/mover/Ming-XX/readme.md index 55417e898..55741a2c3 100644 --- a/mover/Ming-XX/readme.md +++ b/mover/Ming-XX/readme.md @@ -33,15 +33,15 @@ - [✓] scan上的NFT截图:![Scan截图](./images/nft.jpg) ## 04 Move Game -- [✓] game package id :0xc1157171a3c69d7fc44233c5df1a91b95eef4dcf1ff0c01a95aee83ae398df86 -- [✓] deposit Coin hash:D6Lk3Xe9G2C6YRnHTUPnPqYH33ZQnkPRz139QN9PyZ3s -- [✓] withdraw `Coin` hash:6Sgxwo519NPZvvyCXuzpGwgLanm7wZk9XEN75Wy894dB -- [✓] play game hash:FqrxjL6wz2rY8UrvX2WU4ihgUW9HvbJEwuz85rLMxma9 +- [] game package id : +- [] deposit Coin hash: +- [] withdraw `Coin` hash: +- [] play game hash: ## 05 Move Swap -- [✓] swap package id :0x97bd347ac2fa70f0bb11bf19e6ae442c6ea1ae98c1d5ac8b6471ebdb655dc829 -- [✓] call swap CoinA-> CoinB hash :x7Pt6JzPvE7Lz59KAqbdTEF69anfNBgiYckG6sEfqgy -- [✓] call swap CoinB-> CoinA hash :4tZdG2gVm5zxCF8mJ4bKjVzFE4BWoUkR3F9HMQqKe7rC +- [] swap package id : +- [] call swap CoinA-> CoinB hash : +- [] call swap CoinB-> CoinA hash : ## 06 Dapp-kit SDK PTB - [] save hash : diff --git a/mover/Ming-XX/task4/my_game.move b/mover/Ming-XX/task4/my_game.move deleted file mode 100644 index 7b022f20a..000000000 --- a/mover/Ming-XX/task4/my_game.move +++ /dev/null @@ -1,65 +0,0 @@ -module my_game::my_game; -use my_coin::ming_xx_faucet_coin::MING_XX_FAUCET_COIN; -use sui::balance::{Self, Balance}; -use sui::coin::{Self, Coin}; -use sui::random::{Self, Random}; -use sui::transfer::{share_object, public_transfer, transfer}; - -const EExceedBalance: u64 = 0x0; - -public struct Ming_XX_Game has key { - id: UID, - val: Balance, -} - -public struct AdminCap has key { - id: UID, -} - -fun init(ctx: &mut TxContext) { - let game = Ming_XX_Game { - id: object::new(ctx), - val: balance::zero(), - }; - share_object(game); - - let admin = AdminCap { - id: object::new(ctx), - }; - - transfer(admin, ctx.sender()); -} - -public entry fun DepositCoin(game: &mut Ming_XX_Game, coin: Coin,_ctx:&mut TxContext) { - game.val.join(coin::into_balance(coin)); -} - -public entry fun WithdrawCoin(_: &AdminCap, game: &mut Ming_XX_Game, value: u64, ctx: &mut TxContext) { - let out_balance = game.val.split(value); - let out_coin = coin::from_balance(out_balance, ctx); - public_transfer(out_coin, ctx.sender()); -} - -entry fun play( - game: &mut Ming_XX_Game, - rnd: &Random, - guess: bool, - in_coin: Coin, - ctx: &mut TxContext -) { - let mut gen = random::new_generator(rnd, ctx); - let flip_value = random::generate_bool(&mut gen); - let val_value = in_coin.value(); - let game_val = game.val.value(); - assert!(game_val >= val_value * 10, EExceedBalance); - if (guess == flip_value) { - let out_balance = game.val.split(val_value); - let out_coin = coin::from_balance(out_balance, ctx); - public_transfer(out_coin, ctx.sender()); - public_transfer(in_coin, ctx.sender()); - }else { - DepositCoin(game,in_coin,ctx); - } -} - - diff --git a/mover/Ming-XX/task5/my_swap.move b/mover/Ming-XX/task5/my_swap.move deleted file mode 100644 index f0fa0a94f..000000000 --- a/mover/Ming-XX/task5/my_swap.move +++ /dev/null @@ -1,71 +0,0 @@ -module ming_xx::my_swap; - -use my_coin::ming_xx_coin::MING_XX_COIN; -use my_coin::ming_xx_faucet_coin::MING_XX_FAUCET_COIN; - -use sui::balance::{Self, Balance, split}; -use sui::coin::{Coin, into_balance, from_balance}; -use sui::transfer::{share_object, transfer, public_transfer}; - -const EExceedBalance: u64 = 0x0; - -public struct Pool has key { - id: UID, - my_coin_balance: Balance, - faucet_coin_balance: Balance, -} - -public struct AdminCap has key { - id: UID, -} - -fun init(ctx: &mut TxContext) { - let admin_cap = AdminCap { - id: object::new(ctx), - }; - let pool = Pool { - id: object::new(ctx), - my_coin_balance: balance::zero(), - faucet_coin_balance: balance::zero(), - }; - - transfer(admin_cap, ctx.sender()); - share_object(pool); -} - -public entry fun deposit_my_coin(pool: &mut Pool, coins: Coin, _ctx: &mut TxContext) { - balance::join(&mut pool.my_coin_balance, into_balance(coins)); -} - -public entry fun deposit_faucet_coin(pool: &mut Pool, coins: Coin, _ctx: &mut TxContext) { - balance::join(&mut pool.faucet_coin_balance, into_balance(coins)); -} - - -fun withdraw_my_coin(pool: &mut Pool, amount: u64, receiver: address, ctx: &mut TxContext) { - let coins = from_balance(split(&mut pool.my_coin_balance, amount), ctx); - public_transfer(coins, receiver); -} - -fun withdraw_faucet_coin(pool: &mut Pool, amount: u64, receiver: address, ctx: &mut TxContext) { - let coins = from_balance(split(&mut pool.faucet_coin_balance, amount), ctx); - public_transfer(coins, receiver); -} - -public entry fun swap_my_coin(pool: &mut Pool, coins: Coin, ctx: &mut TxContext) { - let swap_address = ctx.sender(); - let swap_value = coins.value() / 10; - assert!(swap_value <= pool.my_coin_balance.value(), EExceedBalance); - deposit_faucet_coin(pool, coins, ctx); - withdraw_my_coin(pool, swap_value, swap_address, ctx); -} - - -public entry fun swap_faucet_coin(pool: &mut Pool, coins: Coin, ctx: &mut TxContext) { - let swap_address = ctx.sender(); - let swap_value = coins.value() * 10; - assert!(swap_value <= pool.faucet_coin_balance.value(), EExceedBalance); - deposit_my_coin(pool, coins, ctx); - withdraw_faucet_coin(pool, swap_value, swap_address, ctx); -} -