leonardocustodio / polkadart

Polkadart provides developers the ability to query a node and interact with the Polkadot based chains using Dart.
https://polkadart.dev
Apache License 2.0
39 stars 16 forks source link

When eraPeriod is 0, get Unhandled exception error #361

Closed BurnWW closed 1 year ago

BurnWW commented 1 year ago

in polkadart-0.2.1/lib/substrate/era.dart encodeMortal

  encodeMortal(int current, int period) {
    final calPeriod = pow(2, (log(period) / log(2)).ceil());
    final phase = current % min(max(calPeriod, 4), 1 << 16);
    final quantizeFactor = max(1, period >> 12);
    final quantizedPhase = phase / quantizeFactor * quantizeFactor;

    return encode(quantizedPhase.toInt(), period);
  }

if period is 0, get error

Unhandled exception:
Unsupported operation: Infinity or NaN toInt
#0      double.toInt (dart:core-patch/double.dart)
#1      double.ceil (dart:core-patch/double.dart:201:32)
#2      Era.encodeMortal (package:polkadart/substrate/era.dart:79:53)
#3      SigningPayload.toEncodedMap (package:polkadart/extrinsic/signing_payload.dart:42:24)
#4      SigningPayload.encode.<anonymous closure> (package:polkadart/extrinsic/signing_payload.dart:63:26)
#5      List.forEach (dart:core-patch/growable_array.dart:416:8)
#6      SigningPayload.encode (package:polkadart/extrinsic/signing_payload.dart:59:40)
#7      main (file:///home/wetee/Work/asyou.me/dtim/hacks/init_dao.dart:63:33)
leonardocustodio commented 1 year ago

Hello @BurnWW, thank you for your report. We have released a new version with a fix for that polkadart 0.2.2