1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use proc_macro2::TokenStream;
/// The rust language generator for `Ethbind`
#[derive(Debug, Default)]
pub struct RustGenerator {
    contracts: Vec<ContractGenerator>,
}

impl RustGenerator {
    /// Push new contract generator to back end of generation list
    pub(crate) fn new_contract(&mut self, name: &str) {
        self.contracts.push(ContractGenerator::new(name))
    }

    /// Returns contract generator at back edn of generation list.
    pub(crate) fn current_contract(&mut self) -> &mut ContractGenerator {
        self.contracts.last_mut().expect("Call new_contract first")
    }

    pub(crate) fn to_runtime_type_token_stream<R: ethbind_gen::RuntimeBinder>(
        &self,
        runtime_binder: &mut R,
        name: &str,
    ) -> anyhow::Result<TokenStream> {
        Ok(runtime_binder
            .get(name)?
            .parse()
            .map_err(|e| anyhow::format_err!("{}", e))?)
    }
}

mod generator;
pub use generator::*;

mod function;
pub use function::*;

mod contract;
use contract::*;

mod event;
pub use event::*;