I'm new to solidity. I am trying to access all elements in my Applicant struct. In my Donate function if the donor does not specify an organization to donate to, then the amount will be split across all organizations within applicants. I have looked online and apparently it is a bad idea to iterate through a mapping due to the high gas cost. How else can I achieve my goal then?
pragma solidity ^0.4.2;
contract DonationContract
{
address owner;
struct Applicant
{
address Org;
string Name;
string OrgType;
string Number;
string Email;
uint256 Wallet;
uint256 DonationFunds;
bool approved;
}
constructor() public
{
owner = msg.sender;
facilitators[msg.sender] = true;
}
mapping (address => Applicant) public applicants;
mapping(address => bool) facilitators;
modifier Owner()
{
require(msg.sender == owner);
_;
}
modifier OnlyFacilitator()
{
require(facilitators[msg.sender] == true);
_;
}
modifier Approved(address Org)
{
require(applicants[Org].approved == true);
_;
}
function approve(address Org) OnlyFacilitator public
{
applicants[Org].approved = true;
}
function Donate(uint256 amount, address Org) Approved(Org) public
{
if(Org==0)
{
//Split donation amount amongst all applicants donationfunds
}
else
applicants[Org].DonationFunds += amount;
if(applicants[Org].DonationFunds >= 10000)
{
applicants[Org].DonationFunds -=10000;
applicants[Org].Wallet += 10000;
}
}
function addFacilitator(address _addr) Owner public
{
facilitators[_addr] = true;
}
}