-
Notifications
You must be signed in to change notification settings - Fork 874
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1971 from flatflax/main
task3
- Loading branch information
Showing
5 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[package] | ||
name = "task3" | ||
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://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. | ||
# 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] | ||
task3 = "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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
module task3::my_nft; | ||
|
||
use sui::url::{Url, Self}; | ||
use std::string; | ||
use sui::object::{Self, ID, UID}; | ||
use sui::event; | ||
use sui::transfer; | ||
use sui::tx_context::{TxContext, Self}; | ||
|
||
public struct FlatflaxNFT has key, store { | ||
id: UID, | ||
name: string::String, | ||
description: string::String, | ||
url: Url, | ||
} | ||
|
||
public struct FlatflaxNFTMintEvent has copy, drop { | ||
object_id: ID, | ||
creator: address, | ||
name: string::String, | ||
} | ||
|
||
|
||
public fun description(nft: &FlatflaxNFT): string::String { | ||
nft.description | ||
} | ||
|
||
public fun url(nft: &FlatflaxNFT): Url { | ||
nft.url | ||
} | ||
public struct FlatflaxNFTTransferEvent has copy, drop { | ||
object_id: ID, | ||
from: address, | ||
to: address, | ||
} | ||
|
||
public struct FlatflaxNFTBurnEvent has copy, drop { | ||
object_id: ID, | ||
} | ||
|
||
public fun name(nft: &FlatflaxNFT): string::String { | ||
nft.name | ||
} | ||
|
||
public entry fun mint_nft( | ||
recipient: address, | ||
ctx: &mut TxContext | ||
) { | ||
let sender = tx_context::sender(ctx); | ||
let nft = FlatflaxNFT { | ||
id: object::new(ctx), | ||
name: string::utf8(b"FlatflaxNft"), | ||
description: string::utf8(b"flatflax's NFT"), | ||
url: url::new_unsafe_from_bytes(b"https://avatars.githubusercontent.com/u/14267118?v=4"), | ||
}; | ||
|
||
event::emit(FlatflaxNFTMintEvent { | ||
object_id: object::id(&nft), | ||
creator: sender, | ||
name: nft.name, | ||
}); | ||
|
||
transfer::public_transfer(nft, recipient); | ||
} | ||
|
||
public entry fun transfer( | ||
nft: FlatflaxNFT, | ||
recipient: address, | ||
_: &mut TxContext | ||
) { | ||
event::emit(FlatflaxNFTTransferEvent { | ||
object_id: object::id(&nft), | ||
from: tx_context::sender(_), | ||
to: recipient, | ||
}); | ||
|
||
transfer::public_transfer(nft, recipient); | ||
} | ||
|
||
public entry fun update_description( | ||
nft: &mut FlatflaxNFT, | ||
description: vector<u8>, | ||
_: &mut TxContext | ||
) { | ||
nft.description = string::utf8(description); | ||
} | ||
|
||
public entry fun burn( | ||
nft: FlatflaxNFT, | ||
_: &mut TxContext | ||
) { | ||
let FlatflaxNFT { id, name: _, description: _, url: _} = nft; | ||
|
||
event::emit(FlatflaxNFTBurnEvent { | ||
object_id: object::uid_to_inner(&id), | ||
}); | ||
|
||
object::delete(id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
#[test_only] | ||
module task3::task3_tests; | ||
// uncomment this line to import the module | ||
// use task3::task3; | ||
const ENotImplemented: u64 = 0; | ||
#[test] | ||
fun test_task3() { | ||
// pass | ||
} | ||
#[test, expected_failure(abort_code = ::task3::task3_tests::ENotImplemented)] | ||
fun test_task3_fail() { | ||
abort ENotImplemented | ||
} | ||
*/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters