Open haltman-at opened 2 years ago
We may want to hold off on this until we have @truffle/codec-components, since the absence of that library makes this format more externally-facing than if we had that library.
Note: @gnidan points out the existence of the superJson package, which would allow us to use BigInt
s. Obviously Big
s would still be a problem, but I'm more OK with using strings there (so long as we can agree on a string format!).
I'm torn... I really like the simplicity of just using strings everywhere and avoiding the need for custom JSON logic. But yeah, trade-offs... 🤷
Issue
This is an issue to collect some potential breaking changes to the codec output format we might want to make. Not all of these are compatible with one another, and some of them might be bad ideas. But I thought I'd collect them here!
BN
s withBigInt
sThe format was designed before
BigInt
s were safe to use everywhere.BN
s are mutable objects which is annoying.BigInt
s would be nicer?BN
s andBig
s withstring
sBecause of its use of
BN
andBig
(and one other thing, see below), the format can't be easily serialized and deserialized withJSON.stringify
andJSON.parse
, something that has caused no end of headaches. That doesn't mean it can't be serialized or deserialized some other way, but so far we haven't bothered to write that.Or rather -- we tried to write that, back in PR #2901, and the method we attempted to use for it hit some snags. Not related to the code itself but rather due to some of the things surrounding the code. Well... I won't bother going over that again here. Anyway it was a problem.
So, if we got rid of the
BN
s andBig
s, and just made it directly serializable withJSON.stringify
andJSON.parse
, that would be nice. Annoyingly,BigInt
s can't be serialized and deserialized in this way, so it'd have to be strings or something. :-/ Blech. Using strings for integers bothers me but it may be unavoidable? Using it for decimal fixed-point doesn't bother me so much, but it does have its own problem, of agreeing on a specific format of string...This is the other thing that would have to be changed if we want native serialization and deserialization. This is much less big a deal though. Long story short -- for reasons that I'll skip going into, when designing the format, I thought, hey, why not represent circular objects with circular objects? (Marked, of course, so code processing it doesn't go into loops.) This wasn't out of nowhere, there was actually a specific use case I had in mind for this, but it never materialized. So, uh, maybe it would be better to get rid of that.
(That said, this change would actually be less necessary than (2), as if we want to simply handle this step separately, well, you can see that done in #2901 and it works fine; it didn't encounter the typing problems that the use of
BN
s andBig
s caused...)Environment
truffle version
): 5.5.27