1

I have a struct with 10 parameters. The idea is to apply this struct for represent the flow of a trace. So I have to set variables values in a stepped way. Now i´m trying to call a function to set the first three values, but the compiler gives me a error.

pragma solidity ^0.4.24;

import "browser/DateTime.sol";

contract Travel {

address private owner;

struct TravelStruct 
{
    //Origin
    address clientAddress;
    string originAirportName;
    uint32 originTime; //In timestamp
    uint16 originBagWeight;
    //Tape
    uint32 tapeArrivedTime; //In timestamp
    //Plane
    bytes8 flyCode;
    uint32 takeOffTime; //In timestamp
    //Destiny
    string destinationAirportName;
    uint32 destinyTime; //In timestamp
    uint16 destinyBagWeight;
}

mapping(uint => Travel) travels;
uint public travelsRegistryCount;

constructor() public
{
    owner = msg.sender;
    travelsRegistryCount = 1;
}

modifier ownerFunc 
{
    require(owner == msg.sender);
    _;
}


function setOrigin (string _originAirportName, uint32 _originTime, uint16 _originBagWeight) private
{
    travels[travelsRegistryCount] = TravelStruct(owner, _originAirportName, _originTime, _originBagWeight, 0, "", 0, "", 0, 0);
}  
}

browser/Travel.sol:45:41: TypeError: Type struct Travel.TravelStruct memory is not implicitly convertible to expected type contract Travel. travels[travelsRegistryCount] = TravelStruct(owner, _originAirportName, _originTime, _originBagWeight, 0, "", 0, "", 0, 0); ^----------------------------------------------------------------------------------------^

First I try to set the first trhee values of the struct but the IDE tell me that the struct have more parameter than the three parameters that I load. So I put the trhee real values and the other 7 fake values. But the problem persist and now is telling my the block quote message.

  • How can I solve this??

  • It´s posible to load just the values that I want(something like: travels[travelsRegistryCount] = TravelStruct(owner, _originAirportName, _originTime, _originBagWeight)??

  • And for a traceability project is the correct way to make all the values in the same struct or is a better practice to make this cain of flow??

1

Travel is contract name.

change mapping to

mapping(uint => TravelStruct) travels;

you can load values like

travels[travelsRegistryCount].clientAddress
travels[travelsRegistryCount].originAirportName

And for a traceability project is the correct way to make all the values in the same struct or is a better practice to make this cain of flow??

It is the correct way. Of course, needs more implementation :)

  • Thats true and solved the problem ;D. But can you help me with the ither questions?? – UnexpectedCharacter Nov 23 '18 at 9:01
  • @Eduardo, I modified :) – TLHBM Nov 23 '18 at 9:41
  • Thx for help men ;D – UnexpectedCharacter Nov 23 '18 at 9:49
  • 1
    I'm studying blockchain/ethereum too. hehe – TLHBM Nov 23 '18 at 10:07
  • 1
    We are explores of new technologies !! ;D – UnexpectedCharacter Nov 23 '18 at 10:40

Your Answer

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

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