Пример #1
0
def register_nodes():
    values = request.get_json()
    print(f'Values is: {values}')
    nodes = values.get('nodes')
    if nodes is None:
        return "Error: Please supply a valid list of nodes", 400
    for node in nodes:
        Blockchain.register_node(node)
    response = {
        'message': 'New nodes have been added',
        'total_nodes': list(Blockchain.nodes),
    }
    return jsonify(response), 201
Пример #2
0
from uuid import uuid4

from flask import Blueprint
from flask_restplus import Api, Resource, fields

from common import app_name, app_slogan
from blockchain.blockchain import Blockchain

# Instantiate the Blockchain
blockchain = Blockchain()
blockchain.register_node("server", "data_source")
blockchain.register_node("sense_hat", "data_source")

# Instantiate the Node
blueprint = Blueprint('blockchain', __name__)
api = Api(blueprint,
          version="1.0",
          title=f"{app_name} Blockchain API",
          description=app_slogan)

nodes = api.model(
    "Nodes", {
        "nodes":
        fields.List(fields.String(description="Node url"),
                    description="List of nodes")
    })

transaction = api.model(
    "Transaction", {
        "sender": fields.String(description="Sender id"),
        "recipient": fields.String(description="Recipient id"),