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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
//! Contains low-level bindings for host-side ("external") functions.
//!
//! Generally should not be used directly.  See the [`contract_api`](crate::contract_api) for
//! high-level bindings suitable for writing smart contracts.
extern "C" {
    /// The bytes in the span of wasm memory from `key_ptr` to `key_ptr + key_size` must correspond
    /// to a valid global state key, otherwise the function will fail. If the key is de-serialized
    /// successfully, then the result of the read is serialized and buffered in the runtime. This
    /// result can be obtained via the [`read_host_buffer`] function. Returns standard error code.
    ///
    /// # Arguments
    ///
    /// * `key_ptr` - pointer (offset in wasm linear memory) to serialized form of the key to read
    /// * `key_size` - size of the serialized key (in bytes)
    /// * `output_size` - pointer to a value where host will write size of bytes read from given key
    pub fn read_value(key_ptr: *const u8, key_size: usize, output_size: *mut usize) -> i32;
    /// The bytes in wasm memory from offset `key_ptr` to `key_ptr + key_size`
    /// will be used together with the current context’s seed to form a local key.
    /// The value at that local key is read from the global state, serialized and
    /// buffered in the runtime. This result can be obtained via the [`read_host_buffer`]
    /// function.
    ///
    /// # Arguments
    ///
    /// * `key_ptr` - pointer to bytes representing the user-defined key
    /// * `key_size` - size of the key (in bytes)
    /// * `output_size` - pointer to a value where host will write size of bytes read from given key
    pub fn read_value_local(key_ptr: *const u8, key_size: usize, output_size: *mut usize) -> i32;
    /// This function writes the provided value (read via de-serializing the bytes
    /// in wasm memory from offset `value_ptr` to `value_ptr + value_size`) under
    /// the provided key (read via de-serializing the bytes in wasm memory from
    /// offset `key_ptr` to `key_ptr + key_size`) in the global state. This
    /// function will cause a `Trap` if the key or value fail to de-serialize or
    /// if writing to that key is not permitted.
    ///
    /// # Arguments
    ///
    /// * `key_ptr` - pointer to bytes representing the key to write to
    /// * `key_size` - size of the key (in bytes)
    /// * `value_ptr` - pointer to bytes representing the value to write at the key
    /// * `value_size` - size of the value (in bytes)
    pub fn write(key_ptr: *const u8, key_size: usize, value_ptr: *const u8, value_size: usize);

    /// The bytes in wasm memory from offset `key_ptr` to `key_ptr + key_size`
    /// will be used together with the current context’s seed to form a local key.
    /// This function writes the provided value (read via de-serializing the bytes
    /// in wasm memory from offset `value_ptr` to `value_ptr + value_size`) under
    /// that local key in the global state. This function will cause a `Trap` if
    /// the value fails to de-serialize.
    ///
    /// # Arguments
    ///
    /// * `key_ptr` - pointer to bytes representing the user-defined key to write to
    /// * `key_size` - size of the key (in bytes)
    /// * `value_ptr` - pointer to bytes representing the value to write at the key
    /// * `value_size` - size of the value (in bytes)
    pub fn write_local(
        key_ptr: *const u8,
        key_size: usize,
        value_ptr: *const u8,
        value_size: usize,
    );
    /// This function adds the provided value (read via de-serializing the bytes
    /// in wasm memory from offset `value_ptr` to `value_ptr + value_size`) to the
    /// current value under the provided key (read via de-serializing the bytes in
    /// wasm memory from offset `key_ptr` to `key_ptr + key_size`) in the global
    /// state. This function will cause a `Trap` if the key or value fail to
    /// de-serialize or if adding to that key is not permitted, or no value
    /// presently exists at that key.
    ///
    /// # Arguments
    ///
    /// * `key_ptr` - pointer to bytes representing the key to write to
    /// * `key_size` - size of the key (in bytes)
    /// * `value_ptr` - pointer to bytes representing the value to write at the key
    /// * `value_size` - size of the value (in bytes)
    pub fn add(key_ptr: *const u8, key_size: usize, value_ptr: *const u8, value_size: usize);
    ///
    pub fn add_local(key_ptr: *const u8, key_size: usize, value_ptr: *const u8, value_size: usize);
    /// This function causes the runtime to generate a new [`casperlabs_types::uref::URef`], with
    /// the provided value stored under it in the global state. The new
    /// [`casperlabs_types::uref::URef`] is written (in serialized form) to the wasm linear
    /// memory starting from the `key_ptr` offset. Note that data corruption is possible if not
    /// enough memory is allocated for the [`casperlabs_types::uref::URef`] at `key_ptr`. This
    /// function will cause a `Trap` if the bytes in wasm memory from offset `value_ptr` to
    /// `value_ptr + value_size` cannot be de-serialized into a `Value`.
    ///
    /// # Arguments
    ///
    /// * `key_ptr` - pointer to the offset in wasm memory where the new
    ///   [`casperlabs_types::uref::URef`] will be written
    /// * `value_ptr` - pointer to bytes representing the value to write under the new
    ///   [`casperlabs_types::uref::URef`]
    /// * `value_size` - size of the value (in bytes)
    pub fn new_uref(uref_ptr: *mut u8, value_ptr: *const u8, value_size: usize);
    ///
    pub fn load_named_keys(total_keys: *mut usize, result_size: *mut usize) -> i32;
    /// This function causes a `Trap`, terminating the currently running module,
    /// but first copies the bytes from `value_ptr` to `value_ptr + value_size` to
    /// a buffer which is returned to the calling module (if this module was
    /// invoked by [`call_contract`] or [`call_versioned_contract`]). Additionally, the known
    /// [`casperlabs_types::uref::URef`]s of the calling context are augmented with the
    /// [`casperlabs_types::uref::URef`]s de-serialized from wasm memory offset
    /// `extra_urefs_ptr` to `extra_urefs_ptr + extra_urefs_size`. This function will cause a
    /// `Trap` if the bytes at `extra_urefs_ptr` cannot be de-serialized as type `Vec<URef>`, or
    /// if any of the extra [`casperlabs_types::uref::URef`]s are invalid in the current
    /// context.
    ///
    /// # Arguments
    ///
    /// * `value_ptr`: pointer to bytes representing the value to return to the caller
    /// * `value_size`: size of the value (in bytes)
    pub fn ret(value_ptr: *const u8, value_size: usize) -> !;
    ///
    pub fn get_key(
        name_ptr: *const u8,
        name_size: usize,
        output_ptr: *mut u8,
        output_size: usize,
        bytes_written_ptr: *mut usize,
    ) -> i32;
    ///
    pub fn has_key(name_ptr: *const u8, name_size: usize) -> i32;
    ///
    pub fn put_key(name_ptr: *const u8, name_size: usize, key_ptr: *const u8, key_size: usize);
    ///
    pub fn remove_key(name_ptr: *const u8, name_size: usize);
    /// This function causes a `Trap` which terminates the currently running
    /// module. Additionally, it signals that the current entire phase of
    /// execution of the deploy should be terminated as well, and that the effects
    /// of the execution up to this point should be reverted. The error code
    /// provided to this function will be included in the error message of the
    /// deploy in the block in which it is included.
    ///
    /// # Arguments
    ///
    /// * `status` - error code of the revert
    pub fn revert(status: u32) -> !;
    /// This function checks if all the keys contained in the given `Value` are
    /// valid in the current context (i.e. the `Value` does not contain any forged
    /// [`casperlabs_types::uref::URef`]s). This function causes a `Trap` if the bytes in wasm
    /// memory from offset `value_ptr` to `value_ptr + value_size` cannot be de-serialized as
    /// type `Value`.
    pub fn is_valid_uref(uref_ptr: *const u8, uref_size: usize) -> i32;
    /// This function attempts to add the given public key as an associated key to
    /// the current account. Presently only 32-byte keys are supported; it is up
    /// to the caller to ensure that the 32-bytes starting from offset
    /// `public_key` represent the key they wish to add. Weights are internally
    /// represented by a `u8`, this function will cause a `Trap` if the weight is
    /// not between 0 and 255 inclusively. The result returned is a status code
    /// for adding the key where 0 represents success, 1 means no more keys can be
    /// added to this account (only 10 keys can be added), 2 means the key is
    /// already associated (if you wish to change the weight of an associated key
    /// then used [`update_associated_key`]), and 3 means permission denied (this
    /// could be because the function was called outside of session code or
    /// because the key management threshold was not met by the keys authorizing
    /// the deploy).
    ///
    /// Returns status code for adding the key, where 0 represents success and non-zero represents
    /// failure.
    ///
    /// # Arguments
    ///
    /// * `public_key` - pointer to the bytes in wasm memory representing the public key to add,
    ///   presently only 32-byte public keys are supported.
    /// * `weight` - the weight to assign to this public key
    pub fn add_associated_key(
        account_hash_ptr: *const u8,
        account_hash_size: usize,
        weight: i32,
    ) -> i32;
    /// This function attempts to remove the given public key from the associated
    /// keys of the current account. Presently only 32-byte keys are supported; it
    /// is up to the caller to ensure that the 32-bytes starting from offset
    /// `public_key` represent the key they wish to remove. The result returned is
    /// a status code for adding the key where 0 represents success, 1 means the
    /// key was not associated to begin with, 2 means means permission denied
    /// (this could be because the function was called outside of session code or
    /// because the key management threshold was not met by the keys authorizing
    /// the deploy), and 3 means this key cannot be removed because otherwise it
    /// would be impossible to meet either the deploy or key management
    /// thresholds.
    ///
    /// Returns status code for adding the key, where 0 represents success and non-zero represents
    /// failure.
    ///
    /// # Arguments
    ///
    /// * `public_key` - pointer to the bytes in wasm memory representing the public key to update,
    ///   presently only 32-byte public keys are supported.
    /// * `weight` - the weight to assign to this public key
    pub fn remove_associated_key(account_hash_ptr: *const u8, account_hash_size: usize) -> i32;
    /// This function attempts to update the given public key as an associated key
    /// to the current account. Presently only 32-byte keys are supported; it is
    /// up to the caller to ensure that the 32-bytes starting from offset
    /// `public_key` represent the key they wish to add. Weights are internally
    /// represented by a `u8`, this function will cause a `Trap` if the weight is
    /// not between 0 and 255 inclusively. The result returned is a status code
    /// for adding the key where 0 represents success, 1 means the key was not
    /// associated to the account (to add a new key use `add_associated_key`), 2
    /// means means permission denied (this could be because the function was
    /// called outside of session code or because the key management threshold was
    /// not met by the keys authorizing the deploy), and 3 means this key cannot
    /// be changed to the specified weight because then it would be impossible to
    /// meet either the deploy or key management thresholds (you may wish to try
    /// again with a higher weight or after lowering the action thresholds).
    ///
    /// # Arguments
    ///
    /// * `public_key` - pointer to the bytes in wasm memory representing the
    ///  public key to update, presently only 32-byte public keys are supported
    /// * `weight` - the weight to assign to this public key
    pub fn update_associated_key(
        account_hash_ptr: *const u8,
        account_hash_size: usize,
        weight: i32,
    ) -> i32;
    /// This function changes the threshold to perform the specified action. The
    /// action index is interpreted as follows: 0 means deployment and 1 means key
    /// management. Thresholds are represented internally as a `u8`, this function
    /// will cause a `Trap` if the new threshold is not between 0 and 255
    /// inclusively. The return value is a status code where 0 means success, 1
    /// means the key management threshold cannot be set lower than the deploy
    /// threshold, 2 means the deployment threshold cannot be set higher than the
    /// key management threshold, 3 means permission denied (this could be because
    /// the function was called outside of session code or because the key
    /// management threshold was not met by the keys authorizing the deploy), and
    /// 4 means the threshold would be set higher than the total weight of
    /// associated keys (and therefore would be impossible to meet).
    ///
    /// # Arguments
    ///
    /// * `action` - index representing the action threshold to set
    /// * `threshold` - new value of the threshold for performing this action
    pub fn set_action_threshold(permission_level: u32, threshold: u32) -> i32;
    /// This function returns the public key of the account for this deploy. The
    /// result is always 36-bytes in length (4 bytes prefix on a 32-byte public
    /// key); it is up to the caller to ensure the right amount of memory is
    /// allocated at `dest_ptr`, data corruption in the wasm memory could occur
    /// otherwise.
    ///
    /// # Arguments
    ///
    /// * `dest_ptr` - pointer to position in wasm memory where to write the result
    pub fn get_caller(output_size: *mut usize) -> i32;
    /// This function gets the timestamp which will be in the block this deploy is
    /// included in. The return value is always a 64-bit unsigned integer,
    /// representing the number of milliseconds since the Unix epoch. It is up to
    /// the caller to ensure there are 8 bytes allocated at `dest_ptr`, otherwise
    /// data corruption in the wasm memory may occur.
    ///
    /// # Arguments
    ///
    /// * `dest_ptr` - pointer in wasm memory where to write the result
    pub fn get_blocktime(dest_ptr: *const u8);
    /// This function uses the mint contract to create a new, empty purse. If the
    /// call is successful then the [`casperlabs_types::uref::URef`] (in serialized form) is written
    /// to the indicated place in wasm memory. It is up to the caller to ensure at
    /// least `purse_size` bytes are allocated at `purse_ptr`, otherwise
    /// data corruption may occur. This function causes a `Trap` if
    /// `purse_size` is not equal to 38.
    ///
    /// # Arguments
    ///
    /// * `purse_ptr` - pointer to position in wasm memory where to write the created
    ///   [`casperlabs_types::uref::URef`]
    /// * `purse_size` - allocated size for the [`casperlabs_types::uref::URef`]
    pub fn create_purse(purse_ptr: *const u8, purse_size: usize) -> i32;
    /// This function uses the mint contract’s transfer function to transfer
    /// tokens from the current account’s main purse to the main purse of the
    /// target account. If the target account does not exist then it is
    /// automatically created, and the tokens are transferred to the main purse of
    /// the new account. The target is a serialized `PublicKey` (i.e. 36 bytes
    /// where the first 4 bytes are the number `32` in little endian encoding, and
    /// the remaining 32-bytes are the public key). The amount must be a
    /// serialized 512-bit unsigned integer. This function causes a `Trap` if the
    /// target cannot be de-serialized as a `PublicKey` or the amount cannot be
    /// de-serialized into a `U512`. The return value indicated what occurred,
    /// where 0 means a successful transfer to an existing account, 1 means a
    /// successful transfer to a new account, and 2 means the transfer failed
    /// (this could be because the current account’s main purse had insufficient
    /// tokens or because the function was called outside of session code and so
    /// does not have access to the account’s main purse).
    ///
    /// # Arguments
    ///
    /// * `target_ptr` - pointer in wasm memory to bytes representing the target account to transfer
    ///   to
    /// * `target_size` - size of the target (in bytes)
    /// * `amount_ptr` - pointer in wasm memory to bytes representing the amount to transfer to the
    ///   target account
    /// * `amount_size` - size of the amount (in bytes)
    pub fn transfer_to_account(
        target_ptr: *const u8,
        target_size: usize,
        amount_ptr: *const u8,
        amount_size: usize,
    ) -> i32;
    /// This function uses the mint contract’s transfer function to transfer
    /// tokens from the specified purse to the main purse of the target account.
    /// If the target account does not exist then it is automatically created, and
    /// the tokens are transferred to the main purse of the new account. The
    /// source is a serialized [`casperlabs_types::uref::URef`].
    /// The target is a serialized `PublicKey` (i.e. 36 bytes where the
    /// first 4 bytes are the number `32` in little endian encoding, and the
    /// remaining 32-bytes are the public key). The amount must be a serialized
    /// 512-bit unsigned integer. This function causes a `Trap` if the source
    /// cannot be de-serialized as a [`casperlabs_types::uref::URef`], or the target cannot be
    /// de-serialized as a `PublicKey` or the amount cannot be de-serialized into
    /// a `U512`. The return value indicated what occurred, where 0 means a
    /// successful transfer to an existing account, 1 means a successful transfer
    /// to a new account, and 2 means the transfer failed (this could be because
    /// the source purse had insufficient tokens or because there was not valid
    /// access to the source purse).
    ///
    /// # Arguments
    ///
    /// * `source_ptr` - pointer in wasm memory to bytes representing the source
    ///   [`casperlabs_types::uref::URef`] to transfer from
    /// * `source_size` - size of the source [`casperlabs_types::uref::URef`] (in bytes)
    /// * `target_ptr` - pointer in wasm memory to bytes representing the target account to transfer
    ///   to
    /// * `target_size` - size of the target (in bytes)
    /// * `amount_ptr` - pointer in wasm memory to bytes representing the amount to transfer to the
    ///   target account
    /// * `amount_size` - size of the amount (in bytes)
    pub fn transfer_from_purse_to_account(
        source_ptr: *const u8,
        source_size: usize,
        target_ptr: *const u8,
        target_size: usize,
        amount_ptr: *const u8,
        amount_size: usize,
    ) -> i32;
    /// This function uses the mint contract’s transfer function to transfer
    /// tokens from the specified source purse to the specified target purse. If
    /// the target account does not exist then it is automatically created, and
    /// the tokens are transferred to the main purse of the new account. The
    /// source is a serialized [`casperlabs_types::uref::URef`].
    /// The target is also a serialized [`casperlabs_types::uref::URef`]. The amount must be a
    /// serialized 512-bit unsigned integer. This function causes a `Trap` if the
    /// source or target cannot be de-serialized as a [`casperlabs_types::uref::URef`] or the amount
    /// cannot be de-serialized into a `U512`. The return value indicated what
    /// occurred, where 0 means a successful transfer, 1 means the transfer
    /// failed (this could be because the source purse had insufficient tokens or
    /// because there was not valid access to the source purse or target purse).
    ///
    /// # Arguments
    ///
    /// * `source_ptr` - pointer in wasm memory to bytes representing the source
    ///   [`casperlabs_types::uref::URef`] to transfer from
    /// * `source_size` - size of the source [`casperlabs_types::uref::URef`] (in bytes)
    /// * `target_ptr` - pointer in wasm memory to bytes representing the target
    ///   [`casperlabs_types::uref::URef`] to transfer to
    /// * `target_size` - size of the target (in bytes)
    /// * `amount_ptr` - pointer in wasm memory to bytes representing the amount to transfer to the
    ///   target account
    /// * `amount_size` - size of the amount (in bytes)
    pub fn transfer_from_purse_to_purse(
        source_ptr: *const u8,
        source_size: usize,
        target_ptr: *const u8,
        target_size: usize,
        amount_ptr: *const u8,
        amount_size: usize,
    ) -> i32;
    /// This function uses the mint contract's balance function to get the balance
    /// of the specified purse. It causes a `Trap` if the bytes in wasm memory
    /// from `purse_ptr` to `purse_ptr + purse_size` cannot be
    /// de-serialized as a [`casperlabs_types::uref::URef`]. The return value is the size of the
    /// result in bytes. The result is copied to the host buffer and thus can be obtained
    /// by any function which copies the buffer into wasm memory (e.g.
    /// `get_read`). The result bytes are serialized from type `Option<U512>` and
    /// should be interpreted as such.
    ///
    /// # Arguments
    ///
    /// * `purse_ptr` - pointer in wasm memory to the bytes representing the
    ///   [`casperlabs_types::uref::URef`] of the purse to get the balance of
    /// * `purse_size` - size of the [`casperlabs_types::uref::URef`] (in bytes)
    pub fn get_balance(purse_ptr: *const u8, purse_size: usize, result_size: *mut usize) -> i32;
    /// This function writes bytes representing the current phase of the deploy
    /// execution to the specified pointer. The size of the result is always one
    /// byte, it is up to the caller to ensure one byte of memory is allocated at
    /// `dest_ptr`, otherwise data corruption in the wasm memory could occur. The
    /// one byte is interpreted as follows: 0 means a system phase (should never
    /// be encountered by user deploys), 1 means the payment phase, 2 means the
    /// session phase and 3 means the finalization phase (should never be
    /// encountered by user code).
    ///
    /// # Arguments
    ///
    /// * `dest_ptr` - pointer to position in wasm memory to write the result
    pub fn get_phase(dest_ptr: *mut u8);
    ///
    pub fn get_system_contract(
        system_contract_index: u32,
        dest_ptr: *mut u8,
        dest_size: usize,
    ) -> i32;
    ///
    pub fn get_main_purse(dest_ptr: *mut u8);
    /// This function copies the contents of the current runtime buffer into the
    /// wasm memory, beginning at the provided offset. It is intended that this
    /// function be called after a call to a function that uses host buffer. It is up to the caller
    /// to ensure that the proper amount of memory is allocated for this write,
    /// otherwise data corruption in the wasm memory may occur due to this call
    /// overwriting some bytes unintentionally. The size of the data which will be
    /// written is stored on the host. The bytes which are written are those corresponding to the
    /// value returned by the called contract; it is up to the developer to know how to attempt
    /// to interpret those bytes.
    ///
    /// # Arguments
    ///
    /// * `dest_ptr` - pointer (offset in wasm memory) to the location where the host buffer should
    ///   be written
    /// * `dest_size` - size of output buffer
    /// * `bytes_written` - a pointer to a value where amount of bytes written will be set
    pub fn read_host_buffer(dest_ptr: *mut u8, dest_size: usize, bytes_written: *mut usize) -> i32;
    /// Creates new contract package at hash. Returns both newly generated
    /// [`casperlabs_types::ContractPackageHash`] and a [`casperlabs_types::URef`] for further
    /// modifying access.
    pub fn create_contract_package_at_hash(hash_addr_ptr: *mut u8, access_addr_ptr: *mut u8);
    /// Creates new named contract user group under a contract package.
    ///
    /// # Arguments
    ///
    /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
    /// * `contract_package_hash_size` - size of contract package hash in serialized form.
    /// * `label_ptr` - serialized group label
    /// * `label_size` - size of serialized group label
    /// * `num_new_urefs` - amount of new urefs to be provisioned by host
    /// * `existing_urefs_ptr` - serialized list of existing [`casperlabs_types::URef`]s
    /// * `existing_urefs_size` - size of serialized list of  [`casperlabs_types::URef`]s
    /// * `output_size_ptr` - pointer to a value where a size of list of [`casperlabs_types::URef`]s
    ///   written to host buffer will be set.
    pub fn create_contract_user_group(
        contract_package_hash_ptr: *const u8,
        contract_package_hash_size: usize,
        label_ptr: *const u8,
        label_size: usize,
        num_new_urefs: u8,
        existing_urefs_ptr: *const u8,
        existing_urefs_size: usize,
        output_size_ptr: *mut usize,
    ) -> i32;
    /// Adds new contract version to a contract package.
    ///
    /// # Arguments
    ///
    /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
    /// * `contract_package_hash_size` - size of contract package hash in serialized form.
    /// * `version_ptr` - output parameter where new version assigned by host is set
    /// * `entry_points_ptr` - pointer to serialized [`casperlabs_types::EntryPoints`]
    /// * `entry_points_size` - size of serialized [`casperlabs_types::EntryPoints`]
    /// * `named_keys_ptr` - pointer to serialized [`casperlabs_types::contracts::NamedKeys`]
    /// * `named_keys_size` - size of serialized [`casperlabs_types::contracts::NamedKeys`]
    /// * `output_ptr` - pointer to a memory where host assigned contract hash is set to
    /// * `output_size` - size of memory area that host can write to
    /// * `bytes_written_ptr` - pointer to a value where host will set a number of bytes written to
    ///   the `output_size` pointer
    pub fn add_contract_version(
        contract_package_hash_ptr: *const u8,
        contract_package_hash_size: usize,
        version_ptr: *const u32,
        entry_points_ptr: *const u8,
        entry_points_size: usize,
        named_keys_ptr: *const u8,
        named_keys_size: usize,
        output_ptr: *mut u8,
        output_size: usize,
        bytes_written_ptr: *mut usize,
    ) -> i32;
    /// Disables contract in a contract package. Returns non-zero standard error for a failure,
    /// otherwise a zero indicates success.
    ///
    /// # Arguments
    ///
    /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
    /// * `contract_package_hash_size` - size of contract package hash in serialized form.
    /// * `contract_hash_ptr` - pointer to serialized contract hash.
    /// * `contract_hash_size` - size of contract hash in serialized form.
    pub fn disable_contract_version(
        contract_package_hash_ptr: *const u8,
        contract_package_hash_size: usize,
        contract_hash_ptr: *const u8,
        contract_hash_size: usize,
    ) -> i32;
    /// Calls a contract by its hash. Requires entry point name that has to be present on a
    /// specified contract, and serialized named arguments. Returns a standard error code in
    /// case of failure, otherwise a successful execution returns zero. Bytes returned from contract
    /// execution are set to `result_size` pointer.
    ///
    /// # Arguments
    /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
    /// * `contract_package_hash_size` - size of contract package hash in serialized form.
    /// * `entry_point_name_ptr` - pointer to serialized contract entry point name
    /// * `entry_point_name_size` - size of serialized contract entry point name
    /// * `runtime_args_ptr` - pointer to serialized runtime arguments
    /// * `runtime_args_size` - size of serialized runtime arguments
    /// * `result_size` - a pointer to a value which will be set to a size of bytes of called
    ///   contract return value
    pub fn call_contract(
        contract_hash_ptr: *const u8,
        contract_hash_size: usize,
        entry_point_name_ptr: *const u8,
        entry_point_name_size: usize,
        runtime_args_ptr: *const u8,
        runtime_args_size: usize,
        result_size: *mut usize,
    ) -> i32;
    /// Calls a contract by its package hash. Optionally accepts a serialized `Option<u32>` as a
    /// version that for `None` case would call most recent version for given protocol version,
    /// otherwise it selects a specific contract version. Requires an entry point name
    /// registered in a given version of contract. Returns a standard error code in case of
    /// failure, otherwise a successful execution returns zero. Bytes returned from contract
    /// execution are set to `result_size` pointer
    ///
    /// # Arguments
    ///
    /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
    /// * `contract_package_hash_size` - size of contract package hash in serialized form.
    /// * `contract_version_ptr` - Contract package hash in a serialized form
    /// * `contract_version_size` -
    /// * `entry_point_name_ptr` -
    /// * `entry_point_name_size` -
    /// * `runtime_args_ptr` -
    /// * `runtime_args_size` -
    /// * `result_size` -
    pub fn call_versioned_contract(
        contract_package_hash_ptr: *const u8,
        contract_package_hash_size: usize,
        contract_version_ptr: *const u8,
        contract_version_size: usize,
        entry_point_name_ptr: *const u8,
        entry_point_name_size: usize,
        runtime_args_ptr: *const u8,
        runtime_args_size: usize,
        result_size: *mut usize,
    ) -> i32;
    /// This function queries the host side to check for given named argument existence and returns
    /// a size in bytes of given argument. Returns zero for success or non-zero value for
    /// failure as described in standard error codes.
    ///
    /// # Arguments
    ///
    /// * `name_ptr` - pointer (offset in wasm memory) to the location where serialized argument
    ///   name is present
    /// * `name_size` - size of serialized bytes of argument name
    /// * `dest_ptr` - pointer to the location where argument bytes will be copied from the host
    ///   side
    /// * `dest_size` - size of destination pointer
    pub fn get_named_arg_size(name_ptr: *const u8, name_size: usize, dest_size: *mut usize) -> i32;
    /// This function copies the contents of the current runtime buffer into the
    /// wasm memory, beginning at the provided offset. It is intended that this
    /// function be called after a call to `load_arg`. It is up to the caller to
    /// ensure that the proper amount of memory is allocated for this write,
    /// otherwise data corruption in the wasm memory may occur due to this call
    /// overwriting some bytes unintentionally. The size of the data which will be
    /// written is returned from the `load_arg` call. The bytes which are written
    /// are the those corresponding to the provided argument; it is up to the
    /// developer to know how to attempt to interpret those bytes.
    ///
    /// # Arguments
    ///
    /// * `name_ptr` - pointer (offset in wasm memory) to the location where serialized argument
    ///   name is present
    /// * `name_size` - size of serialized bytes of argument name
    /// * `dest_ptr` - pointer to the location where argument bytes will be copied from the host
    ///   side
    /// * `dest_size` - size of destination pointer
    pub fn get_named_arg(
        name_ptr: *const u8,
        name_size: usize,
        dest_ptr: *mut u8,
        dest_size: usize,
    ) -> i32;
    /// Removes group from given contract package.
    ///
    /// # Arguments
    ///
    /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
    /// * `contract_package_hash_size` - size of contract package hash in serialized form.
    /// * `label_ptr` - serialized group label
    /// * `label_size` - size of serialized group label
    pub fn remove_contract_user_group(
        contract_package_hash_ptr: *const u8,
        contract_package_hash_size: usize,
        label_ptr: *const u8,
        label_size: usize,
    ) -> i32;
    /// Requests host to provision additional [`casperlabs_types::URef`] to a specified group
    /// identified by its label. Returns standard error code for non-zero value, otherwise zero
    /// indicated success.
    ///
    /// # Arguments
    ///
    /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
    /// * `contract_package_hash_size` - size of contract package hash in serialized form.
    /// * `label_ptr` - serialized group label
    /// * `label_size` - size of serialized group label
    /// * `value_size_ptr` - size of data written to a host buffer will be saved here
    pub fn provision_contract_user_group_uref(
        contract_package_hash_ptr: *const u8,
        contract_package_hash_size: usize,
        label_ptr: *const u8,
        label_size: usize,
        value_size_ptr: *const usize,
    ) -> i32;
    /// Removes user group urefs. Accepts a contract package hash, label name of a group, and a list
    /// of urefs that will be removed from the group.
    ///
    /// # Arguments
    ///
    /// * `contract_package_hash_ptr` - pointer to serialized contract package hash.
    /// * `contract_package_hash_size` - size of contract package hash in serialized form.
    /// * `label_ptr` - serialized group label
    /// * `label_size` - size of serialized group label
    /// * `urefs_ptr` - pointer to serialized list of urefs
    /// * `urefs_size` - size of serialized list of urefs
    pub fn remove_contract_user_group_urefs(
        contract_package_hash_ptr: *const u8,
        contract_package_hash_size: usize,
        label_ptr: *const u8,
        label_size: usize,
        urefs_ptr: *const u8,
        urefs_size: usize,
    ) -> i32;

    /// Prints data directly to stanadard output on the host.
    ///
    /// # Arguments
    ///
    /// * `text_ptr` - pointer to serialized text to print
    /// * `text_size` - size of serialized text to print
    #[cfg(feature = "test-support")]
    pub fn print(text_ptr: *const u8, text_size: usize);
}