예제 #1
0
def runBlockChain():
    blockchain = [create_genesis_block()]
    previous_block = blockchain[0]
    num_of_blocks_to_add = 20

    for i in range(0, num_of_blocks_to_add):
        block_to_add = next_block(previous_block)
        blockchain.append(block_to_add)
        previous_block = block_to_add
        print("Block #{} has been added to the blockchain!\n{}".format(
            block_to_add.index, block_to_add))
예제 #2
0
import json
import requests
import datetime as date
from flask import Flask
from flask import request

from utils import *
from transaction import Transaction
from genesis import create_genesis_block
from block import Block, Data, get_block_obj
from helper import address

node = Flask(__name__)

# Create a blockchain and initialize it with a genesis block
blockchain = [create_genesis_block()]
previous_block = blockchain[0]

# A completely random address of the owner of this node
miner_address = None

# Transactions that this node is doing
nodes_transactions = []

# Link of peer nodes
peer_nodes = set()
# If we are mining or not
mining = True

# Mock the rest request
mock = False
from flask import Flask, request

from block import Block
from genesis import create_genesis_block
from proof_of_work import proof_of_work


node = Flask(__name__)


# Random address of the owner of this node
miner_address = "a-random-miner-address-t2g329873ty51"

blockchain = []
blockchain.append(create_genesis_block())
this_nodes_transactions = []
# list of other nodes in system aka other blockchain users
peer_nodes = []


def log_new_transaction(transaction):
    print "New transaction"
    print "FROM: {}".format(transaction['from'])
    print "TO: {}".format(transaction['to'])
    print "AMOUNT: {}".format(transaction['amount'])

@node.route('/transaction', methods=['POST'])
def transaction():
    if request.method == 'POST':
        new_transaction = request.get_json()
예제 #4
0
파일: app.py 프로젝트: shlliu/SnakeBlock
def main():
    port = 5000
    if len(sys.argv) > 1:
        port = sys.argv[1]
    blockchain.append(create_genesis_block())
    node.run(port=port)