GithubHelp home page GithubHelp logo

Comments (4)

luigy avatar luigy commented on May 5, 2024 1

@emiflake thanks for the report. I did a test in plutus-playground-client and I'm getting a different behavior with encodeJSON if that's an option. Here is what I tried roughly:

import Wallet.Emulator.Wallet
import Data.BigInteger as BI
import Foreign.Generic (encodeJSON)

let
  w :: Wallet
  w = wrap ({ getWallet : BI.fromInt 1 })
in [ div_ [ text $ encodeJSON $ BI.fromInt 100]
   , div_ [ text $ encodeJSON w ]
   ]

2021-07-20-173111_152x70_scrot

from plutus-apps.

emiflake avatar emiflake commented on May 5, 2024 1

Yeah, I understand. RFC7159 says "This specification allows implementations to set limits on the range and precision of numbers accepted." So it all comes down to what the specific implementations support. Aeson supports decoding large integers into Integer, and since we can get PureScript to produce those too, it's fine for those purposes. It's unfortunate to stringly-type BigIntegers just out of fear for other implementations not supporting them. I guess in the case of PureScript we seem to have "reasonable" way to choose which encoding we prefer.

from plutus-apps.

emiflake avatar emiflake commented on May 5, 2024

Yeah, it appears that encoding with encodeJSON does produce correct stringified results (similar to my approach). Manually encode-ing and then using JSON.stringify doesn't (this is what for example Affjax does when you pass it a Json)
image

from plutus-apps.

silky avatar silky commented on May 5, 2024

If it helps, I think this is related to a quirk in JSON; for example if you just have a large integer, then tools like jq choose to interpret it as a floating-point:

echo '{"a":9128730192384570193485710934857}' | jq
{
  "a": 9.12873019238457e+30
}

which is frustrating :) So in some sense it really isn't safe to encode BigIntegers as "integers" in JSON at all; they probably need to be wrapped in strings, so maybe that's why some libraries are making this choice.

from plutus-apps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.