Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task3,7,8 #1345

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions mover/djendjcn/code/task3/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 = "9D4FCF5807A34E3110DFBA44AD92FEFEC55EE3DE8CF58F3D302F55D3004E70D1"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
]

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

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

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

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

[env]

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

# 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]
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.
# 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/djendjcn/code/task3/nft/sources/nft.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module nft::nft {

use std::string::{Self, utf8, String};
use sui::url::{Self, Url};
use sui::display;
use sui::package;

public struct Nft has key, store {
id: UID,
name: String,
description: String,
creator: address,
url: Url,
}

public struct NFT has drop {}

#[allow(lint(share_owned))]
fun init(otw: NFT, ctx: &mut TxContext) {
let publisher = package::claim(otw, ctx);

let keys = vector[
utf8(b"name"),
utf8(b"description"),
utf8(b"creator"),
utf8(b"image_url"),
];

let values = vector[
utf8(b"{name}"),
utf8(b"{description}"),
utf8(b"{creator}"),
utf8(b"{url}"),
];

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

display::update_version(&mut display);

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

entry fun mint(recipient:address, ctx: &mut TxContext) {
let nft = Nft {
id: object::new(ctx),
name: string::utf8(b"djendjcn"),
description: string::utf8(b"djendjcn NFT"),
creator: tx_context::sender(ctx),
url: url::new_unsafe_from_bytes(
b"https://avatars.githubusercontent.com/u/176220540?v=4"
)
};
transfer::public_transfer(nft, recipient);
}
}
19 changes: 19 additions & 0 deletions mover/djendjcn/code/task3/nft/tests/nft_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
#[test_only]
module nft::nft_tests {
// uncomment this line to import the module
// use nft::nft;

const ENotImplemented: u64 = 0;

#[test]
fun test_nft() {
// pass
}

#[test, expected_failure(abort_code = ::nft::nft_tests::ENotImplemented)]
fun test_nft_fail() {
abort ENotImplemented
}
}
*/
34 changes: 34 additions & 0 deletions mover/djendjcn/code/task7/check_in/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 = "60ED2B08562863E03B32E589CB9D813832DBE08E722E777386028AACAA9C2B4A"
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.27.2"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x914099b4d1b4f5513acc8aaa4fdc1f67578522b81d818f61bae527d590c6d87d"
latest-published-id = "0x914099b4d1b4f5513acc8aaa4fdc1f67578522b81d818f61bae527d590c6d87d"
published-version = "1"
36 changes: 36 additions & 0 deletions mover/djendjcn/code/task7/check_in/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "check_in"
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]
check_in = "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"
77 changes: 77 additions & 0 deletions mover/djendjcn/code/task7/check_in/sources/check_in.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module check_in::check_in {
use std::ascii::{String, string};
use std::bcs;
use std::hash::sha3_256;
use std::vector;
use sui::event;
use sui::object;
use sui::random;
use sui::random::Random;
use sui::transfer::share_object;
use sui::tx_context::{Self, TxContext};

const ESTRING: u64 = 0;

public struct Flag has copy, drop {
sender: address,
flag: bool,
ture_num: u64,
github_id: String
}

public struct FlagString has key {
id: UID,
str: String,
ture_num: u64
}

fun init(ctx: &mut TxContext) {
let flag_str = FlagString {
id: object::new(ctx),
str: string(b"LetsMoveCTF"),
ture_num: 0
};
share_object(flag_str);
}


entry fun get_flag(
flag: vector<u8>,
github_id: String,
flag_str: &mut FlagString,
rand: &Random,
ctx: &mut TxContext
) {
let mut bcs_flag = bcs::to_bytes(&flag_str.str);
vector::append<u8>(&mut bcs_flag, *github_id.as_bytes());

assert!(flag == sha3_256(bcs_flag), ESTRING);

flag_str.str = getRandomString(rand, ctx);

flag_str.ture_num = flag_str.ture_num + 1;

event::emit(Flag {
sender: tx_context::sender(ctx),
flag: true,
ture_num: flag_str.ture_num,
github_id
});
}


fun getRandomString(rand: &Random, ctx: &mut TxContext): String {
let mut gen = random::new_generator(rand, ctx);

let mut str_len = random::generate_u8_in_range(&mut gen, 4, 30);

let mut rand: vector<u8> = b"";
while (str_len != 0) {
let rand_num = random::generate_u8_in_range(&mut gen, 34, 126);
vector::push_back(&mut rand, rand_num);
str_len = str_len - 1;
};

string(rand)
}
}
19 changes: 19 additions & 0 deletions mover/djendjcn/code/task7/check_in/tests/check_in_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
#[test_only]
module check_in::check_in_tests {
// uncomment this line to import the module
// use check_in::check_in;

const ENotImplemented: u64 = 0;

#[test]
fun test_check_in() {
// pass
}

#[test, expected_failure(abort_code = ::check_in::check_in_tests::ENotImplemented)]
fun test_check_in_fail() {
abort ENotImplemented
}
}
*/
34 changes: 34 additions & 0 deletions mover/djendjcn/code/task8/lets_move/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 = "786B91A5B97E30CFE4109DB806C7FDAA208AD34906C77AB899770D4D0AEB5DB1"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
]

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

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

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

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

[env]

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