~codeforger/bitcoin-app/wallet_migration

« back to all changes in this revision

Viewing changes to java_files.py

  • Committer: Michael Rochester
  • Date: 2015-09-18 14:20:34 UTC
  • Revision ID: m.rochester93@googlemail.com-20150918142034-b3u3iaggnkixdowo
Added support for importing testnet data from java data files.

Integrated importing testnet address book.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from pycoin.key import BIP32Node, Key
7
7
from pycoin import encoding
8
8
 
9
 
def find_file(extension):
10
 
    path = os.path.expanduser("~/.local/share/org.sambull.bitcoin-app/ubc." +
11
 
                              extension)
 
9
def find_file(extension, test_net=False):
 
10
    prefix = "~/.local/share/org.sambull.bitcoin-app/ubc."
 
11
    if test_net:
 
12
        prefix = "~/.local/share/org.sambull.bitcoin-app-testnet/ubc."
 
13
 
 
14
    path = os.path.expanduser(prefix + extension)
 
15
 
12
16
    if os.path.isfile(path):
13
17
        return path
14
18
    else:
20
24
        wallet.ParseFromString(wallet_file.read())
21
25
    return wallet
22
26
 
23
 
def java_wallet_exists():
24
 
    return not find_file("wallet") == None
 
27
def java_wallet_exists(test_net=False):
 
28
    return not find_file("wallet", test_net) == None
25
29
 
26
 
def import_java_wallet():
 
30
def import_java_wallet(test_net=False):
27
31
    keys = []
28
 
    path = find_file("wallet")
 
32
    path = find_file("wallet", test_net)
29
33
    if path:
30
34
        wallet = open_wallet(path)
31
35
        for key in wallet.key:
34
38
            chaincode = hmac.HMAC(key=b"Bitcoin seed", msg=key.secret_bytes,
35
39
                                  digestmod=hashlib.sha512).digest()[32:]
36
40
 
37
 
            keys.append(BIP32Node.BIP32Node("BTC", chaincode,
 
41
            net_code = "XTN" if test_net else "BTC"
 
42
 
 
43
            keys.append(BIP32Node.BIP32Node(net_code, chaincode,
38
44
                                            secret_exponent=secret))
39
45
    return keys
40
46
 
41
 
def java_chain_exists():
42
 
    return not find_file("blockchain") == None
 
47
def java_chain_exists(test_net=False):
 
48
    return not find_file("blockchain", test_net) == None
43
49
 
44
 
def remove_java_chain():
45
 
    chain_path = find_file("blockchain")
 
50
def remove_java_chain(test_net=False):
 
51
    chain_path = find_file("blockchain", test_net)
46
52
    os.remove(chain_path)
47
53
 
48
 
def java_address_book_exists():
49
 
    return not find_file("addesses") == None
 
54
def java_address_book_exists(test_net=False):
 
55
    return not find_file("addesses", test_net) == None
50
56
 
51
 
def import_java_address_book():
 
57
def import_java_address_book(test_net=False):
52
58
    addressbook = []
53
59
    in_address_book = []
54
 
    path = find_file("addesses")
 
60
    path = find_file("addesses", test_net)
55
61
    if path:
56
62
        with open(path) as book_file:
57
63
            while True:
64
70
                line2 = book_file.readline().strip()
65
71
                addressbook.append((line, line2))
66
72
 
67
 
def remove_java_address_book():
68
 
    addresses_path = find_file("addesses")
 
73
def remove_java_address_book(test_net=False):
 
74
    addresses_path = find_file("addesses", test_net)
69
75
    os.remove(addresses_path)
 
 
b'\\ No newline at end of file'