From adb96adf86cbae278caed5918d18f878cd10a6bc Mon Sep 17 00:00:00 2001 From: JingShang Lu Date: Sat, 16 Mar 2024 16:16:13 +0800 Subject: [PATCH 1/2] first commit --- student_no.txt | 2 ++ task1/sources/main.move | 6 +++++- task2/sources/main.move | 37 +++++++++++++++++++++++++------------ task3/sources/m1.move | 6 +++--- task4/sources/main.move | 11 ++++++++--- 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/student_no.txt b/student_no.txt index 2a6816f..150a249 100644 --- a/student_no.txt +++ b/student_no.txt @@ -1 +1,3 @@ # Please enter your 9-digit student number below. + +100243360 diff --git a/task1/sources/main.move b/task1/sources/main.move index 2507060..485d543 100644 --- a/task1/sources/main.move +++ b/task1/sources/main.move @@ -5,13 +5,17 @@ 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 result = Wallet { + balance: 1000 + }; + result } #[test] diff --git a/task2/sources/main.move b/task2/sources/main.move index d6746d8..f1a38b1 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 { - // ... + fun gen_Fool(u_in:u64, b_in:bool): Foo { + let result = Foo { + u: u_in, + b: b_in + }; + result } #[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 { - // ... + fun gen_Soo(x_in:u64, y_in:u64): Soo { + let result = Soo { + x: x_in, + y: y_in + }; + result } #[test] @@ -56,21 +66,24 @@ module 0x42::Task2{ // TODO // Define a struct Koo with a field: s: Moo with ability - struct Koo { + struct Koo has drop { s: Moo } // TODO // Define a struct Moo with a field: x: u64 with ability - struct Moo { + struct Moo has drop { x: u64 } // TODO // Define a function gen_Moo that takes an argument: x: u64 and returns a Moo - fun gen_Moo(x:u64): Moo { - // ... + fun gen_Moo(x_in:u64): Moo { + let result = Moo { + x: x_in + }; + result } #[test] diff --git a/task3/sources/m1.move b/task3/sources/m1.move index e3542c4..61b8894 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(friend) 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..6a2e60d 100644 --- a/task4/sources/main.move +++ b/task4/sources/main.move @@ -12,19 +12,24 @@ module 0x42::Task4 { // TODO // 1. create a deleteable object public fun createDeleteableObject(caller: &signer):ConstructorRef { - // ... + let caller_address = signer::address_of(caller); + let obj = object::create_object(caller_address); + obj } // TODO // 2. create a named object public fun createNamedObject(caller: &signer):ConstructorRef { - // ... + let obj = object::create_named_object(caller, NAME); + obj } // TODO // 3. create a sticky object public fun createStickyObject(caller: &signer):ConstructorRef { - // ... + let caller_address = signer::address_of(caller); + let obj = object::create_sticky_object(caller_address); + obj } #[test(caller = @0x88)] From a8adc6b39ff4b077bf47086c49e62352a3cfb5bf Mon Sep 17 00:00:00 2001 From: JingShang Lu Date: Sat, 16 Mar 2024 17:05:04 +0800 Subject: [PATCH 2/2] second commit --- task3/sources/m1.move | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/task3/sources/m1.move b/task3/sources/m1.move index 61b8894..589f831 100644 --- a/task3/sources/m1.move +++ b/task3/sources/m1.move @@ -7,7 +7,8 @@ module 0x42::M1{ // TODO // Define a module friend M2 friend 0x42::M2; - + friend 0x42::M3; + // TODO // Define a function num that returns 66 with choose public or friend visibility public(friend) fun num():u64 {