ElectrumOutput.fromJson constructor

ElectrumOutput.fromJson(
  1. Map json
)

Zeniq: { value_coin || value_satoshi: int, ... } Bitcoin: { value: float, ... }

Implementation

factory ElectrumOutput.fromJson(Map json) {
  if (json
      case {
        'value': int value,
        'n': int n,
        'spent': bool spent,
        'belongsToUs': bool belongsToUs,
        'scriptPubKey': Map scriptPubKey,
        'node': Map node,
      }) {
    return ElectrumOutput(
      value: value.toBigInt,
      n: n,
      spent: spent,
      belongsToUs: belongsToUs,
      scriptPubKey: ElectrumScriptPubKey.fromJson(scriptPubKey),
      node: NodeWithAddress.fromJson(node),
    );
  }

  final valIsSatoshi =
      json.containsKey('value_satoshi') || json.containsKey('value_int');

  var value =
      json['value_int'] ?? json['value'] ?? json['value_satoshi'] ?? 0;

  value =
      valIsSatoshi ? BigInt.from(value) : BigInt.from(toSatoshiValue(value));

  final n = json['n'] ?? -1;

  return ElectrumOutput(
    value: value,
    n: n,
    scriptPubKey: ElectrumScriptPubKey.fromJson(
      json['scriptPubKey'],
    ),
    node: EmptyNode(),
  );
}