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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
extern crate core;
use fuels_core::code_gen::abigen::Abigen;
use proc_macro::TokenStream;
use syn::parse_macro_input;
use crate::{
abigen_macro::MacroAbigenTargets,
setup_contract_test_macro::{generate_setup_contract_test_code, TestContractCommands},
};
mod abigen_macro;
mod parse_utils;
mod setup_contract_test_macro;
/// Used to generate bindings for Contracts, Scripts and Predicates. Accepts
/// input in the form of `ProgramType(name="MyBindings", abi=ABI_SOURCE)...`
///
/// `ProgramType` is either `Contract`, `Script` or `Predicate`.
///
/// `ABI_SOURCE` is a string literal representing either a path to the JSON ABI
/// file or the contents of the JSON ABI file itself.
///
///```text
/// abigen!(Contract(
/// name = "MyContract",
/// abi = "packages/fuels/tests/contracts/token_ops/out/debug/token_ops-abi.json"
/// ));
///```
///
/// More details can be found in the [`Fuel Rust SDK Book`](https://fuellabs.github.io/fuels-rs/latest)
#[proc_macro]
pub fn abigen(input: TokenStream) -> TokenStream {
let targets = parse_macro_input!(input as MacroAbigenTargets);
Abigen::generate(targets.into(), false).unwrap().into()
}
#[proc_macro]
pub fn wasm_abigen(input: TokenStream) -> TokenStream {
let targets = parse_macro_input!(input as MacroAbigenTargets);
Abigen::generate(targets.into(), true).unwrap().into()
}
/// Used to reduce boilerplate in integration tests.
///
/// More details can be found in the [`Fuel Rust SDK Book`](https://fuellabs.github.io/fuels-rs/latest)
///```text
///setup_contract_test!(
/// Wallets("wallet"),
/// Abigen(
/// name = "FooContract",
/// abi = "packages/fuels/tests/contracts/foo_contract"
/// ),
/// Abigen(
/// name = "FooCallerContract",
/// abi = "packages/fuels/tests/contracts/foo_caller_contract"
/// ),
/// Deploy(
/// name = "foo_contract_instance",
/// contract = "FooContract",
/// wallet = "wallet"
/// ),
/// Deploy(
/// name = "foo_caller_contract_instance",
/// contract = "FooCallerContract",
/// wallet = "my_own_wallet"
/// ),
///);
///```
#[proc_macro]
pub fn setup_contract_test(input: TokenStream) -> TokenStream {
let test_contract_commands = parse_macro_input!(input as TestContractCommands);
generate_setup_contract_test_code(test_contract_commands)
.unwrap_or_else(|e| e.to_compile_error())
.into()
}