hydra icon indicating copy to clipboard operation
hydra copied to clipboard

Enforce decimal encoding for variants with `BN` fields

Open dzhelezov opened this issue 3 years ago • 0 comments

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()
}

dzhelezov avatar Jun 15 '21 12:06 dzhelezov