Skip to content

Commit

Permalink
Takes some comments into account on chapter string, list, interaction…
Browse files Browse the repository at this point in the history
…, polymorphism
  • Loading branch information
OCTO-FRAH committed Nov 23, 2020
1 parent 1929ed9 commit 14514b1
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ We want to conditionally change the engine attribute (third number) to 1 only if
<!-- prettier-ignore -->1- Define a condition _if_ the engine attribute equal 0. Don't forget the attributes are defined as strings.

<!-- prettier-ignore -->2- If the condition is met, apply changes and return resulting new ship code. Otherwise, return the given ship code (parameter *my\_ship*).

<!-- prettier-ignore -->⚠️ If you have installed LIGO then you can test the execution of the *modify\_ship* function by running the following command:

```
ligo run-function main.ligo modify_ship '("010433")'
```
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ let main (action, store : parameter * storage) : return is
)
```

<!-- prettier-ignore -->2- Consider the contract in the editor. Notice the addresses of each weapon, and that the _orders_ function fetch the corresponding contracts. Your job is now to define the list of operations to send to the weapons. For this, start by creating _operations_ a list of type _operation_.
<!-- prettier-ignore -->⚠️ Notice that the weapon smart contract provides two entrypoints Fire and Stop.

<!-- prettier-ignore -->2- Consider the contract in the editor which is responsible to control the left and right weapons.
<!-- prettier-ignore -->⚠️ Notice the addresses of each weapon, and that the _orders_ function fetch the corresponding contracts. (Variables *right\_laser* and *left\_laser* can be used as the target of a transaction).
Your job is now to define the list of transactions sent to the weapon contracts. For this, start by creating _operations_ a list of type _operation_.

<!-- prettier-ignore -->⚠️ Notice that _operations_ must be filled with transactions and is returned by the function _orders_.

<!-- prettier-ignore -->3- Send a _Fire(5)_ transaction to the *right\_laser* contract, then _Stop_. Send a _Fire(5)_ transaction to the *left\_laser* contract, then _Stop_.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,21 @@ The Central contract can provide information of a ship to a calling contract via
The Squadron contract provides an entry point _ModuleRequest_ to ask for ship information to the central contract.
The Squadron contract provides an entry point _ModuleResponse_ which is called by the central contract when sending back the expected ship information.

As you can see, the entry point _RetrieveShip_ calls the function _sendTx_ which is responsible to send a transaction to a the calling contract. The implementation of the Central contract has not been finished. We need you to finish the _sendTx_ function!
As you can see, the entry point _RetrieveShip_ calls the function _sendTx_ which is responsible to send the requested ship information to the caller (by sending a transaction to the calling contract). The implementation of the Central contract has not been finished. We need you to finish the _sendTx_ function!

<!-- prettier-ignore -->1- Try to retrieve the entry point %moduleResponse of the given *callbackAddress* and store the result in a variable called *contractInterfaceOpt* of type _actionSquadron contract option_
<!-- prettier-ignore -->⚠️ Notice that there are multiple tabs for displaying Squadron and Central smart contracts. Your goal is to complete the Central contract displayed in tab "Exercise".

<!-- prettier-ignore -->2- Use a _match_ operator to extract the entry point if it exists (use temporary variable name *ci* in the _Some_). Otherwise throw an exception with error message "Entrypoint not found in contract Squadron" (and don't forget to cast the exception in the right type). The extracted entry point must be stored in a variable called *contractInterface*.

<!-- prettier-ignore -->3- In order to prepare the ship information that need to be sent back to the Squadron contract. Check the expected type of entry point _ModuleResponse_ and prepare a variable *ee* of this expected type containing the expected ship *e*.
<!-- prettier-ignore -->1- First we want to call the moduleResponse entrypoint of the Squadron but we need to ensure that the *callbackAddress* is a squadron contract and has the expected entrypoint. Try to retrieve the entry point %moduleResponse of the given *callbackAddress* and store the result in a variable called *contractInterfaceOpt* of type _actionSquadron contract option_.
<!-- prettier-ignore -->⚠️Remind that the entry point must be in quotations.
<!-- prettier-ignore -->⚠️Remind that _option_ type means that maybe there is a value
<!-- prettier-ignore -->⚠️Remind that _actionSquadron contract_ represents entrypoints following the _actionSquadron_ format.
<!-- prettier-ignore -->⚠️So the type _actionSquadron contract option_ stands for "Maybe there are entrypoints which follow the _actionSquadron_ format".

<!-- prettier-ignore -->2- Use a _match_ operator to extract the entry point from *contractInterfaceOpt* if it exists (use temporary variable name *ci* in the _Some_). Otherwise throw an exception with error message "Entrypoint not found in contract Squadron" (and don't forget to cast the exception in the right type). The extracted entry point must be stored in a variable called *contractInterface*.

<!-- prettier-ignore -->3- In order to prepare the ship information that need to be sent back to the Squadron contract. Prepare a variable called *ee* of type _actionModuleResponse_ containing the expected ship *e*.
<!-- prettier-ignore -->⚠️ Notice that in Squadron smart contract the entry point _ModuleResponse_ expects a type _actionModuleResponse_. So when Central smart contract sends back the requested ship information it must respect the expected format (in our case it is a _actionModuleResponse_ containing a _ship_ record).


<!-- prettier-ignore -->4- Send a transaction to the retrieved entry point of the Squadron contract. The transaction must point to the _moduleResponse_ entrypoint of squadron contract and passing the right argument prepared in step 3. This transaction sends no money. The transaction is an _operation_ type that you can store in a variable *sendbackOperation*.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ let full_greeting: string = greeting ^ " " ^ name

## Slicing Strings

Strings can be sliced using a built-in function _String.sub_ as follows:
Strings can be sliced using a built-in function _String.sub_ which takes three parameters:
- an _offset_ describing the index of first character that will be copied
- the _length_ describing the number of characters that will be copied (starting from the given offset)
- the _string_ being sliced

The function _String.sub_ can be used as follows:

```
let name: string = "Captain Rogers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@ We want to conditionally change the engine attribute (third number) to 1 only if
<!-- prettier-ignore -->2- Then define a condition _if_ the engine attribute equal 0. Don't forget the attributes are defined as strings.

<!-- prettier-ignore -->3- If the condition is met, change *modified\_ship* to it new value. Otherwise, _skip_ the instructions.

<!-- prettier-ignore -->⚠️ If you have installed LIGO then you can test the execution of the *modify\_ship* function by running the following command:

```
ligo run-function main.ligo modify_ship '("010433")'
```

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ const my_ship_price : tez = 3tez * 1.20
function modify_ship (const my_ship : ship_code) : ship_code is
block {
// Type your solution below
const modified_ship := String.sub(0n, 2n, my_ship) ^ "1" ^ String.sub(3n, 3n, my_ship)
const modified_ship = String.sub(0n, 2n, my_ship) ^ "1" ^ String.sub(3n, 3n, my_ship)
} with modified_ship
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ function main (const action : parameter; const store : storage) : return is
end)
```

<!-- prettier-ignore -->2- Consider the contract in the editor. Notice the addresses of each weapon, and that the _orders_ function fetch the corresponding contracts. Your job is now to define the list of operations to send to the weapons. For this, start by creating _operations_ a list of type _operation_.
<!-- prettier-ignore -->⚠️ Notice that the weapon smart contract provides two entrypoints Fire and Stop.

<!-- prettier-ignore -->2- Consider the contract in the editor which is responsible to control the left and right weapons.
<!-- prettier-ignore -->⚠️ Notice the addresses of each weapon, and that the _orders_ function fetch the corresponding contracts. (Variables *right\_laser* and *left\_laser* can be used as the target of a transaction).
Your job is now to define the list of transactions sent to the weapon contracts. For this, start by creating _operations_ a list of type _operation_.

<!-- prettier-ignore -->⚠️ Notice that _operations_ must be filled with transactions and is returned by the function _orders_.

<!-- prettier-ignore -->3- Send a _Fire(5)_ transaction to the *right\_laser* contract, then _Stop_. Send a _Fire(5)_ transaction to the *left\_laser* contract, then _Stop_.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const smaller_set : set (int) = Set.remove (3, my_set)

## Your mission

<!-- prettier-ignore -->1- Define _itinary_ as a list of string names of celestial bodies representing your course. Start with _"earth"_
<!-- prettier-ignore -->1- Define a variable _itinary_ as a list of string names of celestial bodies representing your course. Start with _"earth"_

<!-- prettier-ignore -->2- On the next line, add _"sun"_ to the itinary.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ Same from sets with _for i in set s_ and maps with _for key -> value in map m_

<!-- prettier-ignore -->1- Check the proposed code in the editor. Notice that we created a star map as a list of planet records.

<!-- prettier-ignore -->2- Notice the unimplemented scan function. Suppose this function is called from the main function with the *star\_map* variable as its input _l_. Code a for loop that iterates through each record of the list.
<!-- prettier-ignore -->2- Notice the unimplemented scan function. Suppose this function is called from the main function onto the *star\_map* variable. Code a for loop that iterates through each record of the list _l_ (given as parameter of the _scan_ function).

<!-- prettier-ignore -->3- Inside the loop, code a conditional for *density* supperior to 100 and *atmospheric\_activity* true. If so, assign the planet to *destination*.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,21 @@ The Central contract can provide information of a ship to a calling contract via
The Squadron contract provides an entry point _ModuleRequest_ to ask for ship information to the central contract.
The Squadron contract provides an entry point _ModuleResponse_ which is called by the central contract when sending back the expected ship information.

As you can see, the entry point _RetrieveShip_ calls the function _sendTx_ which is responsible to send a transaction to a the calling contract. The implementation of the Central contract has not been finished. We need you to finish the _sendTx_ function!
As you can see, the entry point _RetrieveShip_ calls the function _sendTx_ which is responsible to send the requested ship information to the caller (by sending a transaction to the calling contract). The implementation of the Central contract has not been finished. We need you to finish the _sendTx_ function!

<!-- prettier-ignore -->1- Try to retrieve the entry point %moduleResponse of the given *callbackAddress* and store the result in a variable called *contractInterfaceOpt* of type _option(contract(actionSquadron))_
<!-- prettier-ignore -->⚠️ Notice that there are multiple tabs for displaying Squadron and Central smart contracts. Your goal is to complete the Central contract displayed in tab "Exercise".

<!-- prettier-ignore -->2- Use a _case_ operator to extract the entry point if it exists (use temporary variable name *ci* in the case). Otherwise throw an exception with error message "Entrypoint not found in contract Squadron" (and don't forget to cast the exception in the right type). The extracted entry point must be stored in a variable called *contractInterface*.

<!-- prettier-ignore -->3- In order to prepare the ship information that need to be sent back to the Squadron contract. Check the expected type of entry point _ModuleResponse_ and prepare a variable *ee* of this expected type containing the expected ship *e*.
<!-- prettier-ignore -->1- First we want to call the moduleResponse entrypoint of the Squadron but we need to ensure that the *callbackAddress* is a squadron contract and has the expected entrypoint. Try to retrieve the entry point %moduleResponse of the given *callbackAddress* and store the result in a variable called *contractInterfaceOpt* of type _option(contract(actionSquadron))_.
<!-- prettier-ignore -->⚠️Remind that the entry point must be in quotations.
<!-- prettier-ignore -->⚠️Remind that _option_ type means that maybe there is a value
<!-- prettier-ignore -->⚠️Remind that _contract(actionSquadron)_ represents entrypoints following the _actionSquadron_ format.
<!-- prettier-ignore -->⚠️So the type _option(contract(actionSquadron))_ stands for "Maybe there are entrypoints which follow the _actionSquadron_ format".

<!-- prettier-ignore -->2- Use a _case_ operator to extract the entry point from *contractInterfaceOpt* if it exists (use temporary variable name *ci* in the case). Otherwise throw an exception with error message "Entrypoint not found in contract Squadron" (and don't forget to cast the exception in the right type). The extracted entry point must be stored in a variable called *contractInterface*.

<!-- prettier-ignore -->3- In order to prepare the ship information that need to be sent back to the Squadron contract. Prepare a variable called *ee* of type _actionModuleResponse_ containing the expected ship *e*.
<!-- prettier-ignore -->⚠️ Notice that in Squadron smart contract the entry point _ModuleResponse_ expects a type _actionModuleResponse_. So when Central smart contract sends back the requested ship information it must respect the expected format (in our case it is a _actionModuleResponse_ containing a _ship_ record).


<!-- prettier-ignore -->4- Send a transaction to the retrieved entry point of the Squadron contract. The transaction must point to the _moduleResponse_ entrypoint of squadron contract and passing the right argument prepared in step 3. This transaction sends no money. The transaction is an _operation_ type that you can store in a variable *sendbackOperation*.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ const full_greeting: string = greeting ^ " " ^ name

## Slicing Strings

Strings can be sliced using a built-in function _String.sub_ as follows:
Strings can be sliced using a built-in function _String.sub_ which takes three parameters:
- an _offset_ describing the index of first character that will be copied
- the _length_ describing the number of characters that will be copied (starting from the given offset)
- the _string_ being sliced

The function _String.sub_ can be used as follows:

```
const name: string = "Captain Rogers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ We want to conditionally change the engine attribute (third number) to 1 only if
<!-- prettier-ignore -->1- Define a condition _if_ the engine attribute equal 0. Don't forget the attributes are defined as strings.

<!-- prettier-ignore -->2- If the condition is met, compute the new ship_code value in a constant *modified\_ship* and return *modified\_ship*. Otherwise, return the *my\_ship* constant (given as parameter of the function).

<!-- prettier-ignore -->⚠️ If you have installed LIGO then you can test the execution of the *modify\_ship* function by running the following command:

```
ligo run-function main.ligo modify_ship '("010433")'
```
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ let main = ((action, store) : (parameter, storage)) : return => {
}
```

<!-- prettier-ignore -->2- Consider the contract in the editor. Notice the addresses of each weapon, and that the _orders_ function fetch the corresponding contracts. Your job is now to define the list of operations to send to the weapons. For this, start by creating _operations_ a list of type _operation_.

<!-- prettier-ignore -->⚠️ Notice that the weapon smart contract provides two entrypoints Fire and Stop.

<!-- prettier-ignore -->2- Consider the contract in the editor which is responsible to control the left and right weapons.
<!-- prettier-ignore -->⚠️ Notice the addresses of each weapon, and that the _orders_ function fetch the corresponding contracts. (Variables *right\_laser* and *left\_laser* can be used as the target of a transaction).
Your job is now to define the list of transactions sent to the weapon contracts. For this, start by creating _operations_ a list of type _operation_.

<!-- prettier-ignore -->⚠️ Notice that _operations_ must be filled with transactions and is returned by the function _orders_.

<!-- prettier-ignore -->3- Send a _Fire(5)_ transaction to the *right\_laser* contract, then _Stop_. Send a _Fire(5)_ transaction to the *left\_laser* contract, then _Stop_.

Loading

0 comments on commit 14514b1

Please sign in to comment.