def test_load_jsons():
    import helpers
    mydict = helpers.load_jsons("./tests/helpers_testdata")
    assert mydict["some_jsonfile"]["blub"] == "bla"
    assert mydict["some_other_jsonfile"]["bla"] == "blub"
    mydict = helpers.load_jsons("./tests/helpers_testdata", 'id')
    assert "some_jsonfile" not in mydict
    # instead the value for the key "id" is now used as the top-level key
    assert mydict["ID123"]['blub'] == "bla"
    # This also assumes that the key is unique!!!!
    assert mydict["ID124"]['bla'] == "blub"
    # ToDo: check the uniqueness in the implementation to avoid issues
    # the filename is added as alias
    assert mydict["ID123"]['alias'] == "some_jsonfile"
    # We also get the fullpath of that file:
    assert mydict["ID123"][
        'fullpath'] == "./tests/helpers_testdata/some_jsonfile.json"
示例#2
0
 def update(self, data_folder=None):
     if data_folder is not None:
         self.data_folder = data_folder
         if data_folder.startswith("~"):
             data_folder = os.path.expanduser(data_folder)
         # creating folders if they don't exist
         if not os.path.isdir(data_folder):
             os.mkdir(data_folder)
     self._devices = load_jsons(self.data_folder, key="name")
示例#3
0
def fetch_wallet_addresses_for_mining(data_folder=None):
    ''' parses all the wallet-jsons in the folder (default ~/.specter/wallets/regtest)
        and returns an array with the addresses 
    '''
    if data_folder == None:
        data_folder = os.path.expanduser(DATA_FOLDER)
    wallets = load_jsons(data_folder + "/wallets/regtest")
    address_array = [value['address'] for key, value in wallets.items()]
    # remove duplicates
    address_array = list(dict.fromkeys(address_array))
    return address_array
示例#4
0
 def update(self, data_folder=None, cli=None, chain=None):
     if chain is not None:
         self.chain = chain
     if data_folder is not None:
         self.data_folder = data_folder
         if data_folder.startswith("~"):
             data_folder = os.path.expanduser(data_folder)
         # creating folders if they don't exist
         if not os.path.isdir(data_folder):
             os.mkdir(data_folder)
     self.working_folder = None
     if self.chain is not None and self.data_folder is not None:
         self.working_folder = os.path.join(self.data_folder, self.chain)
     if self.working_folder is not None and not os.path.isdir(
             self.working_folder):
         os.mkdir(self.working_folder)
     if cli is not None:
         self.cli = cli
     if self.working_folder is not None:
         self._wallets = load_jsons(self.working_folder, key="name")
     else:
         self._wallets = {}