diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index 9708b82fe..9af4c671f 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -83,7 +83,8 @@ HEADERS += src/qt/bitcoingui.h \ src/bitcoinrpc.h \ src/qt/overviewpage.h \ src/qt/csvmodelwriter.h \ - src/qt/qtwin.h + src/qt/qtwin.h \ + src/crypter.h SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \ src/qt/transactiontablemodel.cpp \ src/qt/addresstablemodel.cpp \ @@ -122,7 +123,8 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \ src/bitcoinrpc.cpp \ src/qt/overviewpage.cpp \ src/qt/csvmodelwriter.cpp \ - src/qt/qtwin.cpp + src/qt/qtwin.cpp \ + src/crypter.cpp RESOURCES += \ src/qt/bitcoin.qrc diff --git a/contrib/Bitcoin.app/Contents/Info.plist b/contrib/Bitcoin.app/Contents/Info.plist index 9a2eccc28..bfeb2f8de 100644 --- a/contrib/Bitcoin.app/Contents/Info.plist +++ b/contrib/Bitcoin.app/Contents/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.3.24 + 0.3.25 CFBundleSignature ???? CFBundleVersion - 324 + 325 LSMinimumSystemVersion 10.5 CFBundleIconFile diff --git a/doc/README b/doc/README index a4df4c227..f72bca01f 100644 --- a/doc/README +++ b/doc/README @@ -1,4 +1,4 @@ -Bitcoin 0.3.24 BETA +Bitcoin 0.3.25 BETA Copyright (c) 2009-2011 Bitcoin Developers Distributed under the MIT/X11 software license, see the accompanying @@ -24,6 +24,49 @@ Unpack the files into a directory and run: bin/64/bitcoin (GUI, 64-bit) bin/64/bitcoind (headless, 64-bit) + +Wallet Encryption +----------------- +Bitcoin supports native wallet encryption so that people who steal your +wallet file don't automatically get access to all of your Bitcoins. +In order to enable this feature, chose "Encrypt Wallet" from the +Options menu. You will be prompted to enter a passphrase, which +will be used as the key to encrypt your wallet and will be needed +every time you wish to send Bitcoins. If you lose this passphrase, +you will lose access to spend all of the bitcoins in your wallet, +no one, not even the Bitcoin developers can recover your Bitcoins. +This means you are responsible for your own security, store your +password in a secure location and do not forget it. + +Remember that the encryption built into bitcoin only encrypts the +actual keys which are required to send your bitcoins, not the full +wallet. This means that someone who steals your wallet file will +be able to see all the addresses which belong to you, as well as the +relevant transactions, you are only protected from someone spending +your coins. + +It is recommended that you backup your wallet file before you +encrypt your wallet. To do this, close the Bitcoin client and +copy the wallet.dat file from ~/.bitcoin/ on Linux, /Users/(user +name)/Application Support/Bitcoin/ on Mac OSX, and %APPDATA%/Bitcoin/ +on Windows (that is /Users/(user name)/AppData/Roaming/Bitcoin on +Windows Vista and 7 and /Documents and Settings/(user name)/Application +Data/Bitcoin on Windows XP). Once you have copied that file to a +safe location, reopen the Bitcoin client and Encrypt your wallet. +If everything goes fine, delete the backup and enjoy your encrypted +wallet. Note that once you encrypt your wallet, you will never be +able to go back to a version of the Bitcoin client older than 0.4. + +Keep in mind that you are always responsible for you own security. +All it takes is a slightly more advanced wallet-stealing trojan which +installs a keylogger to steal your wallet passphrase as you enter it +in addition to your wallet file and you have lost all your Bitcoins. +Wallet encryption cannot keep you safe if you do not practice +good security, such as running up-to-date antivirus software, only +entering your wallet passphrase in the Bitcoin client and using the +same passphrase only as your wallet passphrase. + + See the documentation at the bitcoin wiki: https://en.bitcoin.it/wiki/Main_Page diff --git a/doc/README_windows.txt b/doc/README_windows.txt index a19dcc9e9..e715b3206 100644 --- a/doc/README_windows.txt +++ b/doc/README_windows.txt @@ -1,4 +1,4 @@ -Bitcoin 0.3.24 BETA +Bitcoin 0.3.25 BETA Copyright (c) 2009-2011 Bitcoin Developers Distributed under the MIT/X11 software license, see the accompanying diff --git a/locale/pl/LC_MESSAGES/bitcoin.po b/locale/pl/LC_MESSAGES/bitcoin.po index ef6be0d9d..7c177b82d 100644 --- a/locale/pl/LC_MESSAGES/bitcoin.po +++ b/locale/pl/LC_MESSAGES/bitcoin.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: Bitcoin\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-06-28 20:11+0100\n" +"POT-Creation-Date: 2011-07-14 18:55+0100\n" "PO-Revision-Date: \n" "Last-Translator: Dawid Spiechowicz \n" "Language-Team: Spiechu \n" @@ -18,7 +18,7 @@ msgstr "" "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n" "X-Poedit-SearchPath-0: ../../..\n" -#: ../../../src/net.cpp:1590 +#: ../../../src/net.cpp:1615 #, c-format msgid "Unable to bind to port %d on this computer. Bitcoin is probably already running." msgstr "Nie można powiązać z portem %d tego komputera. Prawdopodobnie program Bitcoin jest już uruchomiony." @@ -188,29 +188,37 @@ msgstr "Błąd ładowania addr.dat \n" msgid "Error loading blkindex.dat \n" msgstr "Błąd ładowania blkindex.dat \n" -#: ../../../src/init.cpp:391 +#: ../../../src/init.cpp:394 +msgid "Error loading wallet.dat: Wallet corrupted \n" +msgstr "Błąd ładowania wallet.dat: Portfel uszkodzony \n" + +#: ../../../src/init.cpp:396 +msgid "Error loading wallet.dat: Wallet requires newer version of Bitcoin \n" +msgstr "Błąd ładowania wallet.dat: Portfel wymaga nowszej wersji Bitcoin \n" + +#: ../../../src/init.cpp:398 msgid "Error loading wallet.dat \n" msgstr "Błąd ładowania wallet.dat \n" -#: ../../../src/init.cpp:481 +#: ../../../src/init.cpp:488 msgid "Invalid -proxy address" msgstr "Niewłaściwy adres -proxy" -#: ../../../src/init.cpp:504 +#: ../../../src/init.cpp:513 msgid "Invalid amount for -paytxfee=" msgstr "Nieprawidłowa kwota w -paytxfee=" -#: ../../../src/init.cpp:508 +#: ../../../src/init.cpp:517 msgid "Warning: -paytxfee is set very high. This is the transaction fee you will pay if you send a transaction." msgstr "Ostrzeżenie: ustawienie -paytxfee jest bardzo wysokie. To jest prowizja transakcji, którą zapłacisz jeżeli wyślesz transakcję." -#: ../../../src/rpc.cpp:1822 -#: ../../../src/rpc.cpp:1824 +#: ../../../src/rpc.cpp:2100 +#: ../../../src/rpc.cpp:2102 #, c-format msgid "To use the %s option" msgstr "Użycie opcji %s" -#: ../../../src/rpc.cpp:1826 +#: ../../../src/rpc.cpp:2104 #, c-format msgid "" "Warning: %s, you must set rpcpassword=\n" @@ -221,7 +229,7 @@ msgstr "" "w pliku konfiguracyjnym: %s\n" "Jeżeli plik nie istnieje, utwórz go z uprawnieniami tylko do odczytu dla właściciela.\n" -#: ../../../src/rpc.cpp:1994 +#: ../../../src/rpc.cpp:2277 #, c-format msgid "" "You must set rpcpassword= in the configuration file:\n" @@ -232,11 +240,11 @@ msgstr "" "%s\n" "Jeżeli plik nie istnieje, utwórz go z uprawnieniami tylko do odczytu dla właściciela." -#: ../../../src/util.cpp:874 +#: ../../../src/util.cpp:869 msgid "Warning: Please check that your computer's date and time are correct. If your clock is wrong Bitcoin will not work properly." msgstr "Ostrzeżenie: Sprawdź czy ustawienia daty i czasu komputera są prawidłowe. Jeżeli zegar jest źle ustawiony, Bitcoin nie będzie poprawnie działał." -#: ../../../src/util.cpp:908 +#: ../../../src/util.cpp:903 msgid "beta" msgstr "beta" @@ -245,104 +253,190 @@ msgstr "beta" msgid "This transaction is over the size limit. You can still send it for a fee of %s, which goes to the nodes that process your transaction and helps to support the network. Do you want to pay the fee?" msgstr "Ta transakcja jest poza limitem wielkości. W dalszym ciągu możesz wysłać ją z prowizją %s, która dotrze do węzłów przetwarzających twoją transakcję i pomoże utrzymać sieć. Chcesz zapłacić prowizję?" -#: ../../../src/ui.cpp:316 +#: ../../../src/ui.cpp:259 +#: ../../../src/ui.cpp:1246 +msgid "Enter the current passphrase to the wallet." +msgstr "Wpisz obecne hasło do portfela." + +#: ../../../src/ui.cpp:260 +#: ../../../src/ui.cpp:1182 +#: ../../../src/ui.cpp:1199 +#: ../../../src/ui.cpp:1247 +#: ../../../src/ui.cpp:1273 +#: ../../../src/ui.cpp:1293 +msgid "Passphrase" +msgstr "Hasło" + +#: ../../../src/ui.cpp:266 +msgid "Please supply the current wallet decryption passphrase." +msgstr "Proszę dostarczyć hasło do odszyfrowania portfela." + +#: ../../../src/ui.cpp:274 +#: ../../../src/ui.cpp:1258 +#: ../../../src/ui.cpp:1315 +msgid "The passphrase entered for the wallet decryption was incorrect." +msgstr "Wpisane hasło do odszyfrowania portfela jest nieprawidłowe." + +#: ../../../src/ui.cpp:351 msgid "Status" msgstr "Status" -#: ../../../src/ui.cpp:317 +#: ../../../src/ui.cpp:352 msgid "Date" msgstr "Data" -#: ../../../src/ui.cpp:318 +#: ../../../src/ui.cpp:353 msgid "Description" msgstr "Opis" -#: ../../../src/ui.cpp:319 +#: ../../../src/ui.cpp:354 msgid "Debit" msgstr "Obciążenie" -#: ../../../src/ui.cpp:320 +#: ../../../src/ui.cpp:355 msgid "Credit" msgstr "Suma" -#: ../../../src/ui.cpp:526 +#: ../../../src/ui.cpp:566 #, c-format msgid "Open for %d blocks" msgstr "Otwórz na %d bloków" -#: ../../../src/ui.cpp:528 +#: ../../../src/ui.cpp:568 #, c-format msgid "Open until %s" msgstr "Otwarte dopóki %s" -#: ../../../src/ui.cpp:534 +#: ../../../src/ui.cpp:574 #, c-format msgid "%d/offline?" msgstr "%d/offline?" -#: ../../../src/ui.cpp:536 +#: ../../../src/ui.cpp:576 #, c-format msgid "%d/unconfirmed" msgstr "%d/niepotwierdzono" -#: ../../../src/ui.cpp:538 +#: ../../../src/ui.cpp:578 #, c-format msgid "%d confirmations" msgstr "%d potwierdzeń" -#: ../../../src/ui.cpp:623 +#: ../../../src/ui.cpp:663 msgid "Generated" msgstr "Wygenerowano" -#: ../../../src/ui.cpp:631 +#: ../../../src/ui.cpp:671 #, c-format msgid "Generated (%s matures in %d more blocks)" msgstr "Wygenerowano (%s dojrzałych w %d więcej bloków)" -#: ../../../src/ui.cpp:635 +#: ../../../src/ui.cpp:675 msgid "Generated - Warning: This block was not received by any other nodes and will probably not be accepted!" msgstr "Wygenerowano - Ostrzeżenie: Ten blok nie został otrzymany przez żaden inny węzeł i prawdopodobnie nie zostanie zaakceptowany!" -#: ../../../src/ui.cpp:639 +#: ../../../src/ui.cpp:679 msgid "Generated (not accepted)" msgstr "Wygenerowano (nie zaakceptowano)" -#: ../../../src/ui.cpp:649 +#: ../../../src/ui.cpp:689 msgid "From: " msgstr "Od:" -#: ../../../src/ui.cpp:673 +#: ../../../src/ui.cpp:713 msgid "Received with: " msgstr "Otrzymano z:" -#: ../../../src/ui.cpp:719 +#: ../../../src/ui.cpp:759 msgid "Payment to yourself" msgstr "Płatność dla siebie samego" -#: ../../../src/ui.cpp:753 +#: ../../../src/ui.cpp:793 msgid "To: " msgstr "Do:" -#: ../../../src/ui.cpp:1068 +#: ../../../src/ui.cpp:1108 msgid " Generating" msgstr " Generowanie" -#: ../../../src/ui.cpp:1070 +#: ../../../src/ui.cpp:1110 msgid "(not connected)" msgstr "(nie połączony)" -#: ../../../src/ui.cpp:1073 +#: ../../../src/ui.cpp:1113 #, c-format msgid " %d connections %d blocks %d transactions" msgstr " %d połączeń %d bloków %d transakcji" -#: ../../../src/ui.cpp:1178 -#: ../../../src/ui.cpp:2571 +#: ../../../src/ui.cpp:1170 +msgid "Wallet already encrypted." +msgstr "Portfel już zaszyfrowany." + +#: ../../../src/ui.cpp:1181 +msgid "" +"Enter the new passphrase to the wallet.\n" +"Please use a passphrase of 10 or more random characters, or eight or more words." +msgstr "" +"Wpisz nowe hasło dla portfela.\n" +"Proszę użyć hasła składającego się z 10 lub więcej losowych znaków albo ośmiu lub więcej słów." + +#: ../../../src/ui.cpp:1188 +#: ../../../src/ui.cpp:1281 +msgid "Error: The supplied passphrase was too short." +msgstr "Błąd: Dostarczone hasło jest za krótkie." + +#: ../../../src/ui.cpp:1192 +msgid "" +"WARNING: If you encrypt your wallet and lose your passphrase, you will LOSE ALL OF YOUR BITCOINS!\n" +"Are you sure you wish to encrypt your wallet?" +msgstr "" +"OSTRZEŻENIE: Jeżeli zaszyfrujesz swój portfel i zgubisz hasło, STRACISZ WSZYSTKIE SWOJE BITCOINY!\n" +"Czy jesteś pewny, że chcesz zaszyfrować swój portfel?" + +#: ../../../src/ui.cpp:1198 +msgid "Please re-enter your new wallet passphrase." +msgstr "Proszę powtórzyć nowe hasło do portfela." + +#: ../../../src/ui.cpp:1207 +#: ../../../src/ui.cpp:1303 +msgid "Error: the supplied passphrases didn't match." +msgstr "Błąd: dostarczone hasła się nie zgadzają." + +#: ../../../src/ui.cpp:1217 +msgid "Wallet encryption failed." +msgstr "Szyfrowanie portfela nie powiodło się." + +#: ../../../src/ui.cpp:1224 +msgid "" +"Wallet Encrypted.\n" +"Remember that encrypting your wallet cannot fully protect your bitcoins from being stolen by malware infecting your computer." +msgstr "" +"Portfel zaszyfrowany.\n" +"Pamiętaj, że zaszyfrowanie portfela nie chroni w pełni twoich bitcoinów przed kradzieżą przeprowadzoną przez złośliwe oprogramowanie infekujące twój komputer." + +#: ../../../src/ui.cpp:1235 +msgid "Wallet is unencrypted, please encrypt it first." +msgstr "Portfel jest niezaszyfrowany, proszę najpierw zaszyfrować." + +#: ../../../src/ui.cpp:1272 +msgid "Enter the new passphrase for the wallet." +msgstr "Wprowadź nowe hasło dla portfela." + +#: ../../../src/ui.cpp:1292 +msgid "Re-enter the new passphrase for the wallet." +msgstr "Powtórnie wprowadź nowe hasło dla portfela." + +#: ../../../src/ui.cpp:1324 +msgid "Wallet Passphrase Changed." +msgstr "Hasło dla portfela zostało zmienione." + +#: ../../../src/ui.cpp:1381 +#: ../../../src/ui.cpp:2816 msgid "New Receiving Address" msgstr "Nowy Adres Odbiorczy" -#: ../../../src/ui.cpp:1179 -#: ../../../src/ui.cpp:2572 +#: ../../../src/ui.cpp:1382 +#: ../../../src/ui.cpp:2817 msgid "" "You should use a new address for each payment you receive.\n" "\n" @@ -352,248 +446,248 @@ msgstr "" "\n" "Etykieta" -#: ../../../src/ui.cpp:1251 +#: ../../../src/ui.cpp:1466 msgid "Status: " msgstr "Status:" -#: ../../../src/ui.cpp:1256 +#: ../../../src/ui.cpp:1471 msgid ", has not been successfully broadcast yet" msgstr ", nie został jeszcze prawidłowo rozgłoszony" -#: ../../../src/ui.cpp:1258 +#: ../../../src/ui.cpp:1473 #, c-format msgid ", broadcast through %d node" msgstr ", rozgłasza przez %d węzeł" -#: ../../../src/ui.cpp:1260 +#: ../../../src/ui.cpp:1475 #, c-format msgid ", broadcast through %d nodes" msgstr ", rozgłasza przez %d węzłów" -#: ../../../src/ui.cpp:1264 +#: ../../../src/ui.cpp:1479 msgid "Date: " msgstr "Data:" -#: ../../../src/ui.cpp:1272 +#: ../../../src/ui.cpp:1487 msgid "Source: Generated
" msgstr "Źródło: Wygenerowano
" -#: ../../../src/ui.cpp:1278 -#: ../../../src/ui.cpp:1296 +#: ../../../src/ui.cpp:1493 +#: ../../../src/ui.cpp:1511 msgid "From: " msgstr "Od:" -#: ../../../src/ui.cpp:1296 +#: ../../../src/ui.cpp:1511 msgid "unknown" msgstr "nieznany" -#: ../../../src/ui.cpp:1297 -#: ../../../src/ui.cpp:1321 -#: ../../../src/ui.cpp:1380 +#: ../../../src/ui.cpp:1512 +#: ../../../src/ui.cpp:1536 +#: ../../../src/ui.cpp:1595 msgid "To: " msgstr "Do:" -#: ../../../src/ui.cpp:1300 +#: ../../../src/ui.cpp:1515 msgid " (yours, label: " msgstr " (twoja, etykieta: " -#: ../../../src/ui.cpp:1302 +#: ../../../src/ui.cpp:1517 msgid " (yours)" msgstr " (twoja)" -#: ../../../src/ui.cpp:1339 -#: ../../../src/ui.cpp:1351 -#: ../../../src/ui.cpp:1397 -#: ../../../src/ui.cpp:1414 +#: ../../../src/ui.cpp:1554 +#: ../../../src/ui.cpp:1566 +#: ../../../src/ui.cpp:1612 +#: ../../../src/ui.cpp:1629 msgid "Credit: " msgstr "Suma:" -#: ../../../src/ui.cpp:1341 +#: ../../../src/ui.cpp:1556 #, c-format msgid "(%s matures in %d more blocks)" msgstr "(%s dojrzałych w %d więcej bloków)" -#: ../../../src/ui.cpp:1343 +#: ../../../src/ui.cpp:1558 msgid "(not accepted)" msgstr "(nie zaakceptowano)" -#: ../../../src/ui.cpp:1388 -#: ../../../src/ui.cpp:1396 -#: ../../../src/ui.cpp:1411 +#: ../../../src/ui.cpp:1603 +#: ../../../src/ui.cpp:1611 +#: ../../../src/ui.cpp:1626 msgid "Debit: " msgstr "Obciążenie:" -#: ../../../src/ui.cpp:1402 +#: ../../../src/ui.cpp:1617 msgid "Transaction fee: " msgstr "Prowizja transakcji:" -#: ../../../src/ui.cpp:1418 +#: ../../../src/ui.cpp:1633 msgid "Net amount: " msgstr "Kwota netto:" -#: ../../../src/ui.cpp:1425 +#: ../../../src/ui.cpp:1640 msgid "Message:" msgstr "Wiadomość:" -#: ../../../src/ui.cpp:1427 +#: ../../../src/ui.cpp:1642 msgid "Comment:" msgstr "Komentarz:" -#: ../../../src/ui.cpp:1430 +#: ../../../src/ui.cpp:1645 msgid "Generated coins must wait 120 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, it will change to \"not accepted\" and not be spendable. This may occasionally happen if another node generates a block within a few seconds of yours." msgstr "Wygenerowane monety muszą poczekać 120 bloków zanim mogą zostać wydane. Gdy wygenerowałeś ten blok, został rozgłoszony do sieci z przeznaczeniem do dodania do łańcucha bloków. Jeżeli nie uda się dodać bloku do łańcucha, zostanie oznaczony jako \"nie zaakceptowany\" i nie będzie mógł zostać wydany. Sporadycznie dzieje się tak jeżeli inny węzeł wygeneruje blok nie dalej niż kilka sekund od ciebie." -#: ../../../src/ui.cpp:1610 +#: ../../../src/ui.cpp:1825 msgid "Cannot write autostart/bitcoin.desktop file" msgstr "Nie mogę zapisać pliku autostart/bitcoin.desktop" -#: ../../../src/ui.cpp:1646 +#: ../../../src/ui.cpp:1861 msgid "Main" msgstr "Główne" -#: ../../../src/ui.cpp:1656 +#: ../../../src/ui.cpp:1871 msgid "&Start Bitcoin on window system startup" msgstr "&Uruchom Bitcoin przy starcie systemu" -#: ../../../src/ui.cpp:1663 +#: ../../../src/ui.cpp:1878 msgid "&Minimize on close" msgstr "&Minimalizuj przy zamknięciu" -#: ../../../src/ui.cpp:1805 +#: ../../../src/ui.cpp:2020 #, c-format msgid "version %s" msgstr "wersja %s" -#: ../../../src/ui.cpp:1928 +#: ../../../src/ui.cpp:2143 msgid "Error in amount " msgstr "Nieprawidłowa kwota" -#: ../../../src/ui.cpp:1928 -#: ../../../src/ui.cpp:1933 -#: ../../../src/ui.cpp:1938 -#: ../../../src/ui.cpp:1973 -#: ../../../src/uibase.cpp:55 +#: ../../../src/ui.cpp:2143 +#: ../../../src/ui.cpp:2148 +#: ../../../src/ui.cpp:2153 +#: ../../../src/ui.cpp:2202 +#: ../../../src/uibase.cpp:61 msgid "Send Coins" msgstr "Wyślij Monety" -#: ../../../src/ui.cpp:1933 +#: ../../../src/ui.cpp:2148 msgid "Amount exceeds your balance " msgstr "Kwota przekracza twój stan konta" -#: ../../../src/ui.cpp:1938 +#: ../../../src/ui.cpp:2153 msgid "Total exceeds your balance when the " msgstr "Przekroczenie twojego stanu konta gdy" -#: ../../../src/ui.cpp:1938 +#: ../../../src/ui.cpp:2153 msgid " transaction fee is included " msgstr " prowizja jest wliczona" -#: ../../../src/ui.cpp:1956 +#: ../../../src/ui.cpp:2176 msgid "Payment sent " msgstr "Wysłano płatność" -#: ../../../src/ui.cpp:1956 -#: ../../../src/ui.cpp:1961 -#: ../../../src/ui.cpp:2107 -#: ../../../src/ui.cpp:2260 -#: ../../../src/wallet.cpp:924 +#: ../../../src/ui.cpp:2176 +#: ../../../src/ui.cpp:2185 +#: ../../../src/ui.cpp:2336 +#: ../../../src/ui.cpp:2500 +#: ../../../src/wallet.cpp:1097 msgid "Sending..." msgstr "Wysyłanie..." -#: ../../../src/ui.cpp:1973 +#: ../../../src/ui.cpp:2202 msgid "Invalid address " msgstr "Nieprawidłowy adres" -#: ../../../src/ui.cpp:2028 +#: ../../../src/ui.cpp:2257 #, c-format msgid "Sending %s to %s" msgstr "Wysyłanie %s do %s" -#: ../../../src/ui.cpp:2101 -#: ../../../src/ui.cpp:2134 +#: ../../../src/ui.cpp:2330 +#: ../../../src/ui.cpp:2363 msgid "CANCELLED" msgstr "ANULOWANO" -#: ../../../src/ui.cpp:2105 +#: ../../../src/ui.cpp:2334 msgid "Cancelled" msgstr "Anulowano" -#: ../../../src/ui.cpp:2107 +#: ../../../src/ui.cpp:2336 msgid "Transfer cancelled " msgstr "Transfer anulowano" -#: ../../../src/ui.cpp:2160 +#: ../../../src/ui.cpp:2389 msgid "Error: " msgstr "Błąd:" -#: ../../../src/ui.cpp:2174 -#: ../../../src/ui.cpp:2245 -#: ../../../src/wallet.cpp:943 +#: ../../../src/ui.cpp:2403 +#: ../../../src/ui.cpp:2474 +#: ../../../src/wallet.cpp:1116 msgid "Insufficient funds" msgstr "Niewystarczające fundusze" -#: ../../../src/ui.cpp:2179 +#: ../../../src/ui.cpp:2408 msgid "Connecting..." msgstr "Łączenie..." -#: ../../../src/ui.cpp:2184 +#: ../../../src/ui.cpp:2413 msgid "Unable to connect" msgstr "Nie można połączyć" -#: ../../../src/ui.cpp:2189 +#: ../../../src/ui.cpp:2418 msgid "Requesting public key..." msgstr "Żądanie klucza publicznego..." -#: ../../../src/ui.cpp:2201 +#: ../../../src/ui.cpp:2430 msgid "Received public key..." msgstr "Otrzymano klucz publiczny..." -#: ../../../src/ui.cpp:2215 +#: ../../../src/ui.cpp:2444 msgid "Recipient is not accepting transactions sent by IP address" msgstr "Adresat nie akceptuje transakcji wysyłanych przez adres IP" -#: ../../../src/ui.cpp:2217 +#: ../../../src/ui.cpp:2446 msgid "Transfer was not accepted" msgstr "Transfer nie został zaakceptowany" -#: ../../../src/ui.cpp:2226 +#: ../../../src/ui.cpp:2455 msgid "Invalid response received" msgstr "Otrzymano niepoprawną odpowiedź" -#: ../../../src/ui.cpp:2241 +#: ../../../src/ui.cpp:2470 msgid "Creating transaction..." msgstr "Tworzenie transakcji..." -#: ../../../src/ui.cpp:2253 +#: ../../../src/ui.cpp:2489 #, c-format msgid "This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds" msgstr "Ta transakcja wymaga prowizji co najmniej %s z uwagi na kwotę, złożoność lub użycie niedawno otrzymanych funduszy" -#: ../../../src/ui.cpp:2255 +#: ../../../src/ui.cpp:2491 msgid "Transaction creation failed" msgstr "Błąd tworzenia transakcji " -#: ../../../src/ui.cpp:2262 +#: ../../../src/ui.cpp:2502 msgid "Transaction aborted" msgstr "Transakcję przerwano" -#: ../../../src/ui.cpp:2270 +#: ../../../src/ui.cpp:2510 msgid "Lost connection, transaction cancelled" msgstr "Utracono połączenie, transakcja anulowana" -#: ../../../src/ui.cpp:2286 +#: ../../../src/ui.cpp:2526 msgid "Sending payment..." msgstr "Wysyłanie płatności..." -#: ../../../src/ui.cpp:2292 +#: ../../../src/ui.cpp:2532 msgid "The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here." msgstr "Transakcja została odrzucona. Może się tak zdarzyć jeżeli część monet w twoim portfelu zostało wydanych, np. gdy użyto kopii pliku wallet.dat i monety zostały wydane w kopii, a tutaj nie zostały oznaczone jako wydane." -#: ../../../src/ui.cpp:2301 +#: ../../../src/ui.cpp:2541 msgid "Waiting for confirmation..." msgstr "Oczekiwanie na potwierdzenie..." -#: ../../../src/ui.cpp:2319 +#: ../../../src/ui.cpp:2559 msgid "" "The payment was sent, but the recipient was unable to verify it.\n" "The transaction is recorded and will credit to the recipient,\n" @@ -603,84 +697,84 @@ msgstr "" "Transakcja została zarejestrowana i zostanie przypisana do odbiorcy,\n" "ale informacja w komentarzu będzie pusta." -#: ../../../src/ui.cpp:2328 +#: ../../../src/ui.cpp:2568 msgid "Payment was sent, but an invalid response was received" msgstr "Płatność została wysłana, ale otrzymano nieprawidłową odpowiedź" -#: ../../../src/ui.cpp:2334 +#: ../../../src/ui.cpp:2574 msgid "Payment completed" msgstr "Płatność zakończona" -#: ../../../src/ui.cpp:2376 -#: ../../../src/ui.cpp:2522 -#: ../../../src/ui.cpp:2559 +#: ../../../src/ui.cpp:2616 +#: ../../../src/ui.cpp:2764 +#: ../../../src/ui.cpp:2804 msgid "Name" msgstr "Nazwa" -#: ../../../src/ui.cpp:2377 -#: ../../../src/ui.cpp:2522 -#: ../../../src/ui.cpp:2559 +#: ../../../src/ui.cpp:2617 +#: ../../../src/ui.cpp:2764 +#: ../../../src/ui.cpp:2804 msgid "Address" msgstr "Adres" -#: ../../../src/ui.cpp:2379 -#: ../../../src/ui.cpp:2534 +#: ../../../src/ui.cpp:2619 +#: ../../../src/ui.cpp:2776 msgid "Label" msgstr "Etykieta" -#: ../../../src/ui.cpp:2380 -#: ../../../src/uibase.cpp:837 +#: ../../../src/ui.cpp:2620 +#: ../../../src/uibase.cpp:847 msgid "Bitcoin Address" msgstr "Adres Bitcoin" -#: ../../../src/ui.cpp:2504 +#: ../../../src/ui.cpp:2746 msgid "This is one of your own addresses for receiving payments and cannot be entered in the address book. " msgstr "To jest jeden z twoich adresów na otrzymywane płatności i nie może zostać wpisany do księgi adresowej." -#: ../../../src/ui.cpp:2522 -#: ../../../src/ui.cpp:2528 +#: ../../../src/ui.cpp:2764 +#: ../../../src/ui.cpp:2770 msgid "Edit Address" msgstr "Edytuj Adres" -#: ../../../src/ui.cpp:2534 +#: ../../../src/ui.cpp:2776 msgid "Edit Address Label" msgstr "Edytuj Etykietę Adresu" -#: ../../../src/ui.cpp:2559 -#: ../../../src/ui.cpp:2565 +#: ../../../src/ui.cpp:2804 +#: ../../../src/ui.cpp:2810 msgid "Add Address" msgstr "Dodaj Adres" -#: ../../../src/ui.cpp:2642 +#: ../../../src/ui.cpp:2898 msgid "Bitcoin" msgstr "Bitcoin" -#: ../../../src/ui.cpp:2644 +#: ../../../src/ui.cpp:2900 msgid "Bitcoin - Generating" msgstr "Bitcoin - Generowanie" -#: ../../../src/ui.cpp:2646 +#: ../../../src/ui.cpp:2902 msgid "Bitcoin - (not connected)" msgstr "Bitcoin - (nie połączony)" -#: ../../../src/ui.cpp:2725 +#: ../../../src/ui.cpp:2981 msgid "&Open Bitcoin" msgstr "&Otwórz Bitcoin" -#: ../../../src/ui.cpp:2726 +#: ../../../src/ui.cpp:2982 msgid "&Send Bitcoins" msgstr "&Wyślij Bitcoiny" -#: ../../../src/ui.cpp:2727 +#: ../../../src/ui.cpp:2983 msgid "O&ptions..." msgstr "O&pcje..." -#: ../../../src/ui.cpp:2730 +#: ../../../src/ui.cpp:2986 #: ../../../src/uibase.cpp:25 msgid "E&xit" msgstr "W&yjście" -#: ../../../src/ui.cpp:2956 +#: ../../../src/ui.cpp:3212 msgid "Program has crashed and will terminate. " msgstr "Program uległ awarii i zostanie przerwany." @@ -696,152 +790,160 @@ msgstr "&Plik" msgid "&Your Receiving Addresses..." msgstr "&Twój Adres Odbiorczy..." -#: ../../../src/uibase.cpp:36 +#: ../../../src/uibase.cpp:35 +msgid "&Encrypt Wallet..." +msgstr "&Zaszyfruj portfel..." + +#: ../../../src/uibase.cpp:38 +msgid "&Change Wallet Encryption Passphrase..." +msgstr "&Zmień hasło szyfrowania portfela..." + +#: ../../../src/uibase.cpp:42 msgid "&Options..." msgstr "&Opcje..." -#: ../../../src/uibase.cpp:39 +#: ../../../src/uibase.cpp:45 msgid "&Settings" msgstr "&Ustawienia" -#: ../../../src/uibase.cpp:43 +#: ../../../src/uibase.cpp:49 msgid "&About..." msgstr "&O programie..." -#: ../../../src/uibase.cpp:46 +#: ../../../src/uibase.cpp:52 msgid "&Help" msgstr "&Pomoc" -#: ../../../src/uibase.cpp:56 +#: ../../../src/uibase.cpp:62 msgid "Address Book" msgstr "Księga Adresowa" -#: ../../../src/uibase.cpp:69 +#: ../../../src/uibase.cpp:75 msgid "Your Bitcoin Address:" msgstr "Twój Adres Bitcoin:" -#: ../../../src/uibase.cpp:76 +#: ../../../src/uibase.cpp:82 msgid " &New... " msgstr " &Nowy..." -#: ../../../src/uibase.cpp:79 -#: ../../../src/uibase.cpp:780 -#: ../../../src/uibase.cpp:883 +#: ../../../src/uibase.cpp:85 +#: ../../../src/uibase.cpp:790 +#: ../../../src/uibase.cpp:893 msgid " &Copy to Clipboard " msgstr " &Kopiuj do schowka " -#: ../../../src/uibase.cpp:93 +#: ../../../src/uibase.cpp:99 msgid "Balance:" msgstr "Saldo:" -#: ../../../src/uibase.cpp:109 +#: ../../../src/uibase.cpp:115 msgid " All" msgstr " Wszystko" -#: ../../../src/uibase.cpp:109 +#: ../../../src/uibase.cpp:115 msgid " Sent" msgstr "Wysłano" -#: ../../../src/uibase.cpp:109 +#: ../../../src/uibase.cpp:115 msgid " Received" msgstr "Otrzymano" -#: ../../../src/uibase.cpp:109 +#: ../../../src/uibase.cpp:115 msgid " In Progress" msgstr "W Trakcie" -#: ../../../src/uibase.cpp:130 +#: ../../../src/uibase.cpp:136 msgid "All Transactions" msgstr "Wszystkie Transakcje" -#: ../../../src/uibase.cpp:141 +#: ../../../src/uibase.cpp:147 msgid "Sent/Received" msgstr "Wysłano/Otrzymano" -#: ../../../src/uibase.cpp:152 +#: ../../../src/uibase.cpp:158 msgid "Sent" msgstr "Wysłano" -#: ../../../src/uibase.cpp:163 +#: ../../../src/uibase.cpp:169 msgid "Received" msgstr "Otrzymano" -#: ../../../src/uibase.cpp:302 -#: ../../../src/uibase.cpp:443 -#: ../../../src/uibase.cpp:542 -#: ../../../src/uibase.cpp:722 -#: ../../../src/uibase.cpp:783 -#: ../../../src/uibase.cpp:892 -#: ../../../src/uibase.cpp:981 +#: ../../../src/uibase.cpp:312 +#: ../../../src/uibase.cpp:453 +#: ../../../src/uibase.cpp:552 +#: ../../../src/uibase.cpp:732 +#: ../../../src/uibase.cpp:793 +#: ../../../src/uibase.cpp:902 +#: ../../../src/uibase.cpp:991 msgid "OK" msgstr "OK" -#: ../../../src/uibase.cpp:345 +#: ../../../src/uibase.cpp:355 msgid "&Start Bitcoin on system startup" msgstr "&Uruchom Bitcoin wraz ze startem systemu" -#: ../../../src/uibase.cpp:348 +#: ../../../src/uibase.cpp:358 msgid "&Minimize to the tray instead of the taskbar" msgstr "&Zminimalizuj do traya zamiast do paska zadań" -#: ../../../src/uibase.cpp:351 +#: ../../../src/uibase.cpp:361 msgid "Map port using &UPnP" msgstr "Mapuj port używając &UPnP" -#: ../../../src/uibase.cpp:354 +#: ../../../src/uibase.cpp:364 msgid "M&inimize to the tray on close" msgstr "Zm&inimalizuj do traya przy zamknięciu" -#: ../../../src/uibase.cpp:360 +#: ../../../src/uibase.cpp:370 msgid "&Connect through socks4 proxy: " msgstr "&Połącz przez socks4 proxy:" -#: ../../../src/uibase.cpp:371 +#: ../../../src/uibase.cpp:381 msgid "Proxy &IP:" msgstr "Proxy &IP:" -#: ../../../src/uibase.cpp:379 +#: ../../../src/uibase.cpp:389 msgid " &Port:" msgstr " &Port:" -#: ../../../src/uibase.cpp:392 +#: ../../../src/uibase.cpp:402 msgid "Optional transaction fee per KB that helps make sure your transactions are processed quickly. Most transactions are 1KB. Fee 0.01 recommended." msgstr "Opcjonalna prowizja określona dla KB transakcji, która zapewni, że twoje transakcje będą szybko przetworzone. Większość transakcji to 1KB. Rekomendowana prowizja to 0.01." -#: ../../../src/uibase.cpp:399 +#: ../../../src/uibase.cpp:409 msgid "Pay transaction fee:" msgstr "Płać prowizję transakcji:" -#: ../../../src/uibase.cpp:420 +#: ../../../src/uibase.cpp:430 msgid "// [don't translate] Test panel 2 for future expansion" msgstr "" -#: ../../../src/uibase.cpp:424 +#: ../../../src/uibase.cpp:434 msgid "// [don't translate] Let's not start multiple pages until the first page is filled up" msgstr "" -#: ../../../src/uibase.cpp:446 -#: ../../../src/uibase.cpp:668 -#: ../../../src/uibase.cpp:727 -#: ../../../src/uibase.cpp:786 -#: ../../../src/uibase.cpp:895 -#: ../../../src/uibase.cpp:984 +#: ../../../src/uibase.cpp:456 +#: ../../../src/uibase.cpp:678 +#: ../../../src/uibase.cpp:737 +#: ../../../src/uibase.cpp:796 +#: ../../../src/uibase.cpp:905 +#: ../../../src/uibase.cpp:994 msgid "Cancel" msgstr "Anuluj" -#: ../../../src/uibase.cpp:449 +#: ../../../src/uibase.cpp:459 msgid "&Apply" msgstr "&Zastosuj" -#: ../../../src/uibase.cpp:508 +#: ../../../src/uibase.cpp:518 msgid "Bitcoin " msgstr "Bitcoin" -#: ../../../src/uibase.cpp:514 +#: ../../../src/uibase.cpp:524 msgid "version" msgstr "wersja" -#: ../../../src/uibase.cpp:525 +#: ../../../src/uibase.cpp:535 msgid "" "Copyright (c) 2009-2011 Bitcoin Developers\n" "\n" @@ -865,39 +967,39 @@ msgstr "" "OpenSSL Toolkit (http://www.openssl.org/) i oprogramowanie kryptograficzne napisane przez \n" "Erica Younga (eay@cryptsoft.com) oraz oprogramowanie UPnP napisane przez Thomasa Bernarda." -#: ../../../src/uibase.cpp:581 +#: ../../../src/uibase.cpp:591 msgid "Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)" msgstr "Wprowadź adres Bitcoin (np. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)" -#: ../../../src/uibase.cpp:595 +#: ../../../src/uibase.cpp:605 msgid "Pay &To:" msgstr "Wpłać &Dla:" -#: ../../../src/uibase.cpp:610 +#: ../../../src/uibase.cpp:620 msgid "&Paste" msgstr "&Wklej" -#: ../../../src/uibase.cpp:613 +#: ../../../src/uibase.cpp:623 msgid " Address &Book..." msgstr " Księga &Adresowa..." -#: ../../../src/uibase.cpp:620 +#: ../../../src/uibase.cpp:630 msgid "&Amount:" msgstr "&Kwota:" -#: ../../../src/uibase.cpp:630 +#: ../../../src/uibase.cpp:640 msgid "T&ransfer:" msgstr "T&ransfer:" -#: ../../../src/uibase.cpp:636 +#: ../../../src/uibase.cpp:646 msgid " Standard" msgstr " Standard" -#: ../../../src/uibase.cpp:663 +#: ../../../src/uibase.cpp:673 msgid "&Send" msgstr "&Wyślij" -#: ../../../src/uibase.cpp:711 +#: ../../../src/uibase.cpp:721 msgid "" "\n" "\n" @@ -907,70 +1009,74 @@ msgstr "" "\n" "Łączenie..." -#: ../../../src/uibase.cpp:761 +#: ../../../src/uibase.cpp:771 msgid "These are your Bitcoin addresses for receiving payments. You may want to give a different one to each sender so you can keep track of who is paying you. The highlighted address is displayed in the main window." msgstr "To są twoje adresy Bitcoin dla otrzymywania płatności. Możesz chcieć podać różne dla każdego płacącego aby kontrolować kto ci płaci. Wyróżniony adres będzie wyświetlany w oknie głównym." -#: ../../../src/uibase.cpp:774 -#: ../../../src/uibase.cpp:886 +#: ../../../src/uibase.cpp:784 +#: ../../../src/uibase.cpp:896 msgid "&Edit..." msgstr "&Edytuj..." -#: ../../../src/uibase.cpp:777 -#: ../../../src/uibase.cpp:889 +#: ../../../src/uibase.cpp:787 +#: ../../../src/uibase.cpp:899 msgid " &New Address... " msgstr " &Nowy Adres..." -#: ../../../src/uibase.cpp:849 +#: ../../../src/uibase.cpp:859 msgid "Sending" msgstr "Wysyłanie" -#: ../../../src/uibase.cpp:857 +#: ../../../src/uibase.cpp:867 msgid "These are your Bitcoin addresses for receiving payments. You can give a different one to each sender to keep track of who is paying you. The highlighted address will be displayed in the main window." msgstr "To są twoje adresy Bitcoin dla otrzymywania płatności. Możesz podać różne dla każdego płacącego aby kontrolować kto ci płaci. Wyróżniony adres będzie wyświetlany w oknie głównym." -#: ../../../src/uibase.cpp:870 +#: ../../../src/uibase.cpp:880 msgid "Receiving" msgstr "Otrzymywanie" -#: ../../../src/uibase.cpp:880 +#: ../../../src/uibase.cpp:890 msgid "&Delete" msgstr "&Usuń" -#: ../../../src/wallet.cpp:917 +#: ../../../src/wallet.cpp:1081 +msgid "Error: Wallet locked, unable to create transaction " +msgstr "Błąd: Portfel zablokowany, nie można utworzyć transakcji" + +#: ../../../src/wallet.cpp:1089 #, c-format msgid "Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds " msgstr "Błąd: Ta transakcja wymaga prowizji co najmniej %s z uwagi na kwotę, złożoność lub użycie niedawno otrzymanych funduszy" -#: ../../../src/wallet.cpp:919 +#: ../../../src/wallet.cpp:1091 msgid "Error: Transaction creation failed " msgstr "Błąd: Nie udało się utworzyć transakcji" -#: ../../../src/wallet.cpp:928 +#: ../../../src/wallet.cpp:1101 msgid "Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here." msgstr "Błąd: Transakcja została odrzucona. Może się tak zdarzyć jeżeli część monet w twoim portfelu zostało wydanych, np. gdy użyto kopii pliku wallet.dat i monety zostały wydane w kopii, a tutaj nie zostały oznaczone jako wydane." -#: ../../../src/wallet.cpp:941 +#: ../../../src/wallet.cpp:1114 msgid "Invalid amount" msgstr "Niewłaściwa kwota" -#: ../../../src/wallet.cpp:948 +#: ../../../src/wallet.cpp:1121 msgid "Invalid bitcoin address" msgstr "Niewłaściwy adres bitcoin" -#: ../../../src/uibase.h:147 +#: ../../../src/uibase.h:151 msgid "Transaction Details" msgstr "Szczegóły Transakcji" -#: ../../../src/uibase.h:199 +#: ../../../src/uibase.h:203 msgid "Options" msgstr "Opcje" -#: ../../../src/uibase.h:228 +#: ../../../src/uibase.h:232 msgid "About Bitcoin" msgstr "O Bitcoin" -#: ../../../src/uibase.h:337 +#: ../../../src/uibase.h:341 msgid "Your Bitcoin Addresses" msgstr "Twoje Adresy Bitcoin" diff --git a/locale/sv/LC_MESSAGES/bitcoin.mo b/locale/sv/LC_MESSAGES/bitcoin.mo new file mode 100644 index 000000000..b61914cb4 Binary files /dev/null and b/locale/sv/LC_MESSAGES/bitcoin.mo differ diff --git a/locale/sv/LC_MESSAGES/bitcoin.po b/locale/sv/LC_MESSAGES/bitcoin.po index fb46e1542..dc635f313 100644 --- a/locale/sv/LC_MESSAGES/bitcoin.po +++ b/locale/sv/LC_MESSAGES/bitcoin.po @@ -2,8 +2,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-06-11 21:58+0100\n" -"PO-Revision-Date: 2011-06-14 09:01+0100\n" +"POT-Creation-Date: 2011-07-03 10:40+0100\n" +"PO-Revision-Date: 2011-07-03 15:13+0100\n" "Last-Translator: Codler \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -11,130 +11,133 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "X-Poedit-KeywordsList: _;gettext;gettext_noop\n" "X-Poedit-Basepath: .\n" -"X-Poedit-Bookmarks: 35,145,-1,-1,-1,-1,-1,-1,-1,-1\n" "X-Poedit-SearchPath-0: ../../..\n" -#: ../../../init.cpp:141 +#: ../../../init.cpp:162 msgid "Bitcoin version" msgstr "Bitcoin version" -#: ../../../init.cpp:142 +#: ../../../init.cpp:163 msgid "Usage:" msgstr "Användning:" -#: ../../../init.cpp:144 +#: ../../../init.cpp:165 msgid "Send command to -server or bitcoind\n" msgstr "Skicka kommando till -server eller bitcoind\n" -#: ../../../init.cpp:145 +#: ../../../init.cpp:166 msgid "List commands\n" msgstr "Lista kommandon\n" -#: ../../../init.cpp:146 +#: ../../../init.cpp:167 msgid "Get help for a command\n" msgstr "Få hjälp om kommandon\n" -#: ../../../init.cpp:147 +#: ../../../init.cpp:168 msgid "Options:\n" msgstr "Val:\n" -#: ../../../init.cpp:148 +#: ../../../init.cpp:169 msgid "Specify configuration file (default: bitcoin.conf)\n" msgstr "Ange konfigurationsfil (standard: bitcoin.conf)\n" -#: ../../../init.cpp:149 +#: ../../../init.cpp:170 msgid "Specify pid file (default: bitcoind.pid)\n" msgstr "Ange pid-fil (standard: bitcoind.pid)\n" -#: ../../../init.cpp:150 +#: ../../../init.cpp:171 msgid "Generate coins\n" msgstr "Generera mynt\n" -#: ../../../init.cpp:151 +#: ../../../init.cpp:172 msgid "Don't generate coins\n" msgstr "Generera inte mynt\n" -#: ../../../init.cpp:152 +#: ../../../init.cpp:173 msgid "Start minimized\n" msgstr "Starta minimerad\n" -#: ../../../init.cpp:153 +#: ../../../init.cpp:174 msgid "Specify data directory\n" msgstr "Ange data mappen\n" -#: ../../../init.cpp:154 +#: ../../../init.cpp:175 +msgid "Specify connection timeout (in milliseconds)\n" +msgstr "Ange timeout för anslutning (i millisekunder)\n" + +#: ../../../init.cpp:176 msgid "Connect through socks4 proxy\n" msgstr "Anslut via socks4 proxy\n" -#: ../../../init.cpp:155 +#: ../../../init.cpp:177 msgid "Allow DNS lookups for addnode and connect\n" msgstr "Tillåt DNS uppslagningar för addnode och connect\n" -#: ../../../init.cpp:156 +#: ../../../init.cpp:178 msgid "Add a node to connect to\n" msgstr "Lägg till en nod att ansluta till\n" -#: ../../../init.cpp:157 +#: ../../../init.cpp:179 msgid "Connect only to the specified node\n" msgstr "Anslut endast till specifik nod\n" -#: ../../../init.cpp:158 +#: ../../../init.cpp:180 msgid "Don't accept connections from outside\n" msgstr "Acceptera ej anslutningar från utsidan\n" -#: ../../../init.cpp:161 +#: ../../../init.cpp:183 msgid "Don't attempt to use UPnP to map the listening port\n" msgstr "Försöker inte använda UPnP till avslyssningsport\n" -#: ../../../init.cpp:163 +#: ../../../init.cpp:185 msgid "Attempt to use UPnP to map the listening port\n" msgstr "Försöker använda UPnP till avlyssningsport\n" -#: ../../../init.cpp:166 +#: ../../../init.cpp:188 msgid "Fee per KB to add to transactions you send\n" msgstr "Avgift per KB som läggs på transaktionen när du sänder\n" -#: ../../../init.cpp:168 +#: ../../../init.cpp:190 msgid "Accept command line and JSON-RPC commands\n" msgstr "Accepterar kommandorad och JSON-RPC kommando\n" -#: ../../../init.cpp:171 +#: ../../../init.cpp:193 msgid "Run in the background as a daemon and accept commands\n" msgstr "Kör i bakgrund som daemon och accepterar kommando\n" -#: ../../../init.cpp:173 +#: ../../../init.cpp:195 msgid "Use the test network\n" msgstr "Använd test nätverk\n" -#: ../../../init.cpp:174 +#: ../../../init.cpp:196 msgid "Username for JSON-RPC connections\n" msgstr "Användarnamn till JSON-RPC anslutning\n" -#: ../../../init.cpp:175 +#: ../../../init.cpp:197 msgid "Password for JSON-RPC connections\n" msgstr "Lösenord till JSON-RPC anslutning\n" -#: ../../../init.cpp:176 +#: ../../../init.cpp:198 msgid "Listen for JSON-RPC connections on (default: 8332)\n" msgstr "Lyssnar på JSON-RPC anslutningar på (standard: 8332)\n" -#: ../../../init.cpp:177 +#: ../../../init.cpp:199 msgid "Allow JSON-RPC connections from specified IP address\n" msgstr "Tillåt JSON-RPC anslutningar från specifik IP-adress\n" -#: ../../../init.cpp:178 +#: ../../../init.cpp:200 msgid "Send commands to node running on (default: 127.0.0.1)\n" msgstr "Skicka kommando till noden som körs på (standard: 127.0.0.1)\n" -#: ../../../init.cpp:179 +#: ../../../init.cpp:201 msgid "Set key pool size to (default: 100)\n" msgstr "Sätt nyckel pool storlek till (standard: 100)\n" -#: ../../../init.cpp:180 +#: ../../../init.cpp:202 msgid "Rescan the block chain for missing wallet transactions\n" msgstr "Scanna om block kedja efter saknade plånbokstransaktioner\n" -#: ../../../init.cpp:184 +#: ../../../init.cpp:206 msgid "" "\n" "SSL options: (see the Bitcoin Wiki for SSL setup instructions)\n" @@ -142,106 +145,71 @@ msgstr "" "\n" "SSL val: (Se på Bitcoin Wiki för SSL installation instruktioner)\n" -#: ../../../init.cpp:185 +#: ../../../init.cpp:207 msgid "Use OpenSSL (https) for JSON-RPC connections\n" msgstr "Använd OpenSSL (https) till JSON-RPC anslutningar\n" -#: ../../../init.cpp:186 +#: ../../../init.cpp:208 msgid "Server certificate file (default: server.cert)\n" msgstr "Server certifikatfil (standard: server.cert)\n" -#: ../../../init.cpp:187 +#: ../../../init.cpp:209 msgid "Server private key (default: server.pem)\n" msgstr "Server privat nyckel (standard: server.pem)\n" -#: ../../../init.cpp:188 +#: ../../../init.cpp:210 msgid "Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)\n" msgstr "Acceptabla krypteringar (standard: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)\n" -#: ../../../init.cpp:192 +#: ../../../init.cpp:214 msgid "This help message\n" msgstr "Detta hjälpmeddelande\n" -#: ../../../init.cpp:329 +#: ../../../init.cpp:351 #, c-format msgid "Cannot obtain a lock on data directory %s. Bitcoin is probably already running." msgstr "Kan inte sätta lås på data mappen %s. Bitcoin körs troligen redan." -#: ../../../init.cpp:355 +#: ../../../init.cpp:377 msgid "Error loading addr.dat \n" msgstr "Fel vid laddning av addr.dat \n" -#: ../../../init.cpp:361 +#: ../../../init.cpp:383 msgid "Error loading blkindex.dat \n" msgstr "Fel vid laddning av blkindex.dat \n" -#: ../../../init.cpp:368 +#: ../../../init.cpp:391 msgid "Error loading wallet.dat \n" msgstr "Fel vid laddning av wallet.dat \n" -#: ../../../init.cpp:448 +#: ../../../init.cpp:481 msgid "Invalid -proxy address" msgstr "Ogiltig -proxy adress" -#: ../../../init.cpp:471 +#: ../../../init.cpp:506 msgid "Invalid amount for -paytxfee=" msgstr "Ogiltig belopp på -paytxfee=" -#: ../../../init.cpp:475 +#: ../../../init.cpp:510 msgid "Warning: -paytxfee is set very high. This is the transaction fee you will pay if you send a transaction." msgstr "Varning: -paytxfee är satt väldigt högt. Denna är transaktionsavgiften som du kommer att betala om du skickar en transaktion." -#: ../../../main.cpp:1866 +#: ../../../main.cpp:1430 msgid "Warning: Disk space is low " msgstr "Varning: Diskutrymme är låg " -#: ../../../main.cpp:3999 -#, c-format -msgid "Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds " -msgstr "Fel: Denna transaktion kräver en transaktionsavgift minst %s för dess belopp, komplexitet, eller användning av nyligen mottagna pengar " - -#: ../../../main.cpp:4001 -msgid "Error: Transaction creation failed " -msgstr "Fel: Misslyckades att skapa transaktion " - -#: ../../../main.cpp:4006 -#: ../../../ui.cpp:1951 -#: ../../../ui.cpp:1956 -#: ../../../ui.cpp:2102 -#: ../../../ui.cpp:2255 -msgid "Sending..." -msgstr "Skickar..." - -#: ../../../main.cpp:4010 -msgid "Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here." -msgstr "Fel: Transaktionen blev nekad. Detta kan hända om några av dina mynt i din plånbok var redan spenderad. Till exempel om du använde en kopia av wallet.dat och mynten var redan spenderad i kopian, men som inte var markerad som spenderad här." - -#: ../../../main.cpp:4023 -msgid "Invalid amount" -msgstr "Ogiltig belopp" - -#: ../../../main.cpp:4025 -#: ../../../ui.cpp:2169 -#: ../../../ui.cpp:2240 -msgid "Insufficient funds" -msgstr "Otillräckligt med pengar" - -#: ../../../main.cpp:4030 -msgid "Invalid bitcoin address" -msgstr "Ogiltig bitcoin adress" - -#: ../../../net.cpp:1505 +#: ../../../net.cpp:1598 #, c-format msgid "Unable to bind to port %d on this computer. Bitcoin is probably already running." msgstr "Det gick inte att binda till port %d på denna dator. Bitcoin körs troligen redan." -#: ../../../rpc.cpp:1816 -#: ../../../rpc.cpp:1818 +#: ../../../rpc.cpp:1828 +#: ../../../rpc.cpp:1830 #, c-format msgid "To use the %s option" msgstr "För att använda %s val" -#: ../../../rpc.cpp:1820 +#: ../../../rpc.cpp:1832 #, c-format msgid "" "Warning: %s, you must set rpcpassword=\n" @@ -252,7 +220,7 @@ msgstr "" "i konfigurationsfilen: %s\n" "Om filen inte existerar, skapa med ägare med filbehörigheten -readable-only.\n" -#: ../../../rpc.cpp:1988 +#: ../../../rpc.cpp:2005 #, c-format msgid "" "You must set rpcpassword= in the configuration file:\n" @@ -263,347 +231,360 @@ msgstr "" "%s\n" "Om filen inte existerar, skapa med ägare med filbehörighete -readable-only." -#: ../../../ui.cpp:211 +#: ../../../ui.cpp:216 #, c-format msgid "This transaction is over the size limit. You can still send it for a fee of %s, which goes to the nodes that process your transaction and helps to support the network. Do you want to pay the fee?" msgstr "Denna transaktion är över storleksbegränsningen. Du kan fortfarande skicka mot en avgift på %s, som går till noderna som bearbetar din transaktion och hjälper att stödja nätverket. Vill du fortfarande betala avgiften?" -#: ../../../ui.cpp:311 +#: ../../../ui.cpp:316 msgid "Status" msgstr "Status" -#: ../../../ui.cpp:312 +#: ../../../ui.cpp:317 msgid "Date" msgstr "Datum" -#: ../../../ui.cpp:313 +#: ../../../ui.cpp:318 msgid "Description" msgstr "Beskrivning" -#: ../../../ui.cpp:314 +#: ../../../ui.cpp:319 msgid "Debit" -msgstr "Debitera" +msgstr "Debet" -#: ../../../ui.cpp:315 +#: ../../../ui.cpp:320 msgid "Credit" -msgstr "Kreditera" +msgstr "Kredit" -#: ../../../ui.cpp:521 +#: ../../../ui.cpp:526 #, c-format msgid "Open for %d blocks" -msgstr "Öppna för %d blocks" +msgstr "Öppen för %d block" -#: ../../../ui.cpp:523 +#: ../../../ui.cpp:528 #, c-format msgid "Open until %s" msgstr "Öppen tills %s" -#: ../../../ui.cpp:529 +#: ../../../ui.cpp:534 #, c-format msgid "%d/offline?" msgstr "%d/offline?" -#: ../../../ui.cpp:531 +#: ../../../ui.cpp:536 #, c-format msgid "%d/unconfirmed" msgstr "%d/obekräftade" -#: ../../../ui.cpp:533 +#: ../../../ui.cpp:538 #, c-format msgid "%d confirmations" msgstr "%d bekräftelser" -#: ../../../ui.cpp:618 +#: ../../../ui.cpp:623 msgid "Generated" msgstr "Genererad" -#: ../../../ui.cpp:626 -#, fuzzy, c-format +#: ../../../ui.cpp:631 +#, c-format msgid "Generated (%s matures in %d more blocks)" -msgstr "Genererad (%s mogna i %d fler block)" +msgstr "Genererad (%s mognar om %d block)" -#: ../../../ui.cpp:630 +#: ../../../ui.cpp:635 msgid "Generated - Warning: This block was not received by any other nodes and will probably not be accepted!" msgstr "Genererad - Varning: Denna block har inte blivit mottagen av någon annan nod och kommer troligtvis inte bli accepterad" -#: ../../../ui.cpp:634 +#: ../../../ui.cpp:639 msgid "Generated (not accepted)" msgstr "Genererad (ej accepterad)" -#: ../../../ui.cpp:644 +#: ../../../ui.cpp:649 msgid "From: " msgstr "Från: " -#: ../../../ui.cpp:668 +#: ../../../ui.cpp:673 msgid "Received with: " msgstr "Mottagen med: " -#: ../../../ui.cpp:714 +#: ../../../ui.cpp:719 msgid "Payment to yourself" msgstr "Betalning till dig själv" -#: ../../../ui.cpp:748 +#: ../../../ui.cpp:753 msgid "To: " msgstr "Till: " -#: ../../../ui.cpp:1063 +#: ../../../ui.cpp:1068 msgid " Generating" msgstr " Generering" -#: ../../../ui.cpp:1065 +#: ../../../ui.cpp:1070 msgid "(not connected)" msgstr "(inte ansluten)" -#: ../../../ui.cpp:1068 +#: ../../../ui.cpp:1073 #, c-format msgid " %d connections %d blocks %d transactions" msgstr " %d anslutningar %d block %d transaktioner" -#: ../../../ui.cpp:1173 -#: ../../../ui.cpp:2566 +#: ../../../ui.cpp:1178 +#: ../../../ui.cpp:2577 msgid "New Receiving Address" msgstr "Ny Mottagningsadress" -#: ../../../ui.cpp:1174 -#: ../../../ui.cpp:2567 +#: ../../../ui.cpp:1179 +#: ../../../ui.cpp:2578 msgid "" "You should use a new address for each payment you receive.\n" "\n" "Label" msgstr "" -"Du borde använda en ny adress för varje betalning som du mottar.\n" +"Du borde använda en ny adress för varje betalning som du mottagit.\n" "\n" "Etikett" -#: ../../../ui.cpp:1246 +#: ../../../ui.cpp:1252 msgid "Status: " msgstr "Status: " -#: ../../../ui.cpp:1251 +#: ../../../ui.cpp:1257 msgid ", has not been successfully broadcast yet" -msgstr ", has not been successfully broadcast yet" +msgstr ", har inte lyckats broadcast än" -#: ../../../ui.cpp:1253 +#: ../../../ui.cpp:1259 #, c-format msgid ", broadcast through %d node" msgstr ", broadcast genom %d nod" -#: ../../../ui.cpp:1255 +#: ../../../ui.cpp:1261 #, c-format msgid ", broadcast through %d nodes" msgstr ", broadcast genom %d noder" -#: ../../../ui.cpp:1259 +#: ../../../ui.cpp:1265 msgid "Date: " msgstr "Datum: " -#: ../../../ui.cpp:1267 +#: ../../../ui.cpp:1273 msgid "Source: Generated
" msgstr "Källa: Genererad
" -#: ../../../ui.cpp:1273 -#: ../../../ui.cpp:1291 +#: ../../../ui.cpp:1279 +#: ../../../ui.cpp:1297 msgid "From: " msgstr "Från: " -#: ../../../ui.cpp:1291 +#: ../../../ui.cpp:1297 msgid "unknown" msgstr "okänd" -#: ../../../ui.cpp:1292 -#: ../../../ui.cpp:1316 -#: ../../../ui.cpp:1375 +#: ../../../ui.cpp:1298 +#: ../../../ui.cpp:1322 +#: ../../../ui.cpp:1381 msgid "To: " msgstr "Till: " -#: ../../../ui.cpp:1295 +#: ../../../ui.cpp:1301 msgid " (yours, label: " msgstr " (din, etikett: " -#: ../../../ui.cpp:1297 +#: ../../../ui.cpp:1303 msgid " (yours)" msgstr " (ditt)" -#: ../../../ui.cpp:1334 -#: ../../../ui.cpp:1346 -#: ../../../ui.cpp:1392 -#: ../../../ui.cpp:1409 +#: ../../../ui.cpp:1340 +#: ../../../ui.cpp:1352 +#: ../../../ui.cpp:1398 +#: ../../../ui.cpp:1415 msgid "Credit: " msgstr "Kredit: " -#: ../../../ui.cpp:1336 -#, fuzzy, c-format +#: ../../../ui.cpp:1342 +#, c-format msgid "(%s matures in %d more blocks)" -msgstr "(%s matures in %d more blocks)" +msgstr "(%s mognar om %d block)" -#: ../../../ui.cpp:1338 +#: ../../../ui.cpp:1344 msgid "(not accepted)" msgstr "(ej accepterad)" -#: ../../../ui.cpp:1383 -#: ../../../ui.cpp:1391 -#: ../../../ui.cpp:1406 -msgid "Debit: " -msgstr "Debit: " - +#: ../../../ui.cpp:1389 #: ../../../ui.cpp:1397 +#: ../../../ui.cpp:1412 +msgid "Debit: " +msgstr "Debet: " + +#: ../../../ui.cpp:1403 msgid "Transaction fee: " msgstr "Transaktionsavgift: " -#: ../../../ui.cpp:1413 -#, fuzzy +#: ../../../ui.cpp:1419 msgid "Net amount: " msgstr "Nät belopp: " -#: ../../../ui.cpp:1420 +#: ../../../ui.cpp:1426 msgid "Message:" msgstr "Meddelande:" -#: ../../../ui.cpp:1422 +#: ../../../ui.cpp:1428 msgid "Comment:" msgstr "Kommentar:" -#: ../../../ui.cpp:1425 +#: ../../../ui.cpp:1431 msgid "Generated coins must wait 120 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, it will change to \"not accepted\" and not be spendable. This may occasionally happen if another node generates a block within a few seconds of yours." msgstr "Genererad mynt måste vänta 120 block innan dem kan användas.När du genererat denna block, skickades en broadcast till nätet och lades till block kedjan. Om den misslyckas att lägga till kedjan så kommer det ändras till \"not accepted\" och är icke brukbar. Detta kan hända om en annan nod genererat en block några sekunder efter din." -#: ../../../ui.cpp:1605 +#: ../../../ui.cpp:1611 msgid "Cannot write autostart/bitcoin.desktop file" msgstr "Kan inte skriva autostart/bitcoin.desktop fil" -#: ../../../ui.cpp:1641 +#: ../../../ui.cpp:1647 msgid "Main" -msgstr "Huvud" +msgstr "Allmänt" -#: ../../../ui.cpp:1651 +#: ../../../ui.cpp:1657 msgid "&Start Bitcoin on window system startup" -msgstr "&Starta Bitcoin vid uppstart i windows" +msgstr "&Starta Bitcoin vid system uppstart" -#: ../../../ui.cpp:1658 +#: ../../../ui.cpp:1664 msgid "&Minimize on close" msgstr "&Minimera vid stängning" -#: ../../../ui.cpp:1800 +#: ../../../ui.cpp:1806 #, c-format msgid "version %s" msgstr "version %s" -#: ../../../ui.cpp:1923 +#: ../../../ui.cpp:1929 msgid "Error in amount " msgstr "Fel i belopp " -#: ../../../ui.cpp:1923 -#: ../../../ui.cpp:1928 -#: ../../../ui.cpp:1933 -#: ../../../ui.cpp:1968 +#: ../../../ui.cpp:1929 +#: ../../../ui.cpp:1934 +#: ../../../ui.cpp:1939 +#: ../../../ui.cpp:1974 #: ../../../uibase.cpp:55 msgid "Send Coins" msgstr "Skicka mynt" -#: ../../../ui.cpp:1928 +#: ../../../ui.cpp:1934 msgid "Amount exceeds your balance " msgstr "Belopp överskrider din balans " -#: ../../../ui.cpp:1933 +#: ../../../ui.cpp:1939 msgid "Total exceeds your balance when the " -msgstr "Totals överskrider din balans när " +msgstr "Totalt överskrider din balans när " -#: ../../../ui.cpp:1933 +#: ../../../ui.cpp:1939 msgid " transaction fee is included " msgstr " transaktionsavgift är inkluderad " -#: ../../../ui.cpp:1951 +#: ../../../ui.cpp:1957 msgid "Payment sent " msgstr "Betalning skickad " -#: ../../../ui.cpp:1968 +#: ../../../ui.cpp:1957 +#: ../../../ui.cpp:1962 +#: ../../../ui.cpp:2108 +#: ../../../ui.cpp:2261 +#: ../../../wallet.cpp:924 +msgid "Sending..." +msgstr "Skickar..." + +#: ../../../ui.cpp:1974 msgid "Invalid address " msgstr "Ogiltig adress " -#: ../../../ui.cpp:2023 +#: ../../../ui.cpp:2029 #, c-format msgid "Sending %s to %s" msgstr "Skickar %s till %s" -#: ../../../ui.cpp:2096 -#: ../../../ui.cpp:2129 +#: ../../../ui.cpp:2102 +#: ../../../ui.cpp:2135 msgid "CANCELLED" msgstr "AVBRUTEN" -#: ../../../ui.cpp:2100 +#: ../../../ui.cpp:2106 msgid "Cancelled" msgstr "Avbruten" -#: ../../../ui.cpp:2102 +#: ../../../ui.cpp:2108 msgid "Transfer cancelled " msgstr "Överföring avbruten " -#: ../../../ui.cpp:2155 +#: ../../../ui.cpp:2161 msgid "Error: " msgstr "Fel: " -#: ../../../ui.cpp:2174 +#: ../../../ui.cpp:2175 +#: ../../../ui.cpp:2246 +#: ../../../wallet.cpp:943 +msgid "Insufficient funds" +msgstr "Otillräckligt med pengar" + +#: ../../../ui.cpp:2180 msgid "Connecting..." msgstr "Ansluter..." -#: ../../../ui.cpp:2179 +#: ../../../ui.cpp:2185 msgid "Unable to connect" msgstr "Det gick inte att ansluta" -#: ../../../ui.cpp:2184 +#: ../../../ui.cpp:2190 msgid "Requesting public key..." msgstr "Efterfrågar publik nyckel..." -#: ../../../ui.cpp:2196 +#: ../../../ui.cpp:2202 msgid "Received public key..." msgstr "Mottagen publik nyckel..." -#: ../../../ui.cpp:2210 +#: ../../../ui.cpp:2216 msgid "Recipient is not accepting transactions sent by IP address" msgstr "Mottagaren accepterar inte transaktioner skickat från IP adress" -#: ../../../ui.cpp:2212 +#: ../../../ui.cpp:2218 msgid "Transfer was not accepted" msgstr "Överföringen var inte accepterad" -#: ../../../ui.cpp:2221 +#: ../../../ui.cpp:2227 msgid "Invalid response received" msgstr "Ogiltig respons mottagen" -#: ../../../ui.cpp:2236 +#: ../../../ui.cpp:2242 msgid "Creating transaction..." msgstr "Skapar transation..." -#: ../../../ui.cpp:2248 +#: ../../../ui.cpp:2254 #, c-format msgid "This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds" msgstr "Denna transaktion kräver en transaktionsavgift minst %s för dess belopp, komplexitet, eller användning av nyligen mottagna pengar" -#: ../../../ui.cpp:2250 +#: ../../../ui.cpp:2256 msgid "Transaction creation failed" msgstr "Misslyckades skapa transaktion" -#: ../../../ui.cpp:2257 +#: ../../../ui.cpp:2263 msgid "Transaction aborted" msgstr "Transaktion avbruten" -#: ../../../ui.cpp:2265 +#: ../../../ui.cpp:2271 msgid "Lost connection, transaction cancelled" msgstr "Förlorad anslutning, transaktionen avbruten" -#: ../../../ui.cpp:2281 +#: ../../../ui.cpp:2287 msgid "Sending payment..." msgstr "Skickar betalning..." -#: ../../../ui.cpp:2287 +#: ../../../ui.cpp:2293 msgid "The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here." msgstr "Transaktionen blev nekad. Detta kan hända om några av dina mynt i din plånbok var redan spenderad. Till exempel om du använde en kopia av wallet.dat och mynten var redan spenderad i kopian, men som inte var markerad som spenderad här." -#: ../../../ui.cpp:2296 +#: ../../../ui.cpp:2302 msgid "Waiting for confirmation..." msgstr "Väntar på bekräftelse..." -#: ../../../ui.cpp:2314 +#: ../../../ui.cpp:2320 msgid "" "The payment was sent, but the recipient was unable to verify it.\n" "The transaction is recorded and will credit to the recipient,\n" @@ -613,84 +594,84 @@ msgstr "" "Transaktionen är registrerad och kommer att kreditera mottagaren,\n" "men kommentar informationen kommer att vara tom." -#: ../../../ui.cpp:2323 +#: ../../../ui.cpp:2329 msgid "Payment was sent, but an invalid response was received" msgstr "Betalning var skickad, men en ogiltig respons var mottagen" -#: ../../../ui.cpp:2329 +#: ../../../ui.cpp:2335 msgid "Payment completed" msgstr "Betalning slutförd" -#: ../../../ui.cpp:2371 -#: ../../../ui.cpp:2517 -#: ../../../ui.cpp:2554 +#: ../../../ui.cpp:2377 +#: ../../../ui.cpp:2525 +#: ../../../ui.cpp:2565 msgid "Name" msgstr "Namn" -#: ../../../ui.cpp:2372 -#: ../../../ui.cpp:2517 -#: ../../../ui.cpp:2554 +#: ../../../ui.cpp:2378 +#: ../../../ui.cpp:2525 +#: ../../../ui.cpp:2565 msgid "Address" msgstr "Adress" -#: ../../../ui.cpp:2374 -#: ../../../ui.cpp:2529 +#: ../../../ui.cpp:2380 +#: ../../../ui.cpp:2537 msgid "Label" msgstr "Etikett" -#: ../../../ui.cpp:2375 +#: ../../../ui.cpp:2381 #: ../../../uibase.cpp:837 msgid "Bitcoin Address" msgstr "Bitcoin Adress" -#: ../../../ui.cpp:2499 +#: ../../../ui.cpp:2507 msgid "This is one of your own addresses for receiving payments and cannot be entered in the address book. " msgstr "Denna är en av dina egna adresser för mottagning av betalningar och kan inte slås in i adressboken. " -#: ../../../ui.cpp:2517 -#: ../../../ui.cpp:2523 +#: ../../../ui.cpp:2525 +#: ../../../ui.cpp:2531 msgid "Edit Address" msgstr "Ändra Adress" -#: ../../../ui.cpp:2529 +#: ../../../ui.cpp:2537 msgid "Edit Address Label" msgstr "Ändra Address Etikett" -#: ../../../ui.cpp:2554 -#: ../../../ui.cpp:2560 +#: ../../../ui.cpp:2565 +#: ../../../ui.cpp:2571 msgid "Add Address" msgstr "Lägg till Adress" -#: ../../../ui.cpp:2637 +#: ../../../ui.cpp:2649 msgid "Bitcoin" msgstr "Bitcoin" -#: ../../../ui.cpp:2639 +#: ../../../ui.cpp:2651 msgid "Bitcoin - Generating" msgstr "Bitcoin - Genererar" -#: ../../../ui.cpp:2641 +#: ../../../ui.cpp:2653 msgid "Bitcoin - (not connected)" msgstr "Bitcoin - (ej ansluten)" -#: ../../../ui.cpp:2720 +#: ../../../ui.cpp:2732 msgid "&Open Bitcoin" msgstr "&Öppna Bitcoin" -#: ../../../ui.cpp:2721 +#: ../../../ui.cpp:2733 msgid "&Send Bitcoins" msgstr "&Skicka Bitcoins" -#: ../../../ui.cpp:2722 +#: ../../../ui.cpp:2734 msgid "O&ptions..." msgstr "&Inställningar..." -#: ../../../ui.cpp:2725 +#: ../../../ui.cpp:2737 #: ../../../uibase.cpp:25 msgid "E&xit" msgstr "&Avsluta" -#: ../../../ui.cpp:2951 +#: ../../../ui.cpp:2963 msgid "Program has crashed and will terminate. " msgstr "Programmet har krachat och kommer att avslutas. " @@ -791,7 +772,6 @@ msgid "&Minimize to the tray instead of the taskbar" msgstr "&Minimerar till systemfältet istället för aktivitetsfält" #: ../../../uibase.cpp:351 -#, fuzzy msgid "Map port using &UPnP" msgstr "Mapp port använder &UPnP" @@ -812,9 +792,8 @@ msgid " &Port:" msgstr " &Port:" #: ../../../uibase.cpp:392 -#, fuzzy msgid "Optional transaction fee per KB that helps make sure your transactions are processed quickly. Most transactions are 1KB. Fee 0.01 recommended." -msgstr "Frivillig transaktionsavgift per KB som garanterar att din transaktion bearbetas snabbt. Flesta transaktioner är 1KB. Most transactions are 1KB. Avgift 0.01 rekommenderas." +msgstr "Frivillig transaktionsavgift per KB som garanterar att din transaktion bearbetas snabbt. Flesta transaktioner är 1KB. Avgift 0.01 rekommenderas." #: ../../../uibase.cpp:399 msgid "Pay transaction fee:" @@ -850,7 +829,6 @@ msgid "version" msgstr "version" #: ../../../uibase.cpp:525 -#, fuzzy msgid "" "Copyright (c) 2009-2011 Bitcoin Developers\n" "\n" @@ -865,14 +843,16 @@ msgid "" msgstr "" "Copyright (c) 2009-2011 Bitcoin Developers\n" "\n" -"This is experimental software.\n" +"Detta är en experimentell mjukvara.\n" "\n" -"Distributed under the MIT/X11 software license, see the accompanying file \n" -"license.txt or http://www.opensource.org/licenses/mit-license.php.\n" +"Distribuerad under MIT/X11 mjukvarulicens, se medföljande fil \n" +"license.txt eller http://www.opensource.org/licenses/mit-license.php.\n" "\n" -"This product includes software developed by the OpenSSL Project for use in the \n" -"OpenSSL Toolkit (http://www.openssl.org/) and cryptographic software written by \n" -"Eric Young (eay@cryptsoft.com) and UPnP software written by Thomas Bernard." +"Denna produkt inkluderar mjukvara utvecklad av OpenSSL Project för användning i \n" +"OpenSSL Toolkit (http://www.openssl.org/) och kryptografisk mjukvara skriven av \n" +"Eric Young (eay@cryptsoft.com) och UPnP mjukvara skriven av Thomas Bernard.\n" +"\n" +"Översatt av Han Lin Yap." #: ../../../uibase.cpp:581 msgid "Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)" @@ -895,9 +875,8 @@ msgid "&Amount:" msgstr "&Belopp:" #: ../../../uibase.cpp:630 -#, fuzzy msgid "T&ransfer:" -msgstr "T&ransfer:" +msgstr "&Överföring:" #: ../../../uibase.cpp:636 msgid " Standard" @@ -918,9 +897,8 @@ msgstr "" "Ansluter..." #: ../../../uibase.cpp:761 -#, fuzzy msgid "These are your Bitcoin addresses for receiving payments. You may want to give a different one to each sender so you can keep track of who is paying you. The highlighted address is displayed in the main window." -msgstr "Dessa är dina Bitcoin adresser för mottagning av betalningar. Du rekommenderas att ge olika till varje avsändare så du kan ha koll på vem som betalar dig. Den markerade adressen är visar i huvudfönstret." +msgstr "Dessa är dina Bitcoin adresser för mottagning av betalningar. Du rekommenderas att ge olika till varje avsändare så du kan ha koll på vem som betalar dig. Den markerade adressen visas i huvudfönstret." #: ../../../uibase.cpp:774 #: ../../../uibase.cpp:886 @@ -937,9 +915,8 @@ msgid "Sending" msgstr "Skickar" #: ../../../uibase.cpp:857 -#, fuzzy msgid "These are your Bitcoin addresses for receiving payments. You can give a different one to each sender to keep track of who is paying you. The highlighted address will be displayed in the main window." -msgstr "Dessa är dina Bitcoin adresser för mottagning av betalningar. Du kan ge olika till varje avsändare så du kan ha koll på vem som betalar dig. Den markerade adressen är visar i huvudfönstret." +msgstr "Dessa är dina Bitcoin adresser för mottagning av betalningar. Du kan ge olika till varje avsändare så du kan ha koll på vem som betalar dig. Den markerade adressen visas i huvudfönstret." #: ../../../uibase.cpp:870 msgid "Receiving" @@ -949,15 +926,35 @@ msgstr "Mottagning" msgid "&Delete" msgstr "&Ta bort" -#: ../../../util.cpp:866 -#, fuzzy +#: ../../../util.cpp:874 msgid "Warning: Please check that your computer's date and time are correct. If your clock is wrong Bitcoin will not work properly." -msgstr "Varning: Var god och kolla att din dator har rätt datum och klockslag. Om din klocka är fel så kommer Bitcoin inte att fungera." +msgstr "Varning: Var god och kolla att din dator har rätt datum och klockslag. Om din klocka är fel så kommer Bitcoin inte att fungera ordentligt." -#: ../../../util.cpp:899 +#: ../../../util.cpp:908 msgid "beta" msgstr "beta" +#: ../../../wallet.cpp:917 +#, c-format +msgid "Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds " +msgstr "Fel: Denna transaktion kräver en transaktionsavgift minst %s för dess belopp, komplexitet, eller användning av nyligen mottagna pengar " + +#: ../../../wallet.cpp:919 +msgid "Error: Transaction creation failed " +msgstr "Fel: Misslyckades att skapa transaktion " + +#: ../../../wallet.cpp:928 +msgid "Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here." +msgstr "Fel: Transaktionen blev nekad. Detta kan hända om några av dina mynt i din plånbok var redan spenderad. Till exempel om du använde en kopia av wallet.dat och mynten var redan spenderad i kopian, men som inte var markerad som spenderad här." + +#: ../../../wallet.cpp:941 +msgid "Invalid amount" +msgstr "Ogiltig belopp" + +#: ../../../wallet.cpp:948 +msgid "Invalid bitcoin address" +msgstr "Ogiltig bitcoin adress" + #: ../../../uibase.h:147 msgid "Transaction Details" msgstr "Transaktion detaljer" @@ -974,5 +971,3 @@ msgstr "Om Bitcoin" msgid "Your Bitcoin Addresses" msgstr "Dina Bitcoin Adresser" -#~ msgid " beta" -#~ msgstr " beta" diff --git a/share/pixmaps/bitcoin.ico b/share/pixmaps/bitcoin.ico index cdec9a037..734d21701 100644 Binary files a/share/pixmaps/bitcoin.ico and b/share/pixmaps/bitcoin.ico differ diff --git a/share/pixmaps/nsis-header.bmp b/share/pixmaps/nsis-header.bmp new file mode 100644 index 000000000..9ab0ce259 Binary files /dev/null and b/share/pixmaps/nsis-header.bmp differ diff --git a/share/pixmaps/nsis-wizard.bmp b/share/pixmaps/nsis-wizard.bmp new file mode 100644 index 000000000..71255c685 Binary files /dev/null and b/share/pixmaps/nsis-wizard.bmp differ diff --git a/share/setup.nsi b/share/setup.nsi index 8677d334e..b4bf3cff4 100644 --- a/share/setup.nsi +++ b/share/setup.nsi @@ -1,15 +1,20 @@ Name Bitcoin RequestExecutionLevel highest +SetCompressor /SOLID lzma # General Symbol Definitions !define REGKEY "SOFTWARE\$(^Name)" -!define VERSION 0.3.24 +!define VERSION 0.3.25 !define COMPANY "Bitcoin project" !define URL http://www.bitcoin.org/ # MUI Symbol Definitions !define MUI_ICON "../share/pixmaps/bitcoin.ico" +!define MUI_WELCOMEFINISHPAGE_BITMAP "../share/pixmaps/nsis-wizard.bmp" +!define MUI_HEADERIMAGE +!define MUI_HEADERIMAGE_RIGHT +!define MUI_HEADERIMAGE_BITMAP "../share/pixmaps/nsis-header.bmp" !define MUI_FINISHPAGE_NOAUTOCLOSE !define MUI_STARTMENUPAGE_REGISTRY_ROOT HKLM !define MUI_STARTMENUPAGE_REGISTRY_KEY ${REGKEY} @@ -17,6 +22,7 @@ RequestExecutionLevel highest !define MUI_STARTMENUPAGE_DEFAULTFOLDER Bitcoin !define MUI_FINISHPAGE_RUN $INSTDIR\bitcoin.exe !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico" +!define MUI_UNWELCOMEFINISHPAGE_BITMAP "../share/pixmaps/nsis-wizard.bmp" !define MUI_UNFINISHPAGE_NOAUTOCLOSE # Included files @@ -39,12 +45,13 @@ Var StartMenuGroup !insertmacro MUI_LANGUAGE English # Installer attributes -OutFile bitcoin-0.3.24-win32-setup.exe +OutFile bitcoin-0.3.25-win32-setup.exe InstallDir $PROGRAMFILES\Bitcoin CRCCheck on XPStyle on +BrandingText " " ShowInstDetails show -VIProductVersion 0.3.24.0 +VIProductVersion 0.3.25.0 VIAddVersionKey ProductName Bitcoin VIAddVersionKey ProductVersion "${VERSION}" VIAddVersionKey CompanyName "${COMPANY}" diff --git a/share/uiproject.fbp b/share/uiproject.fbp index d9d46382d..d5e6b1e36 100644 --- a/share/uiproject.fbp +++ b/share/uiproject.fbp @@ -162,6 +162,36 @@ OnMenuOptionsChangeYourAddress + + + 0 + 1 + + wxID_ANY + wxITEM_NORMAL + &Encrypt Wallet... + m_menuOptionsEncryptWallet + public + + + OnMenuOptionsEncryptWallet + + + + + 0 + 1 + + wxID_ANY + wxITEM_NORMAL + &Change Wallet Encryption Passphrase... + m_menuOptionsChangeWalletPassphrase + public + + + OnMenuOptionsChangeWalletPassphrase + + 0 diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 0493c6a08..872f52eb8 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -36,6 +36,9 @@ void ThreadRPCServer2(void* parg); typedef Value(*rpcfn_type)(const Array& params, bool fHelp); extern map mapCallTable; +static int64 nWalletUnlockTime; +static CCriticalSection cs_nWalletUnlockTime; + Object JSONRPCError(int code, const string& message) { @@ -309,7 +312,10 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("hashespersec", gethashespersec(params, false))); obj.push_back(Pair("testnet", fTestNet)); obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); + obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize())); obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); + if (pwalletMain->IsCrypted()) + obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime)); obj.push_back(Pair("errors", GetWarnings("statusbar"))); return obj; } @@ -324,13 +330,19 @@ Value getnewaddress(const Array& params, bool fHelp) "If [account] is specified (recommended), it is added to the address book " "so payments received with the address will be credited to [account]."); + if (!pwalletMain->IsLocked()) + pwalletMain->TopUpKeyPool(); + + if (pwalletMain->GetKeyPoolSize() < 1) + throw JSONRPCError(-12, "Error: Keypool ran out, please call keypoolrefill first"); + // Parse the account first so we don't generate a key if there's an error string strAccount; if (params.size() > 0) strAccount = AccountFromValue(params[0]); // Generate a new key that is added to wallet - string strAddress = PubKeyToAddress(pwalletMain->GetKeyFromKeyPool()); + string strAddress = PubKeyToAddress(pwalletMain->GetOrReuseKeyFromPool()); // This could be done in the same main CS as GetKeyFromKeyPool. CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) @@ -346,37 +358,48 @@ string GetAccountAddress(string strAccount, bool bForceNew=false) string strAddress; CWalletDB walletdb(pwalletMain->strWalletFile); - walletdb.TxnBegin(); CAccount account; - walletdb.ReadAccount(strAccount, account); - - // Check if the current key has been used - if (!account.vchPubKey.empty()) + CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) { - CScript scriptPubKey; - scriptPubKey.SetBitcoinAddress(account.vchPubKey); - for (map::iterator it = pwalletMain->mapWallet.begin(); - it != pwalletMain->mapWallet.end() && !account.vchPubKey.empty(); - ++it) + walletdb.ReadAccount(strAccount, account); + + bool bKeyUsed = false; + + // Check if the current key has been used + if (!account.vchPubKey.empty()) { - const CWalletTx& wtx = (*it).second; - BOOST_FOREACH(const CTxOut& txout, wtx.vout) - if (txout.scriptPubKey == scriptPubKey) - account.vchPubKey.clear(); + CScript scriptPubKey; + scriptPubKey.SetBitcoinAddress(account.vchPubKey); + for (map::iterator it = pwalletMain->mapWallet.begin(); + it != pwalletMain->mapWallet.end() && !account.vchPubKey.empty(); + ++it) + { + const CWalletTx& wtx = (*it).second; + BOOST_FOREACH(const CTxOut& txout, wtx.vout) + if (txout.scriptPubKey == scriptPubKey) + bKeyUsed = true; + } + } + + // Generate a new key + if (account.vchPubKey.empty() || bForceNew || bKeyUsed) + { + if (pwalletMain->GetKeyPoolSize() < 1) + { + if (bKeyUsed || bForceNew) + throw JSONRPCError(-12, "Error: Keypool ran out, please call topupkeypool first"); + } + else + { + account.vchPubKey = pwalletMain->GetOrReuseKeyFromPool(); + string strAddress = PubKeyToAddress(account.vchPubKey); + pwalletMain->SetAddressBookName(strAddress, strAccount); + walletdb.WriteAccount(strAccount, account); + } } } - // Generate a new key - if (account.vchPubKey.empty() || bForceNew) - { - account.vchPubKey = pwalletMain->GetKeyFromKeyPool(); - string strAddress = PubKeyToAddress(account.vchPubKey); - pwalletMain->SetAddressBookName(strAddress, strAccount); - walletdb.WriteAccount(strAccount, account); - } - - walletdb.TxnCommit(); strAddress = PubKeyToAddress(account.vchPubKey); return strAddress; @@ -510,7 +533,12 @@ Value settxfee(const Array& params, bool fHelp) Value sendtoaddress(const Array& params, bool fHelp) { - if (fHelp || params.size() < 2 || params.size() > 4) + if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4)) + throw runtime_error( + "sendtoaddress [comment] [comment-to]\n" + " is a real and is rounded to the nearest 0.00000001\n" + "requires wallet passphrase to be set with walletpassphrase first"); + if (!pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4)) throw runtime_error( "sendtoaddress [comment] [comment-to]\n" " is a real and is rounded to the nearest 0.00000001"); @@ -528,7 +556,11 @@ Value sendtoaddress(const Array& params, bool fHelp) wtx.mapValue["to"] = params[3].get_str(); CRITICAL_BLOCK(cs_main) + CRITICAL_BLOCK(pwalletMain->cs_vMasterKey) { + if(pwalletMain->IsLocked()) + throw JSONRPCError(-14, "Error: The wallet passphrase entered was incorrect."); + string strError = pwalletMain->SendMoneyToBitcoinAddress(strAddress, nAmount, wtx); if (strError != "") throw JSONRPCError(-4, strError); @@ -674,7 +706,7 @@ int64 GetAccountBalance(const string& strAccount, int nMinDepth) Value getbalance(const Array& params, bool fHelp) { - if (fHelp || params.size() < 0 || params.size() > 2) + if (fHelp || params.size() > 2) throw runtime_error( "getbalance [account] [minconf=1]\n" "If [account] is not specified, returns the server's total available balance.\n" @@ -733,9 +765,9 @@ Value movecmd(const Array& params, bool fHelp) string strFrom = AccountFromValue(params[0]); string strTo = AccountFromValue(params[1]); int64 nAmount = AmountFromValue(params[2]); - int nMinDepth = 1; if (params.size() > 3) - nMinDepth = params[3].get_int(); + // unused parameter, used to be nMinDepth, keep type-checking it though + (void)params[3].get_int(); string strComment; if (params.size() > 4) strComment = params[4].get_str(); @@ -773,7 +805,12 @@ Value movecmd(const Array& params, bool fHelp) Value sendfrom(const Array& params, bool fHelp) { - if (fHelp || params.size() < 3 || params.size() > 6) + if (pwalletMain->IsCrypted() && (fHelp || params.size() < 3 || params.size() > 6)) + throw runtime_error( + "sendfrom [minconf=1] [comment] [comment-to]\n" + " is a real and is rounded to the nearest 0.00000001\n" + "requires wallet passphrase to be set with walletpassphrase first"); + if (!pwalletMain->IsCrypted() && (fHelp || params.size() < 3 || params.size() > 6)) throw runtime_error( "sendfrom [minconf=1] [comment] [comment-to]\n" " is a real and is rounded to the nearest 0.00000001"); @@ -794,7 +831,11 @@ Value sendfrom(const Array& params, bool fHelp) CRITICAL_BLOCK(cs_main) CRITICAL_BLOCK(pwalletMain->cs_mapWallet) + CRITICAL_BLOCK(pwalletMain->cs_vMasterKey) { + if(pwalletMain->IsLocked()) + throw JSONRPCError(-14, "Error: The wallet passphrase entered was incorrect."); + // Check funds int64 nBalance = GetAccountBalance(strAccount, nMinDepth); if (nAmount > nBalance) @@ -809,9 +850,15 @@ Value sendfrom(const Array& params, bool fHelp) return wtx.GetHash().GetHex(); } + Value sendmany(const Array& params, bool fHelp) { - if (fHelp || params.size() < 2 || params.size() > 4) + if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4)) + throw runtime_error( + "sendmany {address:amount,...} [minconf=1] [comment]\n" + "amounts are double-precision floating point numbers\n" + "requires wallet passphrase to be set with walletpassphrase first"); + if (!pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 4)) throw runtime_error( "sendmany {address:amount,...} [minconf=1] [comment]\n" "amounts are double-precision floating point numbers"); @@ -851,7 +898,11 @@ Value sendmany(const Array& params, bool fHelp) CRITICAL_BLOCK(cs_main) CRITICAL_BLOCK(pwalletMain->cs_mapWallet) + CRITICAL_BLOCK(pwalletMain->cs_vMasterKey) { + if(pwalletMain->IsLocked()) + throw JSONRPCError(-14, "Error: The wallet passphrase entered was incorrect."); + // Check funds int64 nBalance = GetAccountBalance(strAccount, nMinDepth); if (totalAmount > nBalance) @@ -1281,6 +1332,219 @@ Value backupwallet(const Array& params, bool fHelp) } +Value keypoolrefill(const Array& params, bool fHelp) +{ + if (pwalletMain->IsCrypted() && (fHelp || params.size() > 0)) + throw runtime_error( + "keypoolrefill\n" + "Fills the keypool, requires wallet passphrase to be set."); + if (!pwalletMain->IsCrypted() && (fHelp || params.size() > 0)) + throw runtime_error( + "keypoolrefill\n" + "Fills the keypool."); + + CRITICAL_BLOCK(pwalletMain->cs_vMasterKey) + { + if (pwalletMain->IsLocked()) + throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first."); + + pwalletMain->TopUpKeyPool(); + } + + if (pwalletMain->GetKeyPoolSize() < GetArg("-keypool", 100)) + throw JSONRPCError(-4, "Error refreshing keypool."); + + return Value::null; +} + + +void ThreadTopUpKeyPool(void* parg) +{ + pwalletMain->TopUpKeyPool(); +} + +void ThreadCleanWalletPassphrase(void* parg) +{ + int64 nMyWakeTime = GetTime() + *((int*)parg); + + if (nWalletUnlockTime == 0) + { + CRITICAL_BLOCK(cs_nWalletUnlockTime) + { + nWalletUnlockTime = nMyWakeTime; + } + + while (GetTime() < nWalletUnlockTime) + Sleep(GetTime() - nWalletUnlockTime); + + CRITICAL_BLOCK(cs_nWalletUnlockTime) + { + nWalletUnlockTime = 0; + } + } + else + { + CRITICAL_BLOCK(cs_nWalletUnlockTime) + { + if (nWalletUnlockTime < nMyWakeTime) + nWalletUnlockTime = nMyWakeTime; + } + free(parg); + return; + } + + pwalletMain->Lock(); + + delete (int*)parg; +} + +Value walletpassphrase(const Array& params, bool fHelp) +{ + if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2)) + throw runtime_error( + "walletpassphrase \n" + "Stores the wallet decryption key in memory for seconds."); + if (fHelp) + return true; + if (!pwalletMain->IsCrypted()) + throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletpassphrase was called."); + + if (!pwalletMain->IsLocked()) + throw JSONRPCError(-17, "Error: Wallet is already unlocked."); + + // Note that the walletpassphrase is stored in params[0] which is not mlock()ed + string strWalletPass; + strWalletPass.reserve(100); + mlock(&strWalletPass[0], strWalletPass.capacity()); + strWalletPass = params[0].get_str(); + + CRITICAL_BLOCK(pwalletMain->cs_vMasterKey) + { + if (strWalletPass.length() > 0) + { + if (!pwalletMain->Unlock(strWalletPass)) + { + fill(strWalletPass.begin(), strWalletPass.end(), '\0'); + munlock(&strWalletPass[0], strWalletPass.capacity()); + throw JSONRPCError(-14, "Error: The wallet passphrase entered was incorrect."); + } + fill(strWalletPass.begin(), strWalletPass.end(), '\0'); + munlock(&strWalletPass[0], strWalletPass.capacity()); + } + else + throw runtime_error( + "walletpassphrase \n" + "Stores the wallet decryption key in memory for seconds."); + } + + CreateThread(ThreadTopUpKeyPool, NULL); + int* pnSleepTime = new int(params[1].get_int()); + CreateThread(ThreadCleanWalletPassphrase, pnSleepTime); + + return Value::null; +} + + +Value walletpassphrasechange(const Array& params, bool fHelp) +{ + if (pwalletMain->IsCrypted() && (fHelp || params.size() != 2)) + throw runtime_error( + "walletpassphrasechange \n" + "Changes the wallet passphrase from to ."); + if (fHelp) + return true; + if (!pwalletMain->IsCrypted()) + throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletpassphrasechange was called."); + + string strOldWalletPass; + strOldWalletPass.reserve(100); + mlock(&strOldWalletPass[0], strOldWalletPass.capacity()); + strOldWalletPass = params[0].get_str(); + + string strNewWalletPass; + strNewWalletPass.reserve(100); + mlock(&strNewWalletPass[0], strNewWalletPass.capacity()); + strNewWalletPass = params[1].get_str(); + + if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1) + throw runtime_error( + "walletpassphrasechange \n" + "Changes the wallet passphrase from to ."); + + if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) + { + fill(strOldWalletPass.begin(), strOldWalletPass.end(), '\0'); + fill(strNewWalletPass.begin(), strNewWalletPass.end(), '\0'); + munlock(&strOldWalletPass[0], strOldWalletPass.capacity()); + munlock(&strNewWalletPass[0], strNewWalletPass.capacity()); + throw JSONRPCError(-14, "Error: The wallet passphrase entered was incorrect."); + } + fill(strNewWalletPass.begin(), strNewWalletPass.end(), '\0'); + fill(strOldWalletPass.begin(), strOldWalletPass.end(), '\0'); + munlock(&strOldWalletPass[0], strOldWalletPass.capacity()); + munlock(&strNewWalletPass[0], strNewWalletPass.capacity()); + + return Value::null; +} + + +Value walletlock(const Array& params, bool fHelp) +{ + if (pwalletMain->IsCrypted() && (fHelp || params.size() != 0)) + throw runtime_error( + "walletlock\n" + "Removes the wallet encryption key from memory, locking the wallet.\n" + "After calling this method, you will need to call walletpassphrase again\n" + "before being able to call any methods which require the wallet to be unlocked."); + if (fHelp) + return true; + if (!pwalletMain->IsCrypted()) + throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletlock was called."); + + pwalletMain->Lock(); + CRITICAL_BLOCK(cs_nWalletUnlockTime) + { + nWalletUnlockTime = 0; + } + + return Value::null; +} + + +Value encryptwallet(const Array& params, bool fHelp) +{ + if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1)) + throw runtime_error( + "encryptwallet \n" + "Encrypts the wallet with ."); + if (fHelp) + return true; + if (pwalletMain->IsCrypted()) + throw JSONRPCError(-15, "Error: running with an encrypted wallet, but encryptwallet was called."); + + string strWalletPass; + strWalletPass.reserve(100); + mlock(&strWalletPass[0], strWalletPass.capacity()); + strWalletPass = params[0].get_str(); + + if (strWalletPass.length() < 1) + throw runtime_error( + "encryptwallet \n" + "Encrypts the wallet with ."); + + if (!pwalletMain->EncryptWallet(strWalletPass)) + { + fill(strWalletPass.begin(), strWalletPass.end(), '\0'); + munlock(&strWalletPass[0], strWalletPass.capacity()); + throw JSONRPCError(-16, "Error: Failed to encrypt the wallet."); + } + fill(strWalletPass.begin(), strWalletPass.end(), '\0'); + munlock(&strWalletPass[0], strWalletPass.capacity()); + + return Value::null; +} + + Value validateaddress(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) @@ -1432,44 +1696,49 @@ Value getwork(const Array& params, bool fHelp) pair pCallTable[] = { - make_pair("help", &help), - make_pair("stop", &stop), - make_pair("getblockcount", &getblockcount), - make_pair("getblocknumber", &getblocknumber), - make_pair("getconnectioncount", &getconnectioncount), - make_pair("getdifficulty", &getdifficulty), - make_pair("getgenerate", &getgenerate), - make_pair("setgenerate", &setgenerate), - make_pair("gethashespersec", &gethashespersec), - make_pair("getinfo", &getinfo), - make_pair("getnewaddress", &getnewaddress), - make_pair("getaccountaddress", &getaccountaddress), - make_pair("setaccount", &setaccount), - make_pair("setlabel", &setaccount), // deprecated - make_pair("getaccount", &getaccount), - make_pair("getlabel", &getaccount), // deprecated - make_pair("getaddressesbyaccount", &getaddressesbyaccount), - make_pair("getaddressesbylabel", &getaddressesbyaccount), // deprecated - make_pair("sendtoaddress", &sendtoaddress), - make_pair("getamountreceived", &getreceivedbyaddress), // deprecated, renamed to getreceivedbyaddress - make_pair("getallreceived", &listreceivedbyaddress), // deprecated, renamed to listreceivedbyaddress - make_pair("getreceivedbyaddress", &getreceivedbyaddress), - make_pair("getreceivedbyaccount", &getreceivedbyaccount), - make_pair("getreceivedbylabel", &getreceivedbyaccount), // deprecated - make_pair("listreceivedbyaddress", &listreceivedbyaddress), - make_pair("listreceivedbyaccount", &listreceivedbyaccount), - make_pair("listreceivedbylabel", &listreceivedbyaccount), // deprecated - make_pair("backupwallet", &backupwallet), - make_pair("validateaddress", &validateaddress), - make_pair("getbalance", &getbalance), - make_pair("move", &movecmd), - make_pair("sendfrom", &sendfrom), - make_pair("sendmany", &sendmany), - make_pair("gettransaction", &gettransaction), - make_pair("listtransactions", &listtransactions), - make_pair("getwork", &getwork), - make_pair("listaccounts", &listaccounts), - make_pair("settxfee", &settxfee), + make_pair("help", &help), + make_pair("stop", &stop), + make_pair("getblockcount", &getblockcount), + make_pair("getblocknumber", &getblocknumber), + make_pair("getconnectioncount", &getconnectioncount), + make_pair("getdifficulty", &getdifficulty), + make_pair("getgenerate", &getgenerate), + make_pair("setgenerate", &setgenerate), + make_pair("gethashespersec", &gethashespersec), + make_pair("getinfo", &getinfo), + make_pair("getnewaddress", &getnewaddress), + make_pair("getaccountaddress", &getaccountaddress), + make_pair("setaccount", &setaccount), + make_pair("setlabel", &setaccount), // deprecated + make_pair("getaccount", &getaccount), + make_pair("getlabel", &getaccount), // deprecated + make_pair("getaddressesbyaccount", &getaddressesbyaccount), + make_pair("getaddressesbylabel", &getaddressesbyaccount), // deprecated + make_pair("sendtoaddress", &sendtoaddress), + make_pair("getamountreceived", &getreceivedbyaddress), // deprecated, renamed to getreceivedbyaddress + make_pair("getallreceived", &listreceivedbyaddress), // deprecated, renamed to listreceivedbyaddress + make_pair("getreceivedbyaddress", &getreceivedbyaddress), + make_pair("getreceivedbyaccount", &getreceivedbyaccount), + make_pair("getreceivedbylabel", &getreceivedbyaccount), // deprecated + make_pair("listreceivedbyaddress", &listreceivedbyaddress), + make_pair("listreceivedbyaccount", &listreceivedbyaccount), + make_pair("listreceivedbylabel", &listreceivedbyaccount), // deprecated + make_pair("backupwallet", &backupwallet), + make_pair("keypoolrefill", &keypoolrefill), + make_pair("walletpassphrase", &walletpassphrase), + make_pair("walletpassphrasechange", &walletpassphrasechange), + make_pair("walletlock", &walletlock), + make_pair("encryptwallet", &encryptwallet), + make_pair("validateaddress", &validateaddress), + make_pair("getbalance", &getbalance), + make_pair("move", &movecmd), + make_pair("sendfrom", &sendfrom), + make_pair("sendmany", &sendmany), + make_pair("gettransaction", &gettransaction), + make_pair("listtransactions", &listtransactions), + make_pair("getwork", &getwork), + make_pair("listaccounts", &listaccounts), + make_pair("settxfee", &settxfee), }; map mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0])); @@ -1493,6 +1762,9 @@ string pAllowInSafeMode[] = "getaddressesbyaccount", "getaddressesbylabel", // deprecated "backupwallet", + "keypoolrefill", + "walletpassphrase", + "walletlock", "validateaddress", "getwork", }; @@ -2130,6 +2402,7 @@ int CommandLineRPC(int argc, char *argv[]) if (strMethod == "listtransactions" && n > 1) ConvertTo(params[1]); if (strMethod == "listtransactions" && n > 2) ConvertTo(params[2]); if (strMethod == "listaccounts" && n > 0) ConvertTo(params[0]); + if (strMethod == "walletpassphrase" && n > 1) ConvertTo(params[1]); if (strMethod == "sendmany" && n > 1) { string s = params[1].get_str(); @@ -2146,7 +2419,6 @@ int CommandLineRPC(int argc, char *argv[]) // Parse reply const Value& result = find_value(reply, "result"); const Value& error = find_value(reply, "error"); - const Value& id = find_value(reply, "id"); if (error.type() != null_type) { diff --git a/src/crypter.cpp b/src/crypter.cpp new file mode 100644 index 000000000..9a8e6ca89 --- /dev/null +++ b/src/crypter.cpp @@ -0,0 +1,132 @@ +// Copyright (c) 2011 The Bitcoin Developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include +#include +#include "headers.h" +#ifdef __WXMSW__ +#include +#endif + +#include "crypter.h" +#include "main.h" +#include "util.h" + +bool CCrypter::SetKeyFromPassphrase(const std::string& strKeyData, const std::vector& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod) +{ + if (nRounds < 1 || chSalt.size() != WALLET_CRYPTO_SALT_SIZE) + return false; + + // Try to keep the keydata out of swap (and be a bit over-careful to keep the IV that we don't even use out of swap) + // Note that this does nothing about suspend-to-disk (which will put all our key data on disk) + // Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process. + mlock(&chKey[0], sizeof chKey); + mlock(&chIV[0], sizeof chIV); + + int i = 0; + if (nDerivationMethod == 0) + i = EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha512(), &chSalt[0], + (unsigned char *)&strKeyData[0], strKeyData.size(), nRounds, chKey, chIV); + + if (i != WALLET_CRYPTO_KEY_SIZE) + { + memset(&chKey, 0, sizeof chKey); + memset(&chIV, 0, sizeof chIV); + return false; + } + + fKeySet = true; + return true; +} + +bool CCrypter::SetKey(const CKeyingMaterial& chNewKey, const std::vector& chNewIV) +{ + if (chNewKey.size() != WALLET_CRYPTO_KEY_SIZE || chNewIV.size() != WALLET_CRYPTO_KEY_SIZE) + return false; + + // Try to keep the keydata out of swap + // Note that this does nothing about suspend-to-disk (which will put all our key data on disk) + // Note as well that at no point in this program is any attempt made to prevent stealing of keys by reading the memory of the running process. + mlock(&chKey[0], sizeof chKey); + mlock(&chIV[0], sizeof chIV); + + memcpy(&chKey[0], &chNewKey[0], sizeof chKey); + memcpy(&chIV[0], &chNewIV[0], sizeof chIV); + + fKeySet = true; + return true; +} + +bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector &vchCiphertext) +{ + if (!fKeySet) + return false; + + // max ciphertext len for a n bytes of plaintext is + // n + AES_BLOCK_SIZE - 1 bytes + int nLen = vchPlaintext.size(); + int nCLen = nLen + AES_BLOCK_SIZE, nFLen = 0; + vchCiphertext = std::vector (nCLen); + + EVP_CIPHER_CTX ctx; + + EVP_CIPHER_CTX_init(&ctx); + EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); + + EVP_EncryptUpdate(&ctx, &vchCiphertext[0], &nCLen, &vchPlaintext[0], nLen); + EVP_EncryptFinal_ex(&ctx, (&vchCiphertext[0])+nCLen, &nFLen); + + EVP_CIPHER_CTX_cleanup(&ctx); + + vchCiphertext.resize(nCLen + nFLen); + return true; +} + +bool CCrypter::Decrypt(const std::vector& vchCiphertext, CKeyingMaterial& vchPlaintext) +{ + if (!fKeySet) + return false; + + // plaintext will always be equal to or lesser than length of ciphertext + int nLen = vchCiphertext.size(); + int nPLen = nLen, nFLen = 0; + + vchPlaintext = CKeyingMaterial(nPLen); + + EVP_CIPHER_CTX ctx; + + EVP_CIPHER_CTX_init(&ctx); + EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, chKey, chIV); + + EVP_DecryptUpdate(&ctx, &vchPlaintext[0], &nPLen, &vchCiphertext[0], nLen); + EVP_DecryptFinal_ex(&ctx, (&vchPlaintext[0])+nPLen, &nFLen); + + EVP_CIPHER_CTX_cleanup(&ctx); + + vchPlaintext.resize(nPLen + nFLen); + return true; +} + + +bool EncryptSecret(CKeyingMaterial& vMasterKey, const CSecret &vchPlaintext, const uint256& nIV, std::vector &vchCiphertext) +{ + CCrypter cKeyCrypter; + std::vector chIV(WALLET_CRYPTO_KEY_SIZE); + memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE); + if(!cKeyCrypter.SetKey(vMasterKey, chIV)) + return false; + return cKeyCrypter.Encrypt((CKeyingMaterial)vchPlaintext, vchCiphertext); +} + +bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector& vchCiphertext, const uint256& nIV, CSecret& vchPlaintext) +{ + CCrypter cKeyCrypter; + std::vector chIV(WALLET_CRYPTO_KEY_SIZE); + memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE); + if(!cKeyCrypter.SetKey(vMasterKey, chIV)) + return false; + return cKeyCrypter.Decrypt(vchCiphertext, *((CKeyingMaterial*)&vchPlaintext)); +} diff --git a/src/crypter.h b/src/crypter.h new file mode 100644 index 000000000..5b95ea415 --- /dev/null +++ b/src/crypter.h @@ -0,0 +1,96 @@ +// Copyright (c) 2011 The Bitcoin Developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. +#ifndef __CRYPTER_H__ +#define __CRYPTER_H__ + +#include "key.h" + +const unsigned int WALLET_CRYPTO_KEY_SIZE = 32; +const unsigned int WALLET_CRYPTO_SALT_SIZE = 8; + +/* +Private key encryption is done based on a CMasterKey, +which holds a salt and random encryption key. + +CMasterKeys is encrypted using AES-256-CBC using a key +derived using derivation method nDerivationMethod +(0 == EVP_sha512()) and derivation iterations nDeriveIterations. +vchOtherDerivationParameters is provided for alternative algorithms +which may require more parameters (such as scrypt). + +Wallet Private Keys are then encrypted using AES-256-CBC +with the double-sha256 of the private key as the IV, and the +master key's key as the encryption key. +*/ + +class CMasterKey +{ +public: + std::vector vchCryptedKey; + std::vector vchSalt; + // 0 = EVP_sha512() + // 1 = scrypt() + unsigned int nDerivationMethod; + unsigned int nDeriveIterations; + // Use this for more parameters to key derivation, + // such as the various parameters to scrypt + std::vector vchOtherDerivationParameters; + + IMPLEMENT_SERIALIZE + ( + READWRITE(vchCryptedKey); + READWRITE(vchSalt); + READWRITE(nDerivationMethod); + READWRITE(nDeriveIterations); + READWRITE(vchOtherDerivationParameters); + ) + CMasterKey() + { + // 25000 rounds is just under 0.1 seconds on a 1.86 GHz Pentium M + // ie slightly lower than the lowest hardware we need bother supporting + nDeriveIterations = 25000; + nDerivationMethod = 0; + vchOtherDerivationParameters = std::vector(0); + } +}; + +typedef std::vector > CKeyingMaterial; + +class CCrypter +{ +private: + unsigned char chKey[WALLET_CRYPTO_KEY_SIZE]; + unsigned char chIV[WALLET_CRYPTO_KEY_SIZE]; + bool fKeySet; + +public: + bool SetKeyFromPassphrase(const std::string &strKeyData, const std::vector& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod); + bool Encrypt(const CKeyingMaterial& vchPlaintext, std::vector &vchCiphertext); + bool Decrypt(const std::vector& vchCiphertext, CKeyingMaterial& vchPlaintext); + bool SetKey(const CKeyingMaterial& chNewKey, const std::vector& chNewIV); + + void CleanKey() + { + memset(&chKey, 0, sizeof chKey); + memset(&chIV, 0, sizeof chIV); + munlock(&chKey, sizeof chKey); + munlock(&chIV, sizeof chIV); + fKeySet = false; + } + + CCrypter() + { + fKeySet = false; + } + + ~CCrypter() + { + CleanKey(); + } +}; + +bool EncryptSecret(CKeyingMaterial& vMasterKey, const CSecret &vchPlaintext, const uint256& nIV, std::vector &vchCiphertext); +bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector &vchCiphertext, const uint256& nIV, CSecret &vchPlaintext); + +#endif diff --git a/src/cryptopp/cpu.cpp b/src/cryptopp/cpu.cpp index 3e4680421..8789dc317 100644 --- a/src/cryptopp/cpu.cpp +++ b/src/cryptopp/cpu.cpp @@ -80,7 +80,7 @@ bool CpuId(word32 input, word32 *output) #endif } -#ifndef _MSC_VER +#if !CRYPTOPP_BOOL_X64 && !defined(_MSC_VER) && defined(__GNUC__) static jmp_buf s_jmpNoSSE2; static void SigIllHandlerSSE2(int) { diff --git a/src/db.cpp b/src/db.cpp index f044355a3..6692db239 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -627,8 +627,6 @@ int64 CWalletDB::GetAccountCreditDebit(const string& strAccount) void CWalletDB::ListAccountCreditDebit(const string& strAccount, list& entries) { - int64 nCreditDebit = 0; - bool fAllAccounts = (strAccount == "*"); Dbc* pcursor = GetCursor(); @@ -670,7 +668,7 @@ void CWalletDB::ListAccountCreditDebit(const string& strAccount, listvchDefaultKey.clear(); int nFileVersion = 0; @@ -685,12 +683,12 @@ bool CWalletDB::LoadWallet(CWallet* pwallet) //// todo: shouldn't we catch exceptions and try to recover and continue? CRITICAL_BLOCK(pwallet->cs_mapWallet) - CRITICAL_BLOCK(pwallet->cs_mapKeys) + CRITICAL_BLOCK(pwallet->cs_KeyStore) { // Get cursor Dbc* pcursor = GetCursor(); if (!pcursor) - return false; + return DB_CORRUPT; loop { @@ -701,7 +699,7 @@ bool CWalletDB::LoadWallet(CWallet* pwallet) if (ret == DB_NOTFOUND) break; else if (ret != 0) - return false; + return DB_CORRUPT; // Unserialize // Taking advantage of the fact that pair serialization @@ -765,14 +763,42 @@ bool CWalletDB::LoadWallet(CWallet* pwallet) { vector vchPubKey; ssKey >> vchPubKey; - CWalletKey wkey; + CKey key; if (strType == "key") - ssValue >> wkey.vchPrivKey; + { + CPrivKey pkey; + ssValue >> pkey; + key.SetPrivKey(pkey); + } else + { + CWalletKey wkey; ssValue >> wkey; - - pwallet->mapKeys[vchPubKey] = wkey.vchPrivKey; - mapPubKeys[Hash160(vchPubKey)] = vchPubKey; + key.SetPrivKey(wkey.vchPrivKey); + } + if (!pwallet->LoadKey(key)) + return DB_CORRUPT; + } + else if (strType == "mkey") + { + unsigned int nID; + ssKey >> nID; + CMasterKey kMasterKey; + ssValue >> kMasterKey; + if(pwallet->mapMasterKeys.count(nID) != 0) + return DB_CORRUPT; + pwallet->mapMasterKeys[nID] = kMasterKey; + if (pwallet->nMasterKeyMaxID < nID) + pwallet->nMasterKeyMaxID = nID; + } + else if (strType == "ckey") + { + vector vchPubKey; + ssKey >> vchPubKey; + vector vchPrivKey; + ssValue >> vchPrivKey; + if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey)) + return DB_CORRUPT; } else if (strType == "defaultkey") { @@ -800,7 +826,6 @@ bool CWalletDB::LoadWallet(CWallet* pwallet) if (strKey == "fGenerateBitcoins") ssValue >> fGenerateBitcoins; #endif if (strKey == "nTransactionFee") ssValue >> nTransactionFee; - if (strKey == "addrIncoming") ssValue >> addrIncoming; if (strKey == "fLimitProcessors") ssValue >> fLimitProcessors; if (strKey == "nLimitProcessors") ssValue >> nLimitProcessors; if (strKey == "fMinimizeToTray") ssValue >> fMinimizeToTray; @@ -809,6 +834,13 @@ bool CWalletDB::LoadWallet(CWallet* pwallet) if (strKey == "addrProxy") ssValue >> addrProxy; if (fHaveUPnP && strKey == "fUseUPnP") ssValue >> fUseUPnP; } + else if (strType == "minversion") + { + int nMinVersion = 0; + ssValue >> nMinVersion; + if (nMinVersion > VERSION) + return DB_TOO_NEW; + } } pcursor->close(); } @@ -819,7 +851,6 @@ bool CWalletDB::LoadWallet(CWallet* pwallet) printf("nFileVersion = %d\n", nFileVersion); printf("fGenerateBitcoins = %d\n", fGenerateBitcoins); printf("nTransactionFee = %"PRI64d"\n", nTransactionFee); - printf("addrIncoming = %s\n", addrIncoming.ToString().c_str()); printf("fMinimizeToTray = %d\n", fMinimizeToTray); printf("fMinimizeOnClose = %d\n", fMinimizeOnClose); printf("fUseProxy = %d\n", fUseProxy); @@ -839,7 +870,7 @@ bool CWalletDB::LoadWallet(CWallet* pwallet) } - return true; + return DB_LOAD_OK; } void ThreadFlushWalletDB(void* parg) diff --git a/src/db.h b/src/db.h index b89b34e00..049857b3a 100644 --- a/src/db.h +++ b/src/db.h @@ -88,7 +88,7 @@ protected: if (!pdb) return false; if (fReadOnly) - assert(("Write called on database in read-only mode", false)); + assert(!"Write called on database in read-only mode"); // Key CDataStream ssKey(SER_DISK); @@ -117,7 +117,7 @@ protected: if (!pdb) return false; if (fReadOnly) - assert(("Erase called on database in read-only mode", false)); + assert(!"Erase called on database in read-only mode"); // Key CDataStream ssKey(SER_DISK); @@ -342,6 +342,14 @@ public: +enum DBErrors +{ + DB_LOAD_OK, + DB_CORRUPT, + DB_TOO_NEW, + DB_LOAD_FAIL, +}; + class CWalletDB : public CDB { public: @@ -391,6 +399,25 @@ public: return Write(std::make_pair(std::string("key"), vchPubKey), vchPrivKey, false); } + bool WriteCryptedKey(const std::vector& vchPubKey, const std::vector& vchCryptedSecret, bool fEraseUnencryptedKey = true) + { + nWalletDBUpdated++; + if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false)) + return false; + if (fEraseUnencryptedKey) + { + Erase(std::make_pair(std::string("key"), vchPubKey)); + Erase(std::make_pair(std::string("wkey"), vchPubKey)); + } + return true; + } + + bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey) + { + nWalletDBUpdated++; + return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true); + } + bool WriteBestBlock(const CBlockLocator& locator) { nWalletDBUpdated++; @@ -450,7 +477,7 @@ public: int64 GetAccountCreditDebit(const std::string& strAccount); void ListAccountCreditDebit(const std::string& strAccount, std::list& acentries); - bool LoadWallet(CWallet* pwallet); + int LoadWallet(CWallet* pwallet); }; #endif diff --git a/src/init.cpp b/src/init.cpp index adbfa18c6..b69abb647 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -386,8 +386,16 @@ bool AppInit2(int argc, char* argv[]) nStart = GetTimeMillis(); bool fFirstRun; pwalletMain = new CWallet("wallet.dat"); - if (!pwalletMain->LoadWallet(fFirstRun)) - strErrors += _("Error loading wallet.dat \n"); + int nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun); + if (nLoadWalletRet != DB_LOAD_OK) + { + if (nLoadWalletRet == DB_CORRUPT) + strErrors += _("Error loading wallet.dat: Wallet corrupted \n"); + else if (nLoadWalletRet == DB_TOO_NEW) + strErrors += _("Error loading wallet.dat: Wallet requires newer version of Bitcoin \n"); + else + strErrors += _("Error loading wallet.dat \n"); + } printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart); RegisterWallet(pwalletMain); @@ -415,7 +423,6 @@ bool AppInit2(int argc, char* argv[]) //// debug print printf("mapBlockIndex.size() = %d\n", mapBlockIndex.size()); printf("nBestHeight = %d\n", nBestHeight); - printf("mapKeys.size() = %d\n", pwalletMain->mapKeys.size()); printf("setKeyPool.size() = %d\n", pwalletMain->setKeyPool.size()); printf("mapPubKeys.size() = %d\n", mapPubKeys.size()); printf("mapWallet.size() = %d\n", pwalletMain->mapWallet.size()); diff --git a/src/key.h b/src/key.h index c973d6eb8..c43e4ee23 100644 --- a/src/key.h +++ b/src/key.h @@ -31,6 +31,41 @@ // see www.keylength.com // script supports up to 75 for single byte push +int static inline EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key) +{ + int ok = 0; + BN_CTX *ctx = NULL; + EC_POINT *pub_key = NULL; + + if (!eckey) return 0; + + const EC_GROUP *group = EC_KEY_get0_group(eckey); + + if ((ctx = BN_CTX_new()) == NULL) + goto err; + + pub_key = EC_POINT_new(group); + + if (pub_key == NULL) + goto err; + + if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx)) + goto err; + + EC_KEY_set_private_key(eckey,priv_key); + EC_KEY_set_public_key(eckey,pub_key); + + ok = 1; + +err: + + if (pub_key) + EC_POINT_free(pub_key); + if (ctx != NULL) + BN_CTX_free(ctx); + + return(ok); +} class key_error : public std::runtime_error @@ -42,8 +77,7 @@ public: // secure_allocator is defined in serialize.h typedef std::vector > CPrivKey; - - +typedef std::vector > CSecret; class CKey { @@ -102,6 +136,38 @@ public: return true; } + bool SetSecret(const CSecret& vchSecret) + { + EC_KEY_free(pkey); + pkey = EC_KEY_new_by_curve_name(NID_secp256k1); + if (pkey == NULL) + throw key_error("CKey::SetSecret() : EC_KEY_new_by_curve_name failed"); + if (vchSecret.size() != 32) + throw key_error("CKey::SetSecret() : secret must be 32 bytes"); + BIGNUM *bn = BN_bin2bn(&vchSecret[0],32,BN_new()); + if (bn == NULL) + throw key_error("CKey::SetSecret() : BN_bin2bn failed"); + if (!EC_KEY_regenerate_key(pkey,bn)) + throw key_error("CKey::SetSecret() : EC_KEY_regenerate_key failed"); + BN_clear_free(bn); + fSet = true; + return true; + } + + CSecret GetSecret() const + { + CSecret vchRet; + vchRet.resize(32); + const BIGNUM *bn = EC_KEY_get0_private_key(pkey); + int nBytes = BN_num_bytes(bn); + if (bn == NULL) + throw key_error("CKey::GetSecret() : EC_KEY_get0_private_key failed"); + int n=BN_bn2bin(bn,&vchRet[32 - nBytes]); + if (n != nBytes) + throw key_error("CKey::GetSecret(): BN_bn2bin failed"); + return vchRet; + } + CPrivKey GetPrivKey() const { unsigned int nSize = i2d_ECPrivateKey(pkey, NULL); @@ -154,22 +220,6 @@ public: return false; return true; } - - static bool Sign(const CPrivKey& vchPrivKey, uint256 hash, std::vector& vchSig) - { - CKey key; - if (!key.SetPrivKey(vchPrivKey)) - return false; - return key.Sign(hash, vchSig); - } - - static bool Verify(const std::vector& vchPubKey, uint256 hash, const std::vector& vchSig) - { - CKey key; - if (!key.SetPubKey(vchPubKey)) - return false; - return key.Verify(hash, vchSig); - } }; #endif diff --git a/src/keystore.cpp b/src/keystore.cpp index bfad27c6d..de13958a8 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -4,13 +4,7 @@ #include "headers.h" #include "db.h" - - - -////////////////////////////////////////////////////////////////////////////// -// -// mapKeys -// +#include "crypter.h" std::vector CKeyStore::GenerateNewKey() { @@ -18,13 +12,14 @@ std::vector CKeyStore::GenerateNewKey() CKey key; key.MakeNewKey(); if (!AddKey(key)) - throw std::runtime_error("GenerateNewKey() : AddKey failed"); + throw std::runtime_error("CKeyStore::GenerateNewKey() : AddKey failed"); return key.GetPubKey(); } -bool CKeyStore::AddKey(const CKey& key) +bool CBasicKeyStore::AddKey(const CKey& key) { - CRITICAL_BLOCK(cs_mapKeys) + CRITICAL_BLOCK(cs_mapPubKeys) + CRITICAL_BLOCK(cs_KeyStore) { mapKeys[key.GetPubKey()] = key.GetPrivKey(); mapPubKeys[Hash160(key.GetPubKey())] = key.GetPubKey(); @@ -32,3 +27,121 @@ bool CKeyStore::AddKey(const CKey& key) return true; } +std::vector CCryptoKeyStore::GenerateNewKey() +{ + RandAddSeedPerfmon(); + CKey key; + key.MakeNewKey(); + if (!AddKey(key)) + throw std::runtime_error("CCryptoKeyStore::GenerateNewKey() : AddKey failed"); + return key.GetPubKey(); +} + +bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn) +{ + CRITICAL_BLOCK(cs_vMasterKey) + { + if (!SetCrypted()) + return false; + + std::map, std::vector >::const_iterator mi = mapCryptedKeys.begin(); + for (; mi != mapCryptedKeys.end(); ++mi) + { + const std::vector &vchPubKey = (*mi).first; + const std::vector &vchCryptedSecret = (*mi).second; + CSecret vchSecret; + if(!DecryptSecret(vMasterKeyIn, vchCryptedSecret, Hash(vchPubKey.begin(), vchPubKey.end()), vchSecret)) + return false; + CKey key; + key.SetSecret(vchSecret); + if (key.GetPubKey() == vchPubKey) + break; + return false; + } + vMasterKey = vMasterKeyIn; + } + return true; +} + +bool CCryptoKeyStore::AddKey(const CKey& key) +{ + CRITICAL_BLOCK(cs_KeyStore) + CRITICAL_BLOCK(cs_vMasterKey) + { + if (!IsCrypted()) + return CBasicKeyStore::AddKey(key); + + if (IsLocked()) + return false; + + std::vector vchCryptedSecret; + std::vector vchPubKey = key.GetPubKey(); + if (!EncryptSecret(vMasterKey, key.GetSecret(), Hash(vchPubKey.begin(), vchPubKey.end()), vchCryptedSecret)) + return false; + + if (!AddCryptedKey(key.GetPubKey(), vchCryptedSecret)) + return false; + } + return true; +} + + +bool CCryptoKeyStore::AddCryptedKey(const std::vector &vchPubKey, const std::vector &vchCryptedSecret) +{ + CRITICAL_BLOCK(cs_mapPubKeys) + CRITICAL_BLOCK(cs_KeyStore) + { + if (!SetCrypted()) + return false; + + mapCryptedKeys[vchPubKey] = vchCryptedSecret; + mapPubKeys[Hash160(vchPubKey)] = vchPubKey; + } + return true; +} + +bool CCryptoKeyStore::GetPrivKey(const std::vector &vchPubKey, CKey& keyOut) const +{ + CRITICAL_BLOCK(cs_vMasterKey) + { + if (!IsCrypted()) + return CBasicKeyStore::GetPrivKey(vchPubKey, keyOut); + + std::map, std::vector >::const_iterator mi = mapCryptedKeys.find(vchPubKey); + if (mi != mapCryptedKeys.end()) + { + const std::vector &vchCryptedSecret = (*mi).second; + CSecret vchSecret; + if (!DecryptSecret(vMasterKey, (*mi).second, Hash((*mi).first.begin(), (*mi).first.end()), vchSecret)) + return false; + keyOut.SetSecret(vchSecret); + return true; + } + } + return false; +} + +bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn) +{ + CRITICAL_BLOCK(cs_KeyStore) + CRITICAL_BLOCK(cs_vMasterKey) + { + if (!mapCryptedKeys.empty() || IsCrypted()) + return false; + + fUseCrypto = true; + CKey key; + BOOST_FOREACH(KeyMap::value_type& mKey, mapKeys) + { + if (!key.SetPrivKey(mKey.second)) + return false; + std::vector vchCryptedSecret; + if (!EncryptSecret(vMasterKeyIn, key.GetSecret(), Hash(mKey.first.begin(), mKey.first.end()), vchCryptedSecret)) + return false; + if (!AddCryptedKey(mKey.first, vchCryptedSecret)) + return false; + } + mapKeys.clear(); + } + return true; +} diff --git a/src/keystore.h b/src/keystore.h index 6080d7d7f..0dc09f05b 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -4,27 +4,112 @@ #ifndef BITCOIN_KEYSTORE_H #define BITCOIN_KEYSTORE_H +#include "crypter.h" + class CKeyStore { public: - std::map, CPrivKey> mapKeys; - mutable CCriticalSection cs_mapKeys; - virtual bool AddKey(const CKey& key); + mutable CCriticalSection cs_KeyStore; + + virtual bool AddKey(const CKey& key) =0; + virtual bool HaveKey(const std::vector &vchPubKey) const =0; + virtual bool GetPrivKey(const std::vector &vchPubKey, CKey& keyOut) const =0; + virtual std::vector GenerateNewKey(); +}; + +typedef std::map, CPrivKey> KeyMap; + +class CBasicKeyStore : public CKeyStore +{ +protected: + KeyMap mapKeys; + +public: + bool AddKey(const CKey& key); bool HaveKey(const std::vector &vchPubKey) const { return (mapKeys.count(vchPubKey) > 0); } - bool GetPrivKey(const std::vector &vchPubKey, CPrivKey& keyOut) const + bool GetPrivKey(const std::vector &vchPubKey, CKey& keyOut) const { std::map, CPrivKey>::const_iterator mi = mapKeys.find(vchPubKey); if (mi != mapKeys.end()) { - keyOut = (*mi).second; + keyOut.SetPrivKey((*mi).second); return true; } return false; } +}; + +class CCryptoKeyStore : public CBasicKeyStore +{ +private: + std::map, std::vector > mapCryptedKeys; + + CKeyingMaterial vMasterKey; + + // if fUseCrypto is true, mapKeys must be empty + // if fUseCrypto is false, vMasterKey must be empty + bool fUseCrypto; + +protected: + bool SetCrypted() + { + if (fUseCrypto) + return true; + if (!mapKeys.empty()) + return false; + fUseCrypto = true; + return true; + } + + // will encrypt previously unencrypted keys + bool EncryptKeys(CKeyingMaterial& vMasterKeyIn); + + bool Unlock(const CKeyingMaterial& vMasterKeyIn); + +public: + mutable CCriticalSection cs_vMasterKey; //No guarantees master key wont get locked before you can use it, so lock this first + + CCryptoKeyStore() : fUseCrypto(false) + { + } + + bool IsCrypted() const + { + return fUseCrypto; + } + + bool IsLocked() const + { + if (!IsCrypted()) + return false; + return vMasterKey.empty(); + } + + bool Lock() + { + CRITICAL_BLOCK(cs_vMasterKey) + { + if (!SetCrypted()) + return false; + + vMasterKey.clear(); + } + return true; + } + + virtual bool AddCryptedKey(const std::vector &vchPubKey, const std::vector &vchCryptedSecret); std::vector GenerateNewKey(); + bool AddKey(const CKey& key); + bool HaveKey(const std::vector &vchPubKey) const + { + if (!IsCrypted()) + return CBasicKeyStore::HaveKey(vchPubKey); + return mapCryptedKeys.count(vchPubKey) > 0; + } + bool GetPrivKey(const std::vector &vchPubKey, CKey& keyOut) const; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 594f1d3bc..e3ad35044 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,7 +55,6 @@ int64 nHPSTimerStart; // Settings int fGenerateBitcoins = false; int64 nTransactionFee = 0; -CAddress addrIncoming; int fLimitProcessors = false; int nLimitProcessors = 1; int fMinimizeToTray = true; @@ -1689,7 +1688,7 @@ string GetWarnings(string strFor) return strStatusBar; else if (strFor == "rpc") return strRPC; - assert(("GetWarnings() : invalid parameter", false)); + assert(!"GetWarnings() : invalid parameter"); return "error"; } @@ -1900,6 +1899,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) return error("message addr size() = %d", vAddr.size()); // Store the new addresses + CAddrDB addrDB; + addrDB.TxnBegin(); int64 nNow = GetAdjustedTime(); int64 nSince = nNow - 10 * 60; BOOST_FOREACH(CAddress& addr, vAddr) @@ -1911,7 +1912,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) continue; if (addr.nTime <= 100000000 || addr.nTime > nNow + 10 * 60) addr.nTime = nNow - 5 * 24 * 60 * 60; - AddAddress(addr, 2 * 60 * 60); + AddAddress(addr, 2 * 60 * 60, &addrDB); pfrom->AddAddressKnown(addr); if (addr.nTime > nSince && !pfrom->fGetAddr && vAddr.size() <= 10 && addr.IsRoutable()) { @@ -1942,6 +1943,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } } } + addrDB.TxnCommit(); // Save addresses (it's ok if this fails) if (vAddr.size() < 1000) pfrom->fGetAddr = false; } @@ -2213,7 +2215,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) // Keep giving the same key to the same ip until they use it if (!mapReuseKey.count(pfrom->addr.ip)) - mapReuseKey[pfrom->addr.ip] = pwalletMain->GetKeyFromKeyPool(); + mapReuseKey[pfrom->addr.ip] = pwalletMain->GetOrReuseKeyFromPool(); // Send back approval of order and pubkey to use CScript scriptPubKey; diff --git a/src/main.h b/src/main.h index 124c7c267..d34f68f9d 100644 --- a/src/main.h +++ b/src/main.h @@ -70,7 +70,6 @@ extern std::set setpwalletRegistered; // Settings extern int fGenerateBitcoins; extern int64 nTransactionFee; -extern CAddress addrIncoming; extern int fLimitProcessors; extern int nLimitProcessors; extern int fMinimizeToTray; diff --git a/src/makefile.linux-mingw b/src/makefile.linux-mingw index 3fb18ff28..59ff03c48 100644 --- a/src/makefile.linux-mingw +++ b/src/makefile.linux-mingw @@ -4,6 +4,8 @@ DEPSDIR:=/usr/i586-mingw32msvc +USE_UPNP:=0 + INCLUDEPATHS= \ -I"$(DEPSDIR)/boost_1_43_0" \ -I"$(DEPSDIR)/db-4.7.25.NC/build_unix" \ @@ -34,23 +36,15 @@ DEFS=-D_MT -DWIN32 -D__WXMSW__ -D_WINDOWS -DNOPCH -DUSE_SSL DEBUGFLAGS=-g -D__WXDEBUG__ CFLAGS=-O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \ - script.h db.h net.h irc.h keystore.h main.h wallet.h rpc.h uibase.h ui.h noui.h init.h + script.h db.h net.h irc.h keystore.h main.h wallet.h rpc.h uibase.h ui.h noui.h \ + crypter.h init.h -bitcoin.exe: USE_UPNP:=1 - ifdef USE_UPNP - INCLUDEPATHS += -I"$(DEPSDIR)/upnpc-exe-win32-20110215" - LIBPATHS += -L"$(DEPSDIR)/upnpc-exe-win32-20110215" - LIBS += -l miniupnpc -l iphlpapi - DEFS += -DSTATICLIB -DUSE_UPNP=$(USE_UPNP) - endif - -bitcoind.exe: USE_UPNP:=0 - ifdef USE_UPNP - INCLUDEPATHS += -I"$(DEPSDIR)/upnpc-exe-win32-20110215" - LIBPATHS += -L"$(DEPSDIR)/upnpc-exe-win32-20110215" - LIBS += -l miniupnpc -l iphlpapi - DEFS += -DSTATICLIB -DUSE_UPNP=$(USE_UPNP) - endif +ifdef USE_UPNP + INCLUDEPATHS += -I"$(DEPSDIR)/upnpc-exe-win32-20110215" + LIBPATHS += -L"$(DEPSDIR)/upnpc-exe-win32-20110215" + LIBS += -l miniupnpc -l iphlpapi + DEFS += -DSTATICLIB -DUSE_UPNP=$(USE_UPNP) +endif LIBS += -l mingwthrd -l kernel32 -l user32 -l gdi32 -l comdlg32 -l winspool -l winmm -l shell32 -l comctl32 -l ole32 -l oleaut32 -l uuid -l rpcrt4 -l advapi32 -l ws2_32 -l shlwapi @@ -65,6 +59,7 @@ OBJS= \ obj/wallet.o \ obj/rpc.o \ obj/init.o \ + obj/crypter.o \ cryptopp/obj/sha.o \ cryptopp/obj/cpu.o diff --git a/src/makefile.mingw b/src/makefile.mingw index 507833be4..16a054009 100644 --- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -33,7 +33,8 @@ DEFS=-DWIN32 -D__WXMSW__ -D_WINDOWS -DNOPCH -DUSE_SSL DEBUGFLAGS=-g -D__WXDEBUG__ CFLAGS=-mthreads -O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \ - script.h db.h net.h irc.h keystore.h main.h wallet.h rpc.h uibase.h ui.h noui.h init.h + script.h db.h net.h irc.h keystore.h main.h wallet.h rpc.h uibase.h ui.h noui.h \ + init.h crypter.h ifdef USE_UPNP INCLUDEPATHS += -I"C:\upnpc-exe-win32-20110215" @@ -55,6 +56,7 @@ OBJS= \ obj/wallet.o \ obj/rpc.o \ obj/init.o \ + obj/crypter.o \ cryptopp/obj/sha.o \ cryptopp/obj/cpu.o diff --git a/src/makefile.osx b/src/makefile.osx index 784596b72..89788562c 100644 --- a/src/makefile.osx +++ b/src/makefile.osx @@ -33,7 +33,8 @@ DEBUGFLAGS=-g -DwxDEBUG_LEVEL=0 # ppc doesn't work because we don't support big-endian CFLAGS=-mmacosx-version-min=10.5 -arch i386 -arch x86_64 -O3 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS) HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \ - script.h db.h net.h irc.h keystore.h main.h wallet.h rpc.h uibase.h ui.h noui.h init.h + script.h db.h net.h irc.h keystore.h main.h wallet.h rpc.h uibase.h ui.h noui.h \ + init.h crypter.h OBJS= \ obj/util.o \ @@ -46,6 +47,7 @@ OBJS= \ obj/wallet.o \ obj/rpc.o \ obj/init.o \ + obj/crypter.o \ cryptopp/obj/sha.o \ cryptopp/obj/cpu.o diff --git a/src/makefile.unix b/src/makefile.unix index bb26bf5ed..0567f8b75 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -39,7 +39,8 @@ LIBS+= \ DEBUGFLAGS=-g -D__WXDEBUG__ CXXFLAGS=-O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \ - script.h db.h net.h irc.h keystore.h main.h wallet.h rpc.h uibase.h ui.h noui.h init.h + script.h db.h net.h irc.h keystore.h main.h wallet.h rpc.h uibase.h ui.h noui.h \ + init.h crypter.h OBJS= \ obj/util.o \ @@ -52,6 +53,7 @@ OBJS= \ obj/wallet.o \ obj/rpc.o \ obj/init.o \ + obj/crypter.o \ cryptopp/obj/sha.o \ cryptopp/obj/cpu.o diff --git a/src/net.cpp b/src/net.cpp index 0d3348da7..2a90f6d0c 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -440,7 +440,7 @@ void ThreadGetMyExternalIP(void* parg) -bool AddAddress(CAddress addr, int64 nTimePenalty) +bool AddAddress(CAddress addr, int64 nTimePenalty, CAddrDB *pAddrDB) { if (!addr.IsRoutable()) return false; @@ -455,7 +455,10 @@ bool AddAddress(CAddress addr, int64 nTimePenalty) // New address printf("AddAddress(%s)\n", addr.ToString().c_str()); mapAddresses.insert(make_pair(addr.GetKey(), addr)); - CAddrDB().WriteAddress(addr); + if (pAddrDB) + pAddrDB->WriteAddress(addr); + else + CAddrDB().WriteAddress(addr); return true; } else @@ -477,7 +480,12 @@ bool AddAddress(CAddress addr, int64 nTimePenalty) fUpdated = true; } if (fUpdated) - CAddrDB().WriteAddress(addrFound); + { + if (pAddrDB) + pAddrDB->WriteAddress(addrFound); + else + CAddrDB().WriteAddress(addrFound); + } } } return false; @@ -831,7 +839,7 @@ void ThreadSocketHandler2(void* parg) { BOOST_FOREACH(CNode* pnode, vNodes) { - if (pnode->hSocket == INVALID_SOCKET || pnode->hSocket < 0) + if (pnode->hSocket == INVALID_SOCKET) continue; FD_SET(pnode->hSocket, &fdsetRecv); FD_SET(pnode->hSocket, &fdsetError); @@ -1158,6 +1166,8 @@ void DNSAddressSeed() if (!fTestNet) { printf("Loading addresses from DNS seeds (could take a while)\n"); + CAddrDB addrDB; + addrDB.TxnBegin(); for (int seed_idx = 0; seed_idx < ARRAYLEN(strDNSSeed); seed_idx++) { vector vaddr; @@ -1168,12 +1178,14 @@ void DNSAddressSeed() if (addr.GetByte(3) != 127) { addr.nTime = 0; - AddAddress(addr); + AddAddress(addr, 0, &addrDB); found++; } } } } + + addrDB.TxnCommit(); // Save addresses (it's ok if this fails) } printf("%d addresses found from DNS seeds\n", found); @@ -1700,7 +1712,7 @@ void StartNode(void* parg) printf("Error: CreateThread(ThreadIRCSeed) failed\n"); // Send and receive from sockets, accept connections - pthread_t hThreadSocketHandler = CreateThread(ThreadSocketHandler, NULL, true); + CreateThread(ThreadSocketHandler, NULL, true); // Initiate outbound connections if (!CreateThread(ThreadOpenConnections, NULL)) diff --git a/src/net.h b/src/net.h index 8f21de8dc..d896defc8 100644 --- a/src/net.h +++ b/src/net.h @@ -15,6 +15,7 @@ class CMessageHeader; class CAddress; +class CAddrDB; class CInv; class CRequestTracker; class CNode; @@ -40,7 +41,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet, int nTimeout bool Lookup(const char *pszName, std::vector& vaddr, int nServices, int nMaxSolutions, bool fAllowLookup = false, int portDefault = 0, bool fAllowPort = false); bool Lookup(const char *pszName, CAddress& addr, int nServices, bool fAllowLookup = false, int portDefault = 0, bool fAllowPort = false); bool GetMyExternalIP(unsigned int& ipRet); -bool AddAddress(CAddress addr, int64 nTimePenalty=0); +bool AddAddress(CAddress addr, int64 nTimePenalty=0, CAddrDB *pAddrDB=NULL); void AddressCurrentlyConnected(const CAddress& addr); CNode* FindNode(unsigned int ip); CNode* ConnectNode(CAddress addrConnect, int64 nTimeout=0); diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index 9ca754201..4578ca740 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -38,7 +38,7 @@ struct AddressTablePriv { cachedAddressTable.clear(); - CRITICAL_BLOCK(wallet->cs_mapKeys) + CRITICAL_BLOCK(cs_mapPubKeys) CRITICAL_BLOCK(wallet->cs_mapAddressBook) { BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item, wallet->mapAddressBook) @@ -255,14 +255,15 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con { // Generate a new address to associate with given label, optionally // set as default receiving address. - strAddress = PubKeyToAddress(wallet->GetKeyFromKeyPool()); + strAddress = PubKeyToAddress(wallet->GetOrReuseKeyFromPool()); } else { return QString(); } // Add entry and update list - wallet->SetAddressBookName(strAddress, strLabel); + CRITICAL_BLOCK(wallet->cs_mapAddressBook) + wallet->SetAddressBookName(strAddress, strLabel); updateList(); return QString::fromStdString(strAddress); } diff --git a/src/script.cpp b/src/script.cpp index bd1b5b3c5..654aaa10e 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -580,6 +580,7 @@ bool EvalScript(vector >& stack, const CScript& script, co case OP_ABS: if (bn < bnZero) bn = -bn; break; case OP_NOT: bn = (bn == bnZero); break; case OP_0NOTEQUAL: bn = (bn != bnZero); break; + default: assert(!"invalid opcode"); break; } popstack(stack); stack.push_back(bn.getvch()); @@ -659,6 +660,7 @@ bool EvalScript(vector >& stack, const CScript& script, co case OP_GREATERTHANOREQUAL: bn = (bn1 >= bn2); break; case OP_MIN: bn = (bn1 < bn2 ? bn1 : bn2); break; case OP_MAX: bn = (bn1 > bn2 ? bn1 : bn2); break; + default: assert(!"invalid opcode"); break; } popstack(stack); popstack(stack); @@ -1030,7 +1032,7 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash return false; // Compile solution - CRITICAL_BLOCK(keystore.cs_mapKeys) + CRITICAL_BLOCK(keystore.cs_KeyStore) { BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution) { @@ -1038,13 +1040,13 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash { // Sign const valtype& vchPubKey = item.second; - CPrivKey privkey; - if (!keystore.GetPrivKey(vchPubKey, privkey)) + CKey key; + if (!keystore.GetPrivKey(vchPubKey, key)) return false; if (hash != 0) { vector vchSig; - if (!CKey::Sign(privkey, hash, vchSig)) + if (!key.Sign(hash, vchSig)) return false; vchSig.push_back((unsigned char)nHashType); scriptSigRet << vchSig; @@ -1057,13 +1059,13 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash if (mi == mapPubKeys.end()) return false; const vector& vchPubKey = (*mi).second; - CPrivKey privkey; - if (!keystore.GetPrivKey(vchPubKey, privkey)) + CKey key; + if (!keystore.GetPrivKey(vchPubKey, key)) return false; if (hash != 0) { vector vchSig; - if (!CKey::Sign(privkey, hash, vchSig)) + if (!key.Sign(hash, vchSig)) return false; vchSig.push_back((unsigned char)nHashType); scriptSigRet << vchSig << vchPubKey; @@ -1089,8 +1091,40 @@ bool IsStandard(const CScript& scriptPubKey) bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) { - CScript scriptSig; - return Solver(keystore, scriptPubKey, 0, 0, scriptSig); + vector > vSolution; + if (!Solver(scriptPubKey, vSolution)) + return false; + + // Compile solution + CRITICAL_BLOCK(keystore.cs_KeyStore) + { + BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution) + { + if (item.first == OP_PUBKEY) + { + // Sign + const valtype& vchPubKey = item.second; + if (!keystore.HaveKey(vchPubKey)) + return false; + } + else if (item.first == OP_PUBKEYHASH) + { + // Sign and give pubkey + map::iterator mi = mapPubKeys.find(uint160(item.second)); + if (mi == mapPubKeys.end()) + return false; + const vector& vchPubKey = (*mi).second; + if (!keystore.HaveKey(vchPubKey)) + return false; + } + else + { + return false; + } + } + } + + return true; } diff --git a/src/script.h b/src/script.h index ae9fdfffa..2a36db2fa 100644 --- a/src/script.h +++ b/src/script.h @@ -486,7 +486,7 @@ public: { // I'm not sure if this should push the script or concatenate scripts. // If there's ever a use for pushing a script onto a script, delete this member fn - assert(("warning: pushing a CScript onto a CScript with << is probably not intended, use + to concatenate", false)); + assert(!"warning: pushing a CScript onto a CScript with << is probably not intended, use + to concatenate"); return *this; } diff --git a/src/serialize.h b/src/serialize.h index 31862a71a..cb3a3ea03 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -28,12 +28,36 @@ typedef unsigned long long uint64; #if defined(_MSC_VER) && _MSC_VER < 1300 #define for if (false) ; else for #endif + +#ifdef __WXMSW__ +// This is used to attempt to keep keying material out of swap +// Note that VirtualLock does not provide this as a guarantee on Windows, +// but, in practice, memory that has been VirtualLock'd almost never gets written to +// the pagefile except in rare circumstances where memory is extremely low. +#define mlock(p, n) VirtualLock((p), (n)); +#define munlock(p, n) VirtualUnlock((p), (n)); +#else +#include +#include +/* This comes from limits.h if it's not defined there set a sane default */ +#ifndef PAGESIZE +#include +#define PAGESIZE sysconf(_SC_PAGESIZE) +#endif +#define mlock(a,b) \ + mlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\ + (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1)))) +#define munlock(a,b) \ + munlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\ + (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1)))) +#endif + class CScript; class CDataStream; class CAutoFile; static const unsigned int MAX_SIZE = 0x02000000; -static const int VERSION = 32400; +static const int VERSION = 32500; static const char* pszSubVer = ""; static const bool VERSION_IS_BETA = true; @@ -755,7 +779,8 @@ struct ser_streamplaceholder // -// Allocator that clears its contents before deletion +// Allocator that locks its contents from being paged +// out of memory and clears its contents before deletion. // template struct secure_allocator : public std::allocator @@ -777,10 +802,22 @@ struct secure_allocator : public std::allocator template struct rebind { typedef secure_allocator<_Other> other; }; + T* allocate(std::size_t n, const void *hint = 0) + { + T *p; + p = std::allocator::allocate(n, hint); + if (p != NULL) + mlock(p, sizeof(T) * n); + return p; + } + void deallocate(T* p, std::size_t n) { if (p != NULL) + { memset(p, 0, sizeof(T) * n); + munlock(p, sizeof(T) * n); + } std::allocator::deallocate(p, n); } }; diff --git a/src/ui.cpp b/src/ui.cpp index ff0b4afb5..eae0a4f4c 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -245,6 +245,41 @@ void SetDefaultReceivingAddress(const string& strAddress) } } +bool GetWalletPassphrase() +{ + if (pwalletMain->IsLocked()) + { + string strWalletPass; + strWalletPass.reserve(100); + mlock(&strWalletPass[0], strWalletPass.capacity()); + + // obtain current wallet encrypt/decrypt key, from passphrase + // Note that the passphrase is not mlock()d during this entry and could potentially + // be obtained from disk long after bitcoin has run. + strWalletPass = wxGetPasswordFromUser(_("Enter the current passphrase to the wallet."), + _("Passphrase")).ToStdString(); + + if (!strWalletPass.size()) + { + fill(strWalletPass.begin(), strWalletPass.end(), '\0'); + munlock(&strWalletPass[0], strWalletPass.capacity()); + wxMessageBox(_("Please supply the current wallet decryption passphrase."), "Bitcoin"); + return false; + } + + if (!pwalletMain->Unlock(strWalletPass)) + { + fill(strWalletPass.begin(), strWalletPass.end(), '\0'); + munlock(&strWalletPass[0], strWalletPass.capacity()); + wxMessageBox(_("The passphrase entered for the wallet decryption was incorrect."), "Bitcoin"); + return false; + } + fill(strWalletPass.begin(), strWalletPass.end(), '\0'); + munlock(&strWalletPass[0], strWalletPass.capacity()); + } + return true; +} + @@ -333,6 +368,11 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent) if (CWalletDB(pwalletMain->strWalletFile,"r").ReadDefaultKey(vchPubKey)) m_textCtrlAddress->SetValue(PubKeyToAddress(vchPubKey)); + if (pwalletMain->IsCrypted()) + m_menuOptions->Remove(m_menuOptionsEncryptWallet); + else + m_menuOptions->Remove(m_menuOptionsChangeWalletPassphrase); + // Fill listctrl with wallet transactions RefreshListCtrl(); } @@ -1122,6 +1162,169 @@ void CMainFrame::OnMenuOptionsChangeYourAddress(wxCommandEvent& event) return; } +void CMainFrame::OnMenuOptionsEncryptWallet(wxCommandEvent& event) +{ + // Options->Encrypt Wallet + if (pwalletMain->IsCrypted()) + { + wxMessageBox(_("Wallet already encrypted."), "Bitcoin", wxOK | wxICON_ERROR); + return; + } + + string strWalletPass; + strWalletPass.reserve(100); + mlock(&strWalletPass[0], strWalletPass.capacity()); + + // obtain current wallet encrypt/decrypt key, from passphrase + // Note that the passphrase is not mlock()d during this entry and could potentially + // be obtained from disk long after bitcoin has run. + strWalletPass = wxGetPasswordFromUser(_("Enter the new passphrase to the wallet.\nPlease use a passphrase of 10 or more random characters, or eight or more words."), + _("Passphrase")).ToStdString(); + + if (!strWalletPass.size()) + { + fill(strWalletPass.begin(), strWalletPass.end(), '\0'); + munlock(&strWalletPass[0], strWalletPass.capacity()); + wxMessageBox(_("Error: The supplied passphrase was too short."), "Bitcoin", wxOK | wxICON_ERROR); + return; + } + + if(wxMessageBox(_("WARNING: If you encrypt your wallet and lose your passphrase, you will LOSE ALL OF YOUR BITCOINS!\nAre you sure you wish to encrypt your wallet?"), "Bitcoin", wxYES_NO) != wxYES) + return; + + string strWalletPassTest; + strWalletPassTest.reserve(100); + mlock(&strWalletPassTest[0], strWalletPassTest.capacity()); + strWalletPassTest = wxGetPasswordFromUser(_("Please re-enter your new wallet passphrase."), + _("Passphrase")).ToStdString(); + + if (strWalletPassTest != strWalletPass) + { + fill(strWalletPass.begin(), strWalletPass.end(), '\0'); + fill(strWalletPassTest.begin(), strWalletPassTest.end(), '\0'); + munlock(&strWalletPass[0], strWalletPass.capacity()); + munlock(&strWalletPassTest[0], strWalletPassTest.capacity()); + wxMessageBox(_("Error: the supplied passphrases didn't match."), "Bitcoin", wxOK | wxICON_ERROR); + return; + } + + if (!pwalletMain->EncryptWallet(strWalletPass)) + { + fill(strWalletPass.begin(), strWalletPass.end(), '\0'); + fill(strWalletPassTest.begin(), strWalletPassTest.end(), '\0'); + munlock(&strWalletPass[0], strWalletPass.capacity()); + munlock(&strWalletPassTest[0], strWalletPassTest.capacity()); + wxMessageBox(_("Wallet encryption failed."), "Bitcoin", wxOK | wxICON_ERROR); + return; + } + fill(strWalletPass.begin(), strWalletPass.end(), '\0'); + fill(strWalletPassTest.begin(), strWalletPassTest.end(), '\0'); + munlock(&strWalletPass[0], strWalletPass.capacity()); + munlock(&strWalletPassTest[0], strWalletPassTest.capacity()); + wxMessageBox(_("Wallet Encrypted.\nRemember that encrypting your wallet cannot fully protect your bitcoins from being stolen by malware infecting your computer."), "Bitcoin"); + + m_menuOptions->Remove(m_menuOptionsEncryptWallet); + m_menuOptions->Insert(m_menuOptions->GetMenuItemCount() - 1, m_menuOptionsChangeWalletPassphrase); +} + +void CMainFrame::OnMenuOptionsChangeWalletPassphrase(wxCommandEvent& event) +{ + // Options->Change Wallet Encryption Passphrase + if (!pwalletMain->IsCrypted()) + { + wxMessageBox(_("Wallet is unencrypted, please encrypt it first."), "Bitcoin", wxOK | wxICON_ERROR); + return; + } + + string strOldWalletPass; + strOldWalletPass.reserve(100); + mlock(&strOldWalletPass[0], strOldWalletPass.capacity()); + + // obtain current wallet encrypt/decrypt key, from passphrase + // Note that the passphrase is not mlock()d during this entry and could potentially + // be obtained from disk long after bitcoin has run. + strOldWalletPass = wxGetPasswordFromUser(_("Enter the current passphrase to the wallet."), + _("Passphrase")).ToStdString(); + + CRITICAL_BLOCK(pwalletMain->cs_vMasterKey) + { + bool fWasLocked = pwalletMain->IsLocked(); + pwalletMain->Lock(); + + if (!strOldWalletPass.size() || !pwalletMain->Unlock(strOldWalletPass)) + { + fill(strOldWalletPass.begin(), strOldWalletPass.end(), '\0'); + munlock(&strOldWalletPass[0], strOldWalletPass.capacity()); + wxMessageBox(_("The passphrase entered for the wallet decryption was incorrect."), "Bitcoin", wxOK | wxICON_ERROR); + return; + } + + if (fWasLocked) + pwalletMain->Lock(); + + string strNewWalletPass; + strNewWalletPass.reserve(100); + mlock(&strNewWalletPass[0], strNewWalletPass.capacity()); + + // obtain new wallet encrypt/decrypt key, from passphrase + // Note that the passphrase is not mlock()d during this entry and could potentially + // be obtained from disk long after bitcoin has run. + strNewWalletPass = wxGetPasswordFromUser(_("Enter the new passphrase for the wallet."), + _("Passphrase")).ToStdString(); + + if (!strNewWalletPass.size()) + { + fill(strOldWalletPass.begin(), strOldWalletPass.end(), '\0'); + fill(strNewWalletPass.begin(), strNewWalletPass.end(), '\0'); + munlock(&strOldWalletPass[0], strOldWalletPass.capacity()); + munlock(&strNewWalletPass[0], strNewWalletPass.capacity()); + wxMessageBox(_("Error: The supplied passphrase was too short."), "Bitcoin", wxOK | wxICON_ERROR); + return; + } + + string strNewWalletPassTest; + strNewWalletPassTest.reserve(100); + mlock(&strNewWalletPassTest[0], strNewWalletPassTest.capacity()); + + // obtain new wallet encrypt/decrypt key, from passphrase + // Note that the passphrase is not mlock()d during this entry and could potentially + // be obtained from disk long after bitcoin has run. + strNewWalletPassTest = wxGetPasswordFromUser(_("Re-enter the new passphrase for the wallet."), + _("Passphrase")).ToStdString(); + + if (strNewWalletPassTest != strNewWalletPass) + { + fill(strOldWalletPass.begin(), strOldWalletPass.end(), '\0'); + fill(strNewWalletPass.begin(), strNewWalletPass.end(), '\0'); + fill(strNewWalletPassTest.begin(), strNewWalletPassTest.end(), '\0'); + munlock(&strOldWalletPass[0], strOldWalletPass.capacity()); + munlock(&strNewWalletPass[0], strNewWalletPass.capacity()); + munlock(&strNewWalletPassTest[0], strNewWalletPassTest.capacity()); + wxMessageBox(_("Error: the supplied passphrases didn't match."), "Bitcoin", wxOK | wxICON_ERROR); + return; + } + + if (!pwalletMain->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) + { + fill(strOldWalletPass.begin(), strOldWalletPass.end(), '\0'); + fill(strNewWalletPass.begin(), strNewWalletPass.end(), '\0'); + fill(strNewWalletPassTest.begin(), strNewWalletPassTest.end(), '\0'); + munlock(&strOldWalletPass[0], strOldWalletPass.capacity()); + munlock(&strNewWalletPass[0], strNewWalletPass.capacity()); + munlock(&strNewWalletPassTest[0], strNewWalletPassTest.capacity()); + wxMessageBox(_("The passphrase entered for the wallet decryption was incorrect."), "Bitcoin", wxOK | wxICON_ERROR); + return; + } + fill(strOldWalletPass.begin(), strOldWalletPass.end(), '\0'); + fill(strNewWalletPass.begin(), strNewWalletPass.end(), '\0'); + fill(strNewWalletPassTest.begin(), strNewWalletPassTest.end(), '\0'); + munlock(&strOldWalletPass[0], strOldWalletPass.capacity()); + munlock(&strNewWalletPass[0], strNewWalletPass.capacity()); + munlock(&strNewWalletPassTest[0], strNewWalletPassTest.capacity()); + wxMessageBox(_("Wallet Passphrase Changed."), "Bitcoin"); + } +} + void CMainFrame::OnMenuOptionsOptions(wxCommandEvent& event) { // Options->Options @@ -1182,8 +1385,19 @@ void CMainFrame::OnButtonNew(wxCommandEvent& event) return; string strName = dialog.GetValue(); - // Generate new key - string strAddress = PubKeyToAddress(pwalletMain->GetKeyFromKeyPool()); + string strAddress; + CRITICAL_BLOCK(pwalletMain->cs_vMasterKey) + { + bool fWasLocked = pwalletMain->IsLocked(); + if (!GetWalletPassphrase()) + return; + + // Generate new key + strAddress = PubKeyToAddress(pwalletMain->GetOrReuseKeyFromPool()); + + if (fWasLocked) + pwalletMain->Lock(); + } // Save CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) @@ -1947,7 +2161,12 @@ void CSendDialog::OnButtonSend(wxCommandEvent& event) if (fBitcoinAddress) { CRITICAL_BLOCK(cs_main) + CRITICAL_BLOCK(pwalletMain->cs_vMasterKey) { + bool fWasLocked = pwalletMain->IsLocked(); + if (!GetWalletPassphrase()) + return; + // Send to bitcoin address CScript scriptPubKey; scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG; @@ -1956,13 +2175,22 @@ void CSendDialog::OnButtonSend(wxCommandEvent& event) if (strError == "") wxMessageBox(_("Payment sent "), _("Sending...")); else if (strError == "ABORTED") + { + if (fWasLocked) + pwalletMain->Lock(); return; // leave send dialog open + } else { wxMessageBox(strError + " ", _("Sending...")); EndModal(false); + if (fWasLocked) + pwalletMain->Lock(); return; } + + if (fWasLocked) + pwalletMain->Lock(); } } else @@ -2246,16 +2474,27 @@ void CSendingDialog::OnReply2(CDataStream& vRecv) Error(_("Insufficient funds")); return; } + CReserveKey reservekey(pwalletMain); int64 nFeeRequired; - if (!pwalletMain->CreateTransaction(scriptPubKey, nPrice, wtx, reservekey, nFeeRequired)) + CRITICAL_BLOCK(pwalletMain->cs_vMasterKey) { - if (nPrice + nFeeRequired > pwalletMain->GetBalance()) - Error(strprintf(_("This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds"), FormatMoney(nFeeRequired).c_str())); - else - Error(_("Transaction creation failed")); - return; - } + bool fWasLocked = pwalletMain->IsLocked(); + if (!GetWalletPassphrase()) + return; + + if (!pwalletMain->CreateTransaction(scriptPubKey, nPrice, wtx, reservekey, nFeeRequired)) + { + if (nPrice + nFeeRequired > pwalletMain->GetBalance()) + Error(strprintf(_("This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds"), FormatMoney(nFeeRequired).c_str())); + else + Error(_("Transaction creation failed")); + return; + } + + if (fWasLocked) + pwalletMain->Lock(); + } // Transaction fee if (!ThreadSafeAskFee(nFeeRequired, _("Sending..."), this)) @@ -2382,7 +2621,7 @@ CAddressBookDialog::CAddressBookDialog(wxWindow* parent, const wxString& strInit m_listCtrlReceiving->SetFocus(); // Fill listctrl with address book data - CRITICAL_BLOCK(pwalletMain->cs_mapKeys) + CRITICAL_BLOCK(pwalletMain->cs_KeyStore) CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) { string strDefaultReceiving = (string)pframeMain->m_textCtrlAddress->GetValue(); @@ -2581,8 +2820,18 @@ void CAddressBookDialog::OnButtonNew(wxCommandEvent& event) return; strName = dialog.GetValue(); - // Generate new key - strAddress = PubKeyToAddress(pwalletMain->GetKeyFromKeyPool()); + CRITICAL_BLOCK(pwalletMain->cs_vMasterKey) + { + bool fWasLocked = pwalletMain->IsLocked(); + if (!GetWalletPassphrase()) + return; + + // Generate new key + strAddress = PubKeyToAddress(pwalletMain->GetOrReuseKeyFromPool()); + + if (fWasLocked) + pwalletMain->Lock(); + } } // Add to list and select it diff --git a/src/ui.h b/src/ui.h index 3f06ad90c..3bf741534 100644 --- a/src/ui.h +++ b/src/ui.h @@ -59,6 +59,8 @@ protected: void OnMenuFileExit(wxCommandEvent& event); void OnUpdateUIOptionsGenerate(wxUpdateUIEvent& event); void OnMenuOptionsChangeYourAddress(wxCommandEvent& event); + void OnMenuOptionsEncryptWallet(wxCommandEvent& event); + void OnMenuOptionsChangeWalletPassphrase(wxCommandEvent& event); void OnMenuOptionsOptions(wxCommandEvent& event); void OnMenuHelpAbout(wxCommandEvent& event); void OnButtonSend(wxCommandEvent& event); diff --git a/src/uibase.cpp b/src/uibase.cpp index 1b901a1ed..18eec4413 100644 --- a/src/uibase.cpp +++ b/src/uibase.cpp @@ -32,6 +32,12 @@ CMainFrameBase::CMainFrameBase( wxWindow* parent, wxWindowID id, const wxString& m_menuOptionsChangeYourAddress = new wxMenuItem( m_menuOptions, wxID_ANY, wxString( _("&Your Receiving Addresses...") ) , wxEmptyString, wxITEM_NORMAL ); m_menuOptions->Append( m_menuOptionsChangeYourAddress ); + m_menuOptionsEncryptWallet = new wxMenuItem( m_menuOptions, wxID_ANY, wxString( _("&Encrypt Wallet...") ) , wxEmptyString, wxITEM_NORMAL ); + m_menuOptions->Append( m_menuOptionsEncryptWallet ); + + m_menuOptionsChangeWalletPassphrase = new wxMenuItem( m_menuOptions, wxID_ANY, wxString( _("&Change Wallet Encryption Passphrase...") ) , wxEmptyString, wxITEM_NORMAL ); + m_menuOptions->Append( m_menuOptionsChangeWalletPassphrase ); + wxMenuItem* m_menuOptionsOptions; m_menuOptionsOptions = new wxMenuItem( m_menuOptions, wxID_PREFERENCES, wxString( _("&Options...") ) , wxEmptyString, wxITEM_NORMAL ); m_menuOptions->Append( m_menuOptionsOptions ); @@ -187,6 +193,8 @@ CMainFrameBase::CMainFrameBase( wxWindow* parent, wxWindowID id, const wxString& this->Connect( wxEVT_PAINT, wxPaintEventHandler( CMainFrameBase::OnPaint ) ); this->Connect( m_menuFileExit->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuFileExit ) ); this->Connect( m_menuOptionsChangeYourAddress->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuOptionsChangeYourAddress ) ); + this->Connect( m_menuOptionsEncryptWallet->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuOptionsEncryptWallet ) ); + this->Connect( m_menuOptionsChangeWalletPassphrase->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuOptionsChangeWalletPassphrase ) ); this->Connect( m_menuOptionsOptions->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuOptionsOptions ) ); this->Connect( m_menuHelpAbout->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuHelpAbout ) ); this->Connect( wxID_BUTTONSEND, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( CMainFrameBase::OnButtonSend ) ); @@ -245,6 +253,8 @@ CMainFrameBase::~CMainFrameBase() this->Disconnect( wxEVT_PAINT, wxPaintEventHandler( CMainFrameBase::OnPaint ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuFileExit ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuOptionsChangeYourAddress ) ); + this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuOptionsEncryptWallet ) ); + this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuOptionsChangeWalletPassphrase ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuOptionsOptions ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( CMainFrameBase::OnMenuHelpAbout ) ); this->Disconnect( wxID_BUTTONSEND, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( CMainFrameBase::OnButtonSend ) ); diff --git a/src/uibase.h b/src/uibase.h index 78f3d1b38..ca0730b20 100644 --- a/src/uibase.h +++ b/src/uibase.h @@ -98,6 +98,8 @@ class CMainFrameBase : public wxFrame virtual void OnPaint( wxPaintEvent& event ) { event.Skip(); } virtual void OnMenuFileExit( wxCommandEvent& event ) { event.Skip(); } virtual void OnMenuOptionsChangeYourAddress( wxCommandEvent& event ) { event.Skip(); } + virtual void OnMenuOptionsEncryptWallet( wxCommandEvent& event ) { event.Skip(); } + virtual void OnMenuOptionsChangeWalletPassphrase( wxCommandEvent& event ) { event.Skip(); } virtual void OnMenuOptionsOptions( wxCommandEvent& event ) { event.Skip(); } virtual void OnMenuHelpAbout( wxCommandEvent& event ) { event.Skip(); } virtual void OnButtonSend( wxCommandEvent& event ) { event.Skip(); } @@ -115,6 +117,8 @@ class CMainFrameBase : public wxFrame public: wxMenu* m_menuOptions; + wxMenuItem* m_menuOptionsEncryptWallet; + wxMenuItem* m_menuOptionsChangeWalletPassphrase; wxStatusBar* m_statusBar; wxTextCtrl* m_textCtrlAddress; wxListCtrl* m_listCtrlAll; diff --git a/src/util.cpp b/src/util.cpp index 3d89f6a82..7cd92d2e8 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -758,8 +758,8 @@ string GetPidFile() void CreatePidFile(string pidFile, pid_t pid) { - FILE* file; - if (file = fopen(pidFile.c_str(), "w")) + FILE* file = fopen(pidFile.c_str(), "w"); + if (file) { fprintf(file, "%d\n", pid); fclose(file); @@ -788,7 +788,9 @@ void ShrinkDebugFile() fseek(file, -sizeof(pch), SEEK_END); int nBytes = fread(pch, 1, sizeof(pch), file); fclose(file); - if (file = fopen(strFile.c_str(), "w")) + + file = fopen(strFile.c_str(), "w"); + if (file) { fwrite(pch, 1, nBytes, file); fclose(file); diff --git a/src/util.h b/src/util.h index 4c1e74b7d..7ac36c0f4 100644 --- a/src/util.h +++ b/src/util.h @@ -262,7 +262,7 @@ public: // I'd rather be careful than suffer the other more error prone syntax. // The compiler will optimise away all this loop junk. #define CRITICAL_BLOCK(cs) \ - for (bool fcriticalblockonce=true; fcriticalblockonce; assert(("break caught by CRITICAL_BLOCK!", !fcriticalblockonce)), fcriticalblockonce=false) \ + for (bool fcriticalblockonce=true; fcriticalblockonce; assert("break caught by CRITICAL_BLOCK!" && !fcriticalblockonce), fcriticalblockonce=false) \ for (CCriticalBlock criticalblock(cs); fcriticalblockonce && (cs.pszFile=__FILE__, cs.nLine=__LINE__, true); fcriticalblockonce=false, cs.pszFile=NULL, cs.nLine=0) class CTryCriticalBlock @@ -276,7 +276,7 @@ public: }; #define TRY_CRITICAL_BLOCK(cs) \ - for (bool fcriticalblockonce=true; fcriticalblockonce; assert(("break caught by TRY_CRITICAL_BLOCK!", !fcriticalblockonce)), fcriticalblockonce=false) \ + for (bool fcriticalblockonce=true; fcriticalblockonce; assert("break caught by TRY_CRITICAL_BLOCK!" && !fcriticalblockonce), fcriticalblockonce=false) \ for (CTryCriticalBlock criticalblock(cs); fcriticalblockonce && (fcriticalblockonce = criticalblock.Entered()) && (cs.pszFile=__FILE__, cs.nLine=__LINE__, true); fcriticalblockonce=false, cs.pszFile=NULL, cs.nLine=0) @@ -646,7 +646,7 @@ inline bool TerminateThread(pthread_t hthread, unsigned int nExitCode) return (pthread_cancel(hthread) == 0); } -inline void ExitThread(unsigned int nExitCode) +inline void ExitThread(size_t nExitCode) { pthread_exit((void*)nExitCode); } diff --git a/src/wallet.cpp b/src/wallet.cpp index fa5775524..3e1bb8e28 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -5,11 +5,11 @@ #include "headers.h" #include "db.h" #include "cryptopp/sha.h" +#include "crypter.h" using namespace std; - ////////////////////////////////////////////////////////////////////////////// // // mapWallet @@ -17,10 +17,181 @@ using namespace std; bool CWallet::AddKey(const CKey& key) { - this->CKeyStore::AddKey(key); + if (!CCryptoKeyStore::AddKey(key)) + return false; if (!fFileBacked) return true; - return CWalletDB(strWalletFile).WriteKey(key.GetPubKey(), key.GetPrivKey()); + if (!IsCrypted()) + return CWalletDB(strWalletFile).WriteKey(key.GetPubKey(), key.GetPrivKey()); + return true; +} + +bool CWallet::AddCryptedKey(const vector &vchPubKey, const vector &vchCryptedSecret) +{ + if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret)) + return false; + if (!fFileBacked) + return true; + CRITICAL_BLOCK(cs_pwalletdbEncryption) + { + if (pwalletdbEncryption) + return pwalletdbEncryption->WriteCryptedKey(vchPubKey, vchCryptedSecret); + else + return CWalletDB(strWalletFile).WriteCryptedKey(vchPubKey, vchCryptedSecret); + } +} + +bool CWallet::Unlock(const string& strWalletPassphrase) +{ + CRITICAL_BLOCK(cs_vMasterKey) + { + if (!IsLocked()) + return false; + + CCrypter crypter; + CKeyingMaterial vMasterKey; + + BOOST_FOREACH(const MasterKeyMap::value_type& pMasterKey, mapMasterKeys) + { + if(!crypter.SetKeyFromPassphrase(strWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) + return false; + if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey)) + return false; + if (CCryptoKeyStore::Unlock(vMasterKey)) + return true; + } + } + return false; +} + +bool CWallet::ChangeWalletPassphrase(const string& strOldWalletPassphrase, const string& strNewWalletPassphrase) +{ + CRITICAL_BLOCK(cs_vMasterKey) + { + bool fWasLocked = IsLocked(); + + Lock(); + + CCrypter crypter; + CKeyingMaterial vMasterKey; + BOOST_FOREACH(MasterKeyMap::value_type& pMasterKey, mapMasterKeys) + { + if(!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) + return false; + if(!crypter.Decrypt(pMasterKey.second.vchCryptedKey, vMasterKey)) + return false; + if (CCryptoKeyStore::Unlock(vMasterKey)) + { + int64 nStartTime = GetTimeMillis(); + crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); + pMasterKey.second.nDeriveIterations = pMasterKey.second.nDeriveIterations * (100 / ((double)(GetTimeMillis() - nStartTime))); + + nStartTime = GetTimeMillis(); + crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod); + pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + pMasterKey.second.nDeriveIterations * 100 / ((double)(GetTimeMillis() - nStartTime))) / 2; + + if (pMasterKey.second.nDeriveIterations < 25000) + pMasterKey.second.nDeriveIterations = 25000; + + printf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations); + + if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod)) + return false; + if (!crypter.Encrypt(vMasterKey, pMasterKey.second.vchCryptedKey)) + return false; + CWalletDB(strWalletFile).WriteMasterKey(pMasterKey.first, pMasterKey.second); + if (fWasLocked) + Lock(); + return true; + } + } + } + return false; +} + + +// This class implements an addrIncoming entry that causes pre-0.4 +// clients to crash on startup if reading a private-key-encrypted wallet. +class CCorruptAddress +{ +public: + IMPLEMENT_SERIALIZE + ( + if (nType & SER_DISK) + READWRITE(nVersion); + ) +}; + +bool CWallet::EncryptWallet(const string& strWalletPassphrase) +{ + CRITICAL_BLOCK(cs_mapPubKeys) + CRITICAL_BLOCK(cs_KeyStore) + CRITICAL_BLOCK(cs_vMasterKey) + CRITICAL_BLOCK(cs_pwalletdbEncryption) + { + if (IsCrypted()) + return false; + + CKeyingMaterial vMasterKey; + RandAddSeedPerfmon(); + + vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE); + RAND_bytes(&vMasterKey[0], WALLET_CRYPTO_KEY_SIZE); + + CMasterKey kMasterKey; + + RandAddSeedPerfmon(); + kMasterKey.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE); + RAND_bytes(&kMasterKey.vchSalt[0], WALLET_CRYPTO_SALT_SIZE); + + CCrypter crypter; + int64 nStartTime = GetTimeMillis(); + crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, 25000, kMasterKey.nDerivationMethod); + kMasterKey.nDeriveIterations = 2500000 / ((double)(GetTimeMillis() - nStartTime)); + + nStartTime = GetTimeMillis(); + crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod); + kMasterKey.nDeriveIterations = (kMasterKey.nDeriveIterations + kMasterKey.nDeriveIterations * 100 / ((double)(GetTimeMillis() - nStartTime))) / 2; + + if (kMasterKey.nDeriveIterations < 25000) + kMasterKey.nDeriveIterations = 25000; + + printf("Encrypting Wallet with an nDeriveIterations of %i\n", kMasterKey.nDeriveIterations); + + if (!crypter.SetKeyFromPassphrase(strWalletPassphrase, kMasterKey.vchSalt, kMasterKey.nDeriveIterations, kMasterKey.nDerivationMethod)) + return false; + if (!crypter.Encrypt(vMasterKey, kMasterKey.vchCryptedKey)) + return false; + + mapMasterKeys[++nMasterKeyMaxID] = kMasterKey; + if (fFileBacked) + { + pwalletdbEncryption = new CWalletDB(strWalletFile); + pwalletdbEncryption->TxnBegin(); + pwalletdbEncryption->WriteMasterKey(nMasterKeyMaxID, kMasterKey); + } + + if (!EncryptKeys(vMasterKey)) + { + if (fFileBacked) + pwalletdbEncryption->TxnAbort(); + exit(1); //We now probably have half of our keys encrypted in memory, and half not...die and let the user reload their unencrypted wallet. + } + + if (fFileBacked) + { + CCorruptAddress corruptAddress; + pwalletdbEncryption->WriteSetting("addrIncoming", corruptAddress); + if (!pwalletdbEncryption->TxnCommit()) + exit(1); //We now have keys encrypted in memory, but no on disk...die to avoid confusion and let the user reload their unencrypted wallet. + + pwalletdbEncryption->Close(); + pwalletdbEncryption = NULL; + } + + Lock(); + } + return true; } void CWallet::WalletUpdateSpent(const CTransaction &tx) @@ -98,7 +269,10 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) BOOST_FOREACH(const CTxOut& txout, wtx.vout) { if (txout.scriptPubKey == scriptDefaultKey) - SetDefaultKey(GetKeyFromKeyPool()); + { + SetDefaultKey(GetOrReuseKeyFromPool()); + SetAddressBookName(PubKeyToAddress(vchDefaultKey), ""); + } } #endif // Notify UI @@ -552,8 +726,6 @@ void CWallet::ResendWalletTransactions() int64 CWallet::GetBalance() const { - int64 nStart = GetTimeMillis(); - int64 nTotal = 0; CRITICAL_BLOCK(cs_mapWallet) { @@ -566,7 +738,6 @@ int64 CWallet::GetBalance() const } } - //printf("GetBalance() %"PRI64d"ms\n", GetTimeMillis() - nStart); return nTotal; } @@ -798,7 +969,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, CW // Reserve a new key pair from key pool vector vchPubKey = reservekey.GetReservedKey(); - assert(mapKeys.count(vchPubKey)); + // assert(mapKeys.count(vchPubKey)); // Fill a vout to ourself, using same address type as the payment CScript scriptChange; @@ -918,15 +1089,24 @@ string CWallet::SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, { CReserveKey reservekey(this); int64 nFeeRequired; - if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired)) + CRITICAL_BLOCK(cs_vMasterKey) { - string strError; - if (nValue + nFeeRequired > GetBalance()) - strError = strprintf(_("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds "), FormatMoney(nFeeRequired).c_str()); - else - strError = _("Error: Transaction creation failed "); - printf("SendMoney() : %s", strError.c_str()); - return strError; + if (IsLocked()) + { + string strError = _("Error: Wallet locked, unable to create transaction "); + printf("SendMoney() : %s", strError.c_str()); + return strError; + } + if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired)) + { + string strError; + if (nValue + nFeeRequired > GetBalance()) + strError = strprintf(_("Error: This transaction requires a transaction fee of at least %s because of its amount, complexity, or use of recently received funds "), FormatMoney(nFeeRequired).c_str()); + else + strError = _("Error: Transaction creation failed "); + printf("SendMoney() : %s", strError.c_str()); + return strError; + } } if (fAskFee && !ThreadSafeAskFee(nFeeRequired, _("Sending..."), NULL)) @@ -961,27 +1141,28 @@ string CWallet::SendMoneyToBitcoinAddress(string strAddress, int64 nValue, CWall -bool CWallet::LoadWallet(bool& fFirstRunRet) +int CWallet::LoadWallet(bool& fFirstRunRet) { if (!fFileBacked) return false; fFirstRunRet = false; - if (!CWalletDB(strWalletFile,"cr+").LoadWallet(this)) - return false; + int nLoadWalletRet = CWalletDB(strWalletFile,"cr+").LoadWallet(this); + if (nLoadWalletRet != DB_LOAD_OK) + return nLoadWalletRet; fFirstRunRet = vchDefaultKey.empty(); - if (!mapKeys.count(vchDefaultKey)) + if (!HaveKey(vchDefaultKey)) { - // Create new default key + // Create new keyUser and set as default key RandAddSeedPerfmon(); - SetDefaultKey(GetKeyFromKeyPool()); + SetDefaultKey(GetOrReuseKeyFromPool()); if (!SetAddressBookName(PubKeyToAddress(vchDefaultKey), "")) - return false; + return DB_LOAD_FAIL; } CreateThread(ThreadFlushWalletDB, &strWalletFile); - return true; + return DB_LOAD_OK; } @@ -1048,14 +1229,16 @@ bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut) return true; } -void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool) +bool CWallet::TopUpKeyPool() { - nIndex = -1; - keypool.vchPubKey.clear(); CRITICAL_BLOCK(cs_main) CRITICAL_BLOCK(cs_mapWallet) CRITICAL_BLOCK(cs_setKeyPool) + CRITICAL_BLOCK(cs_vMasterKey) { + if (IsLocked()) + return false; + CWalletDB walletdb(strWalletFile); // Top up key pool @@ -1066,18 +1249,36 @@ void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool) if (!setKeyPool.empty()) nEnd = *(--setKeyPool.end()) + 1; if (!walletdb.WritePool(nEnd, CKeyPool(GenerateNewKey()))) - throw runtime_error("ReserveKeyFromKeyPool() : writing generated key failed"); + throw runtime_error("TopUpKeyPool() : writing generated key failed"); setKeyPool.insert(nEnd); printf("keypool added key %"PRI64d", size=%d\n", nEnd, setKeyPool.size()); } + } + return true; +} + +void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool) +{ + nIndex = -1; + keypool.vchPubKey.clear(); + CRITICAL_BLOCK(cs_main) + CRITICAL_BLOCK(cs_mapWallet) + CRITICAL_BLOCK(cs_setKeyPool) + { + if (!IsLocked()) + TopUpKeyPool(); // Get the oldest key - assert(!setKeyPool.empty()); + if(setKeyPool.empty()) + return; + + CWalletDB walletdb(strWalletFile); + nIndex = *(setKeyPool.begin()); setKeyPool.erase(setKeyPool.begin()); if (!walletdb.ReadPool(nIndex, keypool)) throw runtime_error("ReserveKeyFromKeyPool() : read failed"); - if (!mapKeys.count(keypool.vchPubKey)) + if (!HaveKey(keypool.vchPubKey)) throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool"); assert(!keypool.vchPubKey.empty()); printf("keypool reserve %"PRI64d"\n", nIndex); @@ -1106,11 +1307,13 @@ void CWallet::ReturnKey(int64 nIndex) printf("keypool return %"PRI64d"\n", nIndex); } -vector CWallet::GetKeyFromKeyPool() +vector CWallet::GetOrReuseKeyFromPool() { int64 nIndex = 0; CKeyPool keypool; ReserveKeyFromKeyPool(nIndex, keypool); + if(nIndex == -1) + return vchDefaultKey; KeepKey(nIndex); return keypool.vchPubKey; } @@ -1120,6 +1323,8 @@ int64 CWallet::GetOldestKeyPoolTime() int64 nIndex = 0; CKeyPool keypool; ReserveKeyFromKeyPool(nIndex, keypool); + if (nIndex == -1) + return GetTime(); ReturnKey(nIndex); return keypool.nTime; } @@ -1130,7 +1335,13 @@ vector CReserveKey::GetReservedKey() { CKeyPool keypool; pwallet->ReserveKeyFromKeyPool(nIndex, keypool); - vchPubKey = keypool.vchPubKey; + if (nIndex != -1) + vchPubKey = keypool.vchPubKey; + else + { + printf("CReserveKey::GetReservedKey(): Warning: using default key instead of a new key, top up your keypool."); + vchPubKey = pwallet->vchDefaultKey; + } } assert(!vchPubKey.empty()); return vchPubKey; diff --git a/src/wallet.h b/src/wallet.h index 078d7e6e9..490745a71 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -12,12 +12,14 @@ class CWalletTx; class CReserveKey; class CWalletDB; -class CWallet : public CKeyStore +class CWallet : public CCryptoKeyStore { private: bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, std::set >& setCoinsRet, int64& nValueRet) const; bool SelectCoins(int64 nTargetValue, std::set >& setCoinsRet, int64& nValueRet) const; + CWalletDB *pwalletdbEncryption; + CCriticalSection cs_pwalletdbEncryption; public: bool fFileBacked; @@ -26,14 +28,22 @@ public: std::set setKeyPool; CCriticalSection cs_setKeyPool; + typedef std::map MasterKeyMap; + MasterKeyMap mapMasterKeys; + unsigned int nMasterKeyMaxID; + CWallet() { fFileBacked = false; + nMasterKeyMaxID = 0; + pwalletdbEncryption = NULL; } CWallet(std::string strWalletFileIn) { strWalletFile = strWalletFileIn; fFileBacked = true; + nMasterKeyMaxID = 0; + pwalletdbEncryption = NULL; } mutable CCriticalSection cs_mapWallet; @@ -48,7 +58,16 @@ public: std::vector vchDefaultKey; + // keystore implementation bool AddKey(const CKey& key); + bool LoadKey(const CKey& key) { return CCryptoKeyStore::AddKey(key); } + bool AddCryptedKey(const std::vector &vchPubKey, const std::vector &vchCryptedSecret); + bool LoadCryptedKey(const std::vector &vchPubKey, const std::vector &vchCryptedSecret) { return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); } + + bool Unlock(const std::string& strWalletPassphrase); + bool ChangeWalletPassphrase(const std::string& strOldWalletPassphrase, const std::string& strNewWalletPassphrase); + bool EncryptWallet(const std::string& strWalletPassphrase); + bool AddToWallet(const CWalletTx& wtxIn); bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false); bool EraseFromWallet(uint256 hash); @@ -65,10 +84,11 @@ public: std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false); std::string SendMoneyToBitcoinAddress(std::string strAddress, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false); + bool TopUpKeyPool(); void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool); void KeepKey(int64 nIndex); void ReturnKey(int64 nIndex); - std::vector GetKeyFromKeyPool(); + std::vector GetOrReuseKeyFromPool(); int64 GetOldestKeyPoolTime(); bool IsMine(const CTxIn& txin) const; @@ -148,7 +168,7 @@ public: walletdb.WriteBestBlock(loc); } - bool LoadWallet(bool& fFirstRunRet); + int LoadWallet(bool& fFirstRunRet); // bool BackupWallet(const std::string& strDest); // requires cs_mapAddressBook lock @@ -175,6 +195,11 @@ public: } } + int GetKeyPoolSize() + { + return setKeyPool.size(); + } + bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx); bool SetDefaultKey(const std::vector &vchPubKey);