I am trying to develop myself on inline-assembly. There are two contracts: CryptoDevs and Whitelist. In the assembly, i copied the whole code of whitelist contract instance into cryptodevs memory. What I am trying to achieve is to get the value of the maxWhitelistedAddresses value in the whitelist contract using inline-assembly. Thanks in advance.
contract CryptoDevs {
// Whitelist contract instance
Whitelist whitelist;
// Number of tokens reserved for whitelisted members
uint256 public reservedTokens;
uint256 public reservedTokensClaimed = 0;
/**
* @dev ERC721 constructor takes in a `name` and a `symbol` to the token collection.
* name in our case is `Crypto Devs` and symbol is `CD`.
* Constructor for Crypto Devs takes in the baseURI to set _baseTokenURI for the collection.
* It also initializes an instance of whitelist interface.
*/
constructor (address whitelistContract) ERC721("Crypto Devs", "CD") {
assembly {
// load free memory pointer
let ptr := mload(0x40)
// retrieve the size of the code
let size := extcodesize(whitelistContract)
mstore(ptr, size)
// copy the code of whitelist contract
extcodecopy(whitelistContract, add(ptr, 0x20), 0, size)
// get the code from memory
let code := mload(0x40)
// store the code in storage
sstore(0x02, code)
}
}
and this is the original code I am trying to turn into assembly.
contract CryptoDevs {
// Whitelist contract instance
Whitelist whitelist;
// Number of tokens reserved for whitelisted members
uint256 public reservedTokens;
uint256 public reservedTokensClaimed = 0;
/**
* @dev ERC721 constructor takes in a `name` and a `symbol` to the token collection.
* name in our case is `Crypto Devs` and symbol is `CD`.
* Constructor for Crypto Devs takes in the baseURI to set _baseTokenURI for the collection.
* It also initializes an instance of whitelist interface.
*/
constructor (address whitelistContract) ERC721("Crypto Devs", "CD") {
whitelist = Whitelist(whitelistContract);
reservedTokens = whitelist.maxWhitelistedAddresses();
}