Skip to content

Commit

Permalink
add task2 & task3
Browse files Browse the repository at this point in the history
  • Loading branch information
brainsk committed Nov 20, 2024
1 parent 55a8fc1 commit 20a8c5b
Show file tree
Hide file tree
Showing 17 changed files with 1,459 additions and 9 deletions.
40 changes: 40 additions & 0 deletions mover/brainsk/code/task2/faucetcoin/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "36AAF1CDEC036D88764BAC3DCDE58C0D7D361D80DBC1ED0F543FFC7DC8AA1BA6"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ id = "Sui", name = "Sui" },
]

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

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

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

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

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x168d6ca257ae1f954f15f72b1cea96e7d5a8c72468f35d0b5c639d2cb0d4de5a"
latest-published-id = "0x168d6ca257ae1f954f15f72b1cea96e7d5a8c72468f35d0b5c639d2cb0d4de5a"
published-version = "1"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0xf55b7f267fbf88f6e195bdb979316293ec492882273e7deffc078a6615ec2bfd"
latest-published-id = "0xf55b7f267fbf88f6e195bdb979316293ec492882273e7deffc078a6615ec2bfd"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/brainsk/code/task2/faucetcoin/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "faucetcoin"
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" }

# 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]
faucetcoin = "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"

20 changes: 20 additions & 0 deletions mover/brainsk/code/task2/faucetcoin/sources/faucetcoin.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module faucetcoin::faucetcoin{
use sui::coin::{Self, Coin, TreasuryCap};

public struct FAUCETCOIN has drop {}

fun init(otw: FAUCETCOIN, ctx: &mut TxContext) {
let (treasury_cap, metadata) = coin::create_currency<FAUCETCOIN>(otw, 2, b"FAUCETCOIN", b"FaucetCoin", b"", option::none(), ctx);
transfer::public_freeze_object(metadata);
transfer::public_share_object(treasury_cap);
}

public entry fun mint(treasury_cap: &mut TreasuryCap<FAUCETCOIN>, amount: u64, recipient: address, ctx: &mut TxContext) {
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx);
}

// burn coins
public entry fun burn(treasury_cap: &mut TreasuryCap<FAUCETCOIN>, coin: Coin<FAUCETCOIN>) {
coin::burn(treasury_cap, coin);
}
}
18 changes: 18 additions & 0 deletions mover/brainsk/code/task2/faucetcoin/tests/faucetcoin_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
#[test_only]
module faucetcoin::faucetcoin_tests;
// uncomment this line to import the module
// use faucetcoin::faucetcoin;
const ENotImplemented: u64 = 0;
#[test]
fun test_faucetcoin() {
// pass
}
#[test, expected_failure(abort_code = ::faucetcoin::faucetcoin_tests::ENotImplemented)]
fun test_faucetcoin_fail() {
abort ENotImplemented
}
*/
40 changes: 40 additions & 0 deletions mover/brainsk/code/task2/mycoin/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "1393B3A86BC22B7FE61E23DBB2EF7BE1A330BF07AB402600F7E7CFF6E9DC82F9"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ id = "Sui", name = "Sui" },
]

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

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

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

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

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x6c0e1b207808f4f2b225b262f30acf2c218be6ffb75d92f9cd7da91ef868db23"
latest-published-id = "0x6c0e1b207808f4f2b225b262f30acf2c218be6ffb75d92f9cd7da91ef868db23"
published-version = "1"

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0x6873544ffc55c257a31c4fac905c730ed5f69c6340528314580b0c499a23c6fb"
latest-published-id = "0x6873544ffc55c257a31c4fac905c730ed5f69c6340528314580b0c499a23c6fb"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/brainsk/code/task2/mycoin/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "mycoin"
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" }

# 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]
mycoin = "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"

20 changes: 20 additions & 0 deletions mover/brainsk/code/task2/mycoin/sources/mycoin.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// Module: mycoin
module mycoin::mycoin {
use sui::coin::{Self, Coin, TreasuryCap};

public struct MYCOIN has drop {}

fun init(otw: MYCOIN, ctx: &mut TxContext) {
let (treasury_cap, metadata) = coin::create_currency<MYCOIN>(otw, 2, b"MYCOIN", b"MyCoin", b"", option::none(), ctx);
transfer::public_freeze_object(metadata);
transfer::public_transfer(treasury_cap, tx_context::sender(ctx))
}

public entry fun mint(treasury_cap: &mut TreasuryCap<MYCOIN>, amount: u64, recipient: address, ctx: &mut TxContext) {
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx);
}

public entry fun burn(treasury_cap: &mut TreasuryCap<MYCOIN>, coin: Coin<MYCOIN>) {
coin::burn(treasury_cap, coin);
}
}
18 changes: 18 additions & 0 deletions mover/brainsk/code/task2/mycoin/tests/mycoin_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
#[test_only]
module mycoin::mycoin_tests;
// uncomment this line to import the module
// use mycoin::mycoin;
const ENotImplemented: u64 = 0;
#[test]
fun test_mycoin() {
// pass
}
#[test, expected_failure(abort_code = ::mycoin::mycoin_tests::ENotImplemented)]
fun test_mycoin_fail() {
abort ENotImplemented
}
*/
7 changes: 7 additions & 0 deletions mover/brainsk/code/task3/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


mint:
sui client call --package 0x03defdabcae9c45534df08f5cdd4f119cd94fbbe80117a6179328ba45555b01d --module task3 --function mint --args "BrainNFT" "BrainNFT sui mainnet" "https://avatars.githubusercontent.com/u/155890963?s=400&u=cae07c1efe9f327be4b959f35adea823c2354bc9&v=4"

transfer:
sui client call --package 0x03defdabcae9c45534df08f5cdd4f119cd94fbbe80117a6179328ba45555b01d --module task3 --function transfer --args 0x95c4ad856bc9da78cc54d1183c5933f812e17ea913f01cda5be228bf08fcd8b4 0x7b8e0864967427679b4e129f79dc332a885c6087ec9e187b53451a9006ee15f2
34 changes: 34 additions & 0 deletions mover/brainsk/code/task3/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 = 3
manifest_digest = "DEDE53BD567ECEDC2009BE853A86F47F6BDC3F1F03A6B00FAED274F07E74A18B"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ id = "Sui", name = "Sui" },
]

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

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

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

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

[env]

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0x03defdabcae9c45534df08f5cdd4f119cd94fbbe80117a6179328ba45555b01d"
latest-published-id = "0x03defdabcae9c45534df08f5cdd4f119cd94fbbe80117a6179328ba45555b01d"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/brainsk/code/task3/Move.toml
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://github.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"

61 changes: 61 additions & 0 deletions mover/brainsk/code/task3/sources/task3.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/// Module: task3
module task3::task3 {
use sui::url::{Self, Url};
use std::string::{Self, String};
use sui::event;

//event
public struct Miai has key, store { id: UID, name: String, description: String, url: Url}
public struct Burned has copy, drop { object_id: ID, destroyer: address, name: String}
public struct Minted has copy, drop { object_id: ID, creator: address, name: String}

public fun get_name(nft: &Miai): &String {
&nft.name
}

public fun get_description(nft: &Miai): &String {
&nft.description
}

public fun get_url(nft: &Miai): &Url {
&nft.url
}

//mint
public fun mint(name: vector<u8>, descriptrion: vector<u8>, url: vector<u8>,ctx: &mut TxContext) {
let sender = tx_context::sender(ctx);
let nft = Miai {
id: object::new(ctx),
name: string::utf8(name),
description: string::utf8(descriptrion),
url: url::new_unsafe_from_bytes(url)
};
event::emit(Minted {
object_id: object::id(&nft),
creator: sender,
name: nft.name
});
transfer::public_transfer(nft, sender);
}

//burn
public fun burn(nft: Miai, ctx: &mut TxContext) {
let Miai {id, name, description: _, url: _} = nft;event::emit(
Burned {
object_id: object::uid_to_inner(&id),
destroyer: tx_context::sender(ctx),
name:name,
}
);
object::delete(id);
}

//transfer
public fun transfer(nft: Miai, recipient: address) {
transfer::public_transfer(nft, recipient);
}

public fun update_description(nft: &mut Miai, new_description: vector<u8>) {
nft.description = string::utf8(new_description);
}
}
18 changes: 18 additions & 0 deletions mover/brainsk/code/task3/tests/task3_tests.move
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
}
*/
Binary file added mover/brainsk/images/nft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 20a8c5b

Please sign in to comment.