0

I am very new to solidity and quite honestly I'm scratching my head a lot.

I am trying to create a contract where a company can facilitate donations. Anyone can apply for a donation, supplying their name, organization type and some general contact details. In order to receive, donations applicants need to be approved first. The owner can select people that are able to approve organizations

I have set up my modifiers and i want to write the first function of allowing the owner to select people to be facilitators that can approve applicants. How would I do this?

contract DonationContract
{
    address owner;

    struct Applicant
    {
        address Appl;
        string Name;
        string OrgType;
        string Number;
        string Email;
        uint256 Funds; 
        bool approved;
    }

    mapping (address => Applicant) applicants;

    modifier Owner() 
    {
        require(msg.sender == owner);
        _;
    }

     modifier Approved() 
    {
        require(applicants[msg.sender].approved == true);
        _;
    }

    function approve(address Org) Owner public
    {
        applicants[Org].approved = true;
    }   
}

1 Answer 1

0

Seems like you need to do a few things.

  • First, you need to create an object of facilitators (mapping make sense to me)
  • Then you need to create a function so the owner can add facilitators
  • Then you need to create a modifier that checks if the caller is a facilitator

Something like this:

pragma solidity ^0.4.24;

contract DonationContract
{
    address owner;

    struct Applicant
    {
        address Appl;
        string Name;
        string OrgType;
        string Number;
        string Email;
        uint256 Funds; 
        bool approved;
    }

    mapping(address => bool) facilitators;

    mapping (address => Applicant) applicants;

    modifier Owner() 
    {
        require(msg.sender == owner);
        _;
    }

     modifier Approved() 
    {
        require(applicants[msg.sender].approved == true);
        _;
    }

    modifier OnlyFacilitator()
    {
        require(facilitators[msg.sender] == true);
        _;
    }

    constructor() public {
        owner = msg.sender;
        facilitators[msg.sender] = true;
    }

    function approve(address Org) OnlyFacilitator public
    {
        applicants[Org].approved = true;
    }   

    function addFacilitator(address _addr) Owner public
    {
        facilitators[_addr] = true;
    }
}
  1. I added mapping(address => bool) facilitators; which will track facilitators
  2. I added function addFacilitator(address _addr) Owner public which allows owner to add new facilitators
  3. I added modifier OnlyFacilitator() to check that the caller is indeed a facilitator
  4. I added constructor() public so that the original contract creator becomes the owner, and is automatically a facilitator as well.
  5. I updated your approve function to use the new modifier

This is just the start, and you will still need to think of other things like removing a facilitator, or writing a getter function to list facilitators, etc...

2
  • Thanks very much. I see you didn't add a "struct facilitators" like I did with Applicant which I thought was required. Is its only purpose then to add more details to its structure?
    – Eli2099
    Commented Aug 16, 2018 at 20:38
  • A struct simply wraps a set of variable types together in a reusable object. If you want to create an object for facilitators which includes details like their name, email, etc, you can do that, but it is not required to creating a mapping like I did. Commented Aug 16, 2018 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.