2

I have a function in my ChangeManager contract which should create multiple ChangeRequests. I tried to model a Change by using a struct and pass this from my ChangeManager to the ChangeRequest:

Code from ChangeManager:

function createNewChangeRequest(
    bytes20 gitHash, string additionalInformation, uint256 costs, uint256 estimation
) public returns (ChangeRequest)
{
    Change memory change = Change(gitHash, additionalInformation, costs, estimation);
    ChangeRequest changerequest = new ChangeRequest(change, msg.sender);
    _changes.push(changerequest);
    emit NewChangeRequest(changerequest, gitHash, additionalInformation, costs, estimation);
}

Code from ChangeRequest:

    function viewChange() public view returns (bytes20, string, uint256, uint256) {
    return (_currentChange.gitHash, _currentChange.additionalInformation, _currentChange.costs, _currentChange.estimation);
}

Code from ChangeTracker (Parent class of ChangeManager and ChangeRequest):

contract ChangeTracker {
enum State {
    changeProposed, changeManaged, changeApproved, changeRejected, changeReleased
}

struct Change {
    bytes20 gitHash;
    string additionalInformation;
    uint256 costs;
    uint256 estimation;
}
}

I have put the "pragma experimental ABIEncoderV2;" before all my codes to be able to use structs in function calls.

I am using truffle to test my code where I get the following result when I am testing the viewChange() function:

[ '0x9a034128a329f4fb7a53043dd1d1e8f74bfc91fc',
  '',
  BigNumber { s: 1, e: 3, c: [ 2400 ] },
  BigNumber {
    s: 1,
    e: 76,
    c:
     [ 6966192,
       89321109306702,
       74526880295124,
       29411066690039,
       54848211183525,
       24260684070912 ] } ]

So the gitHash and the costs work but the additionalInformation and the estimation do not deliver the correct value. Is it even possible to pass a struct from one contract to the constructor of another one?

Maybe I should just destructure the struct for the constructor and just use static variables to initialize ChangeRequest.

Your help is highly appreciated!

  • I have made it work through using the static variables but I am still wondering if there is the possibility to use structs in constructors. – Cryt1c May 30 '18 at 9:41
  • any luck? is it possible at all? – Amarsh Nov 28 '18 at 4:59
  • I have used the workaround and did not further follow up on this question. – Cryt1c Nov 29 '18 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.