Esempio n. 1
0
    def __init__(self):
        global Web3
        try:
            from web3 import Web3, HTTPProvider
        except ImportError:
            raise MarketplaceRequiresPython3()

        self.addresses = get_user_pubaddr()

        if self.addresses[0]['pubAddr'] == '':
            raise MarketplacePubAddressEmpty(filename=os.path.join(
                get_marketplace_folder(), 'addresses.json'))
        self.default_account = self.addresses[0]['pubAddr']

        self.web3 = Web3(HTTPProvider(ETH_REMOTE_NODE))

        contract_url = urllib.urlopen(MARKETPLACE_CONTRACT)

        self.mkt_contract_address = Web3.toChecksumAddress(
            contract_url.readline().decode(
                contract_url.info().get_content_charset()).strip())

        abi_url = urllib.urlopen(MARKETPLACE_CONTRACT_ABI)
        abi_url = abi_url.read().decode(abi_url.info().get_content_charset())

        abi = json.loads(abi_url)

        self.mkt_contract = self.web3.eth.contract(
            self.mkt_contract_address,
            abi=abi,
        )

        contract_url = urllib.urlopen(ENIGMA_CONTRACT)

        self.eng_contract_address = Web3.toChecksumAddress(
            contract_url.readline().decode(
                contract_url.info().get_content_charset()).strip())

        abi_url = urllib.urlopen(ENIGMA_CONTRACT_ABI)
        abi_url = abi_url.read().decode(abi_url.info().get_content_charset())

        abi = json.loads(abi_url)

        self.eng_contract = self.web3.eth.contract(
            self.eng_contract_address,
            abi=abi,
        )
Esempio n. 2
0
    def clean(self, ds_name=None, data_frequency=None):

        if ds_name is None:
            mktplace_root = get_marketplace_folder()
            folders = [
                os.path.basename(f.rstrip('/'))
                for f in glob.glob('{}/*/'.format(mktplace_root))
                if 'temp_bundles' not in f
            ]

            while True:
                for idx, f in enumerate(folders):
                    print('{}\t{}'.format(idx, f))
                dataset_num = input('Choose the dataset you want to '
                                    'clean [0..{}]: '.format(len(folders) - 1))
                try:
                    dataset_num = int(dataset_num)
                except ValueError:
                    print('Enter a number between 0 and {}'.format(
                        len(folders) - 1))
                else:
                    if dataset_num not in range(0, len(folders)):
                        print('Enter a number between 0 and {}'.format(
                            len(folders) - 1))
                    else:
                        ds_name = folders[dataset_num]
                        break

        ds_name = ds_name.lower()

        if data_frequency is None:
            folder = get_data_source_folder(ds_name)

        else:
            folder = get_bundle_folder(ds_name, data_frequency)

        shutil.rmtree(folder)
Esempio n. 3
0
    def __init__(self):
        global Web3
        try:
            from web3 import Web3, HTTPProvider
        except ImportError:
            raise MarketplaceRequiresPython3()

        self.addresses = get_user_pubaddr()
        if not self.addresses[0]['accepted_terms']:
            terms_and_conditions_url = urllib.urlopen(TERMS_AND_CONDITIONS)
            terms_and_conditions = terms_and_conditions_url.read()\
                .decode(terms_and_conditions_url.info().get_content_charset())
            print(terms_and_conditions)
            while True:
                accepted_terms = input('Do you accept these terms and '
                                       'conditions? [y, n] ').lower().strip()
                if accepted_terms == 'y':
                    for address in self.addresses:
                        address['accepted_terms'] = True
                    save_user_pubaddr(self.addresses)
                    print()
                    break

        if self.addresses[0]['pubAddr'] == '':
            print('We need to populate a file located at {} to be used for '
                  'future marketplace requests. \n'
                  'You shouldn\'t need to interact with this file from here '
                  'on out, but if you need to, you can go '
                  'ahead and edit this file directly.'
                  .format(os.path.join(get_marketplace_folder(),
                                       'addresses.json')))
            while True:
                pub_addr = input('What is your Ethereum public address? ')\
                    .strip()
                if pub_addr:
                    break
            desc = input('What is a description for this address (optional, '
                         'but helpful to distinguish between '
                         'multiple accounts you may be using)? ')
            while True:
                wallet = input('What wallet type are you using (strongly '
                               'recommend metamask)? [metamask, ledger, '
                               'bitbox, keystore, key] ')
                if wallet in ['metamask', 'ledger', 'bitbox', 'keystore',
                              'key']:
                    break
            self.addresses[0].update({'pubAddr': pub_addr,
                                      'desc': desc, 'wallet': wallet})
            save_user_pubaddr(self.addresses)
            print()

        self.default_account = self.addresses[0]['pubAddr']

        self.web3 = Web3(HTTPProvider(ETH_REMOTE_NODE))

        contract_url = urllib.urlopen(MARKETPLACE_CONTRACT)

        self.mkt_contract_address = Web3.toChecksumAddress(
            contract_url.readline().decode(
                contract_url.info().get_content_charset()).strip())

        abi_url = urllib.urlopen(MARKETPLACE_CONTRACT_ABI)
        abi_url = abi_url.read().decode(
            abi_url.info().get_content_charset())

        abi = json.loads(abi_url)

        self.mkt_contract = self.web3.eth.contract(
            self.mkt_contract_address,
            abi=abi,
        )

        contract_url = urllib.urlopen(ENIGMA_CONTRACT)

        self.eng_contract_address = Web3.toChecksumAddress(
            contract_url.readline().decode(
                contract_url.info().get_content_charset()).strip())

        abi_url = urllib.urlopen(ENIGMA_CONTRACT_ABI)
        abi_url = abi_url.read().decode(
            abi_url.info().get_content_charset())

        abi = json.loads(abi_url)

        self.eng_contract = self.web3.eth.contract(
            self.eng_contract_address,
            abi=abi,
        )