diff options
Diffstat (limited to 'src/walletcmd.cpp')
| -rw-r--r-- | src/walletcmd.cpp | 135 |
1 files changed, 108 insertions, 27 deletions
diff --git a/src/walletcmd.cpp b/src/walletcmd.cpp index 6f8258d..ce0da02 100644 --- a/src/walletcmd.cpp +++ b/src/walletcmd.cpp | |||
| @@ -472,33 +472,28 @@ int CmdRecoveryAudit() | |||
| 472 | 472 | ||
| 473 | struct WalletStorageAuditCounts | 473 | struct WalletStorageAuditCounts |
| 474 | { | 474 | { |
| 475 | unsigned int nTotal; | 475 | unsigned int nTotal = 0; |
| 476 | unsigned int nMalformed; | 476 | unsigned int nMalformed = 0; |
| 477 | unsigned int nUnknown; | 477 | unsigned int nUnknown = 0; |
| 478 | unsigned int nVersion; | 478 | unsigned int nVersion = 0; |
| 479 | unsigned int nNames; | 479 | unsigned int nNames = 0; |
| 480 | unsigned int nTransactions; | 480 | unsigned int nTransactions = 0; |
| 481 | unsigned int nPlainKeys; | 481 | unsigned int nPlainKeys = 0; |
| 482 | unsigned int nEncryptedKeys; | 482 | unsigned int nEncryptedKeys = 0; |
| 483 | unsigned int nMasterKeys; | 483 | unsigned int nMasterKeys = 0; |
| 484 | unsigned int nDefaultKey; | 484 | unsigned int nDefaultKey = 0; |
| 485 | unsigned int nPlainHDMaster; | 485 | unsigned int nPlainHDMaster = 0; |
| 486 | unsigned int nPlainHDChainCode; | 486 | unsigned int nPlainHDChainCode = 0; |
| 487 | unsigned int nCryptedHDMaster; | 487 | unsigned int nCryptedHDMaster = 0; |
| 488 | unsigned int nCryptedHDChainCode; | 488 | unsigned int nCryptedHDChainCode = 0; |
| 489 | unsigned int nWalletMinVersion; | 489 | unsigned int nWalletMinVersion = 0; |
| 490 | unsigned int nPool; | 490 | unsigned int nPool = 0; |
| 491 | unsigned int nSettings; | 491 | unsigned int nSettings = 0; |
| 492 | unsigned int nHDNext; | 492 | unsigned int nHDNext = 0; |
| 493 | unsigned int nHDSchema; | 493 | unsigned int nHDSchema = 0; |
| 494 | unsigned int nHDCoinType; | 494 | unsigned int nHDCoinType = 0; |
| 495 | unsigned int nHDReceiveNext; | 495 | unsigned int nHDReceiveNext = 0; |
| 496 | unsigned int nHDChangeNext; | 496 | unsigned int nHDChangeNext = 0; |
| 497 | |||
| 498 | WalletStorageAuditCounts() | ||
| 499 | { | ||
| 500 | memset(this, 0, sizeof(*this)); | ||
| 501 | } | ||
| 502 | }; | 497 | }; |
| 503 | 498 | ||
| 504 | static std::string HDSeedStorageState(unsigned int nMaster, unsigned int nChain) | 499 | static std::string HDSeedStorageState(unsigned int nMaster, unsigned int nChain) |
| @@ -658,6 +653,92 @@ static bool WriteAuditTextFile(const std::string& strPath, | |||
| 658 | return true; | 653 | return true; |
| 659 | } | 654 | } |
| 660 | 655 | ||
| 656 | static void AddWalletStorageFailure(std::vector<std::string>& vFailures, | ||
| 657 | const std::string& strFailure) | ||
| 658 | { | ||
| 659 | vFailures.push_back(strFailure); | ||
| 660 | } | ||
| 661 | |||
| 662 | static void BuildWalletStorageSanityFailures(const WalletStorageAuditCounts& counts, | ||
| 663 | std::vector<std::string>& vFailures) | ||
| 664 | { | ||
| 665 | bool fPlainHD = counts.nPlainHDMaster > 0 || counts.nPlainHDChainCode > 0; | ||
| 666 | bool fCryptedHD = counts.nCryptedHDMaster > 0 || counts.nCryptedHDChainCode > 0; | ||
| 667 | bool fEncryptedRecords = counts.nEncryptedKeys > 0 || | ||
| 668 | counts.nMasterKeys > 0 || | ||
| 669 | fCryptedHD; | ||
| 670 | |||
| 671 | if (counts.nMalformed > 0) | ||
| 672 | AddWalletStorageFailure(vFailures, "wallet.dat contains malformed records"); | ||
| 673 | if (counts.nUnknown > 0) | ||
| 674 | AddWalletStorageFailure(vFailures, "wallet.dat contains unknown records"); | ||
| 675 | if ((counts.nPlainHDMaster > 0) != (counts.nPlainHDChainCode > 0)) | ||
| 676 | AddWalletStorageFailure(vFailures, "plain HD seed is incomplete"); | ||
| 677 | if ((counts.nCryptedHDMaster > 0) != (counts.nCryptedHDChainCode > 0)) | ||
| 678 | AddWalletStorageFailure(vFailures, "encrypted HD seed is incomplete"); | ||
| 679 | if (fPlainHD && fCryptedHD) | ||
| 680 | AddWalletStorageFailure(vFailures, "wallet.dat contains both plain and encrypted HD seed records"); | ||
| 681 | if (counts.nDefaultKey > 1) | ||
| 682 | AddWalletStorageFailure(vFailures, "wallet.dat contains more than one default public key record"); | ||
| 683 | if (counts.nWalletMinVersion > 1) | ||
| 684 | AddWalletStorageFailure(vFailures, "wallet.dat contains more than one minimum-version record"); | ||
| 685 | |||
| 686 | if (fEncryptedRecords) | ||
| 687 | { | ||
| 688 | if (counts.nPlainKeys > 0) | ||
| 689 | AddWalletStorageFailure(vFailures, "encrypted wallet still contains plain private key records"); | ||
| 690 | if (fPlainHD) | ||
| 691 | AddWalletStorageFailure(vFailures, "encrypted wallet still contains plain HD seed records"); | ||
| 692 | if (counts.nMasterKeys == 0) | ||
| 693 | AddWalletStorageFailure(vFailures, "encrypted wallet has no encryption master key record"); | ||
| 694 | if (counts.nWalletMinVersion == 0) | ||
| 695 | AddWalletStorageFailure(vFailures, "encrypted wallet has no minimum-version record"); | ||
| 696 | } | ||
| 697 | } | ||
| 698 | |||
| 699 | int CmdWalletStorageCheck() | ||
| 700 | { | ||
| 701 | AttachTerminal(); | ||
| 702 | |||
| 703 | WalletStorageAuditCounts counts; | ||
| 704 | std::string strError; | ||
| 705 | if (!ReadWalletStorageCounts(counts, strError)) | ||
| 706 | { | ||
| 707 | fprintf(stderr, "Cannot check wallet storage: %s\n", strError.c_str()); | ||
| 708 | return 1; | ||
| 709 | } | ||
| 710 | |||
| 711 | std::vector<std::string> vFailures; | ||
| 712 | BuildWalletStorageSanityFailures(counts, vFailures); | ||
| 713 | |||
| 714 | printf("Wallet storage sanity check\n"); | ||
| 715 | printf(" records total: %u\n", counts.nTotal); | ||
| 716 | printf(" encrypted records: %s\n", | ||
| 717 | (counts.nEncryptedKeys || counts.nMasterKeys || | ||
| 718 | counts.nCryptedHDMaster || counts.nCryptedHDChainCode) ? "yes" : "no"); | ||
| 719 | printf(" plain private keys: %u\n", counts.nPlainKeys); | ||
| 720 | printf(" encrypted private keys: %u\n", counts.nEncryptedKeys); | ||
| 721 | printf(" plain HD seed: %s\n", | ||
| 722 | HDSeedStorageState(counts.nPlainHDMaster, | ||
| 723 | counts.nPlainHDChainCode).c_str()); | ||
| 724 | printf(" encrypted HD seed: %s\n", | ||
| 725 | HDSeedStorageState(counts.nCryptedHDMaster, | ||
| 726 | counts.nCryptedHDChainCode).c_str()); | ||
| 727 | if (vFailures.empty()) | ||
| 728 | { | ||
| 729 | printf(" storage sanity: ok\n"); | ||
| 730 | fflush(stdout); | ||
| 731 | return 0; | ||
| 732 | } | ||
| 733 | |||
| 734 | printf(" storage sanity: failed\n"); | ||
| 735 | for (std::vector<std::string>::const_iterator it = vFailures.begin(); | ||
| 736 | it != vFailures.end(); ++it) | ||
| 737 | printf(" failure: %s\n", it->c_str()); | ||
| 738 | fflush(stdout); | ||
| 739 | return 2; | ||
| 740 | } | ||
| 741 | |||
| 661 | int CmdWalletStorageAudit(const std::string& strJsonOut) | 742 | int CmdWalletStorageAudit(const std::string& strJsonOut) |
| 662 | { | 743 | { |
| 663 | AttachTerminal(); | 744 | AttachTerminal(); |