Struct ethers_contract_abigen::MultiAbigen [−][src]
pub struct MultiAbigen { /* fields omitted */ }
Expand description
Generates bindings for a series of contracts
This type can be used to generate multiple ContractBindings
and put them all in a single rust
module, (eg. a contracts
directory).
This can be used to
- write all bindings directly into a new directory in the project’s source directory, so that
it is included in the repository. 2) write all bindings to the value of cargo’s
OUT_DIR
in a build script and import the bindings asinclude!(concat!(env!("OUT_DIR"), "/mod.rs"));
.
However, the main purpose of this generator is to create bindings for option 1)
and write all
contracts to some contracts
module in src
, like src/contracts/mod.rs
once via a build
script or a test. After that it’s recommend to remove the build script and replace it with an
integration test (See MultiAbigen::ensure_consistent_bindings
) that fails if the generated
code is out of date. This has several advantages:
- No need for downstream users to compile the build script
- No need for downstream users to run the whole
abigen!
generation steps - The generated code is more usable in an IDE
- CI will fail if the generated code is out of date (if
abigen!
or the contract’s ABI itself changed)
See MultiAbigen::ensure_consistent_bindings
for the recommended way to set this up to generate
the bindings once via a test and then use the test to ensure consistency.
Implementations
Create a new instance from a series of already resolved Abigen
Create a new instance from a series (contract name
, abi_source
)
See Abigen::new
Reads all json files contained in the given dir
and use the file name for the name of the
ContractBindings
.
This is equivalent to calling MultiAbigen::new
with all the json files and their filename.
Example
abi
├── ERC20.json
├── Contract1.json
├── Contract2.json
...
let gen = MultiAbigen::from_json_files("./abi").unwrap();
Write all bindings into a single rust file instead of separate modules
Generates all the bindings and writes them to the given module
Example
Read all json abi files from the ./abi
directory
abi
├── ERC20.json
├── Contract1.json
├── Contract2.json
...
and write them to the ./src/contracts
location as
src/contracts
├── mod.rs
├── er20.rs
├── contract1.rs
├── contract2.rs
...
let gen = MultiAbigen::from_json_files("./abi").unwrap();
gen.write_to_module("./src/contracts").unwrap();
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for MultiAbigen
impl Send for MultiAbigen
impl Sync for MultiAbigen
impl Unpin for MultiAbigen
impl UnwindSafe for MultiAbigen
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more