Skip to content

Commit

Permalink
nft add display; learn record;
Browse files Browse the repository at this point in the history
  • Loading branch information
greyhao committed Nov 16, 2024
1 parent c5f9475 commit 51e1278
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
2 changes: 2 additions & 0 deletions mover/greyhao/co-learn-2411/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
- [x] 第二篇笔记
- [x] 第三篇笔记
- [x] 第四篇笔记
- [x] 第五篇笔记

## 对外输出学习笔记

- [x] 第一篇笔记 [学习笔记链接](https://learnblockchain.cn/article/9814)
- [x] 第二篇笔记 [学习笔记链接](https://learnblockchain.cn/article/9839)
- [x] 第三篇笔记 [学习笔记链接](https://learnblockchain.cn/article/9866)
- [x] 第四篇笔记 [学习笔记链接](https://learnblockchain.cn/article/9876)
- [x] 第五篇笔记 [学习笔记链接](https://learnblockchain.cn/article/9925)

## 在HOH社区公众号发布自己的技术文章

Expand Down
42 changes: 37 additions & 5 deletions mover/greyhao/code/nft_greyhao/sources/nft_greyhao.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ module nft_greyhao::nft_greyhao;
use std::string::{String , utf8};
use sui::url::{Self, Url};
use sui::event;
use sui::package;
use sui::display;

public struct GreyhaoNFT has key, store {
id: UID,
name: String,
description: String,
url: Url,
image_url: Url,
}

// OTW for module
public struct NFT_GREYHAO has drop {}

// ====Evens ====
public struct NFTMinted has copy, drop {
object_id: ID,
Expand All @@ -32,15 +37,42 @@ public fun description(nft: &GreyhaoNFT): &String {
}

/// Get NFT's url
public fun url(nft: &GreyhaoNFT): &Url {
&nft.url
public fun image_url(nft: &GreyhaoNFT): &Url {
&nft.image_url
}

/// update the `description` of `nft` to `new_description`
public fun update_description(nft: &mut GreyhaoNFT, new_description: vector<u8>, _: &mut TxContext) {
nft.description = utf8(new_description)
}

fun init(otw: NFT_GREYHAO, ctx: &mut TxContext) {
// key包含的值就是 GreyhaoNFT 对象中除 id 外的字段
let keys = vector[
b"name".to_string(),
b"description".to_string(),
b"image_url".to_string(),
];

let values = vector[
b"{name}".to_string(),
b"{description}".to_string(),
b"{image_url}".to_string(),
];

let publisher = package::claim(otw, ctx);

let mut display = display::new_with_fields<GreyhaoNFT>(&publisher, keys, values, ctx);

display.update_version();

transfer::public_transfer(publisher, ctx.sender());
transfer::public_transfer(display, ctx.sender());

let nft = nftInfo(ctx);
transfer::transfer(nft, tx_context::sender(ctx));
}

#[allow(lint(self_transfer))]
public fun mint(ctx: &mut TxContext){
let recipient = tx_context::sender(ctx);
Expand Down Expand Up @@ -74,12 +106,12 @@ fun nftInfo(ctx: &mut TxContext): GreyhaoNFT {
id: object::new(ctx),
name: utf8(b"GREYHAO"),
description: utf8(b"NFT was created by GreyHao."),
url: url,
image_url: url,
}
}

/// delete `nft`
public fun burn(nft: GreyhaoNFT, _: &mut TxContext) {
let GreyhaoNFT {id, name: _, description: _, url: _} = nft;
let GreyhaoNFT {id, name: _, description: _, image_url: _} = nft;
id.delete()
}

0 comments on commit 51e1278

Please sign in to comment.