Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fallback for metadata JSON parsing from pre-existing database #2173

Merged
merged 1 commit into from
Sep 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/core/src/Cardano/Wallet/DB/Sqlite/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,27 @@ instance PersistField TxMetadata where
Aeson.encode .
metadataToJson TxMetadataJsonDetailedSchema
fromPersistValue =
(left (T.pack . displayError) . metadataFromJson TxMetadataJsonDetailedSchema) <=<
(left (T.pack . displayError) . metadataFromJsonWithFallback) <=<
(left T.pack . Aeson.eitherDecode . BL.fromStrict . encodeUtf8) <=<
fromPersistValue
where
-- FIXME
-- Because of time constraints, we have had two consecutives releases
-- of cardano-wallet which ended up using different conversions method
-- for metadata to/from JSON.
-- As a result, some users' databases contain metadata using the direct
-- JSON conversion while we now expect the detailed schema variant.
--
-- We do therefore fallback when deserializing data do the direct
-- conversion (which will then be serialized back using the detailed
-- schema). We can remove that fallback after some time has passed since
-- release v2020-09-22.
metadataFromJsonWithFallback json =
case metadataFromJson TxMetadataJsonDetailedSchema json of
Right meta -> Right meta
Left e -> case metadataFromJson TxMetadataJsonNoSchema json of
Right meta -> Right meta
Left{} -> Left e

instance PersistFieldSql TxMetadata where
sqlType _ = sqlType (Proxy @Text)
Expand Down