linera-execution 0.15.17

Persistent data and the corresponding logics used by the Linera protocol for runtime and execution of smart contracts / applications.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "./LineraTypes.sol";

// The "LineraTypes.sol" is created via the command
// cargo run -p serde-generate-bin -- --language solidity LineraTypes.yaml > LineraTypes.sol
// from the package "serde-reflection" commit 95e57c4c2df2fc7215e627da353071a2cb91fdcb

// This library provides Linera functionalities to EVM contracts
// It should not be modified.

library Linera {

    // Exported types

    struct ChainId {
        bytes32 value;
    }

    function chainid_from(LineraTypes.ChainId memory entry)
        internal
        pure
        returns (ChainId memory)
    {
        return ChainId(entry.value.value);
    }

    struct AccountOwner {
        uint8 choice;
        // choice=0 corresponds to Reserved
        uint8 reserved;
        // choice=1 corresponds to Address32
        bytes32 address32;
        // choice=2 corresponds to Address20
        bytes20 address20;
    }

    function accountowner_from(LineraTypes.AccountOwner memory owner)
        internal
        pure
        returns (AccountOwner memory)
    {
        return AccountOwner(owner.choice, owner.reserved, owner.address32.value, owner.address20);
    }

    function accountowner_to(Linera.AccountOwner memory owner)
        internal
        pure
        returns (LineraTypes.AccountOwner memory)
    {
        LineraTypes.CryptoHash memory hash = LineraTypes.CryptoHash(owner.address32);
        return LineraTypes.AccountOwner(owner.choice, owner.reserved, hash, owner.address20);
    }

    struct AccountOwnerBalance {
        AccountOwner account_owner;
        uint256 balance;
    }

    function accountownerbalance_from(LineraTypes.AccountOwnerBalanceInner memory entry)
        internal
        pure
        returns (AccountOwnerBalance memory)
    {
        uint256 balance = uint256(entry.balance_.value);
        AccountOwner memory account_owner = accountowner_from(entry.account_owner);
        return AccountOwnerBalance(account_owner, balance);
    }

    struct TimeDelta {
        uint64 value;
    }

    function timedelta_from(LineraTypes.TimeDelta memory entry)
        internal
        pure
        returns (TimeDelta memory)
    {
        return TimeDelta(entry.value);
    }

    struct opt_TimeDelta {
        bool has_value;
        uint64 value;
    }

    function opt_timedelta_from(LineraTypes.opt_TimeDelta memory entry)
        internal
        pure
        returns (opt_TimeDelta memory)
    {
        return opt_TimeDelta(entry.has_value, entry.value.value);
    }

    struct TimeoutConfig {
        opt_TimeDelta fast_round_duration;
        TimeDelta base_timeout;
        TimeDelta timeout_increment;
        TimeDelta fallback_duration;
    }

    function timeoutconfig_from(LineraTypes.TimeoutConfig memory entry)
        internal
        pure
        returns (TimeoutConfig memory)
    {
        return TimeoutConfig(opt_timedelta_from(entry.fast_round_duration),
                             timedelta_from(entry.base_timeout),
                             timedelta_from(entry.timeout_increment),
                             timedelta_from(entry.fallback_duration));
    }

    struct AccountOwnerWeight {
        Linera.AccountOwner account_owner;
        uint64 weight;
    }

    function accountownerweight_from(LineraTypes.key_values_AccountOwner_uint64 memory entry)
        internal
        pure
        returns (AccountOwnerWeight memory)
    {
        return AccountOwnerWeight(accountowner_from(entry.key), entry.value);
    }

    struct ChainOwnership {
        AccountOwner[] super_owners;
        AccountOwnerWeight[] owners;
        uint32 multi_leader_rounds;
        bool open_multi_leader_rounds;
        TimeoutConfig timeout_config;
    }

    function chainownership_from(LineraTypes.ChainOwnership memory entry)
        internal
        pure
        returns (ChainOwnership memory)
    {
        uint256 len1 = entry.super_owners.length;
        AccountOwner[] memory super_owners;
        super_owners = new AccountOwner[](len1);
        for (uint256 i=0; i<len1; i++) {
            super_owners[i] = accountowner_from(entry.super_owners[i]);
        }
        uint256 len2 = entry.owners.length;
        AccountOwnerWeight[] memory owners;
        owners = new AccountOwnerWeight[](len2);
        for (uint256 i=0; i<len2; i++) {
            owners[i] = accountownerweight_from(entry.owners[i]);
        }
        return ChainOwnership(super_owners, owners, entry.multi_leader_rounds, entry.open_multi_leader_rounds, timeoutconfig_from(entry.timeout_config));
    }

    struct opt_uint32 {
        bool has_value;
        uint32 value;
    }

    function opt_uint32_from(LineraTypes.opt_uint32 memory entry)
        internal
        pure
        returns (opt_uint32 memory)
    {
        return opt_uint32(entry.has_value, entry.value);
    }

    struct ApplicationId {
        bytes32 application_description_hash;
    }

    function applicationid_from(LineraTypes.ApplicationId memory entry)
        internal
        pure
        returns (ApplicationId memory)
    {
        return ApplicationId(entry.application_description_hash.value);
    }

    struct opt_ApplicationId {
        bool has_value;
        ApplicationId value;
    }

    function opt_applicationid_from(LineraTypes.opt_ApplicationId memory entry)
        internal
        pure
        returns (opt_ApplicationId memory)
    {
        return opt_ApplicationId(entry.has_value, applicationid_from(entry.value));
    }

    struct opt_AccountOwner {
        bool has_value;
        AccountOwner value;
    }

    struct opt_ChainId {
        bool has_value;
        ChainId value;
    }

    function opt_accountowner_from(LineraTypes.opt_AccountOwner memory entry)
        internal
        pure
        returns (opt_AccountOwner memory)
    {
        return opt_AccountOwner(entry.has_value, accountowner_from(entry.value));
    }

    function opt_chainid_from(LineraTypes.opt_ChainId memory entry)
        internal
        pure
        returns (opt_ChainId memory)
    {
        return opt_ChainId(entry.has_value, chainid_from(entry.value));
    }

    function opt_chainid_none()
        internal
        pure
        returns (opt_ChainId memory)
    {
        return opt_ChainId(false, ChainId(bytes32(0)));
    }

    enum OptionBool { None, True, False }

    function optionbool_from(LineraTypes.MessageIsBouncing memory entry)
        internal
        pure
        returns (OptionBool)
    {
        if (entry.value == LineraTypes.OptionBool.True) {
            return OptionBool.True;
        }
        if (entry.value == LineraTypes.OptionBool.False) {
            return OptionBool.False;
        }
        return OptionBool.None;
    }



    struct StreamUpdate {
        ChainId chain_id;
        StreamId stream_id;
        uint32 previous_index;
        uint32 next_index;
    }

    struct StreamId {
        GenericApplicationId application_id;
        StreamName stream_name;
    }

    struct StreamName {
        bytes value;
    }

    struct GenericApplicationId {
        uint8 choice;
        // choice=0 corresponds to System
        // choice=1 corresponds to User
        ApplicationId user;
    }

    // BaseRuntime functions

    function chain_id() internal returns (Linera.ChainId memory) {
        address precompile = address(0x0b);
        LineraTypes.BaseRuntimePrecompile memory base = LineraTypes.BaseRuntimePrecompile_case_chain_id();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_base(base);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output1) = precompile.call(input2);
        require(success);
        LineraTypes.ChainId memory output2 = LineraTypes.bcs_deserialize_ChainId(output1);
        return chainid_from(output2);
    }

    function block_height() internal returns (uint64) {
        address precompile = address(0x0b);
        LineraTypes.BaseRuntimePrecompile memory base = LineraTypes.BaseRuntimePrecompile_case_block_height();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_base(base);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        LineraTypes.BlockHeight memory output2 = LineraTypes.bcs_deserialize_BlockHeight(output);
        return output2.value;
    }

    function application_creator_chain_id() internal returns (ChainId memory) {
        address precompile = address(0x0b);
        LineraTypes.BaseRuntimePrecompile memory base = LineraTypes.BaseRuntimePrecompile_case_application_creator_chain_id();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_base(base);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output1) = precompile.call(input2);
        require(success);
        LineraTypes.ChainId memory output2 = LineraTypes.bcs_deserialize_ChainId(output1);
        return ChainId(output2.value.value);
    }

    function read_system_timestamp() internal returns (uint64) {
        address precompile = address(0x0b);
        LineraTypes.BaseRuntimePrecompile memory base = LineraTypes.BaseRuntimePrecompile_case_read_system_timestamp();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_base(base);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        LineraTypes.Timestamp memory output2 = LineraTypes.bcs_deserialize_Timestamp(output);
        return output2.value;
    }

    function read_chain_balance() internal returns (uint256) {
        address precompile = address(0x0b);
        LineraTypes.BaseRuntimePrecompile memory base = LineraTypes.BaseRuntimePrecompile_case_read_chain_balance();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_base(base);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        LineraTypes.Amount memory output2 = LineraTypes.bcs_deserialize_Amount(output);
        return uint256(output2.value);
    }

    function read_owner_balance(Linera.AccountOwner memory owner) internal returns (uint256) {
        address precompile = address(0x0b);
        LineraTypes.AccountOwner memory owner2 = accountowner_to(owner);
        LineraTypes.BaseRuntimePrecompile memory base = LineraTypes.BaseRuntimePrecompile_case_read_owner_balance(owner2);
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_base(base);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        LineraTypes.Amount memory output2 = LineraTypes.bcs_deserialize_Amount(output);
        return uint256(output2.value);
    }

    function read_owner_balances() internal returns (Linera.AccountOwnerBalance[] memory) {
        address precompile = address(0x0b);
        LineraTypes.BaseRuntimePrecompile memory base = LineraTypes.BaseRuntimePrecompile_case_read_owner_balances();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_base(base);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        LineraTypes.ResponseReadOwnerBalances memory output2 = LineraTypes.bcs_deserialize_ResponseReadOwnerBalances(output);
        uint256 len = output2.value.length;
        Linera.AccountOwnerBalance[] memory elist;
        elist = new Linera.AccountOwnerBalance[](len);
        for (uint256 i=0; i<len; i++) {
            elist[i] = accountownerbalance_from(output2.value[i]);
        }
        return elist;
    }

    function read_balance_owners() internal returns (Linera.AccountOwner[] memory result) {
        address precompile = address(0x0b);
        LineraTypes.BaseRuntimePrecompile memory base = LineraTypes.BaseRuntimePrecompile_case_read_balance_owners();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_base(base);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output1) = precompile.call(input2);
        require(success);
        LineraTypes.ResponseReadBalanceOwners memory output2 = LineraTypes.bcs_deserialize_ResponseReadBalanceOwners(output1);
        uint256 len = output2.value.length;
        Linera.AccountOwner[] memory elist;
        elist = new Linera.AccountOwner[](len);
        for (uint256 i=0; i<len; i++) {
            elist[i] = accountowner_from(output2.value[i]);
        }
        return elist;
    }

    function chain_ownership() internal returns (Linera.ChainOwnership memory) {
        address precompile = address(0x0b);
        LineraTypes.BaseRuntimePrecompile memory base = LineraTypes.BaseRuntimePrecompile_case_chain_ownership();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_base(base);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output1) = precompile.call(input2);
        require(success);
        LineraTypes.ChainOwnership memory output2 = LineraTypes.bcs_deserialize_ChainOwnership(output1);
        return chainownership_from(output2);
    }

    function read_data_blob(bytes32 hash) internal returns (bytes memory) {
        address precompile = address(0x0b);
        LineraTypes.CryptoHash memory hash2 = LineraTypes.CryptoHash(hash);
        LineraTypes.DataBlobHash memory hash3 = LineraTypes.DataBlobHash(hash2);
        LineraTypes.BaseRuntimePrecompile memory base = LineraTypes.BaseRuntimePrecompile_case_read_data_blob(hash3);
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_base(base);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        return output;
    }

    function assert_data_blob_exists(bytes32 hash) internal {
        address precompile = address(0x0b);
        LineraTypes.CryptoHash memory hash2 = LineraTypes.CryptoHash(hash);
        LineraTypes.DataBlobHash memory hash3 = LineraTypes.DataBlobHash(hash2);
        LineraTypes.BaseRuntimePrecompile memory base = LineraTypes.BaseRuntimePrecompile_case_assert_data_blob_exists(hash3);
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_base(base);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        assert(output.length == 0);
    }

    // ContractRuntime functions

    function authenticated_signer() internal returns (Linera.opt_AccountOwner memory) {
        address precompile = address(0x0b);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_authenticated_signer();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output1) = precompile.call(input2);
        require(success);
        LineraTypes.opt_AccountOwner memory output2 = LineraTypes.bcs_deserialize_opt_AccountOwner(output1);
        return opt_accountowner_from(output2);
    }

    function message_origin_chain_id() internal returns (opt_ChainId memory) {
        address precompile = address(0x0b);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_message_origin_chain_id();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output1) = precompile.call(input2);
        require(success);
        LineraTypes.opt_ChainId memory output2 = LineraTypes.bcs_deserialize_opt_ChainId(output1);
        return opt_chainid_from(output2);
    }

    function message_is_bouncing() internal returns (OptionBool) {
        address precompile = address(0x0b);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_message_is_bouncing();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output1) = precompile.call(input2);
        require(success);
        LineraTypes.MessageIsBouncing memory output2 = LineraTypes.bcs_deserialize_MessageIsBouncing(output1);
        return optionbool_from(output2);
    }

    function authenticated_caller_id() internal returns (Linera.opt_ApplicationId memory) {
        address precompile = address(0x0b);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_authenticated_caller_id();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output1) = precompile.call(input2);
        require(success);
        LineraTypes.opt_ApplicationId memory output2 = LineraTypes.bcs_deserialize_opt_ApplicationId(output1);
        return opt_applicationid_from(output2);
    }

    function send_message(bytes32 chain_id1, bytes memory message) internal {
        address precompile = address(0x0b);
        LineraTypes.ChainId memory chain_id2 = LineraTypes.ChainId(LineraTypes.CryptoHash(chain_id1));
        LineraTypes.ContractRuntimePrecompile_TryCallApplication memory try_call_application_;
        LineraTypes.ContractRuntimePrecompile_SendMessage memory send_message_ = LineraTypes.ContractRuntimePrecompile_SendMessage(chain_id2, message);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_send_message(send_message_);
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        require(output.length == 0);
    }

    function try_call_application(bytes32 universal_address, bytes memory operation) internal returns (bytes memory) {
        address precompile = address(0x0b);
        LineraTypes.ApplicationId memory target = LineraTypes.ApplicationId(LineraTypes.CryptoHash(universal_address));
        LineraTypes.ContractRuntimePrecompile_TryCallApplication memory try_call_application_ = LineraTypes.ContractRuntimePrecompile_TryCallApplication(target, operation);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_try_call_application(try_call_application_);
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        return output;
    }

    function linera_emit(bytes memory stream_name, bytes memory value) internal returns (uint32) {
        address precompile = address(0x0b);
        LineraTypes.StreamName memory stream_name2 = LineraTypes.StreamName(stream_name);
        LineraTypes.ContractRuntimePrecompile_Emit memory emit_ = LineraTypes.ContractRuntimePrecompile_Emit(stream_name2, value);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_emit(emit_);
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        return LineraTypes.bcs_deserialize_uint32(output);
    }

    function read_event(bytes32 chain_id1, bytes memory stream_name, uint32 index) internal returns (bytes memory) {
        address precompile = address(0x0b);
        LineraTypes.ChainId memory chain_id2 = LineraTypes.ChainId(LineraTypes.CryptoHash(chain_id1));
        LineraTypes.StreamName memory stream_name2 = LineraTypes.StreamName(stream_name);
        LineraTypes.ContractRuntimePrecompile_ReadEvent memory read_event_ = LineraTypes.ContractRuntimePrecompile_ReadEvent(chain_id2, stream_name2, index);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_read_event(read_event_);
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        return output;
    }

    function subscribe_to_events(bytes32 chain_id1, bytes32 subscribed_application_id, bytes memory stream_name) internal {
        address precompile = address(0x0b);
        LineraTypes.ChainId memory chain_id2 = LineraTypes.ChainId(LineraTypes.CryptoHash(chain_id1));
        LineraTypes.ApplicationId memory application_id2 = LineraTypes.ApplicationId(LineraTypes.CryptoHash(subscribed_application_id));
        LineraTypes.StreamName memory stream_name2 = LineraTypes.StreamName(stream_name);
        LineraTypes.ContractRuntimePrecompile_SubscribeToEvents memory subscribe_to_events_ = LineraTypes.ContractRuntimePrecompile_SubscribeToEvents(chain_id2, application_id2, stream_name2);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_subscribe_to_events(subscribe_to_events_);
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        require(output.length == 0);
    }

    function unsubscribe_from_events(bytes32 chain_id1, bytes32 unsubscribe_application_id, bytes memory stream_name) internal {
        address precompile = address(0x0b);
        LineraTypes.ChainId memory chain_id2 = LineraTypes.ChainId(LineraTypes.CryptoHash(chain_id1));
        LineraTypes.ApplicationId memory application_id2 = LineraTypes.ApplicationId(LineraTypes.CryptoHash(unsubscribe_application_id));
        LineraTypes.StreamName memory stream_name2 = LineraTypes.StreamName(stream_name);
        LineraTypes.ContractRuntimePrecompile_UnsubscribeFromEvents memory unsubscribe_from_events_ = LineraTypes.ContractRuntimePrecompile_UnsubscribeFromEvents(chain_id2, application_id2, stream_name2);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_unsubscribe_from_events(unsubscribe_from_events_);
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        require(output.length == 0);
    }

    function query_service(bytes32 universal_address, bytes memory query) internal returns (bytes memory) {
        address precompile = address(0x0b);
        LineraTypes.ApplicationId memory target = LineraTypes.ApplicationId(LineraTypes.CryptoHash(universal_address));
        LineraTypes.ContractRuntimePrecompile_QueryService memory query_service_ = LineraTypes.ContractRuntimePrecompile_QueryService(target, query);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_query_service(query_service_);
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        return output;
    }

    function validation_round() internal returns (Linera.opt_uint32 memory) {
        address precompile = address(0x0b);
        LineraTypes.ContractRuntimePrecompile memory contract_ = LineraTypes.ContractRuntimePrecompile_case_validation_round();
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_contract(contract_);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        LineraTypes.opt_uint32 memory output2 = LineraTypes.bcs_deserialize_opt_uint32(output);
        return opt_uint32_from(output2);
    }

    // ServiceRuntime functions.

    function try_query_application(bytes32 universal_address, bytes memory argument) internal returns (bytes memory) {
        address precompile = address(0x0b);
        LineraTypes.ApplicationId memory target = LineraTypes.ApplicationId(LineraTypes.CryptoHash(universal_address));
        LineraTypes.ServiceRuntimePrecompile_TryQueryApplication memory try_query_application_ = LineraTypes.ServiceRuntimePrecompile_TryQueryApplication(target, argument);
        LineraTypes.ServiceRuntimePrecompile memory service = LineraTypes.ServiceRuntimePrecompile_case_try_query_application(try_query_application_);
        LineraTypes.RuntimePrecompile memory input1 = LineraTypes.RuntimePrecompile_case_service(service);
        bytes memory input2 = LineraTypes.bcs_serialize_RuntimePrecompile(input1);
        (bool success, bytes memory output) = precompile.call(input2);
        require(success);
        return output;
    }
}