0

I´m trying to call a function insertOrigin inside a struct and then call other function getOrigin to return that values. But VS Code get a error

pragma solidity ^ "0.4.24";

contract Origin {

struct OriginInfo
{
    string airportName;
    uint32 checkInTime; //In timestamp
    uint8 bagWeight;
    address clientAddress;
    bool itsHere;
}

function insertOrigin(string _airportName, uint32 _checkInTime, uint8 _bagWeight, bool _itsHere) external
{
    /*OriginInfo[] originInfoArray;
    originInfoArray.length++;

    originInfoArray[originInfoArray.length-1].airportName = _airportName;
    originInfoArray[originInfoArray.length-1].checkInTime = _checkInTime;
    originInfoArray[originInfoArray.length-1].bagWeight = _bagWeight;
    originInfoArray[originInfoArray.length-1].clientAddress = _clientAddress;
    originInfoArray[originInfoArray.length-1].itsHere = _itsHere;*/


    OriginInfo(_airportName, _checkInTime, _bagWeight, msg.sender, true);
    getOrigin();
}

function getOrigin() private constant returns (string, uint32, uint8, address, bool) 
{
    return (OriginInfo.airportName, 
    OriginInfo.checkInTime, 
    OriginInfo.bagWeight, 
    OriginInfo.clientAddress, 
    OriginInfo.itsHere);
}
}

enter image description here

Any idea?

2

You're not querying an instance of OriginInfo, but the struct declaration itself. You have to use a mapping in order to achieve what you want:

pragma solidity ^ "0.4.24";

contract Origin {

    struct OriginInfo
    {
        string airportName;
        uint32 checkInTime; //In timestamp
        uint8 bagWeight;
        address clientAddress;
        bool itsHere;
    }
    mapping (uint256 => OriginInfo) origins;
    uint256 public originNonce;

    constructor() public {
        originNonce = 1;
    }

    function insertOrigin(string _airportName, uint32 _checkInTime, uint8 _bagWeight, bool _itsHere) 
        external 
    {
        origins[originNonce] = OriginInfo(_airportName, _checkInTime, _bagWeight, msg.sender, true);
        originNonce += 1;
    }

    function getOrigin(uint256 _originId) 
        private 
        constant 
        returns (string, uint32, uint8, address, bool) 
    {
        OriginInfo memory origin = origins[_originId];
        return (
            origin.airportName,
            origin.checkInTime, 
            origin.bagWeight, 
            origin.clientAddress, 
            origin.itsHere
        );
    }
}

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.