0

I have a problem like this. I am very new to solidity Works. I have created two contracts.

This is how my first contract looks.

pragma solidity ^0.4.17;

contract TrafficFine{
    struct Officer {
        string firstName ;
        string lastName;
        address account;
    }


    address public manager;
    uint public numberOfOffiers;

    mapping(address=>Officer) public officers;

    modifier restricted(){
        require(msg.sender == manager);      
        _;
    }

    constructor () public{
        manager = msg.sender;
    }



    function addOfficer(
        string firstName,
        string lastName,
        address officer) public  restricted{

        require(officer!=officers[officer].account);

        Officer  memory newOfficer = Officer({
            firstName:firstName,
            lastName:lastName,
            account:officer
        });

        officers[officer] = newOfficer;
        numberOfOffiers++;
    }



    function getofficer(address officer) public view returns(address){
        return officers[officer].account;

    }
}

This is how my second contract looks like.

contract DriverProfile{
    address watch_adrs=0x0971b5d216af52c411c9016bbc63665b4e6f2542;

    struct Driver{
        string lisenceId;
        string firstName ;
        string lastName; 
        address account;
        string vehicle;
        string vehicleType;
        uint totalOffenceAmount;
        uint offenceCount;
        uint pendingPayments;
        mapping(uint=>Fine)  fines;
    }




    TrafficFine trafficfine;
    Driver public driver;

    constructor(string lisenceId,string firstName,string lastName,string vehicle,string vehicleType,address owner) public{
        trafficfine = TrafficFine(watch_adrs);
        trafficfine.addDriver();
        driver = Driver({
            lisenceId:lisenceId,
            lastName:lastName,
            firstName:firstName,
            account:owner,
            vehicle:vehicle,
            vehicleType:vehicleType,
            totalOffenceAmount:0,
            offenceCount:0,
            pendingPayments:0
        });

    }




     function doFine(uint offenceID,string location,address officer) public {
        address officersel=trafficfine.getOfficer(officer);
        require(officer==officersel);
        driver.offenceCount++;
     }

}

    contract TrafficFine{
        function addOfficer(string firstName,string lastName,address officer) public;
        function getOfficer(address officer) public view returns (address);

    }

This works very finely without ,

address officersel=trafficfine.getOfficer(officer);
require(officer==officersel);

these two lines of code but when I put these two line transaction is failed. I try to figure it out what is wrong with this. But I was unable to do that. Can someone help me to solve this problem? Thank You!!!

0

Your first contract lists the method as getofficer(address officer), while your interface lists it as getOfficer(address officer). Since solidity uses the function name and parameter list to calculate the function signature, it is case sensitive.

As the code currently stands, you are calling a non-existent function. Update your two implementations to have the same function name.

| improve this answer | |

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.