I am working with Truffle on a payroll smart contract that handles payments, employee addresses, etc. Right now my structure looks something like this:
Payroll.sol
pragma solidity ^0.4.19;
import './InterfacePayroll.sol';
import './EmployeeStorage.sol';
import './Token.sol';
contract Payroll is InterfacePayroll, Ownable {
using SafeMath for uint256;
//set employeeStorage to inherit methods of InterfaceEmployeeStorage
InterfaceEmployeeStorage public employeeStorage;
//set employeeToken to Token
Token public employeeToken;
//=======Modifiers
modifier validAddress(address _address){
require (_address != 0x0);
_;
}
modifier higherThanZero(uint256 _uint){
require(_uint > 0);
_;
}
//=======Initialize
//contructor initializes an instance of EmployeeStorage
//Gas limit has to be raised manually
//TODO set gas limit internally
function Payroll() public{
setEmployeeStorage(new EmployeeStorage());
setEmployeeToken(new Token());
}
//set employeeStorage to contract EmployeeStorage
function setEmployeeStorage(address _newEmployeeStorage)
internal
onlyOwner validAddress(_newEmployeeStorage){
employeeStorage = InterfaceEmployeeStorage(_newEmployeeStorage);
}
//set employeeToken to Token contract
function setEmployeeToken(address _newEmployeetoken)
internal
onlyOwner validAddress(_newEmployeetoken){
employeeToken = Token(_newEmployeetoken);
}
//Accept ETH payments
function () payable public { }
//========================= Functions
//=======Add functions
//Add employee to employee storage
function addEmployee(address _address, uint256 _monthlySalary, uint256 _startDate)
public
onlyOwner
validAddress(_address)
higherThanZero(_monthlySalary){
employeeStorage.add(_address, _monthlySalary, _startDate);
}
...
..
.
}
So you can see that Payroll uses an instance of Employeestorage and Token. I have tested it on Remix and it seems to be working fine. My question is, how would my 2_deploy_contracts.js
look like? Seems like it would simply be:
2_deploy_contracts.js
var payroll = artifacts.require("./Payroll");
module.exports = function(deployer) {
deployer.deploy(payroll);
}
Here is my Gist with all the code.
payroll
deploys the instances it depends on sodeploy
is that simple. You can confirm that in Remix. Is the necessary to "Create" more than one contract to get it to work?