I have written a contract as follows:
pragma solidity ^0.4.0;
/*
Simple contract that mediates disputes using a trusted arbiter
*/
contract Taxi {
enum State {IDLE, FINDING_DRIVER, AWAITING_PAYMENT, AWAITING_DESTINATION, COMPLETE}
State public currentState;
mapping (address => uint) public balances;
bytes32 STRING_COMPLETE = "Complete";
bytes32 STRING_PARTIAL = "Partial";
modifier customerOnly() { require(msg.sender == customer); _; }
modifier driverOnly() { require(msg.sender == driver); _; }
modifier arbiterOnly() { require(msg.sender == arbiter); _; }
modifier inState(State expectedState) { require(currentState == expectedState); _; }
address public customer;
address public driver;
address public arbiter;
function Taxi(address _customer, address _driver, address _arbiter) public {
customer = _customer;
driver = _driver;
arbiter = _arbiter;
}
function assignDriver() customerOnly inState(State.IDLE) public {
//arbiter.transfer(this.balance);
currentState = State.FINDING_DRIVER;
}
function confirmAmount(uint amount) driverOnly inState(State.FINDING_DRIVER) public returns (bool ) {
if(amount < 0) {
amount = 20;
}
//driver has set this amount and user has accepted this fare, return true if customer has sufficient balance
if(balances[customer] < amount) {
return false;
}
currentState = State.AWAITING_DESTINATION;
balances[arbiter] += amount;
balances[customer] -= amount;
return true;
}
}
First I execute the assignDriver function which runs correctly. Later, when I execute the confirmAmount function, I get the error:
transact to Taxi.confirmAmount 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.
I tried to add the payable keyword to the constructor, but still I got the same error. What can be the problem?