|
@@ -137,26 +137,25 @@ def own(user_id, ownable_name, amount=0):
|
|
''', (user_id, ownable_name, amount))
|
|
''', (user_id, ownable_name, amount))
|
|
|
|
|
|
|
|
|
|
-def send_ownable(from_user_id, to_user_id, ownable_name, amount):
|
|
|
|
|
|
+def send_ownable(from_user_id, to_user_id, ownable_id, amount):
|
|
connect()
|
|
connect()
|
|
|
|
|
|
if amount < 0:
|
|
if amount < 0:
|
|
- return False
|
|
|
|
|
|
+ raise AssertionError('Can not send negative amount')
|
|
|
|
|
|
- if from_user_id != bank_id():
|
|
|
|
- cursor.execute('''
|
|
|
|
- UPDATE ownership
|
|
|
|
- SET amount = amount - ?
|
|
|
|
- WHERE user_id = ?
|
|
|
|
- AND ownable_id = (SELECT rowid FROM ownables WHERE name = ?)
|
|
|
|
- ''', (amount, from_user_id, ownable_name,))
|
|
|
|
|
|
+ cursor.execute('''
|
|
|
|
+ UPDATE ownership
|
|
|
|
+ SET amount = amount - ?
|
|
|
|
+ WHERE user_id = ?
|
|
|
|
+ AND ownable_id = ?
|
|
|
|
+ ''', (amount, from_user_id, ownable_id,))
|
|
|
|
|
|
cursor.execute('''
|
|
cursor.execute('''
|
|
UPDATE ownership
|
|
UPDATE ownership
|
|
SET amount = amount + ?
|
|
SET amount = amount + ?
|
|
WHERE user_id = ?
|
|
WHERE user_id = ?
|
|
- AND ownable_id = (SELECT rowid FROM ownables WHERE name = ?)
|
|
|
|
- ''', (amount, to_user_id, ownable_name))
|
|
|
|
|
|
+ AND ownable_id = ?
|
|
|
|
+ ''', (amount, to_user_id, ownable_id,))
|
|
return True
|
|
return True
|
|
|
|
|
|
|
|
|
|
@@ -723,7 +722,7 @@ def execute_orders(ownable_id):
|
|
return AssertionError()
|
|
return AssertionError()
|
|
|
|
|
|
# actually execute the order, but the bank does not send or receive anything
|
|
# actually execute the order, but the bank does not send or receive anything
|
|
- send_ownable(buyer_id, seller_id, ownable_id, price * amount)
|
|
|
|
|
|
+ send_ownable(buyer_id, seller_id, currency_id(), price * amount)
|
|
send_ownable(seller_id, buyer_id, ownable_id, amount)
|
|
send_ownable(seller_id, buyer_id, ownable_id, amount)
|
|
|
|
|
|
# update order execution state
|
|
# update order execution state
|