sui_adapter_latest/static_programmable_transactions/linkage/
config.rs1use crate::{
5 data_store::PackageStore,
6 static_programmable_transactions::linkage::resolution::{
7 ResolutionTable, VersionConstraint, add_and_unify, get_package,
8 },
9};
10use move_binary_format::binary_config::BinaryConfig;
11use sui_types::{
12 MOVE_STDLIB_PACKAGE_ID, SUI_FRAMEWORK_PACKAGE_ID, SUI_SYSTEM_PACKAGE_ID, base_types::ObjectID,
13 error::ExecutionError,
14};
15
16const NATIVE_PACKAGE_IDS: &[ObjectID] = &[
21 SUI_FRAMEWORK_PACKAGE_ID,
22 SUI_SYSTEM_PACKAGE_ID,
23 MOVE_STDLIB_PACKAGE_ID,
24];
25
26#[derive(Debug)]
28pub struct ResolutionConfig {
29 pub linkage_config: LinkageConfig,
31 pub binary_config: BinaryConfig,
34}
35
36#[derive(Debug)]
38pub struct LinkageConfig {
39 pub always_include_system_packages: bool,
42}
43
44impl ResolutionConfig {
45 pub fn new(linkage_config: LinkageConfig, binary_config: BinaryConfig) -> Self {
46 Self {
47 linkage_config,
48 binary_config,
49 }
50 }
51}
52
53impl LinkageConfig {
54 pub fn legacy_linkage_settings(always_include_system_packages: bool) -> Self {
55 Self {
56 always_include_system_packages,
57 }
58 }
59
60 pub(crate) fn resolution_table_with_native_packages(
61 &self,
62 store: &dyn PackageStore,
63 ) -> Result<ResolutionTable, ExecutionError> {
64 let mut resolution_table = ResolutionTable::empty();
65 if self.always_include_system_packages {
66 for id in NATIVE_PACKAGE_IDS {
67 #[cfg(debug_assertions)]
68 {
69 let package = get_package(id, store)?;
70 debug_assert_eq!(package.id(), *id);
71 debug_assert_eq!(package.original_package_id(), *id);
72 }
73 add_and_unify(id, store, &mut resolution_table, VersionConstraint::exact)?;
74 }
75 }
76
77 Ok(resolution_table)
78 }
79}