Skip to content

Commit

Permalink
No need for metadata signatures backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Mar 2, 2021
1 parent b87ba10 commit 771c248
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 47 deletions.
12 changes: 3 additions & 9 deletions lib/core/src/Cardano/Wallet/TokenMetadata.hs
Expand Up @@ -114,6 +114,7 @@ import Data.Aeson
, encode
, withObject
, withText
, (.!=)
, (.:)
, (.:?)
)
Expand All @@ -132,7 +133,7 @@ import Data.Functor
import Data.Hashable
( Hashable )
import Data.Maybe
( catMaybes, fromMaybe, mapMaybe )
( catMaybes, mapMaybe )
import Data.Proxy
( Proxy (..) )
import Data.String
Expand Down Expand Up @@ -552,18 +553,11 @@ instance FromJSON SubjectProperties where
instance (HasValidator name, FromJSON (PropertyValue name)) => FromJSON (Property name) where
parseJSON = withObject "Property value" $ \o -> Property
<$> (validate <$> o .: "value")
<*> parseSignatures o
<*> o .:? "signatures" .!= []
where
validate v = first (,v) $ (>>= validatePropertyValue @name) $ tryParse v
tryParse = resultToEither . fromJSON

-- Parse optional signatures field (anSignatures is the old name),
-- requiring the field to parse successfully, if it's present.
parseSignatures o = do
sigs <- o .:? "signatures"
oldSigs <- o .:? "anSignatures"
pure (fromMaybe [] (sigs <|> oldSigs))

resultToEither :: Aeson.Result a -> Either String a
resultToEither = \case
Aeson.Success a -> Right a
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/TokenMetadata/MockServer.hs
Expand Up @@ -220,7 +220,7 @@ instance ToJSON SubjectProperties where
instance ToJSON (PropertyValue name) => ToJSON (Property name) where
toJSON (Property v s) = object
[ "value" .= either snd toJSON v
, "anSignatures" .= s ]
, "signatures" .= s ]

instance ToJSON Signature where
toJSON (Signature s k) = object
Expand Down
6 changes: 3 additions & 3 deletions lib/core/test/data/Cardano/Wallet/TokenMetadata/golden1.json
Expand Up @@ -9,7 +9,7 @@
},
"name": {
"value": "SteveToken",
"anSignatures": [
"signatures": [
{
"signature": "7ef6ed44ba9456737ef8d2e31596fdafb66d5775ac1a254086a553b666516e5895bb0c6b7ba8bef1f6b4d9bd9253b4449d1354de2f9e043ea4eb43fd42f87108",
"publicKey": "0ee262f062528667964782777917cd7139e19e8eb2c591767629e4200070c661"
Expand All @@ -34,7 +34,7 @@
},
"description": {
"value": "A sample description",
"anSignatures": [
"signatures": [
{
"signature": "83ef5c04882e43e5f1c8e9bc386bd51cdda163f5cbd1996d1d066238de063d4b79b1648b48aec63dddff05649911ca116579842c8e9a08a3bc7ae1a0ec7ef000",
"publicKey": "1446c9d327b0f07aa691014c08578867674f3a88b36f2017a58c37a8a7799058"
Expand Down Expand Up @@ -62,7 +62,7 @@
"subject": "missing sigs",
"name": {
"value": "Token1",
"anSignatures": []
"signatures": []
},
"description": {
"value": "description1"
Expand Down
12 changes: 1 addition & 11 deletions lib/core/test/data/Cardano/Wallet/TokenMetadata/golden2.json
Expand Up @@ -9,7 +9,7 @@
},
"name": {
"value": "SteveToken",
"anSignatures": [
"signatures": [
{
"signature": "7ef6ed44ba9456737ef8d2e31596fdafb66d5775ac1a254086a553b666516e5895bb0c6b7ba8bef1f6b4d9bd9253b4449d1354de2f9e043ea4eb43fd42f87108",
"publicKey": "0ee262f062528667964782777917cd7139e19e8eb2c591767629e4200070c661"
Expand Down Expand Up @@ -60,16 +60,6 @@
},
{
"subject": "missing sigs",
"name": {
"value": "Token1",
"anSignatures": []
},
"description": {
"value": "description1"
}
},
{
"subject": "missing sigs 2",
"name": {
"value": "Token1",
"signatures": []
Expand Down
12 changes: 0 additions & 12 deletions lib/core/test/unit/Cardano/Wallet/TokenMetadataSpec.hs
Expand Up @@ -186,18 +186,6 @@ spec = do
, Nothing
)
}
, SubjectProperties
{ subject = "missing sigs 2"
, owner = Nothing
, properties =
( Just $ Property (Right "Token1") []
, Just $ Property (Right "description1") []
, Nothing
, Nothing
, Nothing
, Nothing
)
}
, SubjectProperties
{ subject = "extra fields"
, owner = Nothing
Expand Down
22 changes: 11 additions & 11 deletions lib/shelley/test/data/token-metadata.json
Expand Up @@ -12,7 +12,7 @@
},
"name": {
"value": "SteveToken",
"anSignatures": [
"signatures": [
{
"signature": "7ef6ed44ba9456737ef8d2e31596fdafb66d5775ac1a254086a553b666516e5895bb0c6b7ba8bef1f6b4d9bd9253b4449d1354de2f9e043ea4eb43fd42f87108",
"publicKey": "0ee262f062528667964782777917cd7139e19e8eb2c591767629e4200070c661"
Expand All @@ -21,7 +21,7 @@
},
"description": {
"value": "A sample description",
"anSignatures": [
"signatures": [
{
"signature": "83ef5c04882e43e5f1c8e9bc386bd51cdda163f5cbd1996d1d066238de063d4b79b1648b48aec63dddff05649911ca116579842c8e9a08a3bc7ae1a0ec7ef000",
"publicKey": "1446c9d327b0f07aa691014c08578867674f3a88b36f2017a58c37a8a7799058"
Expand All @@ -30,48 +30,48 @@
},
"ticker": {
"value": "STV",
"anSignatures": []
"signatures": []
},
"unit": {
"value": { "decimals": 6, "name": "MegaSteve" },
"anSignatures": []
"signatures": []
},
"url": {
"value": "https://iohk.io/stevetoken",
"anSignatures": []
"signatures": []
},
"logo": {
"value": "QWxtb3N0IGEgbG9nbw==",
"anSignatures": []
"signatures": []
}
},
{
"subject": "f4137b0691b01c7ca46c2fc05576f4f0ab8eebb8f8e4946cb9107e0f6170706c65",
"name": {
"value": "Apple",
"anSignatures": []
"signatures": []
},
"description": {
"value": "A healthy kind of fruit",
"anSignatures": []
"signatures": []
}
},
{
"subject": "f4137b0691b01c7ca46c2fc05576f4f0ab8eebb8f8e4946cb9107e0f62616e616e61",
"name": {
"value": "Banana",
"anSignatures": []
"signatures": []
},
"description": {
"value": "A yummy kind of fruit",
"anSignatures": []
"signatures": []
}
},
{
"subject": "f4137b0691b01c7ca46c2fc05576f4f0ab8eebb8f8e4946cb9107e0f62636865727279",
"name": {
"value": "Cherry",
"anSignatures": []
"signatures": []
},
"description": {
"value": "A special kind of fruit"
Expand Down

0 comments on commit 771c248

Please sign in to comment.