In my contract, I have separated my code and data. In the "data contract", I am storing the current version of code. Whenever addEmployee() is called, I am trying to delegate it to Current Version address (with string as parameter) where the actual function code resides. But the problem is string being received by the Current Version is always ' ' regardlessof my input. (See the commented part in the contract Data.)The function works as expected if I use bytes32 instead of string. Can someone explain this behaviour??? Am I missing some concept??
pragma solidity ^0.4.11;
contract EmployeeDir{
uint public id;
string public name;
address public currentVersion;
address public owner;
struct employee{
string name;
uint days_present;
}
mapping (uint => employee) public dir;
/**
* Constructor: Sample Input "vishy", "<address of contract Code>"
* @param _name - Name of the EmployeeDir
* @param _versionAddr - Address of the Current Version to which Delegate Call is intended to
**/
function EmployeeDir(string _name, address _versionAddr){
dir[id].name = _name;
currentVersion = _versionAddr;
owner = msg.sender;
}
function updateVersionAddress(address _versionAddr){
if(msg.sender == owner)
currentVersion = _versionAddr;
}
function addEmployee(string _name){
if(msg.sender == owner){
//This is where the string is being passed as empty
//To check if the delegatecall is indeed working, a sample var id has been introduced.
//The var id is getting updated on delegatecall meaning that delegatecall is working but the string is not getting updated.
currentVersion.delegatecall(bytes4(sha3("addEmployee(string)")), _name);
dir[id].name = name;
}
}
}
contract Code{
uint public id;
string public name;
function addEmployee(string _name){
id += 1;
name = _name;
}
}