comparing two addressesAre there well-solved and simple storage patterns for Solidity?Error:...

Is there a minimum amount of electricity that can be fed back into the grid?

Is this standard Japanese employment negotiations, or am I missing something?

Does a Globe of Invulnerability spell block outsiders from teleporting inside with a spell?

Why do most airliners have underwing engines, while business jets have rear-mounted engines?

Gory anime with pink haired girl escaping an asylum

How many Jimmys can fit?

Why did Super-VGA offer the 5:4 1280*1024 resolution?

Computer name naming convention for security

Attach a visible light telescope to the outside of the ISS

Why does "sattsehen" take accusative "mich", not dative "mir"? Even though it is not "me" that I'm looking at?

How serious is plagiarism in a master’s thesis?

Minor differences between two recorded guitars

How do resistors generate different heat if we make the current fixed and changed the voltage and resistance? Notice the flow of charge is constant

How did the IEC decide to create kibibytes?

Can a USB hub be used to access a drive from two devices?

Wouldn't putting an electronic key inside a small Faraday cage render it completely useless?

My professor has told me he will be the corresponding author. Will it hurt my future career?

What's the difference between a type and a kind?

Does the Milky Way orbit around anything?

Will Jimmy fall off his platform?

Park the computer

When is one 'Ready' to make Original Contributions to Mathematics?

Wearing special clothes in public while in niddah- isn't this a lack of tznius?

Groups where no elements commute except for the trivial cases



comparing two addresses


Are there well-solved and simple storage patterns for Solidity?Error: “message”:“function ”Ballot“ arguments must include ”proposalNames“”}This contract does not implement all functions and thus cannot be createdA function declared payable is throwing a VMerror:revert in RemixModifier condition always falseHow do I send tokens with EthereumTesterProvider?How is gas adjusted for a transfer in solidity?How to state private keys when using node.js and ethereum to run a contract?remix ERC223: This contract does not implement all functions and thus cannot be createdCollecting ERC20 balances from multiple addresses?Getting Error as parser error:expected identifier, got event






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I'am trying to create a modifier that allows certain accounts to execute functions.



 address[] authorized; 
function verify (address adrs) internal view returns (bool)
{
bool exist;
uint j=authorized.length;
uint i =0;
exist = false;
address[] memory adrss;
while (i<j){
uint x =0;
if (adrss ==address[i]){
bool = true;
}
i++;
}
return exist;
}



modifie allowed (address adrs){
require ( verify(adrs)==true);
_; }


anyone how has an idea?










share|improve this question




















  • 1





    Hi there. I haven't tried it, but it's clear the above code doesn't compile. Is your question "How do I get this code to compile?" or, more generally, "What is the best way to implement an ACL?". Please be more specific with your question: ethereum.stackexchange.com/help/how-to-ask

    – Richard Horrocks
    12 hours ago


















1















I'am trying to create a modifier that allows certain accounts to execute functions.



 address[] authorized; 
function verify (address adrs) internal view returns (bool)
{
bool exist;
uint j=authorized.length;
uint i =0;
exist = false;
address[] memory adrss;
while (i<j){
uint x =0;
if (adrss ==address[i]){
bool = true;
}
i++;
}
return exist;
}



modifie allowed (address adrs){
require ( verify(adrs)==true);
_; }


anyone how has an idea?










share|improve this question




















  • 1





    Hi there. I haven't tried it, but it's clear the above code doesn't compile. Is your question "How do I get this code to compile?" or, more generally, "What is the best way to implement an ACL?". Please be more specific with your question: ethereum.stackexchange.com/help/how-to-ask

    – Richard Horrocks
    12 hours ago














1












1








1








I'am trying to create a modifier that allows certain accounts to execute functions.



 address[] authorized; 
function verify (address adrs) internal view returns (bool)
{
bool exist;
uint j=authorized.length;
uint i =0;
exist = false;
address[] memory adrss;
while (i<j){
uint x =0;
if (adrss ==address[i]){
bool = true;
}
i++;
}
return exist;
}



modifie allowed (address adrs){
require ( verify(adrs)==true);
_; }


anyone how has an idea?










share|improve this question
















I'am trying to create a modifier that allows certain accounts to execute functions.



 address[] authorized; 
function verify (address adrs) internal view returns (bool)
{
bool exist;
uint j=authorized.length;
uint i =0;
exist = false;
address[] memory adrss;
while (i<j){
uint x =0;
if (adrss ==address[i]){
bool = true;
}
i++;
}
return exist;
}



modifie allowed (address adrs){
require ( verify(adrs)==true);
_; }


anyone how has an idea?







solidity contract-design dapps ethereumjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 9 hours ago









Rob Hitchens - B9lab

31.4k7 gold badges46 silver badges87 bronze badges




31.4k7 gold badges46 silver badges87 bronze badges










asked 12 hours ago









MS BMS B

325 bronze badges




325 bronze badges








  • 1





    Hi there. I haven't tried it, but it's clear the above code doesn't compile. Is your question "How do I get this code to compile?" or, more generally, "What is the best way to implement an ACL?". Please be more specific with your question: ethereum.stackexchange.com/help/how-to-ask

    – Richard Horrocks
    12 hours ago














  • 1





    Hi there. I haven't tried it, but it's clear the above code doesn't compile. Is your question "How do I get this code to compile?" or, more generally, "What is the best way to implement an ACL?". Please be more specific with your question: ethereum.stackexchange.com/help/how-to-ask

    – Richard Horrocks
    12 hours ago








1




1





Hi there. I haven't tried it, but it's clear the above code doesn't compile. Is your question "How do I get this code to compile?" or, more generally, "What is the best way to implement an ACL?". Please be more specific with your question: ethereum.stackexchange.com/help/how-to-ask

– Richard Horrocks
12 hours ago





Hi there. I haven't tried it, but it's clear the above code doesn't compile. Is your question "How do I get this code to compile?" or, more generally, "What is the best way to implement an ACL?". Please be more specific with your question: ethereum.stackexchange.com/help/how-to-ask

– Richard Horrocks
12 hours ago










3 Answers
3






active

oldest

votes


















3














You should avoid iterating the list of permitted accounts. It's an expensive approach that doesn't scale and it has a lot of moving parts.



Consider instead using a mapping. This is a namespace where all the uninitialized indexes return false, 0, empty, depending on type. For example:



mapping(address => bool) public whitelist; returns true or false for each address, and you can set/get without iterating.



pragma solidity 0.5.1;

contract SimpleWhitelist {

address public owner;
mapping(address => bool) public whitelist;

event LogProtected(address sender);

modifier onlyOwner {
require(msg.sender == owner, "You are not the owner.");
_;
}

modifier onlyWhitelist {
require(whitelist[msg.sender], "You are not whitelisted.");
_;
}

function setPermission(address user, bool isAllowed) public onlyOwner {
whitelist[user] = isAllowed;
}

function protected() public onlyWhitelist {
emit LogProtected(msg.sender);
}
}


There are more advanced ways to store the list of whitelisted addresses: Are there well-solved and simple storage patterns for Solidity? and de facto standard implementations of the Ownable concept but I wanted to keep this as simple as possible.




  1. Only the owner is allowed to grant/revoke permission.

  2. Only whitelisted addresses are allowed to run protected(). It will emit an event on success.


Hope it helps.






share|improve this answer































    2














    You are making a fundamental mistake which makes it all seem much harder than it really is.
    Instead of an array, your should use a mapping(address => bool), let's call it whitelisted, since it contains booleans.



    Add people in the whitelist like this: whitelisted[_address] = true;



    then in your modifier, you can simply do this:



    require(whitelist[_address])





    share|improve this answer










    New contributor



    blackscale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.















    • 1





      No need to convert through uint160). if(addr1 == addr2) { ... should work if both are addresses.

      – Rob Hitchens - B9lab
      10 hours ago






    • 1





      You are correct, that trick is useful for comparing short Strings cheaply, and I made some confusion. I edited out that part, as anyway it was slightly besides the OP's topic.

      – blackscale
      7 hours ago





















    2














    I recommend that you look at the OpenZeppelin guide on Access Control, specifically the section on Role-Based Access Control as using Roles from OpenZeppelin appear to meet your needs.
    https://docs.openzeppelin.org/v2.3.0/access-control



    For questions on use, you can also ask in the community forum https://forum.zeppelin.solutions/






    share|improve this answer


























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "642"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f72570%2fcomparing-two-addresses%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      You should avoid iterating the list of permitted accounts. It's an expensive approach that doesn't scale and it has a lot of moving parts.



      Consider instead using a mapping. This is a namespace where all the uninitialized indexes return false, 0, empty, depending on type. For example:



      mapping(address => bool) public whitelist; returns true or false for each address, and you can set/get without iterating.



      pragma solidity 0.5.1;

      contract SimpleWhitelist {

      address public owner;
      mapping(address => bool) public whitelist;

      event LogProtected(address sender);

      modifier onlyOwner {
      require(msg.sender == owner, "You are not the owner.");
      _;
      }

      modifier onlyWhitelist {
      require(whitelist[msg.sender], "You are not whitelisted.");
      _;
      }

      function setPermission(address user, bool isAllowed) public onlyOwner {
      whitelist[user] = isAllowed;
      }

      function protected() public onlyWhitelist {
      emit LogProtected(msg.sender);
      }
      }


      There are more advanced ways to store the list of whitelisted addresses: Are there well-solved and simple storage patterns for Solidity? and de facto standard implementations of the Ownable concept but I wanted to keep this as simple as possible.




      1. Only the owner is allowed to grant/revoke permission.

      2. Only whitelisted addresses are allowed to run protected(). It will emit an event on success.


      Hope it helps.






      share|improve this answer




























        3














        You should avoid iterating the list of permitted accounts. It's an expensive approach that doesn't scale and it has a lot of moving parts.



        Consider instead using a mapping. This is a namespace where all the uninitialized indexes return false, 0, empty, depending on type. For example:



        mapping(address => bool) public whitelist; returns true or false for each address, and you can set/get without iterating.



        pragma solidity 0.5.1;

        contract SimpleWhitelist {

        address public owner;
        mapping(address => bool) public whitelist;

        event LogProtected(address sender);

        modifier onlyOwner {
        require(msg.sender == owner, "You are not the owner.");
        _;
        }

        modifier onlyWhitelist {
        require(whitelist[msg.sender], "You are not whitelisted.");
        _;
        }

        function setPermission(address user, bool isAllowed) public onlyOwner {
        whitelist[user] = isAllowed;
        }

        function protected() public onlyWhitelist {
        emit LogProtected(msg.sender);
        }
        }


        There are more advanced ways to store the list of whitelisted addresses: Are there well-solved and simple storage patterns for Solidity? and de facto standard implementations of the Ownable concept but I wanted to keep this as simple as possible.




        1. Only the owner is allowed to grant/revoke permission.

        2. Only whitelisted addresses are allowed to run protected(). It will emit an event on success.


        Hope it helps.






        share|improve this answer


























          3












          3








          3







          You should avoid iterating the list of permitted accounts. It's an expensive approach that doesn't scale and it has a lot of moving parts.



          Consider instead using a mapping. This is a namespace where all the uninitialized indexes return false, 0, empty, depending on type. For example:



          mapping(address => bool) public whitelist; returns true or false for each address, and you can set/get without iterating.



          pragma solidity 0.5.1;

          contract SimpleWhitelist {

          address public owner;
          mapping(address => bool) public whitelist;

          event LogProtected(address sender);

          modifier onlyOwner {
          require(msg.sender == owner, "You are not the owner.");
          _;
          }

          modifier onlyWhitelist {
          require(whitelist[msg.sender], "You are not whitelisted.");
          _;
          }

          function setPermission(address user, bool isAllowed) public onlyOwner {
          whitelist[user] = isAllowed;
          }

          function protected() public onlyWhitelist {
          emit LogProtected(msg.sender);
          }
          }


          There are more advanced ways to store the list of whitelisted addresses: Are there well-solved and simple storage patterns for Solidity? and de facto standard implementations of the Ownable concept but I wanted to keep this as simple as possible.




          1. Only the owner is allowed to grant/revoke permission.

          2. Only whitelisted addresses are allowed to run protected(). It will emit an event on success.


          Hope it helps.






          share|improve this answer













          You should avoid iterating the list of permitted accounts. It's an expensive approach that doesn't scale and it has a lot of moving parts.



          Consider instead using a mapping. This is a namespace where all the uninitialized indexes return false, 0, empty, depending on type. For example:



          mapping(address => bool) public whitelist; returns true or false for each address, and you can set/get without iterating.



          pragma solidity 0.5.1;

          contract SimpleWhitelist {

          address public owner;
          mapping(address => bool) public whitelist;

          event LogProtected(address sender);

          modifier onlyOwner {
          require(msg.sender == owner, "You are not the owner.");
          _;
          }

          modifier onlyWhitelist {
          require(whitelist[msg.sender], "You are not whitelisted.");
          _;
          }

          function setPermission(address user, bool isAllowed) public onlyOwner {
          whitelist[user] = isAllowed;
          }

          function protected() public onlyWhitelist {
          emit LogProtected(msg.sender);
          }
          }


          There are more advanced ways to store the list of whitelisted addresses: Are there well-solved and simple storage patterns for Solidity? and de facto standard implementations of the Ownable concept but I wanted to keep this as simple as possible.




          1. Only the owner is allowed to grant/revoke permission.

          2. Only whitelisted addresses are allowed to run protected(). It will emit an event on success.


          Hope it helps.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 12 hours ago









          Rob Hitchens - B9labRob Hitchens - B9lab

          31.4k7 gold badges46 silver badges87 bronze badges




          31.4k7 gold badges46 silver badges87 bronze badges

























              2














              You are making a fundamental mistake which makes it all seem much harder than it really is.
              Instead of an array, your should use a mapping(address => bool), let's call it whitelisted, since it contains booleans.



              Add people in the whitelist like this: whitelisted[_address] = true;



              then in your modifier, you can simply do this:



              require(whitelist[_address])





              share|improve this answer










              New contributor



              blackscale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.















              • 1





                No need to convert through uint160). if(addr1 == addr2) { ... should work if both are addresses.

                – Rob Hitchens - B9lab
                10 hours ago






              • 1





                You are correct, that trick is useful for comparing short Strings cheaply, and I made some confusion. I edited out that part, as anyway it was slightly besides the OP's topic.

                – blackscale
                7 hours ago


















              2














              You are making a fundamental mistake which makes it all seem much harder than it really is.
              Instead of an array, your should use a mapping(address => bool), let's call it whitelisted, since it contains booleans.



              Add people in the whitelist like this: whitelisted[_address] = true;



              then in your modifier, you can simply do this:



              require(whitelist[_address])





              share|improve this answer










              New contributor



              blackscale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.















              • 1





                No need to convert through uint160). if(addr1 == addr2) { ... should work if both are addresses.

                – Rob Hitchens - B9lab
                10 hours ago






              • 1





                You are correct, that trick is useful for comparing short Strings cheaply, and I made some confusion. I edited out that part, as anyway it was slightly besides the OP's topic.

                – blackscale
                7 hours ago
















              2












              2








              2







              You are making a fundamental mistake which makes it all seem much harder than it really is.
              Instead of an array, your should use a mapping(address => bool), let's call it whitelisted, since it contains booleans.



              Add people in the whitelist like this: whitelisted[_address] = true;



              then in your modifier, you can simply do this:



              require(whitelist[_address])





              share|improve this answer










              New contributor



              blackscale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              You are making a fundamental mistake which makes it all seem much harder than it really is.
              Instead of an array, your should use a mapping(address => bool), let's call it whitelisted, since it contains booleans.



              Add people in the whitelist like this: whitelisted[_address] = true;



              then in your modifier, you can simply do this:



              require(whitelist[_address])






              share|improve this answer










              New contributor



              blackscale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.








              share|improve this answer



              share|improve this answer








              edited 7 hours ago





















              New contributor



              blackscale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.








              answered 11 hours ago









              blackscaleblackscale

              434 bronze badges




              434 bronze badges




              New contributor



              blackscale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




              New contributor




              blackscale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.










              • 1





                No need to convert through uint160). if(addr1 == addr2) { ... should work if both are addresses.

                – Rob Hitchens - B9lab
                10 hours ago






              • 1





                You are correct, that trick is useful for comparing short Strings cheaply, and I made some confusion. I edited out that part, as anyway it was slightly besides the OP's topic.

                – blackscale
                7 hours ago
















              • 1





                No need to convert through uint160). if(addr1 == addr2) { ... should work if both are addresses.

                – Rob Hitchens - B9lab
                10 hours ago






              • 1





                You are correct, that trick is useful for comparing short Strings cheaply, and I made some confusion. I edited out that part, as anyway it was slightly besides the OP's topic.

                – blackscale
                7 hours ago










              1




              1





              No need to convert through uint160). if(addr1 == addr2) { ... should work if both are addresses.

              – Rob Hitchens - B9lab
              10 hours ago





              No need to convert through uint160). if(addr1 == addr2) { ... should work if both are addresses.

              – Rob Hitchens - B9lab
              10 hours ago




              1




              1





              You are correct, that trick is useful for comparing short Strings cheaply, and I made some confusion. I edited out that part, as anyway it was slightly besides the OP's topic.

              – blackscale
              7 hours ago







              You are correct, that trick is useful for comparing short Strings cheaply, and I made some confusion. I edited out that part, as anyway it was slightly besides the OP's topic.

              – blackscale
              7 hours ago













              2














              I recommend that you look at the OpenZeppelin guide on Access Control, specifically the section on Role-Based Access Control as using Roles from OpenZeppelin appear to meet your needs.
              https://docs.openzeppelin.org/v2.3.0/access-control



              For questions on use, you can also ask in the community forum https://forum.zeppelin.solutions/






              share|improve this answer




























                2














                I recommend that you look at the OpenZeppelin guide on Access Control, specifically the section on Role-Based Access Control as using Roles from OpenZeppelin appear to meet your needs.
                https://docs.openzeppelin.org/v2.3.0/access-control



                For questions on use, you can also ask in the community forum https://forum.zeppelin.solutions/






                share|improve this answer


























                  2












                  2








                  2







                  I recommend that you look at the OpenZeppelin guide on Access Control, specifically the section on Role-Based Access Control as using Roles from OpenZeppelin appear to meet your needs.
                  https://docs.openzeppelin.org/v2.3.0/access-control



                  For questions on use, you can also ask in the community forum https://forum.zeppelin.solutions/






                  share|improve this answer













                  I recommend that you look at the OpenZeppelin guide on Access Control, specifically the section on Role-Based Access Control as using Roles from OpenZeppelin appear to meet your needs.
                  https://docs.openzeppelin.org/v2.3.0/access-control



                  For questions on use, you can also ask in the community forum https://forum.zeppelin.solutions/







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 3 hours ago









                  abcoathupabcoathup

                  3007 bronze badges




                  3007 bronze badges






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Ethereum Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f72570%2fcomparing-two-addresses%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                      Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                      Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...