Сопоставление надежности, в котором могут храниться утвержденные адреса, а затем только те, кому адресованы утвержденные адреса, могут изменять скорость токена

#mapping #token #ethereum #solidity

Вопрос:

// __ Отображение __

mapping (address => uint) approvedUsers;

// __ Функция добавления адресов в сопоставление___

 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()));  }
 

Ответ №1:

Я думаю, вы хотите проверить подлинность некоторых адресов, чтобы изменить скорость, а другие адреса не могут этого сделать.

Для этого вам следует (есть и другие способы, но это проще) сделать это:

 //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()));
}