Exemple #1
0
 def login(self, username=None):
     header = {'Content-Type': 'application/json'}
     data = {'public_key': self.public_key, 'username': username}
     resp = yield treq.post(url=self.url + 'account/v1/login/',
                            headers=header,
                            json=data,
                            persistent=False)
     confirm_info = yield treq.json_content(resp)
     logger.debug("login response: %s", confirm_info)
     self.nonce = confirm_info['message']
     logger.debug('nonce: %s', self.nonce)
     signature = ECCipher.create_signature(self.account.private_key,
                                           self.nonce)
     header_confirm = {'Content-Type': 'application/json'}
     data_confirm = {
         'public_key': self.public_key,
         'code': Encoder.bytes_to_hex(signature)
     }
     resp = yield treq.post(self.url + 'account/v1/confirm/',
                            headers=header_confirm,
                            json=data_confirm,
                            persistent=False)
     confirm_info = yield treq.json_content(resp)
     self.token = confirm_info['message']
     return confirm_info['status']
Exemple #2
0
 def publish_product(self,
                     selected_id,
                     title,
                     ptype,
                     description,
                     price,
                     tags,
                     start_date,
                     end_date,
                     category=None,
                     cover_image=None):
     logger.debug("start publish product")
     header = {'Content-Type': 'multipart/form-data'}  # 'application/json'}
     header['MARKET-KEY'] = self.public_key
     header['MARKET-TOKEN'] = self.token
     logger.debug('header token: %s', self.token)
     data = {
         'owner_address': self.public_key,
         'title': title,
         'ptype': ptype,
         'description': description,
         'price': price,
         'tags': tags,
         'start_date': start_date,
         'end_date': end_date,
         'category': category
     }
     signature_source = str(
         self.public_key) + str(title) + str(ptype) + str(
             description) + str(price) + MarketClient.str_to_timestamp(
                 start_date) + MarketClient.str_to_timestamp(end_date)
     signature = ECCipher.create_signature(self.account.private_key,
                                           signature_source)
     data['signature'] = Encoder.bytes_to_hex(signature)
     logger.debug("signature: %s", data['signature'])
     try:
         url = self.url + 'product/v1/allproducts/'
         resp = yield treq.post(
             url,
             files=dict(cover_image=open(cover_image, 'rb')),
             headers=header,
             data=data,
             persistent=False)
         confirm_info = yield treq.json_content(resp)
         logger.debug('market_hash: %s',
                      confirm_info['data']['market_hash'])
         market_hash = confirm_info['data']['market_hash']
     except Exception as e:
         logger.exception(e)
     if ptype == 'file' or ptype == 'stream':
         publish_file_update(market_hash, selected_id)
     return market_hash
Exemple #3
0
    def __generate_nonce_signature_and_get_token(self, header, nonce, pub_key_str, pri_key):
        url = '%s/account/v1/confirm/' % HOST
        print("nonce:%s" % nonce)
        nonce_signature = ECCipher.create_signature(pri_key, nonce)

        payload = {"public_key": pub_key_str, "code": Encoder.bytes_to_hex(nonce_signature)}
        confirm_resp = requests.post(url, headers=header, json=payload)
        print("response:%s" , confirm_resp.text)
        self.assertEqual(confirm_resp.status_code, 200)
        parsed_json = json.loads(confirm_resp.text)
        self.assertEqual(parsed_json['status'], 1)
        token = parsed_json['message']
        print("token:%s" % token)
        return token
Exemple #4
0
    def publish_product(self, selected_id, title, description, price, tags, start_date, end_date,
                        file_md5, size):

        logger.debug("start publish product")
        header = {'Content-Type': 'application/json'}
        header['MARKET-KEY'] = self.public_key
        header['MARKET-TOKEN'] = self.token
        logger.debug('header token: %s', self.token)
        data = {'owner_address': self.public_key, 'title': title, 'description': description,
                'price': price, 'tags': tags, 'start_date': start_date, 'end_date': end_date,
                'file_md5': file_md5, 'size': size}
        signature_source = str(self.public_key) + str(title) + str(description) + str(
            price) + MarketClient.str_to_timestamp(start_date) + MarketClient.str_to_timestamp(end_date) + str(file_md5)
        signature = ECCipher.create_signature(self.account.private_key, signature_source)
        data['signature'] = Encoder.bytes_to_hex(signature)
        logger.debug("signature: %s", data['signature'])
        resp = yield treq.post(self.url + 'product/v1/product/publish/', headers=header, json=data, persistent=False)
        confirm_info = yield treq.json_content(resp)
        print(confirm_info)

        logger.debug('market_hash: %s', confirm_info['data']['market_hash'])
        market_hash = confirm_info['data']['market_hash']
        publish_file_update(market_hash, selected_id)
        return market_hash
Exemple #5
0
    def __generate_nonce_signature_and_get_token(self, header, nonce,
                                                 pub_key_str, pri_key):
        url = reverse('confirm')
        print("nonce:%s" % nonce)
        nonce_signature = ECCipher.create_signature(pri_key, nonce)

        payload = {
            "public_key": pub_key_str,
            "code": Encoder.bytes_to_hex(nonce_signature)
        }
        # self.client.head(header)
        confirm_resp = self.client.post(url,
                                        data=payload,
                                        format='json',
                                        **header)

        self.assertEqual(confirm_resp.status_code, 200)
        resp = confirm_resp.content.decode("utf-8")
        print("response:%s" % resp)
        parsed_json = json.loads(resp)
        self.assertEqual(parsed_json['status'], 1)
        token = parsed_json['message']
        print("token:%s" % token)
        return token