Пример #1
0
def genesisblock_generate():
    transaction = "Base lab logchain project"
    prev_hash = "N/A"
    nonce = "N/A"
    merkle_root = hashlib.sha256(str(transaction).encode('utf-8')).hexdigest()
    vote_result = "N/A"
    timestamp = "20170904"
    block_header = block.BlockHeader(
        prev_hash, nonce, merkle_root, vote_result, timestamp)

    block_header.block_id = 'genesis_block'
    block_header.block_number = "1"
    block_header.block_info = block_header.prev_hash + block_header.merkle_root
    block_header.block_hash = hashlib.sha256(
        str(block_header.block_info).encode('utf-8')).hexdigest()
    block_header.miner = "Base Lab"
    block_header.num_tx = "1"

    genesisblock = block.Block(block_header, transaction)
    json_genesisblock = json.dumps(
        genesisblock, indent=4, default=lambda o: o.__dict__, sort_keys=True)
    file_controller.create_new_block(
        str(block_header.block_number), json_genesisblock)
    logging.debug('Genesis block created now.')
    logging.debug(" - block hash: "+ block_header.block_hash)
    logging.debug(" - block ID: " + block_header.block_id)
    logging.debug(" - block info: " + block_header.block_info)
    logging.debug(" - block transaction: " + transaction)
Пример #2
0
def receive_event(p_thrd_name, p_inq, p_socketq):
    while True:
        logging.debug("Waiting for B type msg")
        recv_data = p_inq.get()
        request_sock = p_socketq.get()

        file_controller.create_new_block(
            str(receiver.Data_jobj['block_header']['block_number']), recv_data)

        print("End create _new block")
        file_controller.remove_all_transactions()
        file_controller.remove_all_voting()

        request_sock.close()
Пример #3
0
def receive_event(p_thrd_name, p_inq, p_socketq):
    while True:
        monitoring.log("log.Waiting for B type msg")
        recv_data = p_inq.get()
        Data_jobj = json.loads(recv_data)
        request_sock = p_socketq.get()
        monitoring.log("log.B type msg rcvd: " + recv_data)

        file_controller.create_new_block(
            str(Data_jobj['block_header']['block_number']), recv_data)

        monitoring.log("log.End create _new block")
        file_controller.remove_all_transactions()
        file_controller.remove_all_voting()

        request_sock.close()
Пример #4
0
def receive_event(p_thrd_name, p_inq):
    while True:
        monitoring.log("log.Waiting for B type msg")
        (recv_data, request_sock) = p_inq.get()
        Data_jobj = json.loads(recv_data)
        monitoring.log("log.B type msg rcvd: " + recv_data)

        file_controller.create_new_block(
            str(Data_jobj['block_header']['block_number']), recv_data)

        block_verify.verify_tx_list(Data_jobj['tx_list'])

        monitoring.log("log.End create _new block")
        monitoring.log("block." +
                       str(Data_jobj['block_header']['block_number']))

        # try
        file_controller.remove_all_transactions()
        file_controller.remove_all_voting()
        # try

        request_sock.close()