mirror of
https://github.com/pezkuwichain/pezkuwi-wallet-android.git
synced 2026-07-22 19:35:51 +00:00
163e68dcd3
The previous commit's SafeOptional/custom() field wrapper was wrong and broke real tests (RealLocalAccountsCloudBackupFacadeTest, Solana/Tron backfill migration tests - Mockito WantedButNotInvoked, IllegalArgumentException). Root cause of that failure: EncodableStruct.get() (in the external substrate-sdk-android library) only returns null for an unset field when field.dataType is specifically an instance of the library's own `optional<*>` class - not any DataType that merely behaves like one. optional<T> is not open, so no wrapper class can satisfy that check; swapping in a custom DataType just moves the same crash from read-time to access-time. Correct fix: leave the MetaAccountSecrets schema exactly as it always was (plain `.optional()`, real library instances, so get() keeps working), and instead add readMetaAccountSecrets() - a resilient top-level reader that tries the normal Schema.read() first and, only if that throws, falls back to reading each field by hand in schema order, stopping at the first one whose bytes don't exist and leaving every field after it genuinely unset. Because those fields were never set, EncodableStruct.get()'s existing (correct) optional-field handling returns null for them exactly as it already does for any account that was never migrated - no library behavior is being routed around, just extended to tolerate a shorter/older stored blob.