fix "tezos-taco-shop-smart-contract.md"

This commit is contained in:
Lesenechal Remi 2019-12-26 13:48:07 +01:00
parent d859a5ce5c
commit aa35043414

View File

@ -35,7 +35,7 @@ Each taco kind, has its own `max_price` that it sells for, and a finite supply f
Current purchase price is calculated with the following equation:
```pascaligo
```pascaligo skip
current_purchase_price = max_price / available_stock
```
@ -71,7 +71,7 @@ The best way to install the dockerized LIGO is as a **global executable** throug
To begin implementing our smart contract, we need an entry point. We'll call it `main` and it'll specify our contract's storage (`int`) and input parameter (`int`). Of course this is not the final storage/parameter of our contract, but it's something to get us started and test our LIGO installation as well.
### `taco-shop.ligo`
```pascaligo
```pascaligo group=a
function main (const parameter: int; const contractStorage: int) : (list(operation) * int) is
block {skip} with ((nil : list(operation)), contractStorage + parameter)
```
@ -129,7 +129,7 @@ ligo dry-run taco-shop.ligo --syntax pascaligo main 4 3
We know that Pedro's Taco Shop serves two kinds of tacos, so we'll need to manage stock individually, per kind. Let's define a type, that will keep the `stock` & `max_price` per kind - in a record with two fields. Additionally, we'll want to combine our `taco_supply` type into a map, consisting of the entire offer of Pedro's shop.
**Taco shop's storage**
```pascaligo
```pascaligo group=b
type taco_supply is record
current_stock : nat;
max_price : tez;
@ -141,7 +141,7 @@ type taco_shop_storage is map(nat, taco_supply);
Next step is to update the `main` entry point to include `taco_shop_storage` as its storage - while doing that let's set the `parameter` to `unit` as well to clear things up.
**`taco-shop.ligo`**
```pascaligo
```pascaligo group=b+
type taco_supply is record
current_stock : nat;
max_price : tez;
@ -208,7 +208,7 @@ Let's start by customizing our contract a bit, we will:
- change `taco_shop_storage` to a `var` instead of a `const`, because we'll want to modify it
**`taco-shop.ligo`**
```pascaligo
```pascaligo group=c
type taco_supply is record
current_stock : nat;
max_price : tez;
@ -231,7 +231,7 @@ In order to decrease the stock in our contract's storage for a specific taco kin
**`taco-shop.ligo`**
```pascaligo
```pascaligo group=d
type taco_supply is record
current_stock : nat;
max_price : tez;
@ -266,7 +266,7 @@ To make sure we get paid, we will:
- if yes, stock for the given `taco_kind` will be decreased and the payment accepted
**`taco-shop.ligo`**
```pascaligo
```pascaligo group=e
type taco_supply is record
current_stock : nat;
max_price : tez;
@ -282,7 +282,7 @@ function buy_taco (const taco_kind_index: nat ; var taco_shop_storage : taco_sho
if amount =/= current_purchase_price then
// we won't sell tacos if the amount isn't correct
fail("Sorry, the taco you're trying to purchase has a different price");
failwith("Sorry, the taco you're trying to purchase has a different price");
else
// Decrease the stock by 1n, because we've just sold one
taco_kind.current_stock := abs(taco_kind.current_stock - 1n);
@ -324,14 +324,14 @@ end"
## 💰 Bonus: *Accepting tips above the taco purchase price*
If you'd like to accept tips in your contract as well, simply change the following line, depending on which behavior do you prefer.
If you'd like to accept tips in your contract as well, simply change the following line, depending on your preference.
**Without tips**
```pascaligo
```pascaligo skip
if amount =/= current_purchase_price then
```
**With tips**
```pascaligo
```pascaligo skip
if amount >= current_purchase_price then
```