AcalaNetwork / Acala

Acala - cross-chain DeFi hub and stablecoin based on Substrate for Polkadot and Kusama.
https://acala.network
GNU General Public License v3.0
736 stars 517 forks source link

Add account_call and account_create in EVM Runtime RPC #2698

Closed zjb0807 closed 9 months ago

zjb0807 commented 9 months ago

Closes: #2650

codecov[bot] commented 9 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (97bfc23) 67.06% compared to head (94a04ac) 67.09%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2698 +/- ## ========================================== + Coverage 67.06% 67.09% +0.02% ========================================== Files 67 68 +1 Lines 8608 8983 +375 ========================================== + Hits 5773 6027 +254 - Misses 2835 2956 +121 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

shunjizhan commented 9 months ago

currently when adding new runtime code, we need to copy and paste the same code for each of { mandala, karura, acala } runtime definition. I am curious if there is any way to keep the code more DRY? Maybe like a shared runtime definition, and each of the network can extend it with overrides

xlc commented 9 months ago

with this https://github.com/polkadot-js/api/issues/5725, there will be no need to supply runtime API defs anymore

shunjizhan commented 9 months ago

I mean in this PR, we need to write the following runtime codes 3 times. In substrate there is no shortcut to write "shared runtime implementation"?

        // required by xtokens precompile
        #[transactional]
        fn account_call(
            from: AccountId,
            to: H160,
            data: Vec<u8>,
            value: Balance,
            gas_limit: u64,
            storage_limit: u32,
            access_list: Option<Vec<AccessListItem>>,
            estimate: bool,
        ) -> Result<CallInfo, sp_runtime::DispatchError> {
            let from = EvmAddressMapping::<Runtime>::get_or_create_evm_address(&from);

            Self::call(from, to, data, value, gas_limit, storage_limit, access_list, estimate)
        }

        fn account_create(
            from: AccountId,
            data: Vec<u8>,
            value: Balance,
            gas_limit: u64,
            storage_limit: u32,
            access_list: Option<Vec<AccessListItem>>,
            estimate: bool,
        ) -> Result<CreateInfo, sp_runtime::DispatchError> {
            let from = EvmAddressMapping::<Runtime>::get_or_create_evm_address(&from);

            Self::create(from, data, value, gas_limit, storage_limit, access_list, estimate)
        }
    }
xlc commented 9 months ago

oh. right. no. but we could write some macro to help it but macro in macro is going to make things complicated and it is mostly the method signature are duplicated and implementation are shared