forked from vsnation/firo_tipbot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_address.py
50 lines (40 loc) · 1.24 KB
/
update_address.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
38
39
40
41
42
43
44
45
46
47
48
49
50
from pymongo import MongoClient
import json
from api.firo_wallet_api import FiroWalletAPI
with open('services.json') as conf_file:
conf = json.load(conf_file)
connectionString = conf['mongo']['connectionString']
httpprovider = conf['httpprovider']
wallet_api = FiroWalletAPI(httpprovider)
class AddressFix:
def __init__(self, wallet_api):
# INIT
self.wallet_api = wallet_api
client = MongoClient(connectionString)
db = client.get_default_database()
self.col_users = db['users']
self.update_addresses()
def update_addresses(self):
address = self.wallet_api.get_default_address()
users = self.col_users.find({"Address": address[0]})
for user in users:
new_address = wallet_api.create_user_wallet()
# Update address
self.col_users.update_one(
{
"_id": user.get('_id')
},
{
"$set":
{
"Address": new_address,
}
}
)
def main():
try:
AddressFix(wallet_api)
except Exception as e:
print(e)
if __name__ == '__main__':
main()