예제 #1
0
def generate_block():

    index = request.form['index']
    content = request.form['content']
    previous = request.form['previous']

    transaction = Transaction(satoshi.private_key, satoshi.public_key, str(content))
    block = Block(int(index), [transaction], previous, 0)

    block.timestamp = datetime.datetime(2009, 1, 10, 12, 00)
    transaction.timestamp = datetime.datetime(2009, 1, 10, 12, 00)

    response = {'hash': block.calculate_hash() }

    return jsonify(response), 200
예제 #2
0
def generate_nonce():
    index = request.form['index']
    content = request.form['content']
    previous = request.form['previous']
    nonce = request.form['nonce']

    transaction = Transaction(satoshi.private_key, satoshi.public_key, str(content))
    block = Block(int(index), [transaction], previous, 0)

    block.nonce = int(nonce)
    block.timestamp = datetime.datetime(2009, 1, 10, 12, 00)
    transaction.timestamp = datetime.datetime(2009, 1, 10, 12, 00)

    Block.proof_of_work(block, BlockChain)
    response = {'nonce' : block.nonce, 'hash': block.hash }

    return jsonify(response), 200