Example #1
0
    def send_opening(self):
        peers = self.get_peers()

        countryCodes = []
        for country in pycountry.countries:
            countryCodes.append({"code": country.alpha2, "name": country.name})

        settings = self.market.get_settings()

        message = {
            'type': 'myself',
            'pubkey': settings.get('pubkey'),
            'peers': peers,
            'settings': settings,
            'guid': self.transport.guid,
            'sin': self.transport.sin,
            'uri': self.transport.uri,
            'countryCodes': countryCodes,
        }

        self.send_to_client(None, message)

        burnAddr = trust.burnaddr_from_guid(self.transport.guid)

        def found_unspent(amount):
            self.send_to_client(None, {
                'type': 'burn_info_available',
                'amount': amount,
                'addr': burnAddr
            })

        trust.get_unspent(burnAddr, found_unspent)
Example #2
0
    def send_opening(self):
        peers = self.get_peers()

        countryCodes = []
        for country in pycountry.countries:
            countryCodes.append({"code": country.alpha2, "name": country.name})

        settings = self.market.get_settings()

        message = {
            'type': 'myself',
            'pubkey': settings.get('pubkey'),
            'peers': peers,
            'settings': settings,
            'guid': self.transport.guid,
            'sin': self.transport.sin,
            'uri': self.transport.uri,
            'countryCodes': countryCodes,
        }

        self.send_to_client(None, message)

        burnAddr = trust.burnaddr_from_guid(self.transport.guid)

        def found_unspent(amount):
            self.send_to_client(None, {
                'type': 'burn_info_available',
                'amount': amount,
                'addr': burnAddr
            })

        trust.get_unspent(burnAddr, found_unspent)
Example #3
0
    def send_opening(self):
        peers = self.get_peers()

        countryCodes = []
        for country in pycountry.countries:
            countryCodes.append({"code": country.alpha2, "name": country.name})

        settings = self._market.get_settings()
        # globalTrust = trust.getTrust(self._transport.guid)

        # print(trust.get(self._transport.guid))

        message = {
            'type': 'myself',
            'pubkey': settings.get('pubkey'),
            'peers': peers,
            'settings': settings,
            'guid': self._transport.guid,
            'sin': self._transport.sin,
            'uri': self._transport._uri,
            'countryCodes': countryCodes,
            # 'globalTrust': globalTrust
        }

        # print('Sending opening')
        self.send_to_client(None, message)

        burnAddr = trust.burnaddr_from_guid(self._transport.guid)

        # def found_unspent(amount_in_satoshis):

        def found_unspent(amount):
            # print("found_unspent")
            self.send_to_client(None, {
                'type': 'burn_info_available',
                'amount': amount,
                'addr': burnAddr
            })

        # print("getting unspent")

        trust.get_unspent(burnAddr, found_unspent)
Example #4
0
    def send_opening(self):
        peers = self.get_peers()

        countryCodes = []
        for country in pycountry.countries:
            countryCodes.append({"code": country.alpha2, "name": country.name})

        settings = self._market.get_settings()
        # globalTrust = trust.getTrust(self._transport.guid)

        # print(trust.get(self._transport.guid))

        message = {
            'type': 'myself',
            'pubkey': settings.get('pubkey'),
            'peers': peers,
            'settings': settings,
            'guid': self._transport.guid,
            'sin': self._transport.sin,
            'uri': self._transport._uri,
            'countryCodes': countryCodes,
            # 'globalTrust': globalTrust
        }

        # print('Sending opening')
        self.send_to_client(None, message)

        burnAddr = trust.burnaddr_from_guid(self._transport.guid)
        # def found_unspent(amount_in_satoshis):

        def found_unspent(amount):
            # print("found_unspent")
            self.send_to_client(None, {
                'type': 'burn_info_available',
                'amount': amount,
                'addr': burnAddr
            })

        # print("getting unspent")

        trust.get_unspent(burnAddr, found_unspent)
Example #5
0
    def get_order(self, order_id, by_buyer_id=False):

        if not by_buyer_id:
            _order = self.db.selectEntries("orders", {"order_id": order_id})[0]
        else:
            _order = self.db.selectEntries("orders",
                                           {"buyer_order_id": order_id})[0]
        total_price = 0

        offer_data_json = self.get_offer_json(_order['signed_contract_body'],
                                              _order['state'])
        buyer_data_json = self.get_buyer_json(_order['signed_contract_body'],
                                              _order['state'])

        if _order['state'] != Orders.State.SENT:
            notary_json = self.get_notary_json(_order['signed_contract_body'],
                                               _order['state'])
            notary = notary_json['Notary']['notary_GUID']
        else:
            notary = ""

        if _order['state'] in (Orders.State.NEED_TO_PAY,
                               Orders.State.NOTARIZED,
                               Orders.State.WAITING_FOR_PAYMENT,
                               Orders.State.PAID, Orders.State.BUYER_PAID,
                               Orders.State.SHIPPED):

            def cb(total):
                if self.transport.handler is not None:
                    self.transport.handler.send_to_client(
                        None, {
                            "type": "order_payment_amount",
                            "value": total
                        })

            pubkeys = [
                offer_data_json['Seller']['seller_BTC_uncompressed_pubkey'],
                buyer_data_json['Buyer']['buyer_BTC_uncompressed_pubkey'],
                notary_json['Notary']['notary_BTC_uncompressed_pubkey']
            ]

            script = mk_multisig_script(pubkeys, 2, 3)
            payment_address = scriptaddr(script)

            trust.get_unspent(payment_address, cb)

            if 'shipping_price' in _order:
                shipping_price = _order[
                    'shipping_price'] if _order['shipping_price'] != '' else 0
            else:
                shipping_price = 0

            try:
                total_price = str((Decimal(shipping_price) + Decimal(_order['item_price']))) \
                    if 'item_price' in _order else _order['item_price']
            except Exception as e:
                self.log.error('Probably not a number %s' % e)

        # Generate QR code
        print offer_data_json
        qr = self.get_qr_code(offer_data_json['Contract']['item_title'],
                              _order['address'], total_price)
        merchant_bitmessage = offer_data_json.get('Seller').get('seller_Bitmessage') if 'Seller' \
                                                                                        in offer_data_json else ""
        buyer_bitmessage = buyer_data_json.get('Buyer').get('buyer_Bitmessage') if 'Buyer' \
                                                                                   in buyer_data_json else ""

        # Get order prototype object before storing
        order = {
            "id":
            _order['id'],
            "state":
            _order.get('state'),
            "address":
            _order.get('address'),
            "buyer":
            _order.get('buyer'),
            "merchant":
            _order.get('merchant'),
            "order_id":
            _order.get('order_id'),
            "item_price":
            _order.get('item_price'),
            "shipping_price":
            _order.get('shipping_price'),
            "shipping_address":
            str(_order.get('shipping_address'))
            if _order.get("shipping_address") != "" else "",
            "total_price":
            total_price,
            "merchant_bitmessage":
            merchant_bitmessage,
            "buyer_bitmessage":
            buyer_bitmessage,
            "notary":
            notary,
            "payment_address":
            _order.get('payment_address'),
            "payment_address_amount":
            _order.get('payment_address_amount'),
            "qrcode":
            'data:image/png;base64,' + qr,
            "item_title":
            offer_data_json['Contract']['item_title'],
            "signed_contract_body":
            _order.get('signed_contract_body'),
            "note_for_merchant":
            _order.get('note_for_merchant'),
            "updated":
            _order.get('updated')
        }

        if 'item_images' in offer_data_json['Contract'] and offer_data_json[
                'Contract']['item_images'] != {}:
            order['item_image'] = offer_data_json['Contract']['item_images']
        else:
            order['item_image'] = "img/no-photo.png"

        self.log.debug('FULL ORDER: %s' % order)

        return order
Example #6
0
    def get_order(self, order_id, by_buyer_id=False):

        if not by_buyer_id:
            _order = self.db.selectEntries("orders", {"order_id": order_id})[0]
        else:
            _order = self.db.selectEntries("orders", {"buyer_order_id": order_id})[0]
        total_price = 0

        offer_data_json = self.get_offer_json(_order['signed_contract_body'], _order['state'])
        buyer_data_json = self.get_buyer_json(_order['signed_contract_body'], _order['state'])

        if _order['state'] != Orders.State.SENT:
            notary_json = self.get_notary_json(_order['signed_contract_body'], _order['state'])
            notary = notary_json['Notary']['notary_GUID']
        else:
            notary = ""

        if _order['state'] in (Orders.State.NEED_TO_PAY,
                               Orders.State.NOTARIZED,
                               Orders.State.WAITING_FOR_PAYMENT,
                               Orders.State.PAID,
                               Orders.State.BUYER_PAID,
                               Orders.State.SHIPPED):

            def cb(total):
                if self.transport.handler is not None:
                    self.transport.handler.send_to_client(None, {"type": "order_payment_amount",
                                                                 "value": total})

            pubkeys = [
                offer_data_json['Seller']['seller_BTC_uncompressed_pubkey'],
                buyer_data_json['Buyer']['buyer_BTC_uncompressed_pubkey'],
                notary_json['Notary']['notary_BTC_uncompressed_pubkey']
            ]

            script = mk_multisig_script(pubkeys, 2, 3)
            payment_address = scriptaddr(script)

            trust.get_unspent(payment_address, cb)

            if 'shipping_price' in _order:
                shipping_price = _order['shipping_price'] if _order['shipping_price'] != '' else 0
            else:
                shipping_price = 0

            try:
                total_price = str((Decimal(shipping_price) + Decimal(_order['item_price']))) \
                    if 'item_price' in _order else _order['item_price']
            except Exception as e:
                self.log.error('Probably not a number %s', e)

        # Generate QR code
        qr = self.get_qr_code(offer_data_json['Contract']['item_title'], _order['address'], total_price)
        merchant_bitmessage = offer_data_json.get('Seller', '').get('seller_Bitmessage')
        buyer_bitmessage = buyer_data_json.get('Buyer', '').get('buyer_Bitmessage')

        # Get order prototype object before storing
        order = {"id": _order['id'],
                 "state": _order.get('state'),
                 "address": _order.get('address'),
                 "buyer": _order.get('buyer'),
                 "merchant": _order.get('merchant'),
                 "order_id": _order.get('order_id'),
                 "item_price": _order.get('item_price'),
                 "shipping_price": _order.get('shipping_price'),
                 "shipping_address": str(_order.get('shipping_address')),
                 "total_price": total_price,
                 "merchant_bitmessage": merchant_bitmessage,
                 "buyer_bitmessage": buyer_bitmessage,
                 "notary": notary,
                 "payment_address": _order.get('payment_address'),
                 "payment_address_amount": _order.get('payment_address_amount'),
                 "qrcode": 'data:image/png;base64,' + qr,
                 "item_title": offer_data_json['Contract']['item_title'],
                 "signed_contract_body": _order.get('signed_contract_body'),
                 "note_for_merchant": _order.get('note_for_merchant'),
                 "updated": _order.get('updated')}

        if 'item_images' in offer_data_json['Contract'] and offer_data_json['Contract']['item_images'] != {}:
            order['item_image'] = offer_data_json['Contract']['item_images']
        else:
            order['item_image'] = "img/no-photo.png"

        self.log.datadump('FULL ORDER: %s', order)

        return order