WEBVTT

00:00:00.500 --> 00:00:04.393
This is RRT Heavy16, a much larger application.

00:00:05.293 --> 00:00:07.025
Its layout is the one we know.

00:00:07.923 --> 00:00:11.009
Each feature has a folder with its service and a versioned memory

00:00:11.022 --> 00:00:11.543
folder.

00:00:12.442 --> 00:00:13.991
The root wires them together.

00:00:14.890 --> 00:00:16.908
Endpoints are in lib dot r s.

00:00:17.806 --> 00:00:19.421
The root lists eight children.

00:00:20.319 --> 00:00:23.705
Four belong to the application, and the ledger's is called work.

00:00:24.603 --> 00:00:26.465
The other four come from libraries.

00:00:27.364 --> 00:00:30.957
Rechain keeps a recorded history, its replay module remembers

00:00:30.970 --> 00:00:34.851
recent commands, and Reactor delivers messages between canisters.

00:00:35.749 --> 00:00:39.186
A library module is attached just like your own, and you use

00:00:39.200 --> 00:00:40.332
it through its service.

00:00:42.467 --> 00:00:45.813
The request is to count commands by kind and add up their units.

00:00:46.713 --> 00:00:50.581
The ledger's data has an owner, five counts, one for each kind,

00:00:50.867 --> 00:00:52.625
a total, and the last caller.

00:00:53.523 --> 00:00:55.633
A Rechain reducer has two halves.

00:00:56.531 --> 00:00:59.904
Prepare is written for any access, so it can only read.

00:01:00.802 --> 00:01:03.549
It checks the caller against the owner and the units against

00:01:03.562 --> 00:01:05.971
a range, and it uses checked arithmetic.

00:01:06.870 --> 00:01:09.239
Each failure returns a typed business error.

00:01:10.138 --> 00:01:13.172
If everything passes it returns a plan, which holds the new

00:01:13.185 --> 00:01:14.526
counts and the new total.

00:01:15.424 --> 00:01:16.844
Nothing has been written.

00:01:17.742 --> 00:01:20.008
Commit exists only under a write scope.

00:01:20.906 --> 00:01:22.625
It takes the plan and stores it.

00:01:23.523 --> 00:01:26.362
It makes no decisions and has nothing to refuse.

00:01:27.260 --> 00:01:30.646
Rechain calls it after the action has been accepted and recorded.

00:01:31.544 --> 00:01:33.875
The ledger's Commands service ties it together.

00:01:34.773 --> 00:01:37.937
It asks Rechain to dispatch the action on the business chain.

00:01:38.836 --> 00:01:42.039
The reducer it passes is the work view wrapped by the replay

00:01:42.052 --> 00:01:42.651
module.

00:01:43.549 --> 00:01:47.338
Replay runs first and recognizes a command it has already seen.

00:01:49.500 --> 00:01:52.820
The test sends one command of each kind with five units.

00:01:53.720 --> 00:01:56.728
Each returns its block number, zero through four.

00:01:57.627 --> 00:02:01.090
It sends the same dated commands again within the replay window.

00:02:01.989 --> 00:02:04.671
Keep the original creation time on a retry.

00:02:05.569 --> 00:02:08.929
Each repeat returns the same block number, and the total stays

00:02:08.942 --> 00:02:09.866
twenty-five.

00:02:10.765 --> 00:02:12.653
Two more commands are refused.

00:02:13.551 --> 00:02:16.012
One comes from a caller who is not the owner.

00:02:16.910 --> 00:02:18.968
The other asks for zero units.

00:02:19.866 --> 00:02:22.171
Each returns its typed error from prepare.

00:02:23.069 --> 00:02:26.585
The chain's next index is still five, so no block was spent

00:02:26.598 --> 00:02:27.223
on either.

00:02:28.121 --> 00:02:30.439
Other code never reads the ledger's fields.

00:02:31.338 --> 00:02:34.671
It uses the ledger's selectors, small read-only methods such

00:02:34.684 --> 00:02:35.791
as total and owner.

00:02:36.689 --> 00:02:40.035
Endpoints call them through the root, just as the Shop's endpoints

00:02:40.048 --> 00:02:40.895
called tax.

