pragma solidity ^0.8.0;
contract SimpleStorage {
uint public storedData;
address public owner=0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
uint256 public money;
address public thisAddress=address(this);
address public thisAddress2=msg.sender;
uint public etherTest=1 gwei;
mapping(address => uint256) public balances;
event Set(uint x);//事件
enum State { Created, Locked, InValid } // 枚举
State public state;
modifier onlyOwner(){
require(owner == msg.sender,"only owner can call this function");
_;
}
struct Voter { // 结构体
uint weight;
bool voted;
}
Voter[] public voter;
function set(uint x) public onlyOwner {
storedData = x; // 错误的,多加了一个加号
emit Set(storedData);
}
function setState(State _state) public{
state=_state;
}
function f(uint len) public pure {
uint[] memory a = new uint[](7);
bytes memory b = new bytes(len);
assert(a.length == 7);
assert(b.length == len);
a[6] = 8;
}
function setVoter( uint _weight,bool _voted) public {
voter.push(Voter(_weight,_voted));
}
function bal() public view returns(uint){//返回余额
return msg.sender.balance;
}
function testPure(uint x) public pure returns(uint){//纯
return x*2;
}
function buy() public payable{
assert(msg.value>0);//必须大于0,不然不执行下面的
money+=msg.value;
}
function mint(address account,uint256 amount) public onlyOwner{//铸币,当前账号才有权限
balances[account] += amount;
}
}