Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accepting that nodeos returns NaN for floats #78

Merged
merged 2 commits into from
Aug 18, 2023
Merged

Conversation

aaroncox
Copy link
Member

@aaroncox aaroncox commented Aug 18, 2023

This is related to: wharfkit/contract#50

The contract and APIs can apparently return -nan as a value here as a Float. This adds a check that detects this weirdness, and if found, just sets the value to the float as 0 and proceeds.

I'm open to ideas on how better to resolve this. We just need to accept that the APIs will not return valid data here that matches the ABI for some reason.

@aaroncox aaroncox requested a review from jnordberg August 18, 2023 06:00
@jnordberg
Copy link
Collaborator

I don't think it's a good idea to treat NaN as zero. If we need to support this I think we just need to move the checks out of the float constructor and allow it to exist as a NaN or Infinity

@aaroncox
Copy link
Member Author

aaroncox commented Aug 18, 2023

@jnordberg Yeah, that's probably better. It looks like just removing that stuff works in 6fd89b0, and tests still pass.

Those records in a table row call now come back looking like:

  {
    id: UInt64 { value: [BN] },
    token0: { contract: [Name], symbol: [Symbol] },
    token1: { contract: [Name], symbol: [Symbol] },
    reserve0: Asset { units: [Int64], symbol: [Symbol] },
    reserve1: Asset { units: [Int64], symbol: [Symbol] },
    liquidity_token: UInt64 { value: [BN] },
    price0_last: Float64 { value: NaN },
    price1_last: Float64 { value: NaN },
    price0_cumulative_last: UInt64 { value: [BN] },
    price1_cumulative_last: UInt64 { value: [BN] },
    block_time_last: TimePointSec { value: [UInt32] }
  }

Applications upstream can deal with NaN when it exists then.

@aaroncox aaroncox changed the title Accepting that nodeos returns bogus numbers Accepting that nodeos returns NaN for floats Aug 18, 2023
@aaroncox aaroncox merged commit 42b5a30 into master Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants