2020-06-22 08:44:08 +00:00
|
|
|
use super::{util, Context};
|
2020-05-26 18:57:59 +00:00
|
|
|
|
2020-05-31 16:01:34 +00:00
|
|
|
use ethers_core::types::Address;
|
2020-05-26 18:57:59 +00:00
|
|
|
use proc_macro2::{Literal, TokenStream};
|
|
|
|
use quote::quote;
|
|
|
|
|
2020-06-22 08:44:08 +00:00
|
|
|
pub(crate) fn imports(name: &str) -> TokenStream {
|
|
|
|
let doc = util::expand_doc(&format!("{} was auto-generated with ethers-rs Abigen. More information at: https://github.com/gakonst/ethers-rs", name));
|
|
|
|
|
2020-05-26 18:57:59 +00:00
|
|
|
quote! {
|
2020-06-17 06:38:04 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
#![allow(unused_imports)]
|
2020-06-22 08:44:08 +00:00
|
|
|
#doc
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
2020-05-31 18:46:49 +00:00
|
|
|
use ethers::{
|
|
|
|
core::{
|
|
|
|
abi::{Abi, Token, Detokenize, InvalidOutputType, Tokenizable},
|
|
|
|
types::*, // import all the types so that we can codegen for everything
|
|
|
|
},
|
2020-06-11 06:45:14 +00:00
|
|
|
contract::{Contract, builders::{ContractCall, Event}, Lazy},
|
2020-05-27 08:46:16 +00:00
|
|
|
signers::{Client, Signer},
|
2020-06-02 11:56:09 +00:00
|
|
|
providers::JsonRpcClient,
|
2020-05-26 18:57:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-02 21:10:46 +00:00
|
|
|
pub(crate) fn struct_declaration(cx: &Context, abi_name: &proc_macro2::Ident) -> TokenStream {
|
2020-05-26 18:57:59 +00:00
|
|
|
let name = &cx.contract_name;
|
|
|
|
let abi = &cx.abi_str;
|
|
|
|
|
|
|
|
quote! {
|
|
|
|
// Inline ABI declaration
|
2020-06-02 21:10:46 +00:00
|
|
|
pub static #abi_name: Lazy<Abi> = Lazy::new(|| serde_json::from_str(#abi)
|
2020-05-26 18:57:59 +00:00
|
|
|
.expect("invalid abi"));
|
|
|
|
|
|
|
|
// Struct declaration
|
|
|
|
#[derive(Clone)]
|
2020-06-22 08:44:08 +00:00
|
|
|
pub struct #name<P, S>(Contract<P, S>);
|
2020-05-26 18:57:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Deref to the inner contract in order to access more specific functions functions
|
2020-06-22 08:44:08 +00:00
|
|
|
impl<P, S> std::ops::Deref for #name<P, S> {
|
|
|
|
type Target = Contract<P, S>;
|
2020-05-26 18:57:59 +00:00
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target { &self.0 }
|
|
|
|
}
|
|
|
|
|
2020-06-22 08:44:08 +00:00
|
|
|
impl<P: JsonRpcClient, S: Signer> std::fmt::Debug for #name<P, S> {
|
2020-05-26 18:57:59 +00:00
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
f.debug_tuple(stringify!(#name))
|
|
|
|
.field(&self.address())
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|