0

I have one solidity file, inside that file I have a this function:

struct OriginInfo{
    string 1;
    uint32 2; //In timestamp
    uint8 3;
    address 4;
    bool 5;
}

function insertOrigin(string _1, uint32 _2, uint8 _3, address _4) external pure {
    OriginInfo(_1, _2, _3, _4, true);
}

And in a another file I import the previous sol file and I call the function insertOrigin(). The import is great done but the problem is that i dont now how to return a struct in the function and in the other contract get that struct to append to origin param inside the Travel struct.

enter image description here

Any help?? Its that posbile to do??

2
  • Maybe with Solidity compiler v0.5.0 or later. Commented Nov 22, 2018 at 10:12
  • Definitely not before (as in your example, v0.4.24). Commented Nov 22, 2018 at 10:18

1 Answer 1

1

Your programming is wrong.

Origin is a smart contract, when you call new Origin() it will deploy a new smart contract.

You probably might want to use Library with those structs.

If not, try calling

Origin origin = new Origin();
origin.insertOrigin(1,2,3,4,5);
Travel travel = Travel(origin, destination)

The better would be to have Origin library, which contains the function insertOrigin (seems like it would be better named as setOrigin), and the same for Destination. Origin and Destinations would be structs instead of smart contracts. But it depends on your design, maybe you really need Origin and Destination to be a smart contract.

2
  • Thx for the answer. My idea is to create a solidity file for each element of the traceability. So you tell me to make libraries instead of contract no??. And have one generic contract that call that import functions to add elements to each trace. But i not able to return a get the struct from external files. With libraryes, is that posible??? Commented Nov 23, 2018 at 7:31
  • Yes if you use the "using" keyword. See solidity.readthedocs.io/en/v0.5.0/contracts.html#using-for Commented Nov 23, 2018 at 14:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.