| 44 | } |
| 45 | |
| 46 | bool AccountManager::execute(int argc, char** argv) |
| 47 | { |
| 48 | if (string(argv[1]) == "wallet") |
| 49 | { |
| 50 | if (3 < argc && string(argv[2]) == "import") |
| 51 | { |
| 52 | if (!openWallet()) |
| 53 | return false; |
| 54 | string file = argv[3]; |
| 55 | string name = "presale wallet"; |
| 56 | string pw; |
| 57 | try |
| 58 | { |
| 59 | KeyPair k = m_keyManager->presaleSecret( |
| 60 | contentsString(file), |
| 61 | [&](bool){ return (pw = getPassword("Enter the passphrase for the presale key: "));} |
| 62 | ); |
| 63 | m_keyManager->import(k.secret(), name, pw, "Same passphrase as used for presale key"); |
| 64 | cout << " Address: {" << k.address().hex() << "}" << endl; |
| 65 | } |
| 66 | catch (Exception const& _e) |
| 67 | { |
| 68 | if (auto err = boost::get_error_info<errinfo_comment>(_e)) |
| 69 | cout << " Decryption failed: " << *err << endl; |
| 70 | else |
| 71 | cout << " Decryption failed: Unknown reason." << endl; |
| 72 | return false; |
| 73 | } |
| 74 | } |
| 75 | else |
| 76 | streamWalletHelp(cout); |
| 77 | return true; |
| 78 | } |
| 79 | else if (string(argv[1]) == "account") |
| 80 | { |
| 81 | if (argc < 3 || string(argv[2]) == "list") |
| 82 | { |
| 83 | openWallet(); |
| 84 | if (m_keyManager->store().keys().empty()) |
| 85 | cout << "No keys found." << endl; |
| 86 | else |
| 87 | { |
| 88 | vector<u128> bare; |
| 89 | AddressHash got; |
| 90 | int k = 0; |
| 91 | for (auto const& u: m_keyManager->store().keys()) |
| 92 | { |
| 93 | if (Address a = m_keyManager->address(u)) |
| 94 | { |
| 95 | got.insert(a); |
| 96 | cout << "Account #" << k << ": {" << a.hex() << "}" << endl; |
| 97 | k++; |
| 98 | } |
| 99 | else |
| 100 | bare.push_back(u); |
| 101 | } |
| 102 | for (auto const& a: m_keyManager->accounts()) |
| 103 | if (!got.count(a)) |