This repository has been archived by the owner on Mar 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
493 lines (431 loc) · 22.5 KB
/
app.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
from datetime import datetime
from flask import Flask, redirect, url_for, render_template, request, jsonify, send_from_directory
from flask_restx import Resource, Api
from audioop import add
from doctest import master
from email import header
from json.tool import main
from os import stat
from grpc import ServicerContext, StatusCode
from pyqrllib.pyqrllib import str2bin, hstr2bin, bin2hstr
from binascii import hexlify, a2b_base64
from qrl.crypto.xmss import XMSS
from qrl.core import config
from qrl.core.AddressState import AddressState
from qrl.core.OptimizedAddressState import OptimizedAddressState
from qrl.core.PaginatedBitfield import PaginatedBitfield
from qrl.core.Block import Block
from qrl.core.TransactionMetadata import TransactionMetadata
from qrl.core.ChainManager import ChainManager
from qrl.core.GenesisBlock import GenesisBlock
from qrl.core.State import State
from qrl.core.TransactionInfo import TransactionInfo
from qrl.core.txs.TransferTransaction import TransferTransaction
from qrl.core.misc import logger
from qrl.core.node import SyncState, POW
from qrl.core.p2p.p2pfactory import P2PFactory
from qrl.core.qrlnode import QRLNode
from qrl.crypto.misc import sha256
from qrl.generated import qrl_pb2
from qrl.services.PublicAPIService import PublicAPIService
from qrl.generated import qrl_pb2_grpc, qrl_pb2
from google.protobuf.json_format import MessageToJson
from google.protobuf.json_format import MessageToDict
import grpc
import time
import re
import simplejson as json
from os import environ
import logging
from datetime import datetime
from webargs import fields, validate
from webargs.flaskparser import use_kwargs, parser, use_args
import os
from flask_jwt_extended import create_access_token
from flask_jwt_extended import get_jwt_identity
from flask_jwt_extended import jwt_required
from flask_jwt_extended import JWTManager
from flask import Flask, request, jsonify, make_response
from flask_sqlalchemy import SQLAlchemy
import uuid
from werkzeug.security import generate_password_hash, check_password_hash
import jwt
from datetime import datetime, timedelta
from functools import wraps
logging.basicConfig(level=logging.INFO)
app = Flask(__name__)
api = Api(app, version='1.0', title='Zeus-proxy advanced',
description='Zeus-proxy advanced & Testnet faucet')
ns = api.namespace('', description='Communicate with QRL Nodes')
fh = logging.FileHandler("v1.log")
ns.logger.addHandler(fh)
mainnet_node_public_address = "mainnet-1.automated.theqrl.org:19009"
testnet_node_public_address = "testnet-1.automated.theqrl.org:19009"
dt_string = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
CONNECTION_TIMEOUT = 5
HEX_SEED = environ.get('HEX_SEED')
app.config["JWT_SECRET_KEY"] = environ.get('JWT_SECRET_KEY')
app.config['SECRET_KEY'] = environ.get('SECRET_KEY')
# database name
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///Database.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
# creates SQLALCHEMY object
db = SQLAlchemy(app)
jwt = JWTManager(app)
# Database ORMs
class User(db.Model):
id = db.Column(db.Integer, primary_key = True)
public_id = db.Column(db.String(50), unique = True)
name = db.Column(db.String(100))
email = db.Column(db.String(70), unique = True)
password = db.Column(db.String(80))
# decorator for verifying the JWT
def token_required(f):
@wraps(f)
def decorated(*args, **kwargs):
token = None
# jwt is passed in the request header
if 'x-access-token' in request.headers:
token = request.headers['x-access-token']
# return 401 if token is not passed
if not token:
return jsonify({'message' : 'Token is missing !!'}), 401
try:
# decoding the payload to fetch the stored details
data = jwt.decode(token, app.config['SECRET_KEY'], algorithms=["HS256"])
print(data)
current_user = User.query\
.filter_by(public_id = data['public_id'])\
.first()
except:
return jsonify({
'message' : 'Token is invalid !!'
}), 401
# returns the current logged in users contex to the routes
return f(current_user, *args, **kwargs)
return decorated
parser_login = api.parser()
parser_login.add_argument('email', type=str, required=True)
parser_login.add_argument('password', type=int, required=True)
# # signup route
# @ns.route('/signup', methods =['POST'])
# def signup():
# # creates a dictionary of the form data
# data = request.form
# # gets name, email and password
# name, email = data.get('name'), data.get('email')
# password = data.get('password')
# # checking for existing user
# user = User.query\
# .filter_by(email = email)\
# .first()
# if not user:
# # database ORM object
# user = User(
# public_id = str(uuid.uuid4()),
# name = name,
# email = email,
# password = generate_password_hash(password)
# )
# # insert user
# db.session.add(user)
# db.session.commit()
# return make_response('Successfully registered.', 201)
# else:
# # returns 202 if user already exists
# return make_response('User already exists. Please Log in.', 202)
def tx_unbase64(tx_json_str):
tx_json = json.loads(tx_json_str)
tx_json["publicKey"] = base64tohex(tx_json["publicKey"])
tx_json["signature"] = base64tohex(tx_json["signature"])
tx_json["transactionHash"] = base64tohex(tx_json["transactionHash"])
tx_json["transfer"]["addrsTo"] = [base64tohex(v) for v in tx_json["transfer"]["addrsTo"]]
print(tx_json)
return json.dumps(tx_json, indent=True, sort_keys=True)
def base64tohex(data):
return hexlify(a2b_base64(data))
def send_testnet_coins(addrs_to, amount, ots_key):
print(addrs_to)
master_addr = None
bytes_addrs_to = []
fee = 1000000000
message_data = None
xmss_pk = XMSS.from_extended_seed(hstr2bin(HEX_SEED)).pk
# if len([addrs_to]) > 1:
# for i in addrs_to:
# bytes_addrs_to.append(bytes(hstr2bin(i)))
# elif len([addrs_to]) == 1:
# bytes_addrs_to.append(bytes(hstr2bin(addrs_to[1:])))
shor_amounts = [int(float(str(i) + "e9")) for i in [amount]]
# Q0104008eeaa68d90419bc8401b15882d0bcf6c9190d652923f768cac621b58d7e7c7945d7fc97f
tx = TransferTransaction.create(addrs_to=[bytes(hstr2bin(str(addrs_to[1:])))],
amounts = shor_amounts,
message_data = message_data,
fee = fee,
xmss_pk= xmss_pk,
master_addr=master_addr)
# Sign transaction
src_xmss = XMSS.from_extended_seed(hstr2bin(HEX_SEED))
src_xmss.set_ots_index(int(ots_key))
tx.sign(src_xmss)
# Print result
txjson = tx_unbase64(tx.to_json())
print(txjson)
if not tx.validate():
print("It was not possible to validate the signature")
quit(1)
print("\nTransaction Blob (signed): \n")
txblob = tx.pbdata.SerializeToString()
txblobhex = hexlify(txblob).decode()
print(txblobhex)
# Push transaction
print("Sending to a QRL Node...")
channel = grpc.insecure_channel(testnet_node_public_address)
stub = qrl_pb2_grpc.PublicAPIStub(channel)
push_transaction_req = qrl_pb2.PushTransactionReq(transaction_signed=tx.pbdata)
push_transaction_resp = stub.PushTransaction(push_transaction_req, timeout=CONNECTION_TIMEOUT)
return f'{push_transaction_resp}'
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),'favicon.ico',mimetype='image/vnd.microsoft.icon')
parser = api.parser()
parser.add_argument('email', type=str, required=True)
parser.add_argument('password', type=str, required=True)
parser.add_argument('qaddress', type=str, required=True)
parser.add_argument('amount', type=int, required=True)
parser.add_argument('ots_key', type=int, required=True)
@ns.route('/api/faucet')
@api.doc(description=
"""
# Attention:
Return it to Q0104001f0b2c80a2b3843bc33e96c541801989d6a5dcbc17f0672de58853be808fcd24deed3470 once you're finished with the testnet coins!
OTS key can be found on the explorer, search the above QRL address!
Account registration can be done in Discord DMs
Note: Your IP Address & email will be logged.
""")
class Faucet(Resource):
@api.expect(parser, validate=True)
def post(self):
# creates dictionary of form data
args = parser.parse_args()
if not args['email'] or not args['password']:
# returns 401 if any email or / and password is missing
return make_response(
'Incorrect username or password!',
401,
{'WWW-Authenticate' : 'Basic realm ="Login required !!"'}
)
user = User.query\
.filter_by(email = args['email'])\
.first()
if not user:
# returns 401 if user does not exist
return make_response(
'Could not verify',
401,
{'WWW-Authenticate' : 'Basic realm ="User does not exist !!"'}
)
if check_password_hash(user.password, args['password']):
# generates the JWT Token
# return make_response(jsonify({'token' : token}), 201)
if valid_qaddress(args['qaddress']):
ns.logger.info(dt_string + " | Faucet | email: " + str(args['email']) + " | amount: " + str(args['amount']) + " | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return send_testnet_coins(args['qaddress'], args['amount'], args['ots_key'])
else:
error = 'Invalid QRL address'
return error
# returns 403 if password is wrong
return make_response(
'Incorrect username or password!',
403,
{'WWW-Authenticate' : 'Basic realm ="Incorrect username or password!"'}
)
def valid_qaddress(request_form):
if len(request_form) == 79:
return True
else:
return False
@ns.route('/grpc/mainnet/GetHeight')
class GetHeight_Mainnet(Resource):
def get(self):
channel = grpc.insecure_channel(mainnet_node_public_address)
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetHeightReq()
response = stub.GetHeight(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetHeight mainnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route('/grpc/testnet/GetHeight')
class GetHeight_Testnet(Resource):
def get(self):
channel = grpc.insecure_channel(testnet_node_public_address)
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetHeightReq()
response = stub.GetHeight(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetHeight testnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route('/grpc/mainnet/GetStats')
class GetStats_Mainnet(Resource):
def get(self):
channel = grpc.insecure_channel(mainnet_node_public_address)
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetStatsReq()
response = stub.GetStats(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetStats mainnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route('/grpc/testnet/GetStats')
class GetStats_Testnet(Resource):
def get(self):
channel = grpc.insecure_channel(testnet_node_public_address)
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetStatsReq()
response = stub.GetStats(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetStats testnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route('/grpc/mainnet/GetBalance/<string:qaddress>')
class GetBalance_Mainnet(Resource):
def get(self, qaddress):
binary_qrl_address = bytes(hstr2bin(qaddress[1:]))
channel = grpc.insecure_channel(mainnet_node_public_address)
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetBalanceReq(address=binary_qrl_address)
response = stub.GetBalance(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetBalance mainnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route('/grpc/testnet/GetBalance/<string:qaddress>')
class GetBalance_Testnet(Resource):
def get(self, qaddress):
binary_qrl_address = bytes(hstr2bin(qaddress[1:]))
channel = grpc.insecure_channel(testnet_node_public_address)
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetBalanceReq(address=binary_qrl_address)
response = stub.GetBalance(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetBalance testnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route('/grpc/mainnet/GetBlockByNumber/<number>')
class GetBlockByNumber_Mainnet(Resource):
def get(self, number):
channel = grpc.insecure_channel(mainnet_node_public_address)
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetBlockByNumberReq(block_number=int(number))
response = stub.GetBlockByNumber(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetBlockByNumber mainnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route('/grpc/testnet/GetBlockByNumber/<number>')
class GetBlockByNumber_Testnet(Resource):
def get(self, number):
channel = grpc.insecure_channel(mainnet_node_public_address)
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetBlockByNumberReq(block_number=int(number))
response = stub.GetBlockByNumber(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetBlockByNumber testnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route("/grpc/mainnet/GetBlock/<headerhash>")
class GetBlock_Mainnet(Resource):
def get(self, headerhash):
channel = grpc.insecure_channel(mainnet_node_public_address, options=(('grpc.enable_http_proxy', 0),))
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetBlockReq(header_hash=bytes(hstr2bin(headerhash)))
response = stub.GetBlock(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetBlock mainnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route("/grpc/testnet/GetBlock/<headerhash>")
class GetBlock_Testnet(Resource):
def get(self, headerhash):
channel = grpc.insecure_channel(testnet_node_public_address, options=(('grpc.enable_http_proxy', 0),))
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetBlockReq(header_hash=bytes(hstr2bin(headerhash)))
response = stub.GetBlock(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetBlock testnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route("/grpc/mainnet/GetOTS/<qaddress>")
class GetOTS_Mainnet(Resource):
def get(self, qaddress):
channel = grpc.insecure_channel(mainnet_node_public_address, options=(('grpc.enable_http_proxy', 0),))
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetOTSReq(address=bytes(hstr2bin(qaddress[1:])))
response = stub.GetOTS(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetOTS mainnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route("/grpc/testnet/GetOTS/<qaddress>")
class GetOTS_Testnet(Resource):
def get(self, qaddress):
channel = grpc.insecure_channel(testnet_node_public_address, options=(('grpc.enable_http_proxy', 0),))
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetOTSReq(address=bytes(hstr2bin(qaddress[1:])))
response = stub.GetOTS(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetOTS testnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route("/grpc/mainnet/GetTotalBalance/<qaddress>")
class GetTotalBalance_Mainnet(Resource):
def get(self, qaddress):
peer_grpc_channel = grpc.insecure_channel(mainnet_node_public_address, options=(('grpc.enable_http_proxy', 0),))
peer_stub = qrl_pb2_grpc.PublicAPIStub(peer_grpc_channel)
total_Bal_req = qrl_pb2.GetTotalBalanceReq(addresses=[bytes(hstr2bin(str(qaddress[1:])))])
total_Bal_resp = peer_stub.GetTotalBalance(total_Bal_req, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(total_Bal_resp)
ns.logger.info(dt_string + " | GetTotalBalance mainnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route("/grpc/testnet/GetTotalBalance/<qaddress>")
class GetTotalBalance_Testnet(Resource):
def get(self, qaddress):
peer_grpc_channel = grpc.insecure_channel(testnet_node_public_address, options=(('grpc.enable_http_proxy', 0),))
peer_stub = qrl_pb2_grpc.PublicAPIStub(peer_grpc_channel)
total_Bal_req = qrl_pb2.GetTotalBalanceReq(addresses=[bytes(hstr2bin(str(qaddress[1:])))])
total_Bal_resp = peer_stub.GetTotalBalance(total_Bal_req, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(total_Bal_resp)
ns.logger.info(dt_string + " | GetTotalBalance testnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route("/grpc/mainnet/GetTransaction/<transaction_hash>")
class GetTransaction_Mainnet(Resource):
def get(self, transaction_hash):
channel = grpc.insecure_channel(mainnet_node_public_address, options=(('grpc.enable_http_proxy', 0),))
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetTransactionReq(tx_hash=bytes(hstr2bin(transaction_hash)))
response = stub.GetTransaction(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetTransaction mainnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route("/grpc/testnet/GetTransaction/<transaction_hash>")
class GetTransaction_Testnet(Resource):
def get(self, transaction_hash):
channel = grpc.insecure_channel(testnet_node_public_address, options=(('grpc.enable_http_proxy', 0),))
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetTransactionReq(tx_hash=bytes(hstr2bin(transaction_hash)))
response = stub.GetTransaction(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetTransaction testnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route("/grpc/mainnet/GetMiniTransactionsByAddress/<qaddress>")
class GetMiniTransactionByAddress_Mainnet(Resource):
def get(self, qaddress):
channel = grpc.insecure_channel(mainnet_node_public_address, options=(('grpc.enable_http_proxy', 0),))
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetMiniTransactionsByAddressReq(address=bytes(hstr2bin(qaddress[1:])), item_per_page=100000, page_number=1)
response = stub.GetMiniTransactionsByAddress(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetMiniTransactionsByAddress mainnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
@ns.route("/grpc/testnet/GetMiniTransactionsByAddress/<qaddress>")
class GetMiniTransactionByAddress_Testnet(Resource):
def get(self, qaddress):
channel = grpc.insecure_channel(testnet_node_public_address, options=(('grpc.enable_http_proxy', 0),))
stub = qrl_pb2_grpc.PublicAPIStub(channel)
node_request = qrl_pb2.GetMiniTransactionsByAddressReq(address=bytes(hstr2bin(qaddress[1:])), item_per_page=100000, page_number=1)
response = stub.GetMiniTransactionsByAddress(node_request, timeout=CONNECTION_TIMEOUT)
dict_obj = MessageToDict(response)
ns.logger.info(dt_string + " | GetMiniTransactionsByAddress testnet 200 | " + request.environ.get("HTTP_X_FORWARDED_FOR", request.remote_addr))
return app.response_class(json.dumps(dict_obj), mimetype="application/json")
if __name__ == '__main__':
app.run(debug=True)