sui_adapter_latest/static_programmable_transactions/linkage/
legacy_linkage.rs

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

use crate::{
    data_store::PackageStore,
    static_programmable_transactions::linkage::{
        analysis::LinkageAnalysis,
        config::{LinkageConfig, ResolutionConfig},
        resolution::{ConflictResolution, ResolutionTable, add_and_unify, get_package},
        resolved_linkage::ResolvedLinkage,
    },
};
use move_binary_format::binary_config::BinaryConfig;
use sui_types::{base_types::ObjectID, error::ExecutionError, transaction as P};

#[derive(Debug)]
pub struct LegacyLinkage {
    internal: ResolutionConfig,
}

impl LinkageAnalysis for LegacyLinkage {
    fn compute_call_linkage(
        &self,
        move_call: &P::ProgrammableMoveCall,
        store: &dyn PackageStore,
    ) -> Result<ResolvedLinkage, ExecutionError> {
        Ok(ResolvedLinkage::from_resolution_table(
            self.compute_call_linkage(move_call, store)?,
        ))
    }

    fn compute_publication_linkage(
        &self,
        deps: &[ObjectID],
        store: &dyn PackageStore,
    ) -> Result<ResolvedLinkage, ExecutionError> {
        Ok(ResolvedLinkage::from_resolution_table(
            self.compute_publication_linkage(deps, store)?,
        ))
    }

    fn config(&self) -> &ResolutionConfig {
        &self.internal
    }
}

impl LegacyLinkage {
    #[allow(dead_code)]
    pub fn new(
        always_include_system_packages: bool,
        binary_config: BinaryConfig,
        _store: &dyn PackageStore,
    ) -> Result<Self, ExecutionError> {
        let linkage_config = LinkageConfig::legacy_linkage_settings(always_include_system_packages);
        Ok(Self {
            internal: ResolutionConfig {
                linkage_config,
                binary_config,
            },
        })
    }

    fn compute_call_linkage(
        &self,
        move_call: &P::ProgrammableMoveCall,
        store: &dyn PackageStore,
    ) -> Result<ResolutionTable, ExecutionError> {
        let mut resolution_table = self
            .internal
            .linkage_config
            .resolution_table_with_native_packages(store)?;
        let pkg = get_package(&move_call.package, store)?;
        let transitive_deps = pkg
            .linkage_table()
            .values()
            .map(|info| info.upgraded_id)
            .collect::<Vec<_>>();
        for object_id in transitive_deps.iter() {
            add_and_unify(
                object_id,
                store,
                &mut resolution_table,
                ConflictResolution::exact,
            )?;
        }
        add_and_unify(
            &move_call.package,
            store,
            &mut resolution_table,
            ConflictResolution::exact,
        )?;
        Ok(resolution_table)
    }

    /// Compute the linkage for a publish or upgrade command. This is a special case because
    pub(crate) fn compute_publication_linkage(
        &self,
        deps: &[ObjectID],
        store: &dyn PackageStore,
    ) -> Result<ResolutionTable, ExecutionError> {
        let mut resolution_table = self
            .internal
            .linkage_config
            .resolution_table_with_native_packages(store)?;
        for id in deps {
            let pkg = get_package(id, store)?;
            resolution_table.resolution_table.insert(
                pkg.original_package_id(),
                ConflictResolution::Exact(pkg.version(), pkg.id()),
            );
            resolution_table
                .all_versions_resolution_table
                .insert(pkg.id(), pkg.original_package_id());
        }
        Ok(resolution_table)
    }
}