near_api/types/contract.rs
1pub use build_info::BuildInfo;
2use serde::{Deserialize, Serialize};
3
4/// The struct provides information about deployed contract's source code and supported standards.
5///
6/// Contract source metadata follows [**NEP-330 standard**](https://github.com/near/NEPs/blob/master/neps/nep-0330.md) for smart contracts
7///
8/// See the documentation of [`Contract::contract_source_metadata`](crate::Contract::contract_source_metadata) on how to query this for a contract via this crate
9// `rustdoc` clearly lacks functionality of automatic backlinks within a single crate
10#[derive(Debug, Clone, PartialEq, Default, Eq, Serialize, Deserialize)]
11pub struct ContractSourceMetadata {
12 /// Optional version identifier, typically a semantic version
13 ///
14 /// ## Examples:
15 ///
16 /// ```rust,no_run
17 /// # let version: Option<String> =
18 /// // Semantic version
19 /// Some("1.0.0".into())
20 /// # ;
21 /// ```
22 /// ```rust,no_run
23 /// # let version: Option<String> =
24 /// // Git commit
25 /// Some("39f2d2646f2f60e18ab53337501370dc02a5661c".into())
26 /// # ;
27 /// ```
28 pub version: Option<String>,
29
30 // cSpell::ignore bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq
31 /// Optional URL to source code repository/tree
32 ///
33 /// ## Examples:
34 ///
35 /// ```rust,no_run
36 /// # let link: Option<String> =
37 /// // GitHub URL
38 /// Some("https://github.com/org/repo/tree/8d8a8a0fe86a1d8eb3bce45f04ab1a65fecf5a1b".into())
39 /// # ;
40 /// ```
41 /// ```rust,no_run
42 /// # let link: Option<String> =
43 /// // GitHub URL
44 /// Some("https://github.com/near-examples/nft-tutorial".into())
45 /// # ;
46 /// ```
47 /// ```rust,no_run
48 /// # let link: Option<String> =
49 /// // IPFS CID
50 /// Some("bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq".into())
51 /// # ;
52 /// ```
53 pub link: Option<String>,
54
55 /// List of supported NEAR standards (NEPs) with their versions
56 ///
57 /// This field is an addition of **1.1.0** **NEP-330** revision
58 ///
59 /// ## Examples:
60 ///
61 /// This field will always include NEP-330 itself:
62 /// ```rust,no_run
63 /// # use near_api::types::contract::Standard;
64 /// # let link: Vec<Standard> =
65 /// // this is always at least 1.1.0
66 /// vec![Standard { standard: "nep330".into(), version: "1.1.0".into() }]
67 /// # ;
68 /// ```
69 /// ```rust,no_run
70 /// # use near_api::types::contract::Standard;
71 /// # let link: Vec<Standard> =
72 /// vec![Standard { standard: "nep330".into(), version: "1.2.0".into() }]
73 /// # ;
74 /// ```
75 // it's a guess it was added as 1.1.0 of nep330, [nep330 1.1.0 standard recording](https://www.youtube.com/watch?v=pBLN9UyE6AA) actually discusses nep351
76 #[serde(default)]
77 pub standards: Vec<Standard>,
78
79 /// Optional details that are required for formal contract WASM build reproducibility verification
80 ///
81 /// This field is an addition of **1.2.0** **NEP-330** revision
82 pub build_info: Option<BuildInfo>,
83}
84
85/// NEAR Standard implementation descriptor following [NEP-330](https://github.com/near/NEPs/blob/master/neps/nep-0330.md)
86#[derive(Debug, Clone, PartialEq, Default, Eq, Serialize, Deserialize)]
87pub struct Standard {
88 /// Standard name in lowercase NEP format
89 ///
90 /// ## Examples:
91 ///
92 /// ```rust,no_run
93 /// # let standard: String =
94 /// // for fungible tokens
95 /// "nep141".into()
96 /// # ;
97 /// ```
98 pub standard: String,
99
100 /// Implemented standard version using semantic versioning
101 ///
102 /// ## Examples:
103 ///
104 /// ```rust,no_run
105 /// # let version: String =
106 /// // for initial release
107 /// "1.0.0".into()
108 /// # ;
109 /// ```
110 pub version: String,
111}
112
113mod build_info {
114 use serde::{Deserialize, Serialize};
115
116 #[derive(Debug, Clone, PartialEq, Default, Eq, Serialize, Deserialize)]
117 /// Defines all required details for formal WASM build reproducibility verification
118 /// according to [**NEP-330 standard 1.3.0 revision**](https://github.com/near/NEPs/blob/master/neps/nep-0330.md)
119 pub struct BuildInfo {
120 /// Reference to a reproducible build environment docker image
121 ///
122 /// ## Examples:
123 ///
124 /// ```rust,no_run
125 /// # let build_environment: String =
126 /// "sourcescan/cargo-near:0.13.3-rust-1.84.0@sha256:722198ddb92d1b82cbfcd3a4a9f7fba6fd8715f4d0b5fb236d8725c4883f97de".into()
127 /// # ;
128 /// ```
129 pub build_environment: String,
130 /// The exact command that was used to build the contract, with all the flags
131 ///
132 /// ## Examples:
133 ///
134 /// ```rust,no_run
135 /// # let build_command: Vec<String> =
136 /// vec![
137 /// "cargo".into(),
138 /// "near".into(),
139 /// "build".into(),
140 /// "non-reproducible-wasm".into(),
141 /// "--locked".into()
142 /// ]
143 /// # ;
144 /// ```
145 pub build_command: Vec<String>,
146 /// Relative path to contract crate within the source code
147 ///
148 /// ## Examples:
149 ///
150 /// ```rust,no_run
151 /// # let contract_path: String =
152 /// "near/omni-prover/wormhole-omni-prover-proxy".into()
153 /// # ;
154 /// ```
155 /// ```rust,no_run
156 /// # let contract_path: String =
157 /// // root of a repo
158 /// "".into()
159 /// # ;
160 /// ```
161 pub contract_path: String,
162 /// Reference to the source code snapshot that was used to build the contract
163 ///
164 /// ## Examples:
165 ///
166 /// ```rust,no_run
167 /// # let source_code_snapshot: String =
168 /// "git+https://github.com/org/repo?rev=8d8a8a0fe86a1d8eb3bce45f04ab1a65fecf5a1b".into()
169 /// # ;
170 /// ```
171 pub source_code_snapshot: String,
172 /// A path within the build environment, where the result WASM binary has been put
173 /// during build.
174 /// This should be a subpath of `/home/near/code`
175 ///
176 /// This field is an addition of **1.3.0** **NEP-330** revision
177 ///
178 /// ## Examples:
179 ///
180 /// ```rust,no_run
181 /// # let output_wasm_path: Option<String> =
182 /// Some("/home/near/code/target/near/simple_package.wasm".into())
183 /// # ;
184 /// ```
185 pub output_wasm_path: Option<String>,
186 }
187}