【发布时间】:2022-12-10 06:14:41
【问题描述】:
我编写了以下代码来跟踪智能合约中的存款。 我需要能够在未来的功能中引用个人存款。
pragma solidity ^0.8.4;
contract DepositsWithIds {
address owner;
struct Deposit {
uint256 depositAmount;
address depositor;
uint256 counter;
}
constructor() payable {
owner = msg.sender;
}
Deposit[] public activeDeposits;
event DepositMade(address, uint256, uint256);
function deposit() public payable returns (uint256 counter) {
return ++counter;
Deposit memory newDeposit = Deposit(
msg.value,
msg.sender,
counter
);
activeDeposits.push(newDeposit);
emit DepositMade(msg.sender, msg.value, counter);
}
}
使用柜台作为唯一的存款 ID 是个好主意吗?
在编写下一个函数时,如何将activeDeposits.counter 连接到activeDeposits.depositor?
【问题讨论】:
标签: ethereum blockchain solidity smartcontracts