@@ -138,13 +138,13 @@ In this case, the contract needs to store the taco data map and the administrato
138
138
139
139
``` jsligo skip
140
140
export const default_taco_data: taco_data = Map.literal([
141
- [1n , { current_stock: 50n , max_price: 50tez }],
142
- [2n , { current_stock: 20n , max_price: 75tez }]
141
+ [1 as nat , { current_stock: 50 as nat , max_price: 50 as tez }],
142
+ [2 as nat , { current_stock: 20 as nat , max_price: 75 as tez }]
143
143
]);
144
144
```
145
145
146
- Note that the natural numbers are indicated with an ` n ` after the number; otherwise, LIGO assumes that numbers are integers.
147
- Similarly, the maximum prices of the tacos are suffixed with ` tez ` to indicate that they are amounts of tez.
146
+ Note that the natural numbers are indicated with an ` as nat ` after the number; otherwise, LIGO assumes that numbers are integers.
147
+ Similarly, the maximum prices of the tacos have ` as tez` to indicate that they are amounts of tez.
148
148
149
149
1 . To keep the code for the contract organized, put the types and values in a namespace named ` TacoShop ` .
150
150
The contract looks like this so far:
@@ -159,9 +159,9 @@ The contract looks like this so far:
159
159
taco_data: taco_data,
160
160
};
161
161
162
- export const default_taco_data: taco_data = Map.literal ([
163
- [1n , { current_stock: 50n , max_price: 50tez }],
164
- [2n , { current_stock: 20n , max_price: 75tez }]
162
+ export const default_taco_data: taco_data = Map.literal([
163
+ [1 as nat , { current_stock: 50 as nat , max_price: 50 as tez }],
164
+ [2 as nat , { current_stock: 20 as nat , max_price: 75 as tez }]
165
165
]);
166
166
167
167
};
@@ -254,10 +254,10 @@ Add this function inside the namespace, immediately after the `default_taco_data
254
254
// Internal function to get the price of a taco
255
255
const get_taco_price_internal = (taco_kind_index: nat, taco_data: taco_data): tez => {
256
256
const taco_kind: taco_supply =
257
- match (Map.find_opt(taco_kind_index, taco_data)) {
258
- when( Some(kind)): kind;
259
- when( None()): failwith("Unknown kind of taco")
260
- };
257
+ $ match (Map.find_opt(taco_kind_index, taco_data), {
258
+ " Some": (kind) => kind,
259
+ " None": () => failwith("Unknown kind of taco"),
260
+ }) ;
261
261
return taco_kind.max_price / taco_kind.current_stock;
262
262
}
263
263
```
@@ -303,15 +303,15 @@ As described in [Entrypoints](../../syntax/contracts/entrypoints), entrypoints m
303
303
304
304
<Syntax syntax =" jsligo " >
305
305
306
- - Entrypoints are functions marked with the ` @entry ` decorator
306
+ - Entrypoints are functions marked with the ` @entry ` decorator, which (when used in a namespace) must be in a comment immediately before the function
307
307
- Entrypoints receive a parameter from the caller and the current state of the contract storage
308
308
- Entrypoints return a tuple consisting of a list of operations to run (such as calls to other smart contracts or transfers of tez) and the new state of the contract storage
309
309
310
310
1 . In the smart contract file, within the ` TacoShop ` namespace, add this stub of an entrypoint:
311
311
312
312
``` jsligo skip
313
313
// Buy a taco
314
- @entry
314
+ // @entry
315
315
const buy_taco = (taco_kind_index: nat, storage: storage): [
316
316
list<operation>,
317
317
storage
@@ -341,10 +341,10 @@ As described in [Entrypoints](../../syntax/contracts/entrypoints), entrypoints m
341
341
``` jsligo skip
342
342
// Retrieve the kind of taco from the contracts storage or fail
343
343
const taco_kind: taco_supply =
344
- match (Map.find_opt(taco_kind_index, taco_data)) {
345
- when( Some(kind)): kind;
346
- when( None()): failwith("Unknown kind of taco");
347
- } ;
344
+ $ match (Map.find_opt(taco_kind_index, taco_data), {
345
+ " Some": (kind) => kind,
346
+ " None": () => failwith("Unknown kind of taco"),
347
+ }) ;
348
348
```
349
349
350
350
1 . After the code you just added, add this code to get the current price of a taco:
@@ -368,7 +368,7 @@ It uses the `Tezos.get_amount()` function, which returns the amount of tez that
368
368
369
369
``` jsligo skip
370
370
// Verify that there is at least one of this type of taco
371
- if (taco_kind.current_stock == 0n ) {
371
+ if (taco_kind.current_stock == 0 as nat ) {
372
372
return failwith("Sorry, we are out of this type of taco");
373
373
}
374
374
```
@@ -379,7 +379,7 @@ It uses the `Tezos.get_amount()` function, which returns the amount of tez that
379
379
// Update the storage with the new quantity of tacos
380
380
const updated_taco_data: taco_data = Map.update(
381
381
taco_kind_index,
382
- ( Some (( {...taco_kind, current_stock: abs(taco_kind.current_stock - 1n ) }))) ,
382
+ [" Some" as "Some", {...taco_kind, current_stock: abs(taco_kind.current_stock - 1 ) }] ,
383
383
taco_data);
384
384
```
385
385
@@ -404,7 +404,7 @@ It uses the `Tezos.get_amount()` function, which returns the amount of tez that
404
404
1 . After the code for the ` buy_taco ` entrypoint, stub in the code for the entrypoint that allows Pedro to retrieve the tez in the contract, which you will add in a later section:
405
405
406
406
``` jsligo skip
407
- @entry
407
+ // @entry
408
408
const payout = (_u: unit, storage: storage): [
409
409
list<operation>,
410
410
storage
@@ -545,7 +545,7 @@ Unlike entrypoints, they return a single value to the caller instead of a list o
545
545
Add this view to the contract, after the ` get_taco_price_internal ` function and somewhere within the namespace:
546
546
547
547
``` jsligo skip
548
- @view
548
+ // @view
549
549
const get_taco_price = (taco_kind_index: nat, storage: storage): tez =>
550
550
get_taco_price_internal(taco_kind_index, storage.taco_data);
551
551
```
@@ -567,26 +567,26 @@ namespace TacoShop {
567
567
};
568
568
569
569
export const default_taco_data: taco_data = Map.literal([
570
- [1n , { current_stock: 50n , max_price: 50tez }],
571
- [2n , { current_stock: 20n , max_price: 75tez }]
570
+ [1 as nat , { current_stock: 50 as nat , max_price: 50 as tez }],
571
+ [2 as nat , { current_stock: 20 as nat , max_price: 75 as tez }]
572
572
]);
573
573
574
574
// Internal function to get the price of a taco
575
575
const get_taco_price_internal = (taco_kind_index: nat, taco_data: taco_data): tez => {
576
576
const taco_kind: taco_supply =
577
- match (Map.find_opt(taco_kind_index, taco_data)) {
578
- when( Some(kind)): kind;
579
- when( None()): failwith("Unknown kind of taco")
580
- };
577
+ $ match (Map.find_opt(taco_kind_index, taco_data), {
578
+ " Some": (kind) => kind,
579
+ " None": () => failwith("Unknown kind of taco"),
580
+ }) ;
581
581
return taco_kind.max_price / taco_kind.current_stock;
582
582
}
583
583
584
- @view
584
+ // @view
585
585
const get_taco_price = (taco_kind_index: nat, storage: storage): tez =>
586
586
get_taco_price_internal(taco_kind_index, storage.taco_data);
587
587
588
588
// Buy a taco
589
- @entry
589
+ // @entry
590
590
const buy_taco = (taco_kind_index: nat, storage: storage): [
591
591
list<operation>,
592
592
storage
@@ -596,10 +596,10 @@ namespace TacoShop {
596
596
597
597
// Retrieve the kind of taco from the contracts storage or fail
598
598
const taco_kind: taco_supply =
599
- match (Map.find_opt(taco_kind_index, taco_data)) {
600
- when( Some(kind)): kind;
601
- when( None()): failwith("Unknown kind of taco");
602
- };
599
+ $ match (Map.find_opt(taco_kind_index, taco_data), {
600
+ " Some": (kind) => kind,
601
+ " None": () => failwith("Unknown kind of taco"),
602
+ }) ;
603
603
604
604
// Get the current price of this type of taco
605
605
const current_purchase_price = get_taco_price_internal(taco_kind_index, taco_data);
@@ -610,14 +610,14 @@ namespace TacoShop {
610
610
}
611
611
612
612
// Verify that there is at least one of this type of taco
613
- if (taco_kind.current_stock == 0n ) {
613
+ if (taco_kind.current_stock == (0 as nat) ) {
614
614
return failwith("Sorry, we are out of this type of taco");
615
615
}
616
616
617
617
// Update the storage with the new quantity of tacos
618
618
const updated_taco_data: taco_data = Map.update(
619
619
taco_kind_index,
620
- ( Some (( {...taco_kind, current_stock: abs (taco_kind.current_stock - 1n ) }))) ,
620
+ [" Some" as "Some", {...taco_kind, current_stock: abs(taco_kind.current_stock - 1 ) }] ,
621
621
taco_data);
622
622
623
623
const updated_storage: storage = {
@@ -628,7 +628,7 @@ namespace TacoShop {
628
628
return [[], updated_storage];
629
629
}
630
630
631
- @entry
631
+ // @entry
632
632
const payout = (_u: unit, storage: storage): [
633
633
list<operation>,
634
634
storage
@@ -638,6 +638,7 @@ namespace TacoShop {
638
638
639
639
return [[], storage];
640
640
}
641
+
641
642
};
642
643
```
643
644
0 commit comments