Skip to content

Commit 1b5f9ff

Browse files
authored
Revert "Frontend dev"
1 parent 0514406 commit 1b5f9ff

23 files changed

+160
-2323
lines changed

backend/.config

Whitespace-only changes.

backend/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Use a lightweight Python image
2+
FROM python:3.9-slim-buster
3+
4+
# Set the working directory to /app
5+
WORKDIR /app
6+
7+
# Copy the current directory contents into the container at /app
8+
COPY . /app
9+
10+
# Install any needed packages specified in requirements.txt
11+
RUN pip install --no-cache-dir -r requirements.txt
12+
13+
# Expose the port Flask/Gunicorn will run on
14+
EXPOSE 8000
15+
16+
# Start Gunicorn and run the Flask app
17+
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "app:app"]
2.34 KB
Binary file not shown.

backend/app.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import sqlite3
2+
import os
3+
4+
from flask import Flask, request, jsonify, render_template, redirect, url_for
5+
from flask_sqlalchemy import SQLAlchemy
6+
from web3 import Web3, HTTPProvider
7+
import json
8+
from sqlalchemy import create_engine
9+
from sqlalchemy.orm import scoped_session, sessionmaker
10+
11+
app = Flask(__name__)
12+
app.config["TEMPLATES_AUTO_RELOAD"] = True
13+
14+
# Connect to the Ethereum network using Infura
15+
w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/'))
16+
17+
# Load the contract ABI from a JSON file
18+
with open('contract_abi.json', 'r') as f:
19+
contract_abi = json.load(f)
20+
21+
# Connect to the contract
22+
contract = w3.eth.contract(address=contract_address, abi=contract_abi)
23+
24+
# Connect to the database
25+
engine = create_engine(os.getenv("DATABASE_URL"))
26+
db = scoped_session(sessionmaker(bind=engine))
27+
28+
web3auth = web3auth(provider_uri="", contract_address="")
29+
30+
#Landing page
31+
@app.route('/')
32+
def landing_page():
33+
print("Here landing page will be shown in html")
34+
35+
36+
#Endpoint for new user
37+
@app.route('/login')
38+
def signin():
39+
address = request.json.get(address)
40+
if web3.is_signed_in(address):
41+
return jsonify({'error : user already signed in'}), 400
42+
43+
user_id = web3auth.is_sign_in(address)
44+
return jsonify({'user_id':user_id}), 200
45+
46+
#Endpoint for new registration
47+
@app.route('/register')
48+
def register():
49+
address = request.json.get('address')
50+
username = request.json.get('username')
51+
52+
if web3auth.is_signed_in(address):
53+
return jsonify({'error': 'User already signed in'}), 400
54+
55+
user_id = web3auth.register(address, username)
56+
return jsonify({'user_id': user_id}), 200
57+
58+
#View details of a product by ID
59+
@app.route("/products/<string:product_hash>", methods=['GET'])
60+
def get_product(product_hash):
61+
product_id = str(uuid.uuid5(uuid.NAMESPACE_URL, product_hash))
62+
product = contract.functions.getItemDetais(product_id).call()
63+
64+
return jsonify({'product':product})
65+
66+
# Endpoint to view details of a specific user identified by hash
67+
@app.route('/users/<string:user_hash>', methods=['GET'])
68+
def get_user(user_hash):
69+
# Query the smart contract to get the details of the specified user
70+
user_id = str(uuid.uuid5(uuid.NAMESPACE_URL, user_hash))
71+
user = contract.functions.getUserDetails(user_id).call()
72+
73+
# Return the user details as a JSON response
74+
return jsonify({'user': user})
75+
76+
77+
78+
if __name__ == "__main__":
79+
# gunicorn --bind 0.0.0.0:8000 app:app ---> use this to run in cmd
80+
app.run(debug=True)

backend/contracts/hostify.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
contract Artifact {
6+
struct Item {
7+
8+
}
9+
}

backend/hash_id.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Function to convert string to hash
2+
import hashlib
3+
4+
# user ID would follow different format than products IDs
5+
6+
def sha256_hash(string):
7+
return hashlib.sha256(string.encode()).hexdigest()
8+
9+
# print(sha256_hash("Hello World")) --> a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e

backend/main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from web3 import Web3, HTTPProvider
2+
import json
3+
from flask import Flask, request, jsonify
4+
5+
# Connect to the Ethereum network using Infura
6+
w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/YOUR_PROJECT_ID'))
7+
8+
# Load the contract ABI from a JSON file
9+
with open('contract_abi.json', 'r') as f:
10+
contract_abi = json.load(f)
11+
12+
# Load the contract address from a JSON file
13+
with open('contract_address.json', 'r') as f:
14+
contract_address = json.load(f)
15+
16+
# Create a contract instance using the ABI and address
17+
contract = w3.eth.contract(address=contract_address, abi=contract_abi)
18+
19+
# Get the total number of luxury items stored in the contract
20+
num_items = contract.functions.getNumItems().call()
21+
22+
# Get the details of a specific luxury item
23+
item_id = 12345
24+
item_details = contract.functions.getItemDetails(item_id).call()
25+
26+
# Add a new luxury item to the contract
27+
new_item = {
28+
'id': 3232 #product_hash-sha,
29+
'name': 'Diamond Necklace',
30+
'description': '18k white gold necklace with 10-carat diamond',
31+
'price': 1000000,
32+
'seller': '0x1234567890abcdef1234567890abcdef12345678'
33+
}
34+
tx_hash = contract.functions.addItem(**new_item).transact({'from': w3.eth.accounts[0], 'gas': 1000000})
35+
receipt = w3.eth.waitForTransactionReceipt(tx_hash)
36+

backend/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Hostify

backend/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask

frontend/.eslintrc.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)