예제 #1
0
 def __init__(self,
              my_port=50082,
              core_node_host=None,
              core_node_port=None,
              pass_phrase=None):
     self.server_state = STATE_INIT
     print('Initializing server...')
     self.my_ip = self.__get_myip()
     print('Server IP address is set to ... ', self.my_ip)
     self.my_port = my_port
     self.cm = ConnectionManager(self.my_ip, self.my_port,
                                 self.__handle_message)
     self.mpmh = MyProtocolMessageHandler()
     self.core_node_host = core_node_host
     self.core_node_port = core_node_port
     self.bb = BlockBuilder()
     my_genesis_block = self.bb.generate_genesis_block()
     self.bm = BlockchainManager(my_genesis_block.to_dict())
     self.prev_block_hash = self.bm.get_hash(my_genesis_block.to_dict())
     self.tp = TransactionPool()
     self.is_bb_running = False
     self.flag_stop_block_build = False
     self.mpm_store = MessageStore()
     self.km = KeyManager(None, pass_phrase)
     self.rsa_util = RSAUtil()
     self.um = UTXOManager(self.km.my_address())
예제 #2
0
def main():
    global FLAG_STOP_BLOCK_BUILD

    bb = BlockBuilder()
    my_genesis_block = bb.generate_genesis_block()
    bm = BlockchainManager(my_genesis_block.to_dict())

    tp = TransactionPool()

    prev_block_hash = bm.get_hash(my_genesis_block.to_dict())
    print('genesis_block_hash :', prev_block_hash)

    transaction = {'sender': 'test1', 'recipient': 'test2', 'value': 3}

    tp.set_new_transaction(transaction)

    transaction2 = {'sender': 'test1', 'recipient': 'test3', 'value': 2}

    tp.set_new_transaction(transaction2)

    start_thread(tp, bb, bm, prev_block_hash)

    sleep(20)

    transaction3 = {'sender': 'test5', 'recipient': 'test6', 'value': 10}

    tp.set_new_transaction(transaction3)

    sleep(30)

    print('Stop the Thread for generate_block_with_tp')
    FLAG_STOP_BLOCK_BUILD = True
예제 #3
0
 def __init__(self,
              my_port=50082,
              core_node_host=None,
              core_node_port=None):
     self.server_state = STATE_INIT
     print('Initializing server...')
     self.my_ip = self.__get_myip()
     print('Server IP address is set to ... ', self.my_ip)
     self.my_port = my_port
     self.cm = ConnectionManager(self.my_ip, self.my_port,
                                 self.__handle_message)
     self.mpmh = MyProtocolMessageHandler()
     self.core_node_host = core_node_host
     self.core_node_port = core_node_port
     self.bb = BlockBuilder()
     self.flag_stop_block_build = False
     self.is_bb_running = False
     my_genesis_block = self.bb.generate_genesis_block()
     self.bm = BlockchainManager(my_genesis_block.to_dict())
     self.prev_block_hash = self.bm.get_hash(my_genesis_block.to_dict())
     self.tp = TransactionPool()
     self.vl = VerifyLocinfo()
     # 位置情報の偽装を検知するようのカウンタ
     self.c_cnt = 0
     self.bc_cnt = 0
     self.false_cnt = 0
예제 #4
0
def main():
    bb = BlockBuilder()
    my_genesis_block = bb.generate_genesis_block()
    bm = BlockchainManager(my_genesis_block.to_dict())

    prev_block_hash = bm.get_hash(my_genesis_block.to_dict())
    print('genesis_block_hash :', prev_block_hash)

    transaction = {
            'sender': 'test',
            'recipient': 'test2',
            'value': 3
            }

    new_block = bb.generate_new_block(transaction, prev_block_hash)
    bm.set_new_block(new_block.to_dict())
   
    new_block_hash = bm.get_hash(new_block.to_dict())
    print('1st_block_hash :', new_block_hash)

    transaction = {
            'sender': 'test1',
            'recipient': 'test3',
            'value': 2
            }
    new_block2 = bb.generate_new_block(transaction, new_block_hash)
    bm.set_new_block(new_block2.to_dict())

    print(bm.chain)
    chain = bm.chain
    print(bm.is_valid(chain))
예제 #5
0
    def __init__(self,
                 my_port=50082,
                 core_node_host=None,
                 core_node_port=None):
        self.server_state = STATE_INIT
        # self.main_window = GuiTest()
        print('Initializing server...')
        self.my_ip = self.__get_myip()
        print('Server IP address is set to ... ', self.my_ip)
        self.my_port = my_port
        self.cm = ConnectionManager(
            self.my_ip, self.my_port, self.__handle_message, self
        )  #, self.main_window.set_cnode_list, self.main_window.set_enode_list)
        self.mpmh = MyProtocolMessageHandler()
        self.core_node_host = core_node_host
        self.core_node_port = core_node_port
        self.bb = BlockBuilder()
        self.flag_stop_block_build = False
        self.is_bb_running = False
        my_genesis_block = self.bb.generate_genesis_block()
        self.bm = BlockchainManager(my_genesis_block.to_dict())
        self.prev_block_hash = self.bm.get_hash(my_genesis_block.to_dict())
        self.tp = TransactionPool()

        if core_node_host and core_node_port:
            self.plz_share_db()
예제 #6
0
def main():
    bb = BlockBuilder()
    my_genesis_block = bb.generate_genesis_block()
    bm = BlockchainManager(my_genesis_block.to_dict())

    tp = TransactionPool()

    prev_block_hash = bm.get_hash(my_genesis_block.to_dict())
    print('genesis_block_hash :', prev_block_hash)

    transaction = {'sender': 'test', 'recipient': 'test2', 'value': 3}

    tp.set_new_transaction(transaction)

    transaction = {'sender': 'test1', 'recipient': 'test3', 'value': 2}

    tp.set_new_transaction(transaction)

    block_timer = threading.Timer(CHECK_INTERVAL,
                                  generate_block_with_tp,
                                  args=(tp, bb, bm, prev_block_hash))

    block_timer.start()

    time.sleep(11)

    transaction3 = {'sender': 'test5', 'recipient': 'test6', 'value': 10}
    tp.set_new_transaction(transaction3)
예제 #7
0
def test_set_new_block():
    genesis = GenesisBlock()
    bm = BlockchainManager(genesis.to_dict())
    block = Block('transaction', 'prev_block_hash')
    bm.set_new_block(block)
    assert len(bm.chain) == 2
    assert bm.chain[0] == genesis.to_dict()
    assert bm.chain[1] == block
예제 #8
0
def test_get_hash():
    bm = BlockchainManager(None)
    block = Block('transaction', 'prev_block_hash')
    block_json = json.dumps(block.to_dict(), sort_keys=True)
    hash_b = hashlib.sha256(
        hashlib.sha256(block_json.encode('utf-8')).digest()).digest()
    actual_hash = binascii.hexlify(hash_b).decode('ascii')
    assert bm.get_hash(block.to_dict()) == actual_hash
예제 #9
0
    def __init__(self,
                 my_port=50082,
                 core_node_host=None,
                 core_node_port=None):
        self.server_state = STATE_INIT
        print('Initializing server...')
        self.my_ip = self.__get_myip()
        print('Server IP address is set to ... ', self.my_ip)
        self.my_port = my_port
        self.cm = ConnectionManager(self.my_ip, self.my_port,
                                    self.__handle_message, self)
        self.mpmh = MyProtocolMessageHandler()
        self.core_node_host = core_node_host
        self.core_node_port = core_node_port
        self.bb = BlockBuilder()
        self.flag_stop_block_build = True
        self.is_bb_running = False
        if main_level.get_genesis(LDB_P):
            self.bm = BlockchainManager()
            latest_dbd_block = main_level.get_latest_block(LDB_P)
            self.prev_block_hash = self.bm.get_hash(latest_dbd_block)
            block_num = level_param.get_block_num(PARAM_P) + len(self.bm.chain)
            new_block = self.bb.generate_new_block({}, self.prev_block_hash,
                                                   str(block_num), ADDRESS, {},
                                                   self)
            self.bm.set_reconnect_block(new_block.to_dict())
            self.prev_block_hash = self.bm.get_hash(new_block.to_dict())
        else:
            my_genesis_block = self.bb.generate_genesis_block()
            self.bm = BlockchainManager(my_genesis_block.to_dict())
            self.prev_block_hash = self.bm.get_hash(my_genesis_block.to_dict())
        self.tp = TransactionPool()

        if core_node_host and core_node_port:
            self.plz_share_db()
        else:
            self.flag_stop_block_build = False
 def __init__(self, my_port=50082, core_node_host=None, core_node_port=None):
     self.server_state = STATE_INIT
     print('Initializeing server...')
     self.my_ip = self.__get_myip()
     self.my_port = my_port
     print('Server IP address is set to ...', self.my_ip)
     print('Server Port is set to ...', self.my_port)
     self.cm = ConnectionManager(self.my_ip, self.my_port, self.__handle_message)
     self.core_node_host = core_node_host
     self.core_node_port = core_node_port
     self.mpmh = MyProtocolMessageHandler()
     self.my_protocol_message_store = []
     self.bb = BlockBuilder()
     my_genesis_block = self.bb.generate_genesis_block()
     self.bm = BlockchainManager(my_genesis_block.to_dict())
     self.prev_block_hash = self.bm.get_hash(my_genesis_block.to_dict())
     self.tp = TransactionPool()
예제 #11
0
    def __init__(self, my_port=50082, core_host=None, core_port=None, server_id=1, callback=None, mpmh_callback=None):
        self.client_state = STATE_INIT
        print('Initializing ClientCore...')
        self.my_ip = self.__get_myip()
        print('Server IP address is set to ... ', self.my_ip)
        self.my_port = my_port
        self.my_core_host = core_host
        self.my_core_port = core_port
        self.my_server_id = server_id
        self.cm = ConnectionManager4Edge(self.my_ip, self.my_port, core_host, core_port, self.__handle_message)
        self.mpmh = MyProtocolMessageHandler()
        self.mpm_store = MessageStore()
        self.mpmh_callback = mpmh_callback

        self.bb = BlockBuilder()
        my_genesis_block = self.bb.generate_genesis_block(self.my_server_id)
        self.bm = BlockchainManager(my_genesis_block.to_dict())
        self.callback = callback
예제 #12
0
def main():
    bb = BlockBuilder()
    my_genesis_block = bb.generate_new_block(
        'this_is_simple_bitcoin_genesis_block', None)
    bm = BlockchainManager(my_genesis_block.to_dict())

    prev_block_hash = bm.get_hash(my_genesis_block.to_dict())
    print('genesis_block_hash :', prev_block_hash)

    transaction = {'sender': 'test1', 'recipient': 'test2', 'value': 3}

    new_block = bb.generate_new_block(transaction, prev_block_hash)
    bm.set_new_block(new_block.to_dict())

    new_block_hash = bm.get_hash(new_block.to_dict())
    print('1st_block_hash :', new_block_hash)

    transaction2 = {'sender': 'test1', 'recipient': 'test3', 'value': 2}
    new_block2 = bb.generate_new_block(transaction2, new_block_hash)
    bm.set_new_block(new_block2.to_dict())

    print(bm.chain)
예제 #13
0
    def __init__(self):
        self.name = sys.argv[-1]
        self.make_table()
        self.port = 11111
        with open("/fika/output/log.txt", "w") as f:
            f.write("Hello")
        self.lock = threading.Lock()
        self.mm = MessageManager()
        self.bm = BlockchainManager()
        self.miner = BlockMiner()
        genesis_block = self.miner.mine_gblock()
        self.bm.chained(genesis_block)
        self.previous_hash = self.bm.get_hash(genesis_block)

        self.MINING_NOW = False
        self.STOP_MINING = False
        signal.signal(signal.SIGINT, self.__KeyboardInterruptHandler)
        self.wait_thread = threading.Thread(target=self.__wait_access)
        self.wait_thread.start()
        self.mining_timer = threading.Timer(MINING_INTERVAL,
                                            self.__start_mining)
        self.mining_timer.start()
예제 #14
0
def test__get_double_sha256():
    bm = BlockchainManager(None)
    actual_hash = hashlib.sha256(
        hashlib.sha256('abc'.encode('utf-8')).digest()).digest()
    assert bm._get_double_sha256('abc') == actual_hash