Skip to main content

multiversx_sc/abi/
build_info_abi.rs

1use alloc::{borrow::ToOwned, string::String};
2
3/// Designed to hold metadata of the contract crate.
4/// Must be instanced inside the smart contract crate to work,
5/// that is why a `create` associated method would not make sense here.
6#[derive(Clone, Default, Debug)]
7pub struct BuildInfoAbi {
8    pub rustc: Option<RustcAbi>,
9    pub contract_crate: ContractCrateBuildAbi,
10    pub framework: FrameworkBuildAbi,
11}
12
13#[derive(Clone, Default, Debug)]
14pub struct RustcAbi {
15    pub version: String,
16    pub commit_hash: String,
17    pub commit_date: String,
18    pub build_date: Option<String>,
19    pub channel: String,
20    pub host: String,
21    pub short: String,
22    pub llvm_version: Option<String>,
23}
24
25#[derive(Clone, Default, Debug)]
26pub struct ContractCrateBuildAbi {
27    pub name: String,
28    pub version: String,
29    pub git_version: String,
30}
31
32impl ContractCrateBuildAbi {
33    /// Called from the ABI generator in every contract.
34    ///
35    /// Note: the values come from env! macros in the caller, to capture the crate info of the contract, not of the framework.
36    pub fn new(name: &str, version: &str) -> Self {
37        ContractCrateBuildAbi {
38            name: name.to_owned(),
39            version: version.to_owned(),
40            git_version: String::new(),
41        }
42    }
43}
44
45/// Gives the multiversx-sc metadata.
46/// Should be instanced via the `create` associated function.
47#[derive(Clone, Default, Debug)]
48pub struct FrameworkBuildAbi {
49    pub name: String,
50    pub version: String,
51}
52
53impl FrameworkBuildAbi {
54    /// Called from the ABI generator in every contract.
55    ///
56    /// Note: the values are extracted here, this makes them capture the framework crate info.
57    pub fn create() -> Self {
58        FrameworkBuildAbi {
59            name: env!("CARGO_PKG_NAME").to_owned(),
60            version: env!("CARGO_PKG_VERSION").to_owned(),
61        }
62    }
63}