LCOV - code coverage report
Current view: top level - crypto/evm/entities/contract - contract_function_param.dart (source / functions) Coverage Total Hit
Test: lcov.info Lines: 64.3 % 42 27
Test Date: 2025-01-30 01:10:00 Functions: - 0 0

            Line data    Source code
       1              : import 'package:walletkit_dart/src/common/types.dart';
       2              : import 'package:walletkit_dart/src/crypto/evm/entities/contract/parameter_type/function_parameter_type.dart';
       3              : 
       4              : class FunctionParam {
       5              :   final String? name;
       6              :   final FunctionParamType type;
       7              :   final bool? indexed;
       8              : 
       9            0 :   bool get isDynamic => type.isDynamic;
      10              : 
      11            8 :   const FunctionParam({
      12              :     required this.name,
      13              :     required this.type,
      14              :     this.indexed,
      15              :   });
      16              : 
      17            4 :   factory FunctionParam.fromJson(Map<String, dynamic> map) {
      18            4 :     return FunctionParam(
      19            4 :       name: map['name'],
      20            8 :       type: FunctionParamType.fromString(map['type']),
      21            4 :       indexed: map['indexed'] as bool? ?? false,
      22              :     );
      23              :   }
      24              : 
      25            0 :   Json toJson() {
      26            0 :     return {
      27            0 :       'name': name,
      28            0 :       'indexed': indexed,
      29            0 :       'type': type.name,
      30              :     };
      31              :   }
      32              : }
      33              : 
      34              : class FunctionParamWithValue<T> extends FunctionParam {
      35              :   final T value;
      36              : 
      37            7 :   const FunctionParamWithValue({
      38              :     required this.value,
      39              :     required super.name,
      40              :     required super.type,
      41              :     super.indexed,
      42              :   });
      43              : 
      44            7 :   static FunctionParamWithValue fromParam<T>(
      45              :     FunctionParam param,
      46              :     T value,
      47              :   ) {
      48            7 :     return FunctionParamWithValue<T>(
      49              :       value: value,
      50            7 :       name: param.name,
      51            7 :       type: param.type,
      52            7 :       indexed: param.indexed,
      53              :     );
      54              :   }
      55              : 
      56            2 :   T castValue<T>() {
      57            4 :     if (value is T) {
      58            2 :       return value as T;
      59              :     }
      60            0 :     throw Exception('Invalid cast');
      61              :   }
      62              : 
      63            0 :   FunctionParamWithValue<T> cast<T>() {
      64            0 :     if (value! is T) {
      65            0 :       throw Exception('Invalid cast');
      66              :     }
      67            0 :     return FunctionParamWithValue<T>(
      68            0 :       value: value as T,
      69            0 :       name: name,
      70            0 :       type: type,
      71            0 :       indexed: indexed,
      72              :     );
      73              :   }
      74              : 
      75            1 :   Json toJson() {
      76            1 :     return {
      77            1 :       'name': name,
      78            1 :       'indexed': indexed,
      79            2 :       'type': type.name,
      80            3 :       'value': type.valueToJson(value),
      81              :     };
      82              :   }
      83              : 
      84            1 :   factory FunctionParamWithValue.fromJson(Map map) {
      85            2 :     final type = FunctionParamType.fromString(map['type']);
      86            1 :     return FunctionParamWithValue(
      87            2 :       value: type.valueFromJson(map['value']),
      88            1 :       name: map['name'],
      89            1 :       indexed: map['indexed'] as bool? ?? false,
      90              :       type: type,
      91              :     );
      92              :   }
      93              : }
        

Generated by: LCOV version 2.0-1