· 8 years ago · Jan 16, 2018, 03:24 AM
1"files": [
2 {
3 "path": "/src/SimpleWallet/SimpleWallet.cpp",
4 "changes": [
5 {
6 "action": "replace",
7 "marker": "std::cout << \"Nor 'generate-new-wallet' neither 'wallet-file' argument was specified.\\nWhat do you want to do?\\n[O]pen existing wallet, [G]enerate new wallet file or [E]xit.\\n\";",
8 "parameters": {
9 "text": [
10 " std::cout << \"Nor 'generate-new-wallet' neither 'wallet-file' argument was specified.\\nWhat do you want to do?\\n[O]pen existing wallet, [G]enerate new wallet file, [I]mport wallet or [E]xit.\\n\";"
11 ]
12 }
13 },
14
15
16 {
17 "action": "replace",
18 "marker": "std::cout << \"Nor 'generate-new-wallet' neither 'wallet-file' argument was specified.\\nWhat do you want to do?\\n[O]pen existing wallet, [G]enerate new wallet file or [E]xit.\\n\";",
19 "parameters": {
20 "text": [
21 " std::cout << \"Nor 'generate-new-wallet' neither 'wallet-file' argument was specified.\\nWhat do you want to do?\\n[O]pen existing wallet, [G]enerate new wallet file, [I]mport wallet or [E]xit.\\n\";"
22 ]
23 }
24 },
25 {
26 "action": "replace",
27 "marker": "if (!(c == 'O' || c == 'G' || c == 'E' || c == 'o' || c == 'g' || c == 'e')) {",
28 "parameters": {
29 "text": [
30 " if (!(c == 'O' || c == 'G' || c == 'E' || c == 'I' || c == 'o' || c == 'g' || c == 'e' || c == 'i')) {"
31 ]
32 }
33 },
34 {
35 "action": "replace",
36 "marker": "if (c == 'g' || c == 'G') {",
37 "parameters": {
38 "text": [
39 " if (c == 'i' || c == 'I') {",
40 " m_import_new = userInput;",
41 " } else if (c == 'g' || c == 'G') {"
42 ]
43 }
44 },
45 {
46 "action": "replace",
47 "marker": "if (!m_generate_new.empty() && !m_wallet_file_arg.empty()) {",
48 "parameters": {
49 "text": [
50 " if (!m_generate_new.empty() && !m_wallet_file_arg.empty() && !m_import_new.empty()) {"
51 ]
52 }
53 },
54 {
55 "action": "add_above",
56 "marker": "bool simple_wallet::close_wallet()",
57 "parameters": {
58 "text": [
59 "bool simple_wallet::new_wallet(Crypto::SecretKey &secret_key, Crypto::SecretKey &view_key, const std::string &wallet_file, const std::string& password) {",
60 " m_wallet_file = wallet_file;",
61 "",
62 " m_wallet.reset(new WalletLegacy(m_currency, *m_node.get()));",
63 " m_node->addObserver(static_cast<INodeObserver*>(this));",
64 " m_wallet->addObserver(this);",
65 " try {",
66 " m_initResultPromise.reset(new std::promise<std::error_code>());",
67 " std::future<std::error_code> f_initError = m_initResultPromise->get_future();",
68 "",
69 " AccountKeys wallet_keys;",
70 " wallet_keys.spendSecretKey = secret_key;",
71 " wallet_keys.viewSecretKey = view_key;",
72 " Crypto::secret_key_to_public_key(wallet_keys.spendSecretKey, wallet_keys.address.spendPublicKey);",
73 " Crypto::secret_key_to_public_key(wallet_keys.viewSecretKey, wallet_keys.address.viewPublicKey);",
74 "",
75 " m_wallet->initWithKeys(wallet_keys, password);",
76 " auto initError = f_initError.get();",
77 " m_initResultPromise.reset(nullptr);",
78 " if (initError) {",
79 " fail_msg_writer() << \"failed to generate new wallet: \" << initError.message();",
80 " return false;",
81 " }",
82 "",
83 " try {",
84 " CryptoNote::WalletHelper::storeWallet(*m_wallet, m_wallet_file);",
85 " } catch (std::exception& e) {",
86 " fail_msg_writer() << \"failed to save new wallet: \" << e.what();",
87 " throw;",
88 " }",
89 "",
90 " AccountKeys keys;",
91 " m_wallet->getAccountKeys(keys);",
92 "",
93 " logger(INFO, BRIGHT_WHITE) <<",
94 " \"Imported wallet: \" << m_wallet->getAddress() << std::endl;",
95 " }",
96 " catch (const std::exception& e) {",
97 " fail_msg_writer() << \"failed to import wallet: \" << e.what();",
98 " return false;",
99 " }",
100 "",
101 " success_msg_writer() <<",
102 " \"**********************************************************************\\n\" <<",
103 " \"Your wallet has been imported.\\n\" <<",
104 " \"Use \\\"help\\\" command to see the list of available commands.\\n\" <<",
105 " \"Always use \\\"exit\\\" command when closing simplewallet to save\\n\" <<",
106 " \"current session's state. Otherwise, you will possibly need to synchronize \\n\" <<",
107 " \"your wallet again. Your wallet key is NOT under risk anyway.\\n\" <<",
108 " \"**********************************************************************\";",
109 " return true;",
110 "}",
111 "//----------------------------------------------------------------------------------------------------"
112 ]
113 }
114 }
115 ]
116 },
117 {
118 "path": "/src/SimpleWallet/SimpleWallet.cpp",
119 "multiline": true,
120 "changes": [
121 {
122 "action": "replace",
123 "marker": "if \\(!m_generate_new.empty\\(\\)\\) {\\s+std::string ignoredString;[^}]+}",
124 "parameters": {
125 "text": [
126 " if (!m_generate_new.empty() || !m_import_new.empty()) {",
127 " std::string ignoredString;",
128 " if (!m_generate_new.empty()) {",
129 " WalletHelper::prepareFileNames(m_generate_new, ignoredString, walletFileName);",
130 " } else if (!m_import_new.empty()) {",
131 " WalletHelper::prepareFileNames(m_import_new, ignoredString, walletFileName);",
132 " }",
133 " boost::system::error_code ignore;",
134 " if (boost::filesystem::exists(walletFileName, ignore)) {",
135 " fail_msg_writer() << walletFileName << \" already exists\";",
136 " return false;",
137 " }"
138 ]
139 }
140 },
141 {
142 "action": "replace",
143 "marker": "} else {\\s+m_wallet\\.reset\\(new WalletLegacy\\(m_currency, \\*m_node\\)\\);",
144 "parameters": {
145 "text": [
146 "} else if (!m_import_new.empty()) {",
147 " std::string walletAddressFile = prepareWalletAddressFilename(m_import_new);",
148 " boost::system::error_code ignore;",
149 " if (boost::filesystem::exists(walletAddressFile, ignore)) {",
150 " logger(ERROR, BRIGHT_RED) << \"Address file already exists: \" + walletAddressFile;",
151 " return false;",
152 " }",
153 "",
154 " std::string private_spend_key_string;",
155 " std::string private_view_key_string;",
156 " do {",
157 " std::cout << \"Private Spend Key: \";",
158 " std::getline(std::cin, private_spend_key_string);",
159 " boost::algorithm::trim(private_spend_key_string);",
160 " } while (private_spend_key_string.empty());",
161 " do {",
162 " std::cout << \"Private View Key: \";",
163 " std::getline(std::cin, private_view_key_string);",
164 " boost::algorithm::trim(private_view_key_string);",
165 " } while (private_view_key_string.empty());",
166 "",
167 " Crypto::Hash private_spend_key_hash;",
168 " Crypto::Hash private_view_key_hash;",
169 " size_t size;",
170 " if (!Common::fromHex(private_spend_key_string, &private_spend_key_hash, sizeof(private_spend_key_hash), size) || size != sizeof(private_spend_key_hash)) {",
171 " return false;",
172 " }",
173 " if (!Common::fromHex(private_view_key_string, &private_view_key_hash, sizeof(private_view_key_hash), size) || size != sizeof(private_spend_key_hash)) {",
174 " return false;",
175 " }",
176 " Crypto::SecretKey private_spend_key = *(struct Crypto::SecretKey *) &private_spend_key_hash;",
177 " Crypto::SecretKey private_view_key = *(struct Crypto::SecretKey *) &private_view_key_hash;",
178 "",
179 " if (!new_wallet(private_spend_key, private_view_key, walletFileName, pwd_container.password())) {",
180 " logger(ERROR, BRIGHT_RED) << \"account creation failed\";",
181 " return false;",
182 " }",
183 "",
184 " if (!writeAddressFile(walletAddressFile, m_wallet->getAddress())) {",
185 " logger(WARNING, BRIGHT_RED) << \"Couldn't write wallet address file: \" + walletAddressFile;",
186 " }",
187 " } else {",
188 " m_wallet.reset(new WalletLegacy(m_currency, *m_node));",
189 ""
190 ]
191 }
192 }
193 ]
194 },
195 {
196 "path": "/src/SimpleWallet/SimpleWallet.h",
197 "changes": [
198 {
199 "action": "add_below",
200 "marker": "bool new_wallet(const std::string &wallet_file, const std::string& password);",
201 "parameters": {
202 "text": [
203 "bool new_wallet(Crypto::SecretKey &secret_key, Crypto::SecretKey &view_key, const std::string &wallet_file, const std::string& password);"
204 ]
205 }
206 },
207 {
208 "action": "add_below",
209 "marker": "std::string m_generate_new;",
210 "parameters": {
211 "text": [
212 "std::string m_import_new;"
213 ]
214 }
215 }
216 ]
217 }
218 ]
219}