/** @title Contractor contract */
contract Contractor {
address public owner;
uint256 private coins;
uint256 private cash;
bytes32 private service;
event logContractorChanged(
address indexed owner, 
bytes32 firstname, 
bytes32 lastname, 
uint256 coins, 
uint256 cash, 
bytes32 service
);
event logAssetsChanged(address indexed owner, uint256 coins, uint256 cash, bytes32 service);
struct ContractorData {
bytes32 firstname;
bytes32 lastname;
uint256 coins;
uint256 cash;
bytes32 service;
}
mapping (address => ContractorData) ContractorsData;
/**
* @dev Modifier which checks if sender is equal to owner.
*/
modifier onlyContractor() {
require(owner == msg.sender, "Sender not authorized.");
_;
}
/**
* @dev Constructor which inits at contract creation.
*/
constructor() public {
owner = msg.sender;
coins = 0;
cash = 0;
service = "";
}
/**
* @dev Sets all data for Contractor
* @param _firstname The first name of the Contractor
* @param _lastname The last name of the Contractor
* @param _coins Amount of coins available
* @param _cash Amount of cash available
* @param _service Service offered by the Contractor
* @return ContractorData struct of the owner
*/
function setContractor(
bytes32 _firstname,
bytes32 _lastname,
uint256 _coins,
uint256 _cash,
bytes32 _service) public onlyContractor returns (ContractorData)
{
ContractorsData[owner].firstname = _firstname;
ContractorsData[owner].lastname = _lastname;
ContractorsData[owner].coins = _coins;
ContractorsData[owner].cash = _cash;
ContractorsData[owner].service = _service;
emit logContractorChanged(owner, _firstname, _lastname, _coins, _cash, _service);
return ContractorsData[owner];
}
/**
* @dev Sets all assets for Contractor
* @param _coins Amount of coins available
* @param _cash Amount of cash available
* @param _service Service offered by the Contractor
* @return ContractorData struct of the owner
*/
function setAssets(uint256 _coins, uint256 _cash, bytes32 _service) 
public 
onlyContractor 
returns (ContractorData) {
ContractorsData[owner].coins = _coins;
ContractorsData[owner].cash = _cash;
ContractorsData[owner].service = _service;
emit logAssetsChanged(owner, _coins, _cash, _service);
return ContractorsData[owner];
}
/**
* @dev Gets the account data of the Contractor
* @return ContractorData struct of the owner
*/
function myAccount() public onlyContractor view returns (ContractorData) 
{
ContractorData memory fdata = ContractorsData[owner];
return fdata;
}
}