-
Notifications
You must be signed in to change notification settings - Fork 10
/
transactions.py
36 lines (31 loc) · 1.1 KB
/
transactions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
import json
import mongo
import command
class Transactions(command.Command):
""" Gives the user a list of their transactions,
allowing clients to display changes of coins
to and from the given address.
fingerprint: {"cmd": "transactions", "addr": _, "pwd": _}
"""
required = ['addr', 'pwd']
def handle(self, *args, **kwargs):
addr = self.data['addr']
pwd = self.data['pwd']
if not mongo.db.addresses.find_one({"addr": addr, "pwd": pwd}):
self.error("Your address or password was invalid")
return
payload = {"transactions": []}
for t in mongo.db.transactions.find({"to": addr}):
payload['transactions'].append({
"from": t['from'],
"to": addr,
"amount": t['amount']
})
for t in mongo.db.transactions.find({"from": addr}):
payload['transactions'].append({
"from": addr,
"to": t['to'],
"amount": t['amount']
})
self.success(payload)