官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 桃园市| 山丹县| 长子县| 馆陶县| 陇西县| 察隅县| 安多县| 磐石市| 游戏| 金昌市| 什邡市| 南安市| 馆陶县| 恩平市| 县级市| 年辖:市辖区| 尖扎县| 溆浦县| 仙居县| 井冈山市| 道真| 甘孜县| 景泰县| 朝阳市| 临汾市| 莒南县| 泸西县| 航空| 商丘市| 吕梁市| 油尖旺区| 高台县| 银川市| 青河县| 贵南县| 恩平市| 揭阳市| 衢州市| 建昌县| 合作市| 措美县|