diff options
| author | mtg0001 <106211915+mtg0001@users.noreply.github.com> | 2026-08-03 10:43:42 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-03 10:43:42 -0300 |
| commit | 57441faffb02f4f2eea37d31b29728de25f18bef (patch) | |
| tree | edade03dddf472790e8bc7e3bc52d3e8f8eac87b /src/walletcmd.cpp | |
| parent | 5e37647023463cec4331dc48dc360ba60b22c888 (diff) | |
Add wallet recovery balance audit (#117)
Co-authored-by: Gilcimar Duarte <ti@gpm.infra>
Diffstat (limited to 'src/walletcmd.cpp')
| -rw-r--r-- | src/walletcmd.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/walletcmd.cpp b/src/walletcmd.cpp index 6d5f32b..41b4ed2 100644 --- a/src/walletcmd.cpp +++ b/src/walletcmd.cpp | |||
| @@ -272,6 +272,65 @@ int CmdShowDerived(int nCount) | |||
| 272 | return 0; | 272 | return 0; |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | int CmdRecoveryAudit() | ||
| 276 | { | ||
| 277 | AttachTerminal(); | ||
| 278 | |||
| 279 | WalletRecoveryAudit audit = GetWalletRecoveryAudit(); | ||
| 280 | int64 nTotal = audit.nRecoverableCredit + audit.nLegacyCredit; | ||
| 281 | int64 nImmatureTotal = audit.nRecoverableImmatureCredit + audit.nLegacyImmatureCredit; | ||
| 282 | |||
| 283 | printf("Wallet recovery audit\n"); | ||
| 284 | printf(" recovery phrase: %s\n", audit.fHaveSeed ? "present" : "not installed"); | ||
| 285 | if (audit.fHaveSeed) | ||
| 286 | printf(" derived keys known to this wallet: %u\n", audit.nDerivedKnown); | ||
| 287 | if (!audit.fDeriveComplete) | ||
| 288 | printf(" derivation warning: %s\n", audit.strDeriveError.c_str()); | ||
| 289 | printf(" total spendable balance: %s BTF\n", FormatMoney(nTotal).c_str()); | ||
| 290 | printf(" covered by recovery phrase: %s BTF (%d transaction(s))\n", | ||
| 291 | FormatMoney(audit.nRecoverableCredit).c_str(), audit.nRecoverableTx); | ||
| 292 | printf(" wallet.dat-only balance: %s BTF (%d transaction(s))\n", | ||
| 293 | FormatMoney(audit.nLegacyCredit).c_str(), audit.nLegacyTx); | ||
| 294 | printf(" immature mining rewards: %s BTF\n", FormatMoney(nImmatureTotal).c_str()); | ||
| 295 | printf(" phrase-backed immature: %s BTF (%d transaction(s))\n", | ||
| 296 | FormatMoney(audit.nRecoverableImmatureCredit).c_str(), | ||
| 297 | audit.nRecoverableImmatureTx); | ||
| 298 | printf(" wallet.dat-only immature: %s BTF (%d transaction(s))\n", | ||
| 299 | FormatMoney(audit.nLegacyImmatureCredit).c_str(), | ||
| 300 | audit.nLegacyImmatureTx); | ||
| 301 | |||
| 302 | if (!audit.fHaveSeed) | ||
| 303 | { | ||
| 304 | printf("\n"); | ||
| 305 | printf("This wallet has no recovery phrase. A file backup is the only backup.\n"); | ||
| 306 | fflush(stdout); | ||
| 307 | return nTotal + nImmatureTotal > 0 ? 2 : 0; | ||
| 308 | } | ||
| 309 | if (!audit.fDeriveComplete) | ||
| 310 | { | ||
| 311 | printf("\n"); | ||
| 312 | printf("Warning: the audit could not derive every known phrase key, so coverage is incomplete.\n"); | ||
| 313 | fflush(stdout); | ||
| 314 | return 2; | ||
| 315 | } | ||
| 316 | if (audit.nLegacyCredit > 0 || audit.nLegacyImmatureCredit > 0) | ||
| 317 | { | ||
| 318 | printf("\n"); | ||
| 319 | printf("Warning: some coins are on keys the phrase does not reproduce.\n"); | ||
| 320 | printf("Keep wallet.dat backups until that balance has been moved to a phrase-backed address.\n"); | ||
| 321 | fflush(stdout); | ||
| 322 | return 2; | ||
| 323 | } | ||
| 324 | |||
| 325 | printf("\n"); | ||
| 326 | if (nTotal + nImmatureTotal > 0) | ||
| 327 | printf("All known wallet balance is covered by the recovery phrase.\n"); | ||
| 328 | else | ||
| 329 | printf("No wallet balance found yet.\n"); | ||
| 330 | fflush(stdout); | ||
| 331 | return 0; | ||
| 332 | } | ||
| 333 | |||
| 275 | // Spend, from the command line. | 334 | // Spend, from the command line. |
| 276 | // | 335 | // |
| 277 | // SendMoney() has been in this tree since 0.1.0 and only the window ever called | 336 | // SendMoney() has been in this tree since 0.1.0 and only the window ever called |