alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
758 stars 131 forks source link

feat(sol-macro): support namespaces #694

Closed DaniPopes closed 4 weeks ago

DaniPopes commented 1 month ago

Closes https://github.com/alloy-rs/core/issues/660 Closes https://github.com/alloy-rs/core/issues/599

klkvr commented 1 month ago

just tested locally and it seems that derives aren't applied to generated libraries in json abi input causing compilation issues

e.g. this would cause Lib::Struct doesn't implement Debug because Lib::Struct is used in some of the Contract types

sol!(
    #[derive(Debug)]
    Contract,
    r#"[
        {
            "type": "function",
            "name": "f",
            "inputs": [
                {
                    "name": "s",
                    "type": "tuple",
                    "internalType": "struct Lib.Struct",
                    "components": [
                        {
                            "name": "a",
                            "type": "uint256",
                            "internalType": "uint256"
                        }
                    ]
                }
            ],
            "outputs": [],
            "stateMutability": "nonpayable"
        }
    ]"#
);
DaniPopes commented 1 month ago

And would also be a pretty big breaking change

DaniPopes commented 1 month ago

This is broken now, marking as draft again:

sol! {
    contract Vm {
        struct Wallet {
            uint stuff;
        }

        /// Gets the nonce of an account.
        function getNonce(address account) external view returns (uint64 nonce);

        /// Get the nonce of a `Wallet`.
        function getNonce(Wallet calldata wallet) external returns (uint64 nonce);
    }
}
klkvr commented 1 month ago

Updated in 8fe0df0, we didn't apply namespaces when resolving overloads