WEBVTT

00:00:00.500 --> 00:00:02.518
Clients receive typed messages.

00:00:03.418 --> 00:00:06.348
The Shop declares an Item message with a price and a stock.

00:00:07.246 --> 00:00:10.801
It derives Serialize, Deserialize and Wire Type.

00:00:11.700 --> 00:00:15.020
The query returns an optional Item, and the build produces a

00:00:15.033 --> 00:00:17.806
matching client interface from these declarations.

00:00:18.705 --> 00:00:20.710
Two rules come with a message type.

00:00:21.608 --> 00:00:24.681
The order of the fields is the message format, so reordering

00:00:24.694 --> 00:00:27.194
them changes what clients must send and read.

00:00:28.093 --> 00:00:32.155
And integers have a fixed width, like u sixty-four and u thirty-two.

00:00:33.054 --> 00:00:35.853
A pointer-sized integer is not allowed in a message.

00:00:36.752 --> 00:00:39.213
The Shop has two Item types on purpose.

00:00:40.111 --> 00:00:41.257
One is the message.

00:00:42.155 --> 00:00:44.668
The other is the saved item inside Inventory.

00:00:45.567 --> 00:00:48.679
The service copies fields from the saved one into the message.

00:00:49.577 --> 00:00:51.869
Each can now change on its own schedule.

00:00:54.000 --> 00:00:55.953
Access checks have two homes.

00:00:56.853 --> 00:01:00.134
A guard on the attribute runs before the arguments are decoded,

00:01:00.382 --> 00:01:02.830
and the SDK ships one for controllers.

00:01:03.728 --> 00:01:07.140
When the rule depends on saved data, the check goes inside the

00:01:07.153 --> 00:01:07.660
method.

00:01:08.559 --> 00:01:11.723
This endpoint from a larger app compares the caller with a saved

00:01:11.736 --> 00:01:13.142
owner and answers false.

00:01:14.041 --> 00:01:18.025
For an expected refusal, return false, None or an error before

00:01:18.038 --> 00:01:19.288
making any changes.

00:01:20.187 --> 00:01:23.585
This synchronous test method changes a counter and then traps.

00:01:24.483 --> 00:01:27.660
The Internet Computer rolls back that message's writes, so the

00:01:27.673 --> 00:01:29.353
counter is back where it was.

00:01:31.467 --> 00:01:33.407
Roundtrip is an async update.

00:01:34.307 --> 00:01:36.690
It first records that a call has started.

00:01:37.588 --> 00:01:40.648
That write happens inside root with, and the scope ends on the

00:01:40.661 --> 00:01:41.443
same line.

00:01:42.341 --> 00:01:44.711
Nothing borrowed from the app is still held.

00:01:45.609 --> 00:01:46.885
Now the call leaves.

00:01:47.784 --> 00:01:51.508
With arg encodes the value as a typed message, and await suspends

00:01:51.521 --> 00:01:53.474
this method until the peer replies.

00:01:54.372 --> 00:01:56.338
Other calls can run in the meantime.

00:01:57.237 --> 00:02:00.206
The reply is decoded into a u sixty-four.

00:02:01.104 --> 00:02:04.346
A failed call or a bad reply becomes an error value that the

00:02:04.359 --> 00:02:05.245
method owns.

00:02:06.143 --> 00:02:09.346
After the reply, the method asks for write access again.

00:02:10.245 --> 00:02:11.508
This is a new scope.

00:02:12.406 --> 00:02:15.232
Whatever the first one read may have changed while the call

00:02:15.245 --> 00:02:17.771
was out, so the code reads again if it needs to.

00:02:18.669 --> 00:02:21.208
It records the outcome and returns the answer.

00:02:22.107 --> 00:02:25.648
A native test can model the two scopes as two separate calls.

00:02:26.547 --> 00:02:29.685
The real suspension, the real peer and the trap are checked

00:02:29.698 --> 00:02:33.057
on PocketIC, where roundtrip returns eleven and the counters

00:02:33.070 --> 00:02:33.565
match.

