Example #1
0
def remove_contact(index):
    contacts = db_get('contacts')
    temp_contact = copy.deepcopy(contacts[index])
    del contacts[index]

    file_name = db_get('default_wallet')
    key = db_get('default_wallet_key')
    AESCipher.decrypt_file(key, file_name, file_name + '.dec')

    with open(file_name + '.dec') as data_file:
        my_read = data_file.read()
        data_file.close()
        os.remove(file_name + '.dec')

        try:
            data = json.loads(my_read)
        except:
            return 'Could not add contact\n'
        if 'seed' in data.keys():
            data['contacts'] = contacts
        else:
            return 'Could not add contact\n'

        data_file = open(db_get('default_wallet'), 'w')
        data_file.write(json.dumps(data))
        data_file.close()
        AESCipher.encrypt_into(key, file_name)

    db_put('contacts', contacts)
    return 'Removed contact \nName: ' + temp_contact[0] + '\nAddress: ' + temp_contact[1]
Example #2
0
def add_contact(contact):
    if not valid_address(contact[1]):
        return 'Address is not valid\n'

    contacts = db_get('contacts')
    contact_json = {'name': contact[0], 'address': contact[1]}
    contacts.append(contact_json)

    file_name = db_get('default_wallet')
    key = db_get('default_wallet_key')
    AESCipher.decrypt_file(key, file_name, file_name + '.dec')

    with open(file_name + '.dec') as data_file:
        my_read = data_file.read()
        data_file.close()
        os.remove(file_name + '.dec')

        try:
            data = json.loads(my_read)
        except:
            return 'Could not add contact\n'
        if 'seed' in data.keys():
            data['contacts'] = contacts
        else:
            return 'Could not add contact\n'

        data_file = open(db_get('default_wallet'), 'w')
        data_file.write(json.dumps(data))
        data_file.close()
        AESCipher.encrypt_into(key, file_name)

    db_put('contacts', contacts)
    return 'Added contact \nName: ' + contact[0] + '\nAddress: ' + contact[1]
Example #3
0
def create_new_wallet(wallet_name, key, seed=None, contacts=[]):
    if seed == None:
        seed = generate_seed()

    print ":".join("{:02x}".format(ord(c)) for c in key)

    data = {}
    data['seed'] = seed
    data['contacts'] = contacts

    if not os.path.exists(custom.wallets_dir):
        os.makedirs(custom.wallets_dir)

    wallet_name = os.path.join(custom.wallets_dir, str(wallet_name))
    f = open(wallet_name, 'w')
    f.write(json.dumps(data))
    f.close()
    AESCipher.encrypt_into(key, wallet_name)
    return wallet_name