diem_types/on_chain_config/
vm_publishing_option.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::on_chain_config::OnChainConfig;
5use diem_crypto::HashValue;
6use serde::{Deserialize, Serialize};
7
8/// Defines and holds the publishing policies for the VM. There are three possible configurations:
9/// 1. No module publishing, only allowlisted scripts are allowed.
10/// 2. No module publishing, custom scripts are allowed.
11/// 3. Both module publishing and custom scripts are allowed.
12/// We represent these as an enum instead of a struct since allowlisting and module/script
13/// publishing are mutually exclusive options.
14#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
15pub struct VMPublishingOption {
16    pub script_allow_list: Vec<HashValue>,
17    pub is_open_module: bool,
18}
19
20impl VMPublishingOption {
21    pub fn locked(allowlist: Vec<HashValue>) -> Self {
22        Self {
23            script_allow_list: allowlist,
24            is_open_module: false,
25        }
26    }
27
28    pub fn custom_scripts() -> Self {
29        Self {
30            script_allow_list: vec![],
31            is_open_module: false,
32        }
33    }
34
35    pub fn open() -> Self {
36        Self {
37            script_allow_list: vec![],
38            is_open_module: true,
39        }
40    }
41
42    pub fn is_open_module(&self) -> bool {
43        self.is_open_module
44    }
45
46    pub fn is_open_script(&self) -> bool {
47        self.script_allow_list.is_empty()
48    }
49}
50
51impl OnChainConfig for VMPublishingOption {
52    const IDENTIFIER: &'static str = "DiemTransactionPublishingOption";
53}