Voter.fromJson constructor

Voter.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory Voter.fromJson(Map<String, dynamic> json) {
  final type = VoterType.fromName(json.keys.firstOrNull);
  return switch (type) {
    VoterType.constitutionalCommitteeHotKeyHash =>
      VoterConstitutionalCommitteeHotKeyHash.fromJson(json),
    VoterType.constitutionalCommitteeHotScriptHash =>
      VoterConstitutionalCommitteeHotScriptHash.fromJson(json),
    VoterType.drepKeyHash => VoterDRepKeyHash.fromJson(json),
    VoterType.drepScriptHash => VoterDRepScriptHash.fromJson(json),
    VoterType.stakingPoolKeyHash => VoterStakingPoolKeyHash.fromJson(json),
    _ => throw UnimplementedError("Invalid voter type.")
  };
}