bnToBn function

BigInt bnToBn(
  1. dynamic value
)

Implementation

BigInt bnToBn(dynamic value) {
  try {
    if (value == null) {
      return BigInt.zero;
    }
    BigInt? result;
    if (value is BigInt) {
      return value;
    } else if (value is int) {
      return BigInt.from(value);
    } else if (isHex(value)) {
      return hexToBn(value.toString());
    } else if (value is Map<String, dynamic>) {
      return compactToBn(value);
    } else if (value is String && !isHex(value)) {
      result = BigInt.tryParse(value, radix: 10);
    }
    if (result != null) {
      return result;
    }
    throw "failed converting:'$value' to BigInt";
  } catch (e) {
    throw "$e";
  }
}