class TxValidatorAccountBalanceValidator implements TxValidatorStep {

    @Override
    public boolean validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx) {
        if (isFreeTx) {
            return true;
        }

        if (state == null) {
            return false;
        }

        BigInteger txGasLimit = tx.getGasLimitAsInteger();
        Coin maximumPrice = tx.getGasPrice().multiply(txGasLimit);
        return state.getBalance().compareTo(maximumPrice) >= 0;
    }

}