Add ToJSON instances for IntN, UintN and generated datatypes #136
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
From the
Network.Ethereum.Contract.TH
module we can generate native ADTs to events specified on a contract ABIs. This is great if the rest of you project uses exclusively Haskell, but if you need to play along another languages or ecosystems, having a common representation such a JSON is necessary. This PR addsToJSON
instances for all events types (not internalData$
norIndexed$
ADTs though).Changes
ToJSON
instances forUintN
andIntN
.ToJSON
instances for generated datatypes usingGeneric
deriving (aeson default).Known infelicities
The
init'
function I use to recover the input name from the record selector of an ADT is a hack. The correct way should be to obtain that name from theeveArgName
field on the inputs. But if I follow path, I would have to write custom code for instance generation, losing the benefits of using theGeneric
instance. It is a tradeoff and I choose succinctness.Tests
I have been using this for 1 month, storing the JSONs produced on a postgresql database. So far the output matches what I would expect.
For a event declared like this
We generate the following instance
On anohter event with arguments prefixed by _
The json instance is
License
Copyright belongs to SuperRare Labs. It is licensed under the Apache 2.0 terms as the rest of this project. If another license is needed with more liberal terms we can accommodate that. Thank you for all your work on this library!