-
Notifications
You must be signed in to change notification settings - Fork 205
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
Switch to using json structure for metering report [DPP-1134] #14891
Conversation
07292cb
to
add64c6
Compare
kindToAesonValue (S.ValueKindStructValue (S.Struct sMap)) = | ||
A.Object aMap | ||
where | ||
aMap = KeyMap.fromMap $ fmap s2a $ Map.mapKeys Key.fromText $ Map.mapKeys TL.toStrict sMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aMap = KeyMap.fromMap $ fmap s2a $ Map.mapKeys Key.fromText $ Map.mapKeys TL.toStrict sMap | |
aMap = KeyMap.fromMap $ s2a <$> Map.mapKeys (Key.fromText . TL.toStrict) sMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, done.
kindToAesonValue (S.ValueKindNumberValue num) = A.Number $ Scientific.fromFloatDigits num | ||
kindToAesonValue (S.ValueKindBoolValue b) = A.Bool b | ||
|
||
toRawAesonValue :: S.Value -> A.Value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that it would be better to use the toJSON function provided by the instance ToJSON
defined and autogenerated in Google.Protobuf.Struct.hs
.
s2a (Just v) = toRawAesonValue v | ||
s2a Nothing = A.Null | ||
|
||
a2s :: A.Value -> Maybe S.Value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the fromJSON could be used since the instance FromJSON
is defined and autogenerated in Google.Protobuf.Struct.hs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From discussion w/ @simonmaxen-da, it was stated that these auto generated instances add noisy metadata. So this way of providing Aeson.Value
s was not followed.
A.Object aMap | ||
where | ||
aMap = KeyMap.fromMap $ fmap s2a $ Map.mapKeys Key.fromText $ Map.mapKeys TL.toStrict sMap | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a2s :: A.Value -> Maybe S.Value | ||
a2s v = Just $ toRawStructValue v | ||
|
||
kindToAesonValue :: S.ValueKind -> A.Value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is specific to toRawAesonValue
and maybe it is better to move it there under a where
clause
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for a2s
and s2a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
raiseParticipantMeteringReport request report | ||
raiseGetMeteringReportResponse :: LL.GetMeteringReportResponse -> Perhaps A.Value | ||
raiseGetMeteringReportResponse (LL.GetMeteringReportResponse _ _ _ (Just reportStruct)) = | ||
Right $ toRawAesonValue $ S.Value $ Just $ S.ValueKindStructValue reportStruct | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
daml-assistant changes look fine.
import qualified Data.Aeson as A | ||
import qualified Data.Aeson.KeyMap as KeyMap | ||
import qualified Data.Aeson.Key as Key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import qualified Data.Aeson as A | |
import qualified Data.Aeson.KeyMap as KeyMap | |
import qualified Data.Aeson.Key as Key | |
import qualified Data.Aeson as A | |
import qualified Data.Aeson.KeyMap as A | |
import qualified Data.Aeson.Key as A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, done.
changelog_begin changelog_end
add64c6
to
323ac6e
Compare
No description provided.