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

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.

主站蜘蛛池模板: 临澧县| 遂溪县| 和龙市| 金乡县| 兴化市| 班玛县| 佳木斯市| 花垣县| 前郭尔| 汤原县| 邵阳县| 论坛| 鹤山市| 石棉县| 汉沽区| 韶关市| 定南县| 天柱县| 长宁区| 招远市| 曲水县| 甘谷县| 丰宁| 鹤壁市| 成都市| 房山区| 从江县| 图木舒克市| 屏山县| 梧州市| 彝良县| 勐海县| 贺兰县| 温宿县| 玉屏| 景宁| 丰宁| 祁阳县| 右玉县| 南江县| 综艺|