Skip to main content

iota_types/
execution_config_utils.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use iota_protocol_config::ProtocolConfig;
6use move_binary_format::{
7    binary_config::{BinaryConfig, TableConfig},
8    file_format_common::VERSION_1,
9};
10
11/// Build a `BinaryConfig` from a `ProtocolConfig`
12///
13/// `override_deprecate_global_storage_ops` takes precedence over the
14/// `deprecate_global_storage_ops` protocol flag. The signing path passes
15/// `Some(true)` so that rejection of the deprecated global storage
16/// instructions ships with the binary rather than with a protocol version.
17pub fn to_binary_config(
18    protocol_config: &ProtocolConfig,
19    override_deprecate_global_storage_ops: Option<bool>,
20) -> BinaryConfig {
21    let deprecate_global_storage_ops = override_deprecate_global_storage_ops
22        .unwrap_or_else(|| protocol_config.deprecate_global_storage_ops());
23    BinaryConfig::new(
24        protocol_config.move_binary_format_version(),
25        protocol_config
26            .min_move_binary_format_version_as_option()
27            .unwrap_or(VERSION_1),
28        protocol_config.no_extraneous_module_bytes(),
29        protocol_config.metadata_in_module_bytes(),
30        deprecate_global_storage_ops,
31        TableConfig {
32            module_handles: protocol_config
33                .binary_module_handles_as_option()
34                .unwrap_or(u16::MAX),
35            datatype_handles: protocol_config
36                .binary_struct_handles_as_option()
37                .unwrap_or(u16::MAX),
38            function_handles: protocol_config
39                .binary_function_handles_as_option()
40                .unwrap_or(u16::MAX),
41            function_instantiations: protocol_config
42                .binary_function_instantiations_as_option()
43                .unwrap_or(u16::MAX),
44            signatures: protocol_config
45                .binary_signatures_as_option()
46                .unwrap_or(u16::MAX),
47            constant_pool: protocol_config
48                .binary_constant_pool_as_option()
49                .unwrap_or(u16::MAX),
50            identifiers: protocol_config
51                .binary_identifiers_as_option()
52                .unwrap_or(u16::MAX),
53            address_identifiers: protocol_config
54                .binary_address_identifiers_as_option()
55                .unwrap_or(u16::MAX),
56            struct_defs: protocol_config
57                .binary_struct_defs_as_option()
58                .unwrap_or(u16::MAX),
59            struct_def_instantiations: protocol_config
60                .binary_struct_def_instantiations_as_option()
61                .unwrap_or(u16::MAX),
62            function_defs: protocol_config
63                .binary_function_defs_as_option()
64                .unwrap_or(u16::MAX),
65            field_handles: protocol_config
66                .binary_field_handles_as_option()
67                .unwrap_or(u16::MAX),
68            field_instantiations: protocol_config
69                .binary_field_instantiations_as_option()
70                .unwrap_or(u16::MAX),
71            friend_decls: protocol_config
72                .binary_friend_decls_as_option()
73                .unwrap_or(u16::MAX),
74            enum_defs: protocol_config
75                .binary_enum_defs_as_option()
76                .unwrap_or(u16::MAX),
77            enum_def_instantiations: protocol_config
78                .binary_enum_def_instantiations_as_option()
79                .unwrap_or(u16::MAX),
80            variant_handles: protocol_config
81                .binary_variant_handles_as_option()
82                .unwrap_or(u16::MAX),
83            variant_instantiation_handles: protocol_config
84                .binary_variant_instantiation_handles_as_option()
85                .unwrap_or(u16::MAX),
86        },
87    )
88}