-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbd.py
37 lines (28 loc) · 1.02 KB
/
bd.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
37
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from redis import Redis
import mongoengine
from mongoengine import Document, IntField, StringField, EmbeddedDocumentField, FloatField, ListField, EmbeddedDocument
import json
mongoengine.connect()
redis = Redis()
class Wallet(Document):
address = StringField(required=True)
device_token = StringField(required=True)
class UTOX(EmbeddedDocument):
tx_hash = StringField(required=True)
script = StringField(required=True)
value = FloatField(required=True)
vout = IntField(required=True)
confirmations = IntField(required=True)
class AddressUTOX(Document):
address = StringField(required=True)
UTOX = ListField(EmbeddedDocumentField(UTOX))
def get_wallets_from_db():
# wallets = redis.get('wallets')
# wallets = json.loads(wallets) if wallets is not None else []
return Wallet.objects
def add_wallet_to_db(wallet):
wallet = Wallet(address=wallet['address'], device_token=wallet['device_token'])
wallet.save()
return wallet