- Truffle Quick Start Guide
- Nikhil Bhaskar
- 174字
- 2021-06-25 20:47:34
Creating a reward method
This will be invoked by the owner to reward a doer for their successful completion of a task:
pragma solidity ^0.4.17;
contract TaskMaster {
mapping (address => uint) public balances; // balances of everyone
address public owner; // owner of the contract
function TaskMaster() public {
owner = msg.sender;
balances[msg.sender] = 10000;
}
function reward(address doer, uint rewardAmount)
public
returns(bool sufficientFunds)
{
balances[msg.sender] -= rewardAmount;
balances[doer] += rewardAmount;
return sufficientFunds;
}
}
This function accepts the following:
- an address for the doer
- an integer amount for their reward
We are almost there—we need to add some necessary security touches.
Notice how we are not performing a real transfer of ETH, but rather we simply decrement the balance of the owner and increment the balance of the doer. The reason we don't perform a real transfer here is because we simply hard-coded a balance value of 10000 and made up a token called TodoCoin. Remember, our goal in this chapter is to get a fully functioning Dapp using Truffle.
推薦閱讀
- 黑客攻防實(shí)戰(zhàn)技術(shù)完全手冊(cè):掃描、嗅探、入侵與防御
- 網(wǎng)絡(luò)云百問百答
- Cisco OSPF命令與配置手冊(cè)
- 物聯(lián)網(wǎng)短距離無線通信技術(shù)應(yīng)用與開發(fā)
- 物聯(lián)網(wǎng)之魂:物聯(lián)網(wǎng)協(xié)議與物聯(lián)網(wǎng)操作系統(tǒng)
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- 物聯(lián)網(wǎng)關(guān)鍵技術(shù)及應(yīng)用
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- Yii Application Development Cookbook(Second Edition)
- Metasploit Penetration Testing Cookbook
- Learning Swift(Second Edition)
- 網(wǎng)絡(luò)安全應(yīng)急響應(yīng)技術(shù)實(shí)戰(zhàn)
- 圖解手機(jī)元器件維修技巧
- 網(wǎng)管員必讀:網(wǎng)絡(luò)管理(第2版)
- 網(wǎng)絡(luò)環(huán)境中基于用戶視角的信息質(zhì)量評(píng)價(jià)研究