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

Wrapping up

Your final TaskMaster.sol file should look like this:

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
isOwner()
hasSufficientFunds(rewardAmount)
returns(bool sufficientFunds)
{
balances[msg.sender] -= rewardAmount;
balances[doer] += rewardAmount;
return sufficientFunds;
}

function getBalance(address addr) public view returns(uint) {
return balances[addr];
}

modifier isOwner() {
require(msg.sender == owner);
_;
}

modifier hasSufficientFunds(uint rewardAmount) {
require(balances[msg.sender] >= rewardAmount);
_;
}
}

You can also find this file in the repo, under contracts (https://github.com/PacktPublishing/Truffle-Quick-Start-Guide/blob/master/chapter1/contracts/TaskMaster.sol).

Now that we've created a full TaskMaster.sol file, you can do the following bit of housekeeping.

Delete all contents of migrations/2_deploy_contracts.js and replace them with the following code:

var TaskMaster = artifacts.require("./TaskMaster.sol");

module.exports = function(deployer) {
deployer.deploy(TaskMaster);
};

This specifies that TaskMaster.sol should be deployed to a blockchain. You will learn more about migrations in Chapter 4, Migrating Your Dapp to Ethereum Blockchains.

主站蜘蛛池模板: 静宁县| 彭水| 吉首市| 定陶县| 竹溪县| 霍州市| 临洮县| 衢州市| 介休市| 乌拉特前旗| 肥西县| 江油市| 楚雄市| 临夏市| 樟树市| 马边| 界首市| 永昌县| 松阳县| 稻城县| 安顺市| 元谋县| 镶黄旗| 广水市| 赤城县| 晋中市| 深州市| 保康县| 璧山县| 安国市| 广宗县| 平凉市| 阿拉尔市| 汉阴县| 罗山县| 岚皋县| 吉林市| 陆河县| 河津市| 霍邱县| 新乐市|