Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter transactions by incoming and outgoing #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,54 @@ def get_by_address(address):
return e


@app.route("/address/<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/<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,
Expand Down
12 changes: 9 additions & 3 deletions utils/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ def listTransactions(w3, address):
for i in range(0,blocks+1):
block = w3.eth.getBlock(i, True)
for txn in block['transactions']:
print(type(txn))
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


Expand Down