一.合约案例简介
- 此案例为入门案例,从 合约 -> 编译 -> web3部署和调用
二.彩票合约源码
pragma solidity ^0.4.25;
contract LotteryShop{
event BuyLottery(address indexed buyer,uint money,uint16 luckNum);
event DrawLottery(address winner,uint money,uint16 luckNum);
mapping(address=>uint) buyMapping;
address[] usrAdrList;
address manageAdr;
address contractAdr;
constructor() public payable{
manageAdr=msg.sender;
contractAdr= address(this);
}
function ShowManageAdr() constant returns(address){
return manageAdr;
}
function ShowInvokerCaiPiao() constant returns(uint){
return buyMapping[msg.sender];
}
function ShowManageBalance() constant returns(uint){
return manageAdr.balance;
}
function ShowContractMoney() constant returns(uint){
return contractAdr.balance;
}
function getAllUsrAddress() view returns(address[]){
return usrAdrList;
}
function BuyCaiPiao(uint16 haoMa) payable{
require(msg.value == 1 ether);
require(buyMapping[msg.sender]==0);
contractAdr.send(msg.value);
emit BuyLottery(msg.sender,msg.value,haoMa);
buyMapping[msg.sender] = haoMa;
usrAdrList.push(msg.sender);
}
function KaiJiang() adminOnly payable returns(uint){
uint256 luckNum = uint256(keccak256(abi.encodePacked(block.difficulty,now)));
luckNum = luckNum