#pragma once #include namespace dragonx { namespace data { enum class EncryptionPendingAction { None, Clear, Warn }; // What to do with the persisted "encryption requested in the wizard" flag, given ONE parsed getwalletinfo // result. rpcOk must come from the parsed reply (a -28 warm-up failure or a throw is rpcOk=false => None); // never derive it from WalletState (a 15 s timeout forces encrypted=false there). inline EncryptionPendingAction decideEncryptionPending(bool flagSet, bool rpcOk, bool walletEncrypted, bool deferredPending, bool encryptInProgress, bool alreadyWarned) { if (!flagSet || !rpcOk) return EncryptionPendingAction::None; if (walletEncrypted) return EncryptionPendingAction::Clear; if (deferredPending || encryptInProgress || alreadyWarned) return EncryptionPendingAction::None; return EncryptionPendingAction::Warn; } // ---- C90 ---- constexpr int kSetPinProbeSecs = 5; // the verification unlock used when the wallet is locked struct SetPinVerifyPlan { int timeoutSecs; // walletpassphrase timeout for the passphrase check bool relockAfter; // call walletlock afterwards (only if the wallet was locked before) }; // Set PIN verifies the passphrase with walletpassphrase. If the wallet is unlocked now, re-unlock with the time // it has left (replaces the daemon's timer with the same deadline) and DO NOT relock; otherwise a 5 s probe + relock. inline SetPinVerifyPlan planSetPinVerify(bool guiUnlocked, std::int64_t unlockedUntil, std::int64_t now) { const std::int64_t left = unlockedUntil - now; if (guiUnlocked && left > kSetPinProbeSecs) { const std::int64_t capped = left > 86400 * 7 ? 86400 * 7 : left; return {static_cast(capped), false}; } return {kSetPinProbeSecs, true}; } // The daemon's absolute unlock window has run out but the GUI still says "unlocked". Wall clock, because the // deadline is an absolute unix time. unlockedUntil == 0 means "no deadline known" => never expired here. inline bool unlockWindowExpired(bool encrypted, bool locked, std::int64_t unlockedUntil, std::int64_t now) { return encrypted && !locked && unlockedUntil > 0 && now >= unlockedUntil; } } // namespace data } // namespace dragonx