Skip to content

Commit

Permalink
Merge pull request #2090 from fengfengxiong123/main
Browse files Browse the repository at this point in the history
task4
  • Loading branch information
Sifotd authored Dec 4, 2024
2 parents 9d35d89 + 8a519a1 commit ae72476
Show file tree
Hide file tree
Showing 27 changed files with 742 additions and 89 deletions.
55 changes: 53 additions & 2 deletions mover/fengfengxiong123/code/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
# sui中一些操作和方法
use sui::balance::Balance

// Balance 结构体可以存储代币,避免管理过多对象
struct Game {
id:UID,
amt : Balance<SUI>
}
// 设置余额为零
balance::zero<SUI>()

// 将对象共享出去
share_object(game);

// 定义外部调用方法,使用Random的函数不能用public修饰
entry fun play(game:&mut Game,rand:&Random,in:bool,amt:Coin<SUI>,ctx){}

// 将Coin转为Balance
let in_amt_balance:Balance<> = coin::into_balance(amt);

// 使用balance相加
balance::join(game.amt,in_amt_balance);

// 从coin对象中取值
let val = amt.value()

// 将game中余额拿出来一部分
let out_balance = game.amt.split(val)

// balance没有key能力,不能直接放入账户中
let out_coin = coin::from_balance(out_balance,ctx)

// 函数中使用&Random,外面直接传0x8
// 创建随机数生成器
// 生成随机数
let mut gen = random::new_generator(rand,ctx);
let value = random::generate_bool(&mut gen);

# 命令
```shell

Expand All @@ -13,12 +51,22 @@ https://github.com/move-cn/letsmove
# 配置代理拉取代码
git clone -c http.proxy="127.0.0.1:2334" https://github.com/fengfengxiong123/letsmove.git

# 配置git代理
git config --global https.proxy https://127.0.0.1:2334
git config --global http.proxy http://127.0.0.1:2334

git config --global --unset http.proxy
git config --global --unset https.proxy

# 查看版本
sui -V

# 零测试网sui币
sui client faucet

# 添加环境
sui client new-env --alias devnet --rpc https://fullnode.devnet.sui.io:443

# 正在使用的地址
sui client active-address

Expand Down Expand Up @@ -181,6 +229,9 @@ faucet coin TreasuryCap obj id : 0x56d0bb3c37de365e23a2c56180601da49d8b23794b4
0x7b8e0864967427679b4e129f79dc332a885c6087ec9e187b53451a9006ee15f2 \
--gas-budget 100000000
```

--args 第一个是 FAUCETCOIN 所在对象的id
## 使用sui cli转账
sui client transfer-sui --to 0x2e312e10390700d045ae462dcac090354bda4a81dc151c0d538a250beb0492f5 --amount 13266772 --sui-coin-object-id 0x1feb5ad79c303c52cca592272203b259119fc3fb02e037209ceaf9570474ce08 --gas-budget 100000000
sui client transfer-sui --to 0x2e312e10390700d045ae462dcac090354bda4a81dc151c0d538a250beb0492f5 --amount 13266772 --sui-coin-object-id 0x1feb5ad79c303c52cca592272203b259119fc3fb02e037209ceaf9570474ce08 --gas-budget 100000000

## task3
摘要: Hjn95SsHsm59si6zVhcLamy7wL7KS8Vx6YYbbXuQecXZ
34 changes: 0 additions & 34 deletions mover/fengfengxiong123/code/task2/my_coin2/Move.lock

This file was deleted.

24 changes: 0 additions & 24 deletions mover/fengfengxiong123/code/task2/my_coin2/sources/my_coin2.move

This file was deleted.

This file was deleted.

10 changes: 10 additions & 0 deletions mover/fengfengxiong123/code/task2/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sui client call \
--package 0x2 \
--module coin \
--function mint_and_transfer \
--type-args 0xd54f752374f2112fec4a0707c51daa98d5d1e8f0ace74977090ccff9d083a40a::faucetcoin::FAUCETCOIN \
--args \
0x7f4a9920bdda5357d382ba8f6f46a3733b66a88aabfa0031d71e1f0d98abf778 \
1000000000 \
0x2af6c1938280cf418ce388f62deffe9a56746d0887c9e6c031a4127016987e35 \
--gas-budget 100000000
34 changes: 34 additions & 0 deletions mover/fengfengxiong123/code/task3/my_nft/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 2
manifest_digest = "1C7E4E6784885553F41F77ACBDC5306913E332B17CDD69A828BE8590288858D2"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
]

[[move.package]]
name = "MoveStdlib"
source = { git = "https://gitee.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates\\sui-framework\\packages\\move-stdlib" }

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

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

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

[env]

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0x7dcd01039a557295a02e0790a5821ff807dd2707b13e1aa7ae8eb15e21948465"
latest-published-id = "0x7dcd01039a557295a02e0790a5821ff807dd2707b13e1aa7ae8eb15e21948465"
published-version = "1"
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "my_coin2"
name = "my_nft"
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/testnet" }
Sui = { git = "https://gitee.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }

# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
# Revision can be a branch, a tag, and a commit hash.
Expand All @@ -19,7 +19,7 @@ Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-fram
# Override = { local = "../conflicting/version", override = true }

[addresses]
my_coin2 = "0x0"
my_nft = "0x0"

# Named addresses will be accessible in Move as `@name`. They're also exported:
# for example, `std = "0x1"` is exported by the Standard Library.
Expand Down
48 changes: 48 additions & 0 deletions mover/fengfengxiong123/code/task3/my_nft/sources/nft2.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module my_nft::nft2 {
use std::string::String;
use std::string::utf8;
use sui::display;
// use sui::object;
use sui::package;
// use sui::transfer::transfer;
use sui::transfer::public_transfer;

public struct NFT2 has drop {}

public struct MyNft2 has key, store {
id: UID,
name: String,
image_url: String,
}

fun init(otw: NFT2, ctx: &mut TxContext) {
let keys = vector[
utf8(b"name"),
utf8(b"description"),
utf8(b"image_url"),
];
let values = vector[
utf8(b"{name}"),
utf8(b"this is {name}'s NFT"),
utf8(b"{image_url}"),
];
let publisher = package::claim(otw, ctx);
let mut display = display::new_with_fields<MyNft2>(&publisher, keys, values, ctx);

display.update_version();

public_transfer(publisher, tx_context::sender(ctx));
public_transfer(display, tx_context::sender(ctx));
}

public entry fun mint(addr: address, ctx: &mut TxContext) {
let nft = MyNft2 {
id: object::new(ctx),
name: utf8(b"fengfengxiong123"),
image_url: utf8(
b"https://avatars.githubusercontent.com/u/46967327?u=d074eb812d53a9d64a78464af56e0a801cfbbbf2&v=4"
)
};
public_transfer(nft, addr)
}
}
19 changes: 19 additions & 0 deletions mover/fengfengxiong123/code/task3/my_nft/tests/my_nft_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
#[test_only]
module my_nft::my_nft_tests {
// uncomment this line to import the module
// use my_nft::my_nft;
const ENotImplemented: u64 = 0;
#[test]
fun test_my_nft() {
// pass
}
#[test, expected_failure(abort_code = ::my_nft::my_nft_tests::ENotImplemented)]
fun test_my_nft_fail() {
abort ENotImplemented
}
}
*/
Loading

0 comments on commit ae72476

Please sign in to comment.