Repository navigation
Expand file tree
/
Copy pathmdcontracts.py
More file actions
75 lines (57 loc) · 2.09 KB
/
Copy pathmdcontracts.py
File metadata and controls
75 lines (57 loc) · 2.09 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import constants
from datetime import datetime
from pymongo import MongoClient
def mongo_connection():
client = MongoClient("127.0.0.1", 27017)
db = client[constants.MONGO_DATABASE]
collection = db[constants.MONGO_COLLECTION]
return collection
def mongo_results_connection():
client = MongoClient("127.0.0.1", 27017)
db = client[constants.MONGO_RESULTS_DATABASE]
collection = db[constants.MONGO_RESULTS_COLLECTION]
return collection
def get_contract(id):
collection = mongo_connection()
if type(id) != int:
id = int(id)
c_contracts = collection.find({'contract_id': id})
return c_contracts.next()
def get_contract_by_address(address):
collection = mongo_connection()
c_contracts = collection.find({'address': '{}'.format(address)})
return c_contracts.next()
def get_all_contract_id():
collection = mongo_connection()
c_contracts = collection.find({'contract_id': {"$exists": 'true', "$ne": ""}}, no_cursor_timeout=True)
return c_contracts
def get_range_contract(start_id, end_id):
collection = mongo_connection()
c_contracts = collection.find({'contract_id': {"$gte": start_id, "$lte": end_id}}, no_cursor_timeout=True)
return c_contracts
def get_from_number(start_id):
collection = mongo_connection()
c_contracts = collection.find({'contract_id': {"$gte": start_id}}, no_cursor_timeout=True)
return c_contracts
def insert_result(id, address, field, value, time_elapsed):
collection = mongo_results_connection()
query = {'contract_id': id}
new_values = {
"$set": {
"{}".format(field): {
"output": "{}".format(value),
"time_elapsed": time_elapsed
},
"timestamp": datetime.now()
},
"$setOnInsert": {
"contract_id": id,
"address": address
}
}
collection.update(query, new_values, upsert=True)
def remove_result(id):
collection = mongo_connection()
query = {"contract_id": id}
remove_values = {"$unset": {"results": ""}}
collection.update(query, remove_values)