arnaucube
arnaucube/sonobePublic Self-hosted repository
sonobe/solidity-verifiers/src/utils/mod.rs
solidity-verifiers/src/utils/mod.rsRaw
 1use crate::{GPL3_SDPX_IDENTIFIER, PRAGMA_GROTH16_VERIFIER};
 2use askama::Template;
 3
 4pub mod encoding;
 5
 6#[derive(Template)]
 7#[template(path = "header_template.askama.sol", ext = "sol")]
 8pub(crate) struct HeaderInclusion<T: Template> {
 9    /// SPDX-License-Identifier
10    pub sdpx: String,
11    /// The `pragma` statement.
12    pub pragma_version: String,
13    /// The template to render alongside the header.
14    pub template: T,
15}
16
17impl<T: Template + Default> HeaderInclusion<T> {
18    pub fn builder() -> HeaderInclusionBuilder<T> {
19        HeaderInclusionBuilder::default()
20    }
21}
22
23#[derive(Debug)]
24pub struct HeaderInclusionBuilder<T: Template + Default> {
25    /// SPDX-License-Identifier
26    sdpx: String,
27    /// The `pragma` statement.
28    pragma_version: String,
29    /// The template to render alongside the header.
30    template: T,
31}
32
33impl<T: Template + Default> Default for HeaderInclusionBuilder<T> {
34    fn default() -> Self {
35        Self {
36            sdpx: GPL3_SDPX_IDENTIFIER.to_string(),
37            pragma_version: PRAGMA_GROTH16_VERIFIER.to_string(),
38            template: T::default(),
39        }
40    }
41}
42
43impl<T: Template + Default> HeaderInclusionBuilder<T> {
44    pub fn sdpx<S: Into<String>>(mut self, sdpx: S) -> Self {
45        self.sdpx = sdpx.into();
46        self
47    }
48
49    pub fn pragma_version<S: Into<String>>(mut self, pragma_version: S) -> Self {
50        self.pragma_version = pragma_version.into();
51        self
52    }
53
54    pub fn template(mut self, template: impl Into<T>) -> Self {
55        self.template = template.into();
56        self
57    }
58
59    pub fn build(self) -> HeaderInclusion<T> {
60        HeaderInclusion {
61            sdpx: self.sdpx,
62            pragma_version: self.pragma_version,
63            template: self.template,
64        }
65    }
66}