Comments (4)
@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 ]
]
from plutus-apps.
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.
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
)
from plutus-apps.
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)
- Running the suggested command for evaluating the plutus benchmark fails HOT 1
- plutus-chain-index swagger documentation isn't complete and/or rendering correctly HOT 1
- plutus-use-cases-scripts not working for generating scripts HOT 2
- Missing export method in Ledger Tx
- Error: Dependency on unbuildable library 'gen' from cardano-api HOT 8
- plutus-pab/pab-blockfrost: Blockfrost version incompatible with Preprod environment HOT 1
- missing dependency HOT 3
- fromCardanoTxOutDatum is creating OutputDatumHash but receiving TxOutDatumInTx HOT 1
- Emulator log not working for QuickCheck and Plutus.Contract.Test.ContractModel HOT 1
- Wen inline datum? HOT 1
- The `create-script-context` tool fails with `TextEnvelopeTypeError` HOT 2
- What is the status of plutus-apps? HOT 3
- `plutus-script-utils` is incomparable with `plutus-ledger-api >= 1.2` HOT 1
- State Machine can take benefit of inline datum HOT 1
- create-script-context - Custom redeemer no longer works for PlutusScriptV1 HOT 2
- test
- Serializing Plutus Scripts
- Why doesn't this contract work? HOT 2
- "The second data argument, does not decode to a context" when minting NFT with Mesh HOT 1
- Vesting use case succeeds even if validator is set to True HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plutus-apps.