0
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.3;

contract Storage {
    struct People {
        uint256 personId;
        string vorname;
        string nachname;
        uint256 birthdate;
    }

    struct Decision {
        string decision;
        string wantdonate;
        string dontwantdonate;
    }

    People[] public people;
    mapping(string => Decision) internal vornameToDonation;
    mapping(string => mapping(string => Decision)) internal nachnameToDonation;
    mapping(uint256 => mapping(string => mapping(string => Decision)))
        public birthdayToDonation;

    address public owner;

    constructor() {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        if (msg.sender != owner) {
            revert("NotOwnerError");
        }
        _;
    }

    uint256 public peopleCount = 0;

    function addPerson(
        uint256 _birthdate,
        string memory _vorname,
        string memory _nachname,
        string memory _decision,
        string memory _wantdonate,
        string memory _dontwantdonate
    ) public onlyOwner {
        people.push(People(peopleCount, _vorname, _nachname, _birthdate));
        birthdayToDonation[_birthdate][_nachname][_vorname] = Decision(
            _decision,
            _wantdonate,
            _dontwantdonate
        );
        peopleCount++;
    }

    function readDonation(
        uint256 _birthdate,
        string memory _vorname,
        string memory _nachname
    ) public view onlyOwner returns (Decision memory) {
        Decision memory readOnly = vornameToDonation[type(Storage).name];

        return readOnly;
    }

    function removePerson(uint256 index) external onlyOwner {
        //if (index >= people.length) return revert('Person does not exist!');
        if (index == people[index].personId) delete people[index];
        peopleCount--;
    }
}

With my function readDonation i want to look for people i added with my function addPeople. I used this extra function because i want to make sure that only the owner of the contract can look for people. But i found no possibility to tip in the first name, last name and the birthdate and then get the answer for donation, wantdonate and dontwantdonate. Also i want to look for this with the mapping. Can somebody give me an idea or approach for make this happen?

1 Answer 1

0

Your first problem is that you can't restrict reads to your smart contract. The information is readable by anyone, so even if your read function is onlyOwner, anyone with enough skill can access your vornameToDonation mapping.

Your solutions are to either encrypt that information (You'll still have GDPR problems) or keep it off chain.

Also, your function addPerson() or any function in your code, adds anything to the vornameToDonation mapping

Best of luck!

Your Answer

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

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