Skip to content

Commit a7650e8

Browse files
authored
Merge pull request #14 from PythonicBoat/revert-13-frontend-dev
Revert "Frontend dev"
2 parents 0514406 + 1b5f9ff commit a7650e8

23 files changed

+160
-2323
lines changed

Diff for: backend/.config

Whitespace-only changes.

Diff for: backend/Dockerfile

+17
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"]

Diff for: backend/__pycache__/app.cpython-39.pyc

2.34 KB
Binary file not shown.

Diff for: backend/app.py

+80
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)

Diff for: backend/contracts/hostify.sol

+9
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+
}

Diff for: backend/hash_id.py

+9
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

Diff for: backend/main.py

+36
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+

Diff for: backend/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Hostify

Diff for: backend/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask

Diff for: frontend/.eslintrc.json

-3
This file was deleted.

Diff for: frontend/.gitignore

-32
This file was deleted.

Diff for: frontend/next.config.js

-6
This file was deleted.

Diff for: frontend/package.json

-20
This file was deleted.

Diff for: frontend/pages/_app.js

-7
This file was deleted.

Diff for: frontend/pages/api/hello.js

-5
This file was deleted.

Diff for: frontend/pages/index.js

-69
This file was deleted.

Diff for: frontend/public/favicon.ico

-25.3 KB
Binary file not shown.

Diff for: frontend/public/vercel.svg

-4
This file was deleted.

Diff for: frontend/readme.md

-34
Original file line numberDiff line numberDiff line change
@@ -1,34 +0,0 @@
1-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2-
3-
## Getting Started
4-
5-
First, run the development server:
6-
7-
```bash
8-
npm run dev
9-
# or
10-
yarn dev
11-
```
12-
13-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
14-
15-
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
16-
17-
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
18-
19-
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
20-
21-
## Learn More
22-
23-
To learn more about Next.js, take a look at the following resources:
24-
25-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
27-
28-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
29-
30-
## Deploy on Vercel
31-
32-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
33-
34-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

0 commit comments

Comments
 (0)