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

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.

主站蜘蛛池模板: 宝鸡市| 双鸭山市| 阿巴嘎旗| 宜昌市| 尼玛县| 苗栗市| 西青区| 宁河县| 抚顺市| 玉林市| 双桥区| 通榆县| 安丘市| 师宗县| 五华县| 娱乐| 清镇市| 湖州市| 南漳县| 托克逊县| 滦平县| 汉源县| 甘德县| 万宁市| 酒泉市| 青浦区| 元江| 洪湖市| 桦南县| 霍州市| 南木林县| 红安县| 汉沽区| 扎赉特旗| 蕉岭县| 准格尔旗| 理塘县| 章丘市| 宁阳县| 婺源县| 枣强县|