1

how do I interact with two different contracts?

my deployed contracts:

ILoan.sol

pragma solidity ^0.4.18;

contract ILoan {
        function getBorrowerIDsViaAddress(address _address) view public returns (uint[]);
        function countLoans() view public returns (uint);
        function executeLoan(uint256 _loanId,uint256 _issuedTokens) public;
        function checkValidParameters(uint256 _loanId,uint256 lenderID,uint256 amount) view public returns (bool);
}

ILoanParams.sol

pragma solidity ^0.4.18;

contract ILoanParams {

    function setParams(uint256 id,uint256 _lenderID,address _borrowerAddress,string loanHughString) public;

    function loanStatus(uint256 _loanId) public returns(string status);

    function setSignatures(uint256 _loanId,string _signatures) public;

    function getBorrowerAddress(uint256 _loanId) public returns(address);

    function getLenderID(uint256 _loanId) view public returns(uint256);

    function setStatus(uint256 _loanId,string _status) public;


    //*********************TEST FUNCTIONS*****************************//
    function testGetLoanAddress() public view returns(address);

    function testGetStatus(uint256 _loanId) public view returns(string);


}

Loans.sol

pragma solidity ^0.4.18;

import "./Ownable.sol";
import "./strings.sol";
import "./interfaces/ILoan.sol";
import "./helpers/Utils.sol";
import "./interfaces/ILoanParams.sol";
contract Loan is ILoan,Ownable,Utils {

    event consoleLogAddress(address _address);
    event consoleLogString(string _string);
    event consoleLogUint(uint256 _int);
    event consoleLogUint2(uint _int);
    event consoleLogBool(bool _bool);
    address treasuryAddress;
    ILoanParams public loanParams;
    using strings for *;    
    event RegisterLoan(uint256 indexed _loanId);
    event ApprovedLoan(uint256 indexed _loanId);
    event UserSign(uint256 indexed _loanId);
    event AdminSign(uint256 indexed _loanId);
    event Funded(uint256 indexed _loanId);
    mapping (address => uint256[]) public addressToLoanKey;
    uint[] public loansAccts;

    modifier onlyTreasury() {
    require(treasuryAddress == msg.sender);
        _;
    }

    function setLoanParamContractInstance(address _loanParamAddress) public onlyOwner{
        loanParams = ILoanParams(_loanParamAddress);
    }

   function Loan(address _Treasury) public {
    treasuryAddress = _Treasury;
   }

   function registerLoan(uint256 id,uint256 _lenderID,address _borrowerAddress,string loanHughString) public onlyOwner
    {
        loanParams.setParams(id,_lenderID,_borrowerAddress,loanHughString);
        addressToLoanKey[_borrowerAddress].push(id);
        loansAccts.push(id);
        RegisterLoan(id);
    }

   function validateStatusParam(uint256 _loanId,string _status) private returns(bool){
        consoleLogBool(keccak256(loanParams.loanStatus(_loanId)) == keccak256(_status));
        return (keccak256(loanParams.loanStatus(_loanId)) == keccak256(_status));
   }


   function checkValidParameters(uint256 _loanId,uint256 lenderID,uint256 amount) view public returns (bool)
   {
       bool isStatusValid = validateStatusParam(_loanId,"Registered");
       if(isStatusValid)
       {
           uint256 _lenderID = loanParams.getLenderID(_loanId);
           if(_lenderID == lenderID)
           {
               return true;

           }else{
               return false;

           }
    }else{
        return false;
    }
    return true;
   }
   //onlyTreasury
   function executeLoan(uint256 _loanId,uint256 _issuedTokens) public {
        loanParams.setStatus(_loanId,"Funded");
        Funded(_loanId);
   }

   function getBorrowerIDsViaAddress(address _address) view public returns(uint[]){
        return (addressToLoanKey[_address]);
   }
    //onlyOwner
   function approvedViaAdmins(uint256 _loanId) public {
        string memory currentStatus = loanParams.loanStatus(_loanId);
        consoleLogString("Registered");
        consoleLogString(currentStatus);
        ApprovedLoan(_loanId);
    }

   function signedViaAdmin(uint256 _loanId,string _signatures) public onlyOwner{
       bool isStatusValid = validateStatusParam(_loanId,"SignedViaUser");
        if(isStatusValid)
        {
                loanParams.setStatus(_loanId,"Signed");
                loanParams.setSignatures(_loanId,_signatures);
                AdminSign(_loanId);
        }
   }

   function signedViaUser(uint256 _loanId) public onlyOwner{
       bool isStatusValid = validateStatusParam(_loanId,"Approved");
       address borrowerWalletAddress = loanParams.getBorrowerAddress(_loanId);
       if(isStatusValid && (msg.sender == borrowerWalletAddress))
       {
           loanParams.setStatus(_loanId,"SignedViaUser");
           UserSign(_loanId);
       }
   }



}

LoanParams.sol

pragma solidity ^0.4.18;

import "./Ownable.sol";
import "./strings.sol";
import "./helpers/Utils.sol";
import "./interfaces/ILoanParams.sol";
contract LoanParams is Ownable,Utils,ILoanParams {
    event consoleLogAddress(address _address);
    event consoleLogString(string _string);
    event consoleLogUint(uint256 _int);
    event consoleLogBool(bool _bool);
    address onlyLoanAddress;
    using strings for *;    
    event RegisterLoan(uint256 indexed _loanId);
    event ApprovedLoan(uint256 indexed _loanId);
    event UserSign(uint256 indexed _loanId);
    event AdminSign(uint256 indexed _loanId);
    event Funded(uint256 indexed _loanId);
    mapping (uint256 => propertyLien) public propertyLienMap;
    mapping (uint256 => witness) public witnessMap;
    mapping (uint256 => schedule) public scheduleMap;
    mapping (uint256 => info) public infoMap;
    mapping (uint256 => montgageDetails) public montgageDetailsMap;
    mapping (uint256 => solidityInfo) public solidityInfoMap; 
    mapping (uint256 => amountFee) public amountFeeMap;
    mapping (address => uint256[]) public addressToLoanKey;
    mapping (uint256 => string) public signaturesMap;
    uint[] public loansAccts;

    struct propertyLien{
    string propertyCountry;
        string propertyPremises;
        uint256 block;
        string lot;
    }

    struct witness{
    string witnessFirstName;
        string witnessLastName;
        string witnessSignature;
    }

    struct schedule{
    string governingJouridicationState;
        string governingCountry;
        string notaryDate;
        string notaryPublicSignature;
    }

    struct info{
        string lenderAddress;
        string borrowerAddress;
        string borrowerFirstName;
        string borrowerLastName;
        string status;
    }

    struct montgageDetails {
        uint256 date;
        string borrowerLegalEntity;
        string borrowerLegalAddress;
        string monthlyInstallments;
        uint256 commencingDate;
        uint256 untilDate;
    }

    struct amountFee{
    uint256 repaymentDayOfMonth;
        uint256 repaymentLateFeePrecent;
    uint256 defaultInterestRatePrecentPerAnum;
    uint256 loanAmount;
    uint256 interestRatePrecentPerAnum;
    }

    struct solidityInfo{
    uint256 lenderID;
    address borrowerWalletAddress;
    }

   function LoanParams(address _loanContract) public {
        onlyLoanAddress = _loanContract;
   }

   function setParams(uint256 id,uint256 _lenderID,address _borrowerAddress,string loanHughString) public isAddressEqual(onlyLoanAddress,msg.sender){
       strings.slice memory s = loanHughString.toSlice();
       strings.slice memory delim = "-".toSlice();
        string[] memory parts = new string[](s.count(delim));
        for (uint i = 0; i < parts.length; i++) {
            parts[i] = s.split(delim).toString();
        }

        montgageDetailsMap[id] = montgageDetails({
            date : stringToUint(parts[0]),
            borrowerLegalEntity : parts[1],
            borrowerLegalAddress : parts[2],
            monthlyInstallments : parts[8],
            commencingDate : stringToUint(parts[9]),
            untilDate : stringToUint(parts[10])
        });
        amountFeeMap[id] = amountFee({
            loanAmount : stringToUint(parts[3]),
            interestRatePrecentPerAnum : stringToUint(parts[4]),
            repaymentLateFeePrecent : stringToUint(parts[5]),
            defaultInterestRatePrecentPerAnum : stringToUint(parts[6]),
            repaymentDayOfMonth : stringToUint(parts[7])
        });

        propertyLienMap[id] = propertyLien({
            propertyCountry:parts[11],
            propertyPremises:parts[12],
            block:stringToUint(parts[13]),
            lot:parts[14]
        });

        witnessMap[id] = witness({
            witnessFirstName:parts[15],
            witnessLastName:parts[16],
            witnessSignature:parts[17]
        });

        scheduleMap[id] = schedule({
            governingJouridicationState:parts[18],
            governingCountry:parts[19],
            notaryDate:parts[20],
            notaryPublicSignature:parts[21]
        });

        infoMap[id] = info({
            lenderAddress : parts[24],
            borrowerAddress : parts[25],
            borrowerFirstName : parts[22],
            borrowerLastName : parts[23],
            status : "Registered"   
        });

        solidityInfoMap[id] = solidityInfo({
            lenderID : _lenderID,
            borrowerWalletAddress : _borrowerAddress
        }); 

   }


   //isAddressEqual(onlyLoanAddress,msg.sender);
   function loanStatus(uint256 _loanId) public isAddressEqual(onlyLoanAddress,msg.sender) returns(string){
        return(infoMap[_loanId].status);
   }

   function setSignatures(uint256 _loanId,string _signatures) public isAddressEqual(onlyLoanAddress,msg.sender){
       signaturesMap[_loanId] = _signatures;
   }

   function getBorrowerAddress(uint256 _loanId) public isAddressEqual(onlyLoanAddress,msg.sender) returns(address){
       return solidityInfoMap[_loanId].borrowerWalletAddress;
   }

   function getLenderID(uint256 _loanId) view public isAddressEqual(onlyLoanAddress,msg.sender) returns(uint256){
        return solidityInfoMap[_loanId].lenderID;
   }


    function setStatus(uint256 _loanId,string _status) public isAddressEqual(onlyLoanAddress,msg.sender) {
         infoMap[_loanId].status = _status;   
    }


    //*********************TEST FUNCTIONS*****************************//
   function testGetLoanAddress() public view returns(address){
       return onlyLoanAddress;
   }

   function testGetStatus(uint256 _loanId) public view returns(string){
       return(infoMap[_loanId].status);
   }


}

the function that call other function on another deployed contract:

function approvedViaAdmins(uint256 _loanId) public {
        string memory currentStatus = loanParams.loanStatus(_loanId);
        consoleLogString("Registered");
        consoleLogString(currentStatus);
        ApprovedLoan(_loanId);
    }

now, this is the output of running this specific function:

truffle(development)> loan.approvedViaAdmins(1)
{ tx: '0x4f2afe49d26c6982bafe050da6bd23ad6290fb1cd211f0e72d14f8902fa691c2',
  receipt: 
   { blockHash: '0x98b6288a096c1485cc7bb8da056f7940e8e1693d54b6e17a54b46f7ec195cffb',
     blockNumber: 678906,
     contractAddress: null,
     cumulativeGasUsed: 4712388,
     from: '0xd8c661c2a783d1a89ef00ad32a8b07aff3c1c33a',
     gasUsed: 4712388,
     logs: [],
     logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
     root: '0xe8203ebb301bcbb403e092ac682f33a6e500c7f60c4bd8d818f8117d0830f258',
     to: '0xeca8ac00deda12a965c32ee3d49014606d60b325',
     transactionHash: '0x4f2afe49d26c6982bafe050da6bd23ad6290fb1cd211f0e72d14f8902fa691c2',
     transactionIndex: 0 },
  logs: [] }

as you can see, there is no logs on the transaction object.. that means that the transaction failed..

i tested the function without return argument and it is running.. for example:

//onlyOwner
   function approvedViaAdmins(uint256 _loanId) public {
        loanParams.loanStatus(_loanId);
        consoleLogString("Registered");
        ApprovedLoan(_loanId);
    }

//isAddressEqual(onlyLoanAddress,msg.sender);
   function loanStatus(uint256 _loanId) public isAddressEqual(onlyLoanAddress,msg.sender) {
        consoleLogString(infoMap[_loanId].status);
   }

why??

Your Answer

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

Browse other questions tagged or ask your own question.