[Ethereum] Undeclared identifier

identitysolidity

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) 
    external 
{
    origins[originNonce] = OriginInfo(_airportName, _checkInTime, _bagWeight, msg.sender, true);
    originNonce += 1;

    recoverOrigin(originNonce);
}

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



pragma solidity ^ "0.4.24";

import "./TraceabilityProcedures/Origin.sol";

contract Travel is Origin{


struct TravelInfo {

    Origin origin;
}

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

function addOrigin (string _airportName, uint32 _checkInTime, uint8 _bagWeight){
    insertOrigin(_airportName, _checkInTime, _bagWeight);

}

}

I have this files and I not able to declare de identifier because I dont now what is the problem. The problema appear here:

insertOrigin(_airportName, _checkInTime, _bagWeight);

Any help??

EDIT:

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) 
    public 
{
    origins[originNonce] = OriginInfo(_airportName, _checkInTime, _bagWeight, msg.sender, true);
    originNonce += 1;

    recoverOrigin(originNonce);
}

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

pragma solidity ^ "0.4.24";

import "./TraceabilityProcedures/Origin.sol";
import "./TraceabilityProcedures/Tape.sol";
import "./TraceabilityProcedures/Plane.sol";
import "./TraceabilityProcedures/Destiny.sol";

contract Travel{


struct TravelInfo {
    uint test;
    //Origin origin;
}

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

function addOrigin (string _airportName, uint32 _checkInTime, uint8 _bagWeight) public {
    insertOrigin(_airportName, _checkInTime, _bagWeight);

}
}

Best Answer

The problem here is that you have marked the insertOrigin() function as external, but it needs to be marked public since you are making an internal call the way you have written your code.

function insertOrigin(string _airportName, uint32 _checkInTime, uint8 _bagWeight) 
    public 
{
    ...
}

Take a look at the visibility documentation.

External functions are part of the contract interface, which means they can be called from other contracts and via transactions. An external function f cannot be called internally (i.e. f() does not work, but this.f() works).

To be more clear here, since you wrote contract Travel is Origin, you have then absorbed all the functions from Origin into your Travel contract, thus these are all internal function. If instead, Origin was deployed on its own to a specific address, and then you made your new Travel contract call those functions as transactions between the two contracts, then external would be the right thing to do.

Related Topic