小明今天繼續進行每個功能的實作,今天先完成的是用戶存提以太幣的功能:
function depositEther() public payable {
require(balanceEthForAddress[msg.sender] + msg.value >= balanceEthForAddress[msg.sender]);
balanceEthForAddress[msg.sender] += msg.value;
emit DepositForEthReceived(msg.sender, msg.value, now);
}
function withdrawEther(uint amountInWei) public {
require(balanceEthForAddress[msg.sender] - amountInWei >= 0);
require(balanceEthForAddress[msg.sender] - amountInWei <= balanceEthForAddress[msg.sender]);
balanceEthForAddress[msg.sender] -= amountInWei;
msg.sender.transfer(amountInWei);
emit WithdrawalEth(msg.sender, amountInWei, now);
}
function getEthBalanceInWei() view public returns (uint){
return balanceEthForAddress[msg.sender];
}
本文同時發佈於作者部落格:https://www.bdetw.com/blog
想找區塊鏈人才或想學習區塊鏈知識的夥伴。歡迎參加社群小聚,一起來輕鬆交流、互相學習成長、認識新朋友、發現新機會!
台北區塊鏈社群
https://bitlly.co/Q4dIK
BDE 區塊鏈學院 - 提供專業的區塊鏈培訓與顧問服務。
https://bitlly.co/mbDwX