Solidity Mapping,可以存储批准的地址,然后那些批准的地址是唯一可以更改代币费率的人

Solidity Mapping, which can store approved addresses, and then those approved addressed are the only one who can change the rate of the token

// __ 映射 __

mapping (address => uint) approvedUsers;

// __函数添加地址到mapping___

function _addApprover(address _approver, uint _i) public{
  approvedUsers[_approver]  += approvedUsers[_i];

}

// ___ 映射中的用户已检查,如果为真则可以更改费率,否则不能_

function pricing(address _user, uint _rate) public{
    require(approvedUsers[_user] == approvedUsers,"User not in the approvers list");
rate = _rate * (10 ** uint256(decimals()));  }

我想你想验证一些地址来改变费率,而其他地址是做不到的。

为此,您应该(还有其他方法,但这更容易)这样做:

//First you declare owner to have access to approve or disapprove users
address owner;

//Then you declare mapping
mapping(address=>bool) approvedUsers;
//Automatically all addresses return false so no one has access to it.

//In constructor, you specify the owner
constructor(){
  owner = msg.sender
}
//By using msg.sender, contract who deployed contract will be owner.

//A modify to make some functions just callable by owner
modifier isOwner(){
  require(msg.sender == owner, "Access denied");
  _;
}

//Now function to approve and disapprove users
function _addApprover(address _approver) public isOwner{
  approvedUsers[_approver]  = true;
function _removeApprovedUser(address _disapprover) public isOwner{
  approvedUsers[_disapprover]  = false;

//Now change rating function
function pricing(uint _rate) public{
  require(approvedUsers[msg.sender],"User not in the approvers list");
  //Because approvedUsers mapping returns a bool, you do not need to compare it and if it is true,
  //user have access to change and if it is false user does not have access to change it
  rate = _rate * (10 ** uint256(decimals()));
}