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;
}
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
add a comment |
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
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
add a comment |
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
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
solidity contract-design dapps ethereumjs
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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.
- Only the owner is allowed to grant/revoke permission.
- Only whitelisted addresses are allowed to run
protected()
. It will emit an event on success.
Hope it helps.
add a comment |
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])
New contributor
1
No need to convert throughuint160)
.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
add a comment |
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/
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
- Only the owner is allowed to grant/revoke permission.
- Only whitelisted addresses are allowed to run
protected()
. It will emit an event on success.
Hope it helps.
add a comment |
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.
- Only the owner is allowed to grant/revoke permission.
- Only whitelisted addresses are allowed to run
protected()
. It will emit an event on success.
Hope it helps.
add a comment |
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.
- Only the owner is allowed to grant/revoke permission.
- Only whitelisted addresses are allowed to run
protected()
. It will emit an event on success.
Hope it helps.
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.
- Only the owner is allowed to grant/revoke permission.
- Only whitelisted addresses are allowed to run
protected()
. It will emit an event on success.
Hope it helps.
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
add a comment |
add a comment |
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])
New contributor
1
No need to convert throughuint160)
.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
add a comment |
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])
New contributor
1
No need to convert throughuint160)
.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
add a comment |
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])
New contributor
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])
New contributor
edited 7 hours ago
New contributor
answered 11 hours ago
blackscaleblackscale
434 bronze badges
434 bronze badges
New contributor
New contributor
1
No need to convert throughuint160)
.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
add a comment |
1
No need to convert throughuint160)
.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
add a comment |
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/
add a comment |
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/
add a comment |
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/
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/
answered 3 hours ago
abcoathupabcoathup
3007 bronze badges
3007 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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