+logger = require('./logger')
 
 Dequeue = require('deque').Dequeue
 

  constructor: ->
    @transaction_log = new TransactionLog(@)
    @datastore = new DataStore()

  start: =>
    return Q.fcall =>
      return @transaction_log.start()
    .then =>
      console.log 'STARTED ENGINE'

  receive_message: (message) =>
    # journal + replicate

      @replay_message(message)

  replay_message: (message) =>
    console.log 'REPLAY MESSAGE'

    engine = this

    message[1].callback = () ->
      # if there is a socket connected to the trade engine
      if engine.socket
        message[1].etime = new Date().getTime() # <- stub execution time estimate ( inaccurate )
        # send the message back out through that socket
        engine.socket.send(JSON.stringify(message))

    if message[0] == operations.ADD_DEPOSIT
      @datastore.add_deposit(message[1])
    else
      throw new Error("Unknown Operation Type")

  flush: =>
    @transaction_log.flush()