首页 > 解决方案 > 在 uint256 中的参数相关查找后未找到或不可见成员“付款”

问题描述

嗨,我正在做一个培训实验室,涉及使用结构并将付款和余额映射到发件人。在 setter 函数 sendMoney() 中,在 uint256 中的参数相关查找后,我收到错误“成员“付款”未找到或不可见

编译指示 ^0.8.4;

contract MappingsStructExample {

    struct Payment {
        uint amount;
        uint timestamp;
    }  

    struct Balance {
        uint TotalBalance;
        uint NumPayments;
        mapping(uint => Payment) payments;
    }                                                      

    mapping(address => uint) public BalanceReceived;  // created a mapping 


    function GetBalance () public view returns (uint) {
      return address(this).balance;   // get balance of this smart contract
   }

   function SendMoney() public payable {  // allows you to send money to the smart contract
       BalanceReceived[msg.sender] += msg.value;  // this tracks the funds and who sent how much

       Payment memory payment = Payment(msg.value, block.timestamp);
       *BalanceReceived[msg.sender].payments[BalanceReceived[msg.sender].numPayments] = payment;*
       BalanceReceived[msg.sender].numPayments++;
   }

   function WithdrawMoney(address payable _to, uint _amount) public {
        require(_amount <= BalanceReceived[msg.sender], "not enough funds");
        BalanceReceived[msg.sender] -= _amount;
   }
   function WithdrawAllMoney(address payable _to) public {
        uint balanceToSend = BalanceReceived[msg.sender];     // If that same person tried to withdraw money again using "withdrawAllMoney" , 
        BalanceReceived[msg.sender] = 0; // We look in that mapping to see how much he sen, 
        // there previously, then rest the mapping and send the amount
        _to.transfer(address(this).balance);  

标签: solidity

解决方案


推荐阅读