I'm working on two contracts, one of which will contain an array of indeterminate size. The second contract wants to request a subset of this contract for its functions. My initial attempts seem to suggest that this is either difficult or impossible, at least without some sort of Rube-Goldberg-esque machinery. Does anyone have any suggestions? The code is here:
pragma solidity ^0.4.19;
contract EMWhiteList {
/*This contract is meant to abstract out the whitelist functionality from the EMBallot contract so that the voting contracts can be
reused more easily. IE we will be able to create a new EMBallot for each county and have a seperate whiteList for each.
*/
address[] whiteList;
struct Voter {
address addr;
string region;
}
Voter[] voters;
address[] regionalVoters;
function addToWhiteList (address voter){
whiteList.push(voter);
}
function returnWhiteList () constant returns(address[]){
return whiteList;
}
function addVoter(address key, string region){
Voter memory newVoter = Voter (key, region);
voters.push(newVoter);
}
function getRegion(string region) constant returns (address[]){
for(uint8 i=0; i<voters.length; i++){
if(keccak256(voters[i].region) == keccak256(region)){
regionalVoters.push(voters[i].addr);
}
}
}
function getVoter(uint256 key) constant returns(address){
return voters[key].addr;
}
}
contract RegionalContract {
address[] whiteList;
function getList(string region, address whiteListAddress){
EMWhiteList fullWL = EMWhiteList(whiteListAddress);
whiteList = fullWL.getRegion(region);
}
}