Is there anyone who can show me [closed]

Python

import hashlib

import json

from time import time

from flask import Flask, jsonify, request



class Blockchain:

    def __init__(self):

        self.chain = []

        self.current_transactions = []

        self.new_block(previous_hash='1', proof=100)  # Create the genesis block



    def new_block(self, proof, previous_hash=None):

        block = {

            'index': len(self.chain) + 1,

            'timestamp': time(),

            'transactions': self.current_transactions,

            'proof': proof,

            'previous_hash': previous_hash or self.hash(self.chain[-1]),

        }

        self.current_transactions = []

        self.chain.append(block)

        return block



    def new_transaction(self, sender, recipient, amount):

        self.current_transactions.append({

            'sender': sender,

            'recipient': recipient,

            'amount': amount,

        })

        return self.last_block['index'] + 1



    @staticmethod

    def hash(block):

        block_string = json.dumps(block, sort_keys=True).encode()

        return hashlib.sha256(block_string).hexdigest()



    @property

    def last_block(self):

        return self.chain[-1]



# Create a Flask web server

app = Flask(__name__)



# Create an instance of the Blockchain

blockchain = Blockchain()



@app.route('/mine', methods=['GET'])

def mine():

    last_block = blockchain.last_block

    last_proof = last_block['proof']

    proof = blockchain.proof_of_work(last_proof)



    blockchain.new_transaction(

        sender="0",  # This signifies that this node has mined a new coin

        recipient="your_address",  # Replace with your address

        amount=1,  # Amount of MyCoin awarded

    )



    block = blockchain.new_block(proof, blockchain.hash(last_block))

    response = {

        'message': 'New Block Forged',

        'index': block['index'],

        'transactions': block['transactions'],

        'proof': block['proof'],

        'previous_hash': block['previous_hash'],

    }

    return jsonify(response), 200



@app.route('/transactions/new', methods=['POST'])

def new_transaction():

    values = request.get_json()

    required = ['sender', 'recipient', 'amount']



    if not all(k in values for k in required):

        return 'Missing values', 400



    index = blockchain.new_transaction(values['sender'], values['recipient'], values['amount'])

    response = {'message': f'Transaction will be added to Block {index}'}

    return jsonify(response), 201



@app.route('/chain', methods=['GET'])

def full_chain():

    response = {

        'chain': blockchain.chain,

        'length': len(blockchain.chain),

    }

    return jsonify(response), 200



if __name__ == '__main__':

    app.run(host='0.0.0.0', port=5000)

```



### Step 3: Running the Blockchain



1. Save the code in a file named `blockchain.py`.

2. Run the server using the command:



```bash

python blockchain.py



import time



class Block:

    def __init__(self, index, proof_no, prev_hash, data, timestamp=None):

        self.index = index

        self.proof_no = proof_no

        self.prev_hash = prev_hash

        self.data = data

        self.timestamp = timestamp or time.time()



    @property

    def calculate_hash(self):

        block_string = f"{self.index}{self.proof_no}{self.prev_hash}{self.data}{self.timestamp}"

        return hashlib.sha256(block_string.encode()).hexdigest()



class BlockChain:

    def __init__(self):

        self.chain = []

        self.construct_genesis()



    def construct_genesis(self):

        # Create the initial block (genesis block)

        pass  # Your implementation here



    def construct_block(self, proof_no, prev_hash):

        # Create a new block and add it to the chain

        pass  # Your implementation here



    @staticmethod

    def check_validity():

        # Check whether the blockchain is valid

        pass  # Your implementation here



    def new_data(self, sender, recipient, quantity):

        # Add a new transaction to the data of the transactions

        pass  # Your implementation here



    @staticmethod

    def construct_proof_of_work(prev_proof):

        # Protect the blockchain from attack

        pass  # Your implementation here



    @property

    def last_block(self):

        # Return the last block in the chain

        return self.chain[-1]

Help building the app and making it would wide

New contributor

Richie Talents is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật