I have a function makePayment in one Contract:
function payLoan(Loan _loanAddress) payable onlyOwner public {
// Outgoing payment
Loan myLoan = Loan(_loanAddress);
uint256 payment = msg.value;
// Make payment if sufficient funds, otherwise only pay what is available
if (funds >= payment){
// Make payment
myLoan.makePayment.value(payment);
funds -= payment;
}else{
// Partial payment
myLoan.makePayment.value(funds);
funds = 0;
}
and I want to make a payment into another contract with the function makePayment:
function makePayment() onlyOwner payable public {
received = msg.value;
if (received >= balance){
received -= balance;
amtPaid += balance;
balance = 0;
} else {
balance -= received;
amtPaid += received;
received = 0;
}
}
It seems to work and the funds are received by the first contract, but the amount sent is never received. None of the variables are changed as a result of the call. Any idea what is wrong? Thanks.
Here is a further simplification and revised attempt. I still get the error "transact to Borrower.payLoan errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The constructor should be payable if you send value. Debug the transaction to get more information."
pragma solidity ^0.4.18;
contract Borrower {
uint256 public amountReceived;
function Borrower() payable public {
}
function payLoan(Loan _loan) payable public {
// Outgoing payment
Loan loan = Loan(_loan);
amountReceived = msg.value;
// Make payment
loan.payLoan.value(amountReceived)();
}
function getThisBalance() public view returns (uint256){
return this.balance;
}
} // Borrower
contract Loan {
address public borrower;
uint256 public loanBalance;
function payLoan() payable public {
uint256 received = msg.value;
loanBalance -= received;
}
function Loan(address _borrower) payable public {
borrower = _borrower;
loanBalance = msg.value;
}
function getThisBalance() public view returns (uint256){
return this.balance;
}
} // Loan