Skip to content

Commit 5f45896

Browse files
Minor improvements for shop tutorial
1 parent 35453a9 commit 5f45896

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

docs/Shop Tutorial.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The SDK provides wallets in the form of `SingleAddressWallet` and `OnlineWallet`
4848

4949
### How wallets are handled in the demo
5050

51-
In the demo, the wallet is loaded via a singleton class. This is chosen as a simple a example of how to initialize the user's wallet and allow it to persist between multiple scenes and is assumed to be the most general for a blockchain game. It also allows better management of queries by enabling caching, where loading a new wallet per scene may mean additional queries. Other approaches may still be preferred depending on the particular needs of a game.
51+
In the demo, the wallet is loaded via a singleton class. This is chosen as a simple a example of how to initialize the user's wallet and allow it to persist between multiple scenes and is assumed to be the most general approach for a blockchain game. It also allows better management of queries by enabling caching, where loading a new wallet per scene may mean additional queries. Other approaches may still be preferred depending on the particular needs of a game.
5252

5353
For the purposes of the demo, the user's password is simply hardcoded in-place as a string literal. This choice allows for a smoother demonstration, but is naturally not recommended for real-world use. It is recommended that your game require the user to select a sufficiently complex password to encrypt their private key on wallet creation, and to intermittently prompt the user for their password during the game. Depending on your game, it may also be acceptable to prompt the user for their password every time they sign a transaction.
5454

@@ -224,7 +224,6 @@ This approach is not without its disadvantages, though: to keep the number of co
224224
We can see an example of adding constraints in `mint_tokens`. All constraints are implemented as methods of the `TxBuilder` class:
225225

226226
```python
227-
228227
func mint_tokens() -> bool:
229228
busy = true
230229
var shop_address := provider.make_address(
@@ -280,7 +279,7 @@ func mint_tokens() -> bool:
280279
Here we are:
281280

282281
- Adding a minting constraint: `mint_cip68_pair` makes sure that the generated TX mints a valid pair of CIP68 tokens (in this case, one reference token and multiple fungible user tokens).
283-
- Adding two paying constraints: `pay_cip68_ref_token` sets the destination address of the reference token to the shop script. `pay_cip68_user_tokens_with_datum` does the same, while also specifying the datum the output should have (the owner’s PubKeyHash). Notice that the first constraint conveniently sets the datum of the reference token: this is necessary for any CIP68 reference token, so it is handled automatically.
282+
- Adding two paying constraints: `pay_cip68_ref_token` sets the destination address of the reference token to the ref lock script. `pay_cip68_user_tokens_with_datum` sets the destination address of the user tokens to the shop script, while also specifying the datum the output should have (the owner’s PubKeyHash). Notice that the first constraint conveniently sets the datum of the reference token: this is necessary for any CIP68 reference token, so it is handled automatically.
284283

285284
This function should also be a good example of all the points at which errors may be reported via `Result`s in the process of building, signing, and submitting a transaction.
286285

@@ -331,7 +330,7 @@ func load_script_and_create_ref(filename: String) -> PlutusScriptSource:
331330
func(tx_builder: TxBuilder):
332331
tx_builder.pay_to_address(
333332
provider.make_address(
334-
Credential.from_script_source(source)
333+
Credential.from_script_source(ref_lock_source)
335334
),
336335
BigInt.zero(),
337336
MultiAsset.empty(),
@@ -350,7 +349,7 @@ func load_script_and_create_ref(filename: String) -> PlutusScriptSource:
350349
return source
351350
```
352351

353-
In addition, you can provide a `ScriptResource` as the "Minting Policy" field of a `Cip68Config` resource and (after calling `Cip68Config.init_script`) allow the `TxBuilder` to handle the script requirements with the CIP68 helper methods provided:
352+
In addition, you can provide a `ScriptResource` as the "Minting Policy" field of a `Cip68Config` resource and (after calling `Cip68Config.init_script`) allow the `TxBuilder` to handle the script requirements with the CIP68 helper methods provided. This usage can be seen in the demo under `res://cip68_data/`. The helper functions include:
354353

355354
```python
356355
func mint_cip68_pair(redeemer: PlutusData, conf: Cip68Config) -> TxBuilder:
@@ -373,8 +372,6 @@ func pay_cip68_user_tokens_with_datum(
373372
) -> TxBuilder:
374373
```
375374

376-
This usage can also be seen in the demo under `res://cip68_data/`.
377-
378375
The scripts provided in the demo each take a tag argument used to generate unique addresses and policy IDs. You can generate a unique shop of which your wallet is the owner by changing the tag to a number that has not yet been used. This tag can be found in the demo as `res://cip68_data/scripts_tag.tres`
379376

380377
### Script evaluation

shop-demo/shop.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ func load_script_and_create_ref(filename: String) -> PlutusScriptSource:
420420
func(tx_builder: TxBuilder):
421421
tx_builder.pay_to_address(
422422
provider.make_address(
423-
Credential.from_script_source(source)
423+
Credential.from_script_source(ref_lock_source)
424424
),
425425
BigInt.zero(),
426426
MultiAsset.empty(),

0 commit comments

Comments
 (0)