0

I have the following contract:

// Inspired by  https://fravoll.github.io/solidity-patterns/eternal_storage.html
pragma solidity ^0.5.8;

import "./lib/Ownable.sol";
import "./MemberStruct.sol";

contract Registry is Ownable, MemberStruct {
    // ------
    // STATE
    // ------

    // Maps member address to Member data
    // Note, this address is used to map to the owner and delegates in the ERC-1056 registry
    mapping(address => Member) public members;
    bytes32 public charter;

    // ------------
    // CONSTRUCTOR:
    // ------------

    /**
    @dev Contructor     Sets the addresses for token, voting, and parameterizer
    */
    constructor (
        bytes32 _charter
    ) public {
        charter = _charter;
    }

    // --------------------
    // GETTER FUNCTIONS
    // --------------------

    function getChallengeID(address _member) external view returns (uint256) {
        Member memory member = members[_member];
        return member.challengeID;
    }

    function getMembershipStartTime(address _member) external view returns (uint256) {
        Member memory member = members[_member];
        return member.membershipStartTime;
    }

    // --------------------
    // SETTER FUNCTIONS
    // --------------------

    function updateCharter(bytes32 _newCharter) external onlyOwner {
        charter = _newCharter;
    }

    function setMember(
        address _member,
        uint256 _membershipStartTime
    ) external onlyOwner {
        // Create the member struct
        Member memory member = Member({
            challengeID: 0,
            membershipStartTime: _membershipStartTime
        });
        // Store the member
        members[_member] = member;
    }

    function editChallengeID(address _member, uint256 _newChallengeID) external onlyOwner {
        Member storage member = members[_member];
        member.challengeID = _newChallengeID;
    }

    function editMembershipStartTime(address _member, uint256 _newTime) external onlyOwner {
        Member storage member = members[_member];
        member.membershipStartTime = _newTime;
    }

    function deleteMember(address _member) external onlyOwner {
        delete members[_member];
    }
}

And the MemberStruct contract:

pragma solidity ^0.5.8;

/*
 The delegate address can execute voting on behalf of the owner of the
 member project.
 The delegate and owner are stored in ERC-1056s registry
*/

// MemberStruct is here so that both Everest and Registry can inherit, and stay seperate contracts
contract MemberStruct {
    struct Member {
        uint256 challengeID;    // Is 0 if it is not challenged
        // Used for reputation: (now - membershipStartTime) = voteWeight
        // Used to determine membership as well: membershipStartTime > now
        uint256 membershipStartTime;
    }
}

Accessing setMember() is not working. When I try to access the mapping, it just crashes with revert. I know it is this line because when I comment it out my code gets past this. I really have no clue what could be the issue. I also tested teg editMembershipStartTime() function and it has the same problem.

The most bizarre thing is the function editChallengeID() works!!! This has confused me even more.

Can someone help?

  • I tried your contract in remix.ethereum.org and it works as expected. – Ismael Jan 18 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.