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

Switch to using json structure for metering report [DPP-1134] #14891

Merged
merged 2 commits into from
Sep 6, 2022

Conversation

simonmaxen-da
Copy link
Contributor

No description provided.

kindToAesonValue (S.ValueKindStructValue (S.Struct sMap)) =
A.Object aMap
where
aMap = KeyMap.fromMap $ fmap s2a $ Map.mapKeys Key.fromText $ Map.mapKeys TL.toStrict sMap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

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.Values was not followed.

A.Object aMap
where
aMap = KeyMap.fromMap $ fmap s2a $ Map.mapKeys Key.fromText $ Map.mapKeys TL.toStrict sMap

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

a2s :: A.Value -> Maybe S.Value
a2s v = Just $ toRawStructValue v

kindToAesonValue :: S.ValueKind -> A.Value
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Contributor

@S11001001 S11001001 left a 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.

Comment on lines 30 to 32
import qualified Data.Aeson as A
import qualified Data.Aeson.KeyMap as KeyMap
import qualified Data.Aeson.Key as Key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

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
@simonmaxen-da simonmaxen-da merged commit fe2d5b0 into main Sep 6, 2022
@simonmaxen-da simonmaxen-da deleted the help-json-metering branch September 6, 2022 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants