From d00ab47302d854aaceb2392d5a60a3d67c2534e2 Mon Sep 17 00:00:00 2001 From: willcking <19372142252@163.com> Date: Fri, 15 Mar 2024 14:45:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BD=A0=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- student_no.txt | 1 + task1/sources/main.move | 7 +++++-- task2/sources/main.move | 29 +++++++++++++++++++++-------- task3/sources/m1.move | 6 +++--- task4/sources/main.move | 14 +++++++++----- 5 files changed, 39 insertions(+), 18 deletions(-) diff --git a/student_no.txt b/student_no.txt index 2a6816f..38daa74 100644 --- a/student_no.txt +++ b/student_no.txt @@ -1 +1,2 @@ # Please enter your 9-digit student number below. +100243348 \ No newline at end of file diff --git a/task1/sources/main.move b/task1/sources/main.move index 2507060..2c403f4 100644 --- a/task1/sources/main.move +++ b/task1/sources/main.move @@ -5,13 +5,16 @@ module 0x42::Task1 { // TODO // Define a struct called Wallet with a single field called balance of type u64. struct Wallet has drop { - // ... + balance: u64, } // TODO // Define a function called myWallet that returns a Wallet with a balance of 1000. fun myWallet(): Wallet { - // ... + let wallet = Wallet { + balance: 1000 + }; + wallet } #[test] diff --git a/task2/sources/main.move b/task2/sources/main.move index d6746d8..63cd307 100644 --- a/task2/sources/main.move +++ b/task2/sources/main.move @@ -4,14 +4,19 @@ module 0x42::Task2{ // TODO // Define a struct Foo with two fields: u: u64, b: bool with ability to drop - struct Foo { - // ... + struct Foo has drop { + u: u64, + b: bool, } // TODO // Define a function gen_Fool that takes two arguments: u: u64, b: bool and returns a Foo fun gen_Fool(u:u64, b:bool): Foo { - // ... + let foo = Foo{ + u, + b, + }; + foo } #[test] @@ -32,14 +37,19 @@ module 0x42::Task2{ // TODO // Define a struct Soo with two fields: x: u64, y: u64 with ability to copy - struct Soo { - // ... + struct Soo has copy { + x: u64, + y: u64, } // TODO // Define a function gen_Soo that takes two arguments: x: u64, y: u64 and returns a Soo fun gen_Soo(x:u64, y:u64): Soo { - // ... + let soo = Soo{ + x, + y, + }; + soo } #[test] @@ -62,7 +72,7 @@ module 0x42::Task2{ // TODO // Define a struct Moo with a field: x: u64 with ability - struct Moo { + struct Moo has store { x: u64 } @@ -70,7 +80,10 @@ module 0x42::Task2{ // TODO // Define a function gen_Moo that takes an argument: x: u64 and returns a Moo fun gen_Moo(x:u64): Moo { - // ... + let moo = Moo{ + x, + }; + moo } #[test] diff --git a/task3/sources/m1.move b/task3/sources/m1.move index e3542c4..5637741 100644 --- a/task3/sources/m1.move +++ b/task3/sources/m1.move @@ -6,17 +6,17 @@ module 0x42::M1{ // TODO // Define a module friend M2 - friend ; + friend 0x42::M2; // TODO // Define a function num that returns 66 with choose public or friend visibility - fun num():u64 { + public fun num():u64 { 66 } // TODO // Define a function num2 that returns 88 with choose public or friend visibility - fun num2():u64 { + public(friend) fun num2():u64 { 88 } } \ No newline at end of file diff --git a/task4/sources/main.move b/task4/sources/main.move index daa4423..4958110 100644 --- a/task4/sources/main.move +++ b/task4/sources/main.move @@ -3,28 +3,32 @@ // 2. Create a named object // 3. Create a sticky object module 0x42::Task4 { - use aptos_framework::object::{Self, ConstructorRef}; - use std::signer; + use aptos_framework::object::{Self, ConstructorRef}; const NAME:vector = b"myObject"; // TODO // 1. create a deleteable object public fun createDeleteableObject(caller: &signer):ConstructorRef { - // ... + let caller_address = signer::address_of(caller); + let constructor_ref = object::create_object(caller_address); + constructor_ref } // TODO // 2. create a named object public fun createNamedObject(caller: &signer):ConstructorRef { - // ... + let constructor_ref = object::create_named_object(caller, NAME); + constructor_ref } // TODO // 3. create a sticky object public fun createStickyObject(caller: &signer):ConstructorRef { - // ... + let caller_address = signer::address_of(caller); + let constructor_ref = object::create_sticky_object(caller_address); + constructor_ref } #[test(caller = @0x88)] From c6c5e42b8c3777e58c4723f70cfe5aed42275818 Mon Sep 17 00:00:00 2001 From: willcking <19372142252@163.com> Date: Fri, 15 Mar 2024 14:50:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BD=A0=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task4/sources/main.move | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/task4/sources/main.move b/task4/sources/main.move index 4958110..d8b0c21 100644 --- a/task4/sources/main.move +++ b/task4/sources/main.move @@ -3,9 +3,10 @@ // 2. Create a named object // 3. Create a sticky object module 0x42::Task4 { - use std::signer; use aptos_framework::object::{Self, ConstructorRef}; + use std::signer; + const NAME:vector = b"myObject"; // TODO