wharfkit / antelope

Core types, client interfaces, and other tools for working with Antelope-based blockchains.
Other
42 stars 23 forks source link

Accepting that nodeos returns NaN for floats #78

Closed aaroncox closed 10 months ago

aaroncox commented 10 months ago

This is related to: https://github.com/wharfkit/contract/issues/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.

jnordberg commented 10 months ago

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 commented 10 months ago

@jnordberg Yeah, that's probably better. It looks like just removing that stuff works in https://github.com/wharfkit/antelope/pull/78/commits/6fd89b04cadc88a9c16eaeb0a207227ff31aadaf, 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.