Struct ethcontract_generate::ContractBuilder[][src]

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

Creates a new contract builder with default settings.

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

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

Sets the optional contract module name override.

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.

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.

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.

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.

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 unformatted code will be used.

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");

Generates the contract bindings.

Trait Implementations

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.