예제 #1
0
def nbc(request, seller_id, notification):
    # from, to, product id, product title
    data = {}
    noti = notification.split('-')
    buyer_id = noti[0]
    p_id = noti[-1]
    data["from"] = seller_id
    data["to"] = buyer_id
    data["product"] = p_id
    last_ledger = ledger[-1]
    new_block = next_block(last_ledger)
    new_block.data = data
    new_block.hash = new_block.hash_block()

    not1 = Notification.objects.filter(notification=notification)
    not1.delete()
    log = BlockChain()
    log.log = new_block.data
    log.save()

    # ledger.append(new_block)
    # new_ledger = []
    # for x in ledger:
    # 	new_ledger.append(x.data)
    # json_list = new_ledger
    x = JsonResponse(log.log, safe=False)
    return redirect('/home')
예제 #2
0
def process_transaction():
    global lock
    global node
    while len(transactions) > 0:
        t = transactions.pop()
        if t.forwarder == node.fingerprint:
            own_transactions.append(t)
        else:
            if not lock.locked():
                previous_block = temporary_quartz[-1]
                candidate = blockchain.next_block(previous_block)
                print("POW incoming!")
                candidate.proof_of_work(t, node.fingerprint)
                if not lock.locked():
                    print("POW done!")
                    print(candidate.overview())
                    advertise_block(candidate)
                    lock.acquire()
                    quartz.append(candidate)
                    temporary_quartz.append(candidate)
                    lock.release()
                else:
                    print("Scheduling transaction!")
                    transaction.append(t)
            else:
                transactions.append(t)
예제 #3
0
def broadcast():
    while True:
        if (LEADER) and (gui.ballotQueue.empty() != True):
            index = len(blockchain.chain)
            queuedData = gui.ballotQueue.get_nowait()
            blockToAdd = blockchain.next_block(MACHINE_ID, queuedData)
            if (blockToAdd.previous_hash == blockchain.chain[index - 1].hash):
                blockchain.append_block(blockToAdd)
                saveBlockchain(blockchain.chain, 'localBlockchain.pk1')
            message = (str)(blockToAdd.machine_id) + '%' + (str)(
                blockToAdd.timestamp) + '%' + (str)(blockToAdd.data) + '%' + (
                    str)(blockToAdd.hash) + '%' + (str)(
                        blockToAdd.previous_hash)
            outgoing_command_handler('ADDB', message)
예제 #4
0
#sample machine ID
machine_id = '1234'

block_to_add = None

#Machine will receive genesis_block from server so that all machines have the same genesis block
#In that case genesis_block = whatver server gives it
genesis_block = blockchain.create_genesis_block()

#machine will then create its own local blockchain utilitzing the genesis block given
blockchain.create_new_chain(genesis_block)

# Voter will vote and data will be packaged into proposed block
proposed_data = [["Voter ID", "000001"], ["President", "Eric Schweitzer"],
                 ["Senate", "Eric Schweitzer"], ["Mayor", "Eric Schweitzer"]]
block_to_add = blockchain.next_block(machine_id, proposed_data)

blockchain.chain.append(block_to_add)

print("First Block")
print("Machine ID: ", blockchain.chain[1].machine_id)
print("Time: ", blockchain.chain[1].timestamp)
print("Ballot: ", blockchain.chain[1].data)
print("Current Hash: ", blockchain.chain[1].hash)
print("Previous Hash: ", blockchain.chain[1].previous_hash, "\n")

message = str(block_to_add.machine_id) + '?' + str(block_to_add.timestamp) \
              + '?' + str(block_to_add.data) + '?' + str(block_to_add.hash) + '?' + str(block_to_add.previous_hash)
#print(message)

message = message.split("?")
예제 #5
0
import blockchain as bc
import block

if __name__ == "__main__":
    bc = bc.Blockchain()
    bc.create_genesis_block()
    bc.next_block(block.Data('a', 'b', 'c'))
    bc.next_block(block.Data('z', 'a', 'x'))
    # print(bc.get_last_block().hash)
    c = bc.next_block(block.Data('k', 'f', 'g'))
    print(bc.get_block('2').hash)
    print(bc.get_relate_blocks('a'))

    pass