solidity - 在 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);
解决方案
推荐阅读
- android - Flutter Isolate,将 RepaintBoundary 的 GlobalKey 发送到 Isolate
- linux - 如何保留命令输出中的换行符并使用 ansible 复制模块将其写入文件
- node.js - 为什么在子集合中创建多个文档后,我收到 Cloud Function 内存泄漏警告?
- firebase - google-services.json 文件有时间限制(有效期)吗?
- kotlin - MVVM kotlin 中的 LiveData Observer 首先返回之前的结果
- java - 响应 403 无效的 CSRF 令牌
- python - 以x轴0.05的固定间隔提取Y轴的值
- android - 如何在 android 中获取 HLS(.m3u8) 视频链接的持续时间?
- reactjs - 打包一个自定义的 Material UI ThemeProvider 组件
- css - 在 React Link 元素上设置样式会导致点击中断