Struct ContractBuilder

Source
pub struct ContractBuilder {
    pub runtime_crate_name: String,
    pub visibility_modifier: Option<String>,
    pub contract_mod_override: Option<String>,
    pub contract_name_override: Option<String>,
    pub networks: HashMap<String, Network>,
    pub method_aliases: HashMap<String, String>,
    pub event_derives: Vec<String>,
    pub rustfmt: bool,
}
Expand description

Builder for generating contract code. Note that no code is generated until the builder is finalized with generate or output.

Fields§

§runtime_crate_name: String

The runtime crate name to use.

§visibility_modifier: Option<String>

The visibility modifier to use for the generated module and contract re-export.

§contract_mod_override: Option<String>

Override the contract module name that contains the generated code.

§contract_name_override: Option<String>

Override the contract name to use for the generated type.

§networks: HashMap<String, Network>

Manually specified deployed contract address and transaction hash.

§method_aliases: HashMap<String, String>

Manually specified contract method aliases.

§event_derives: Vec<String>

Derives added to event structs and enums.

§rustfmt: bool

Format generated code sing locally installed copy of rustfmt.

Implementations§

Source§

impl ContractBuilder

Source

pub fn new() -> Self

Creates a new contract builder with default settings.

Source

pub fn runtime_crate_name(self, name: impl Into<String>) -> Self

Sets the crate name for the runtime crate. This setting is usually only needed if the crate was renamed in the Cargo manifest.

Source

pub fn visibility_modifier(self, vis: impl Into<String>) -> Self

Sets an optional visibility modifier for the generated module and contract re-export.

Source

pub fn contract_mod_override(self, name: impl Into<String>) -> Self

Sets the optional contract module name override.

Source

pub fn contract_name_override(self, name: impl Into<String>) -> Self

Sets the optional contract name override. This setting is needed when using an artifact JSON source that does not provide a contract name such as Etherscan.

Source

pub fn add_network(self, chain_id: impl Into<String>, network: Network) -> Self

Adds a deployed address and deployment transaction hash or block of a contract for a given network. Note that manually specified deployments take precedence over deployments in the artifact.

This is useful for integration test scenarios where the address of a contract on the test node is deterministic, but the contract address is not in the artifact.

Source

pub fn add_network_str(self, chain_id: impl Into<String>, address: &str) -> Self

Adds a deployed address. Parses address from string. See [add_deployment] for more information.

§Panics

This method panics if the specified address string is invalid. See parse_address for more information on the address string format.

Source

pub fn add_method_alias( self, signature: impl Into<String>, alias: impl Into<String>, ) -> Self

Adds a solidity method alias to specify what the method name will be in Rust. For solidity methods without an alias, the snake cased method name will be used.

Source

pub fn rustfmt(self, rustfmt: bool) -> Self

Specifies whether or not to format the code using a locally installed copy of rustfmt.

Note that in case rustfmt does not exist or produces an error, the un-formatted code will be used.

Source

pub fn add_event_derive(self, derive: impl Into<String>) -> Self

Adds a custom derive to the derives for event structs and enums.

This makes it possible to, for example, derive serde::Serialize and serde::Deserialize for events.

§Examples
let builder = ContractBuilder::new()
    .add_event_derive("serde::Serialize")
    .add_event_derive("serde::Deserialize");
Source

pub fn generate(self, contract: &Contract) -> Result<ContractBindings>

Generates the contract bindings.

Trait Implementations§

Source§

impl Default for ContractBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,