pragma solidity 0.5.1;
// contract MyContract2{
// uint256 public peopleCount = 0;
// mapping(uint => Person) public people;
// struct Person{
// uint _id;
// string _firstName;
// string _lastName;
// }
// function addPerson(string memory _firstName,string memory _lastName) public{
// peopleCount += 1;
// people[peopleCount] = Person(peopleCount,_firstName,_lastName);
// }
// }
// contract MyContract3{
// uint256 public peopleCount = 0;
// mapping(uint => Person) public people;
// struct Person{
// uint _id;
// string _firstName;
// string _lastName;
// }
// function addPerson(string memory _firstName,string memory _lastName) public{
// incrementCount();
// people[peopleCount] = Person(peopleCount,_firstName,_lastName);
// }
// function incrementCount() internal{
// peopleCount += 1;
// }
// }
// 限制拥有者才能操作
// contract MyContract4{
// uint256 public peopleCount = 0;
// mapping(uint => Person) public people;
// address owner;
// modifier onlyOwner(){
// require(msg.sender == owner,"not owner");
// _;
// }
// struct Person{
// uint _id;
// string _firstName;
// string _lastName;
// }
// constructor() public{
// owner = msg.sender;
// }
// function addPerson(string memory _firstName,string memory _lastName) public onlyOwner{
// incrementCount();
// people[peopleCount] = Person(peopleCount,_firstName,_lastName);
// }
// function incrementCount() internal{
// peopleCount += 1;
// }
// }
// 限制开放时间
// contract MyContract5{
// uint256 public peopleCount = 0;
// mapping(uint => Person) public people;
// uint256 openingTime = 1556181850;
// modifier onlyWhileOpen(){
// require(block.timestamp >= openingTime,"not reach open time");
// _;
// }
// struct Person{
// uint _id;
// string _firstName;
// string _lastName;
// }
// function addPerson(string memory _firstName,string memory _lastName) public onlyWhileOpen{
// incrementCount();
// people[peopleCount] = Person(peopleCount,_firstName,_lastName);
// }
// function incrementCount() internal{
// peopleCount += 1;
// }
// }
// 利用event查看log
// contract MyContract6{
// mapping(address => uint256) public balances;
// address payable wallet;
// event Purchase(address indexed _buyer,uint256 _amount);
// constructor(address payable _wallect) public{
// wallet = _wallect;
// }
// function() external payable{
// buyToken();
// }
// function buyToken() public payable{
// balances[msg.sender] += 1;
// wallet.transfer(msg.value);
// emit Purchase(msg.sender,1);
// }
// }
网友评论