From abda601ef3c8bc92fb9edb048361db8dec77416c Mon Sep 17 00:00:00 2001 From: micey969 Date: Fri, 10 Aug 2018 12:05:45 -0400 Subject: [PATCH 1/2] feat(transaction): filter transactions by incoming and outgoing --- app.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ utils/transaction.py | 11 ++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index b86582e..a6bcf7c 100644 --- a/app.py +++ b/app.py @@ -54,6 +54,54 @@ def get_by_address(address): return e +@app.route("/address/
/outgoing", methods=["GET"]) +def get_outgoing(address): + """ + Returns outgoing transactions of an address + + param + address(string): account address + + return + transactions(list): list of transformed outgoing transaction blocks + """ + outgoing = [] + try: + if w3.isAddress(address): + transactions = listTransactions(address) + for data in transactions: + if "to" in data: + outgoing.append(data) + return jsonify({"data":{"transactions": outgoing}}), 200 + return jsonify({"message": "Invalid Ethereum Address."}), 400 + except Exception as e: + return e + + +@app.route("/address/
/incoming", methods=["GET"]) +def get_incoming(address): + """ + Returns incoming transactions of an address + + param + address(string): account address + + return + transactions(list): list of transformed incoming transaction blocks + """ + incoming = [] + try: + if w3.isAddress(address): + transactions = listTransactions(address) + for data in transactions: + if "from" in data: + incoming.append(data) + return jsonify({"data":{"transactions": incoming}}), 200 + return jsonify({"message": "Invalid Ethereum Address."}), 400 + except Exception as e: + return e + + if __name__ == "__main__": app.run(debug=True, threaded=True, diff --git a/utils/transaction.py b/utils/transaction.py index 87d0f9b..c80d0eb 100644 --- a/utils/transaction.py +++ b/utils/transaction.py @@ -25,8 +25,15 @@ def listTransactions(address): for i in range(0,blocks+1): block = w3.eth.getBlock(i, True) for txn in block['transactions']: - if txn['to'] == address or txn['from'] == address: - txns.append(transformTransaction(txn)) + if txn['to'] == address: + data = transformTransaction(txn) + del data["to"] + elif txn['from'] == address: + data = transformTransaction(txn) + del data["from"] + else: + continue + txns.append(data) return txns From 4d92dc5421b80992186f9bcbeef8ffb98135efc3 Mon Sep 17 00:00:00 2001 From: Shazelle Date: Wed, 22 Aug 2018 08:29:19 -0400 Subject: [PATCH 2/2] fix(transaction): remove missed merge lines --- utils/transaction.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/utils/transaction.py b/utils/transaction.py index 21d830d..7fe3959 100644 --- a/utils/transaction.py +++ b/utils/transaction.py @@ -21,7 +21,6 @@ def listTransactions(w3, address): for i in range(0,blocks+1): block = w3.eth.getBlock(i, True) for txn in block['transactions']: -<<<<<<< HEAD if txn['to'] == address: data = transformTransaction(txn) del data["to"] @@ -31,11 +30,6 @@ def listTransactions(w3, address): else: continue txns.append(data) -======= - print(type(txn)) - if txn['to'] == address or txn['from'] == address: - txns.append(transformTransaction(txn)) ->>>>>>> master return txns