From bdf2719a7087df0b377f4cf30835f31ebdac35de Mon Sep 17 00:00:00 2001 From: yuechen Date: Thu, 14 Mar 2024 22:52:08 +0800 Subject: [PATCH 1/4] init no --- student_no.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/student_no.txt b/student_no.txt index 2a6816f..6b91151 100644 --- a/student_no.txt +++ b/student_no.txt @@ -1 +1,2 @@ # Please enter your 9-digit student number below. +100243213 From f08455af53aaee80fc6993bfcc7558dab7e7de26 Mon Sep 17 00:00:00 2001 From: yuechen Date: Sat, 16 Mar 2024 10:50:39 +0800 Subject: [PATCH 2/4] write code --- task1/sources/main.move | 6 ++++-- task2/sources/main.move | 25 ++++++++++++++++--------- task3/sources/m1.move | 6 +++--- task3/sources/m3.move | 2 +- task4/sources/main.move | 9 ++++----- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/task1/sources/main.move b/task1/sources/main.move index 2507060..087cfdd 100644 --- a/task1/sources/main.move +++ b/task1/sources/main.move @@ -5,13 +5,15 @@ 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 { - // ... + Wallet { + balance: 1000 + } } #[test] diff --git a/task2/sources/main.move b/task2/sources/main.move index d6746d8..a0197be 100644 --- a/task2/sources/main.move +++ b/task2/sources/main.move @@ -1,17 +1,19 @@ // Task2 - drop, copy, store module 0x42::Task2{ - use std::signer; // 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 { - // ... + Foo { + u, b + } } #[test] @@ -32,21 +34,24 @@ 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 { - // ... + Soo { + x, y + } } #[test] fun test3(){ let c = gen_Soo(42, 43); let c2 = copy c; - let Soo{x,y} = &mut c2; + let Soo{x,y:_} = &mut c2; *x = 44; assert!(c.x == 42,0); assert!(c2.x == 44,1); @@ -70,7 +75,9 @@ 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 { - // ... + Moo { + x + } } #[test] diff --git a/task3/sources/m1.move b/task3/sources/m1.move index e3542c4..cb6d467 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/task3/sources/m3.move b/task3/sources/m3.move index 1b25c74..1748ac0 100644 --- a/task3/sources/m3.move +++ b/task3/sources/m3.move @@ -4,6 +4,6 @@ module 0x42::M3{ use 0x42::M1::num; let n = num(); - assert(n == 66,0); + assert!(n == 66,0); } } \ No newline at end of file diff --git a/task4/sources/main.move b/task4/sources/main.move index daa4423..d4f83f0 100644 --- a/task4/sources/main.move +++ b/task4/sources/main.move @@ -4,27 +4,26 @@ // 3. Create a sticky object module 0x42::Task4 { use aptos_framework::object::{Self, ConstructorRef}; - - use std::signer; + use std::signer::address_of; const NAME:vector = b"myObject"; // TODO // 1. create a deleteable object public fun createDeleteableObject(caller: &signer):ConstructorRef { - // ... + object::create_object(address_of(caller)) } // TODO // 2. create a named object public fun createNamedObject(caller: &signer):ConstructorRef { - // ... + object::create_named_object(caller, NAME) } // TODO // 3. create a sticky object public fun createStickyObject(caller: &signer):ConstructorRef { - // ... + object::create_sticky_object(address_of(caller)) } #[test(caller = @0x88)] From 741653232dcb906ef2e978d2627b886c5bf3716b Mon Sep 17 00:00:00 2001 From: yuechen Date: Sat, 16 Mar 2024 10:53:41 +0800 Subject: [PATCH 3/4] delete TODO word --- task2/sources/main.move | 7 +------ task3/sources/m1.move | 5 +---- task4/sources/main.move | 3 --- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/task2/sources/main.move b/task2/sources/main.move index a0197be..ab37665 100644 --- a/task2/sources/main.move +++ b/task2/sources/main.move @@ -1,14 +1,12 @@ // Task2 - drop, copy, store module 0x42::Task2{ - // TODO // Define a struct Foo with two fields: u: u64, b: bool with ability to drop 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 { Foo { @@ -59,20 +57,17 @@ module 0x42::Task2{ let Soo { x: _, y: _ } = c2; } - // TODO // Define a struct Koo with a field: s: Moo with ability struct Koo { s: Moo } - // TODO // Define a struct Moo with a field: x: u64 with ability struct Moo { x: u64 } - - // TODO + // Define a function gen_Moo that takes an argument: x: u64 and returns a Moo fun gen_Moo(x:u64): Moo { Moo { diff --git a/task3/sources/m1.move b/task3/sources/m1.move index cb6d467..591d1ce 100644 --- a/task3/sources/m1.move +++ b/task3/sources/m1.move @@ -4,17 +4,14 @@ // modify the visibility of the functions in M1, and set the M1 module visibility. module 0x42::M1{ - // TODO // Define a module friend M2 friend 0x42::M2 ; - - // TODO + // Define a function num that returns 66 with choose public or friend visibility public(friend) fun num():u64 { 66 } - // TODO // Define a function num2 that returns 88 with choose public or friend visibility public(friend) fun num2():u64 { 88 diff --git a/task4/sources/main.move b/task4/sources/main.move index d4f83f0..f9f45cb 100644 --- a/task4/sources/main.move +++ b/task4/sources/main.move @@ -8,19 +8,16 @@ module 0x42::Task4 { const NAME:vector = b"myObject"; - // TODO // 1. create a deleteable object public fun createDeleteableObject(caller: &signer):ConstructorRef { object::create_object(address_of(caller)) } - // TODO // 2. create a named object public fun createNamedObject(caller: &signer):ConstructorRef { object::create_named_object(caller, NAME) } - // TODO // 3. create a sticky object public fun createStickyObject(caller: &signer):ConstructorRef { object::create_sticky_object(address_of(caller)) From 94d42d20f16bde51142e30dec07e9687977d8d30 Mon Sep 17 00:00:00 2001 From: yuechen Date: Sat, 16 Mar 2024 19:26:09 +0800 Subject: [PATCH 4/4] refine --- task2/sources/main.move | 2 +- task3/sources/m1.move | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/task2/sources/main.move b/task2/sources/main.move index ab37665..8ff8f45 100644 --- a/task2/sources/main.move +++ b/task2/sources/main.move @@ -24,7 +24,7 @@ module 0x42::Task2{ #[test] fun test2(){ let f = gen_Fool(42, true); - let Foo{u,b} = &mut f; + let Foo{u,b: _} = &mut f; *u = 43; assert!(f.u == 43,0); assert!(f.b == true,1); diff --git a/task3/sources/m1.move b/task3/sources/m1.move index 591d1ce..c0df1b2 100644 --- a/task3/sources/m1.move +++ b/task3/sources/m1.move @@ -6,6 +6,7 @@ module 0x42::M1{ // Define a module friend M2 friend 0x42::M2 ; + friend 0x42::M3 ; // Define a function num that returns 66 with choose public or friend visibility public(friend) fun num():u64 {