Skip to content

Commit

Permalink
Add final changes before talk
Browse files Browse the repository at this point in the history
  • Loading branch information
GrishonNganga committed May 7, 2022
1 parent 3d02857 commit 6dc3d89
Show file tree
Hide file tree
Showing 11 changed files with 901 additions and 99 deletions.
Binary file modified __pycache__/blockchain.cpython-38.pyc
Binary file not shown.
68 changes: 61 additions & 7 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
from flask_cors import CORS
from functools import wraps
from ipfs import upload
from blockchain import create_account
from blockchain import create_account, get_eth_balance, mint_price, purchase_nft, nfts_for_user
from datetime import datetime, timedelta
import jwt

# nft = generate_unique_nft()
# response = upload(nft)
# print(response)

app = Flask(__name__)
app.config["APP_SECRET"] = "KSiJ65bGtapUEQeg"
Expand Down Expand Up @@ -40,14 +35,73 @@ def signup():
def refresh_token():
if request.cookies and "public_key" in request.cookies:
public_key = request.cookies.get("public_key")
response = {'status': 'success', 'message':'Admin signin successful','user': public_key}
nfts = nfts_for_user(public_key)
print(nfts)
response = {'status': 'success', 'message':'Admin signin successful','user': public_key, 'nfts': nfts}
response = make_response(jsonify(response), 200)
else:
response = {'status': 'error', 'message': 'Authentication failed'}
response = make_response(jsonify(response), 400)

return response

@app.route('/get_user_balance')
def get_user_balance():
if request.cookies and "public_key" in request.cookies:
public_key = request.cookies.get("public_key")
balance = get_eth_balance(public_key)
response = {'status': 'success','balance': balance}
response = make_response(jsonify(response), 200)
else:
response = {'status': 'error', 'message': 'User not provided'}
response = make_response(jsonify(response), 400)

return response

@app.route('/get_nft_price')
def get_price():
price = mint_price()
response = {'status': 'success','price': price}
response = make_response(jsonify(response), 200)
return response


@app.route('/generate_nft', methods=['POST'])
def generate_nft():
post_data = request.get_json(force=True)
if not request.cookies or "public_key" not in request.cookies or not post_data or "private_key" not in post_data:
response = {'status': 'error', 'message': 'Provide all details'}
response = make_response(jsonify(response), 400)
return response

public_key = request.cookies.get("public_key")
private_key = post_data["private_key"]
match_public_key = create_account(private_key)

if match_public_key != public_key:
response = {'status': 'error', 'message': 'Provide correct details'}
response = make_response(jsonify(response), 400)
return response


if get_eth_balance(public_key) < mint_price():
response = {'status': 'error', 'message': 'Insufficient balance to generate NFT'}
response = make_response(jsonify(response), 400)
return response

nft = generate_unique_nft()
response = upload(nft)
if response:
IpfsHash = response['IpfsHash']
nft, message = purchase_nft(IpfsHash, public_key, private_key)
if nft:
response = {'status': 'error', 'message': 'NFT created successfully'}
response = make_response(jsonify(response), 200)
return response
else:
response = {'status': 'error', 'message': message}
response = make_response(jsonify(response), 400)
return response

if __name__ == '__main__':
app.run()
Loading

0 comments on commit 6dc3d89

Please sign in to comment.