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
// Copyright (c) Mysten Labs, Inc.
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use iota_protocol_config::ProtocolConfig;
use move_binary_format::{
    binary_config::{BinaryConfig, TableConfig},
    file_format_common::VERSION_1,
};

/// Build a `BinaryConfig` from a `ProtocolConfig`
pub fn to_binary_config(protocol_config: &ProtocolConfig) -> BinaryConfig {
    BinaryConfig::new(
        protocol_config.move_binary_format_version(),
        protocol_config
            .min_move_binary_format_version_as_option()
            .unwrap_or(VERSION_1),
        protocol_config.no_extraneous_module_bytes(),
        TableConfig {
            module_handles: protocol_config
                .binary_module_handles_as_option()
                .unwrap_or(u16::MAX),
            datatype_handles: protocol_config
                .binary_struct_handles_as_option()
                .unwrap_or(u16::MAX),
            function_handles: protocol_config
                .binary_function_handles_as_option()
                .unwrap_or(u16::MAX),
            function_instantiations: protocol_config
                .binary_function_instantiations_as_option()
                .unwrap_or(u16::MAX),
            signatures: protocol_config
                .binary_signatures_as_option()
                .unwrap_or(u16::MAX),
            constant_pool: protocol_config
                .binary_constant_pool_as_option()
                .unwrap_or(u16::MAX),
            identifiers: protocol_config
                .binary_identifiers_as_option()
                .unwrap_or(u16::MAX),
            address_identifiers: protocol_config
                .binary_address_identifiers_as_option()
                .unwrap_or(u16::MAX),
            struct_defs: protocol_config
                .binary_struct_defs_as_option()
                .unwrap_or(u16::MAX),
            struct_def_instantiations: protocol_config
                .binary_struct_def_instantiations_as_option()
                .unwrap_or(u16::MAX),
            function_defs: protocol_config
                .binary_function_defs_as_option()
                .unwrap_or(u16::MAX),
            field_handles: protocol_config
                .binary_field_handles_as_option()
                .unwrap_or(u16::MAX),
            field_instantiations: protocol_config
                .binary_field_instantiations_as_option()
                .unwrap_or(u16::MAX),
            friend_decls: protocol_config
                .binary_friend_decls_as_option()
                .unwrap_or(u16::MAX),
            enum_defs: protocol_config
                .binary_enum_defs_as_option()
                .unwrap_or(u16::MAX),
            enum_def_instantiations: protocol_config
                .binary_enum_def_instantiations_as_option()
                .unwrap_or(u16::MAX),
            variant_handles: protocol_config
                .binary_variant_handles_as_option()
                .unwrap_or(u16::MAX),
            variant_instantiation_handles: protocol_config
                .binary_variant_instantiation_handles_as_option()
                .unwrap_or(u16::MAX),
        },
    )
}