hydra
hydra copied to clipboard
Enforce decimal encoding for variants with `BN` fields
By default, BN.toJSON()
uses hex encoding, and thus a variant field of BN
type is serialized as a hex string. When queried, the query-node then returns a hex string instead of a decimal. For example, the JSON in the database is stored as
{ "newAmount" : "0f4240", "isTypeOf": "MyVariantField" }
instead of
{ "newAmount" : "1000000", "isTypeOf": "MyVariantField" }
A workaround is to override
BN.prototype.toJSON = function () {
return this.toString()
}