def record_exchange_result(db, exchange_id, status, error, participant):
 with db.get_cursor() as cursor:
  (amount, fee, username, route) = cursor.one(u'\n            UPDATE exchanges e\n               SET status=%(status)s\n                 , note=%(error)s\n             WHERE id=%(exchange_id)s\n               AND status <> %(status)s\n         RETURNING amount, fee, participant\n                 , ( SELECT r.*::exchange_routes\n                       FROM exchange_routes r\n                      WHERE r.id = e.route\n                   ) AS route\n        ', locals())
  assert (participant.username == username)
  assert isinstance(route, ExchangeRoute)
  route.set_attributes(participant=participant)
  if (amount < 0):
   amount -= fee
   amount = (amount if (status == u'failed') else 0)
   propagate_exchange(cursor, participant, route, error, (- amount))
  else:
   amount = (amount if (status == u'succeeded') else 0)
   propagate_exchange(cursor, participant, route, error, amount)

def record_exchange_result ( db , exchange_id , status , error , participant ) : with db . get_cursor ( ) as cursor : ( amount , fee , username , route ) = cursor . one ( u'\n            UPDATE exchanges e\n               SET status=%(status)s\n                 , note=%(error)s\n             WHERE id=%(exchange_id)s\n               AND status <> %(status)s\n         RETURNING amount, fee, participant\n                 , ( SELECT r.*::exchange_routes\n                       FROM exchange_routes r\n                      WHERE r.id = e.route\n                   ) AS route\n        ' , locals ( ) ) assert ( participant . username == username ) assert isinstance ( route , ExchangeRoute ) route . set_attributes ( participant = participant ) if ( amount < 0 ) : amount -= fee amount = ( amount if ( status == u'failed' ) else 0 ) propagate_exchange ( cursor , participant , route , error , ( - amount ) ) else : amount = ( amount if ( status == u'succeeded' ) else 0 ) propagate_exchange ( cursor , participant , route , error , amount )
updates the status of an exchange .