From abfdac1dcd9388b6a554d855c9210d83165611e2 Mon Sep 17 00:00:00 2001 From: kozyrevdev <73348153+kozyrevdev@users.noreply.github.com> Date: Thu, 02 Sep 2021 10:17:16 +0000 Subject: [PATCH] Merge pull request #194 from UniqueNetwork/feature/getSponsoringRateLimit-helper Add getSponsoringRateLimit helper --- --- a/Makefile +++ b/Makefile @@ -1,5 +1,10 @@ -.PHONY: _eth_codegen -_eth_codegen: +.PHONY: _help +_help: + @echo "regenerate_solidity - generate stubs/interfaces for contracts defined in native (via evm-coder)" + @echo "evm_stubs - recompile contract stubs" + @echo "bench - run frame-benchmarking" + @echo " bench-evm-migration" + @echo " bench-nft" .PHONY: regenerate_solidity regenerate_solidity: --- a/pallets/evm-contract-helpers/src/eth.rs +++ b/pallets/evm-contract-helpers/src/eth.rs @@ -8,7 +8,7 @@ }; use frame_support::traits::Get; use up_sponsorship::SponsorshipHandler; -use sp_std::vec::Vec; +use sp_std::{convert::TryInto, vec::Vec}; struct ContractHelpers(SubstrateRecorder); @@ -50,6 +50,13 @@ Ok(()) } + fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result { + self.0.consume_sload()?; + Ok(>::get(contract_address) + .try_into() + .map_err(|_| "rate limit > u32::MAX")?) + } + fn allowed(&self, contract_address: address, user: address) -> Result { self.0.consume_sload()?; Ok(>::allowed(contract_address, user, true)) --- a/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol +++ b/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol @@ -52,6 +52,18 @@ dummy = 0; } + // Selector: getSponsoringRateLimit(address) 610cfabd + function getSponsoringRateLimit(address contractAddress) + public + view + returns (uint32) + { + require(false, stub_error); + contractAddress; + dummy; + return 0; + } + // Selector: allowed(address,address) 5c658165 function allowed(address contractAddress, address user) public --- a/tests/src/eth/api/ContractHelpers.sol +++ b/tests/src/eth/api/ContractHelpers.sol @@ -28,6 +28,12 @@ function setSponsoringRateLimit(address contractAddress, uint32 rateLimit) external; + // Selector: getSponsoringRateLimit(address) 610cfabd + function getSponsoringRateLimit(address contractAddress) + external + view + returns (uint32); + // Selector: allowed(address,address) 5c658165 function allowed(address contractAddress, address user) external -- gitstuff