Example #1
0
    def buy_product(self, msg_hash, file_title, proxy, seller, value):
        logger.debug("start to buy product")
        seller_addr = get_address_from_public_key_object(seller)
        desc_hash = Encoder.str_to_base64_byte(msg_hash)
        rsa_key = RSACipher.load_public_key()
        # rsa_key = self.broker.wallet.market_client.public_key
        logger.debug("desc hash: %s", desc_hash)
        logger.info('Value: %s', value)
        product = OrderInfo(
            desc_hash=desc_hash,
            buyer_rsa_pubkey=rsa_key,
            seller=self.broker.buyer.web3.toChecksumAddress(seller_addr),
            proxy=self.broker.buyer.web3.toChecksumAddress(proxy),
            secondary_proxy=self.broker.buyer.web3.toChecksumAddress(proxy),
            proxy_value=10,
            value=value,
            time_allowed=3600 * 24
        )
        logger.debug("product info has been created")
        logger.debug("product info: %s", product)
        logger.debug("seller address: %s", product.seller)
        d_placed_order = deferToThread(self.broker.buyer.place_order, product)

        def add_bought_order(order_id):
            logger.debug("start to update local database")
            new_buyer_file_info = BuyerFileInfo(order_id=order_id,
                                                market_hash=Encoder.bytes_to_base64_str(desc_hash),
                                                file_title=file_title, is_downloaded=False)
            add_file(new_buyer_file_info)
            logger.debug("update local db completed")
            event.emit(events.PAY, (order_id, msg_hash))
            # Update the purchased downloaded tab in the main window of wallet
        d_placed_order.addCallback(add_bought_order)
Example #2
0
    def buy_product(self, msg_hash, file_title, proxy, seller):
        logger.debug("start to buy product")
        seller_addr = get_address_from_public_key_object(seller)
        desc_hash = Encoder.str_to_base64_byte(msg_hash)
        rsa_key = RSACipher.load_public_key()
        logger.debug("desc hash: %s", desc_hash)
        product = OrderInfo(
            desc_hash=desc_hash,
            buyer_rsa_pubkey=rsa_key,
            seller=self.broker.buyer.web3.toChecksumAddress(seller_addr),
            proxy=self.broker.buyer.web3.toChecksumAddress(proxy),
            secondary_proxy=self.broker.buyer.web3.toChecksumAddress(proxy),
            proxy_value=10,
            value=20,
            time_allowed=1000)
        logger.debug("product info has been created")
        logger.debug("product info: %s", product)
        logger.debug("seller address: %s", product.seller)
        logger.debug("bought order queue size: %s",
                     self.broker.bought_order_queue.qsize())
        d_placed_order = deferToThread(self.broker.buyer.place_order, product)

        def add_bought_order(order_id):
            logger.debug("order has been placed to chain")
            self.broker.bought_order_queue.put(order_id)
            logger.debug("new order has been put into bought order queue")
            logger.debug("bought order queue size: %s",
                         self.broker.bought_order_queue.qsize())
            logger.debug("start to update local database")
            new_buyer_file_info = BuyerFileInfo(
                order_id=order_id,
                market_hash=Encoder.bytes_to_base64_str(desc_hash),
                file_title=file_title,
                is_downloaded=False)
            add_file(new_buyer_file_info)
            logger.debug("update local db completed")

            # Update the purchased downloaded tab in the main window of wallet
            self.broker.wallet.main_wnd.update_purchased_tab('downloading')

        d_placed_order.addCallback(add_bought_order)

        return self.broker.bought_order_queue
Example #3
0
def test_place_order(bAgent):
    sellerAccount = get_addr_from_public_key(Accounts()[1].public_key)
    proxyAccount = get_addr_from_public_key(Accounts()[2].public_key)

    buyer_rsa_pubkey = RSACipher.load_public_key()
    order_info = OrderInfo(
        desc_hash=bytes([0, 1, 2, 3] * 8),
        buyer_rsa_pubkey=buyer_rsa_pubkey,
        seller=bAgent.web3.toChecksumAddress(sellerAccount),
        proxy=bAgent.web3.toChecksumAddress(proxyAccount),
        secondary_proxy=bAgent.web3.toChecksumAddress(proxyAccount),
        proxy_value=10,
        value=20,
        time_allowed=time_allowed)
    global order_id
    order_id = bAgent.place_order(order_info)
    #assert order_id == 1
    test_record = bAgent.query_order(order_id)
    assert test_record[0] == bytes([0, 1, 2, 3] * 8)
    assert test_record[2] == bAgent.account
    # Check state is Created
    assert test_record[10] == 0