Skip to main content

revive_common/
contract_identifier.rs

1//! The contract identifier helper library.
2
3use serde::{Deserialize, Serialize};
4
5/// This structure simplifies passing the contract identifiers through the compilation pipeline.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ContractIdentifier {
8    /// The absolute file path.
9    pub path: String,
10    /// The contract name.
11    /// Is set for Solidity contracts only. Otherwise it would be equal to the file name.
12    pub name: Option<String>,
13    /// The full contract identifier.
14    /// For Solidity, The format is `<absolute file path>:<contract name>`.
15    /// For other languages, `<absolute file path>`.
16    pub full_path: String,
17}
18
19impl ContractIdentifier {
20    /// A shortcut constructor.
21    pub fn new(path: String, name: Option<String>) -> Self {
22        let full_path = match name {
23            Some(ref name) => format!("{path}:{name}"),
24            None => path.clone(),
25        };
26
27        Self {
28            path,
29            name,
30            full_path,
31        }
32    }
33}