convertToJSON method

String convertToJSON()

Convert the transaction in JSON

Implementation

String convertToJSON() {
  final json = jsonEncode(<String, Object?>{
    'version': version,
    'address': address == null ? '' : address!.address,
    'type': type,
    'data': {
      'content': data!.content!,
      'code': data == null || data!.code == null ? '' : data!.code!,
      'ownerships': List<dynamic>.from(
        data!.ownerships.map((Ownership x) {
          return <String, Object?>{
            'secret': x.secret == null ? '' : x.secret!,
            'authorizedKeys': x.authorizedPublicKeys,
          };
        }),
      ),
      'ledger': {
        'uco': {
          'transfers': List<dynamic>.from(
            data!.ledger!.uco!.transfers.map((UCOTransfer x) {
              return {
                'to': x.to == null ? '' : x.to!,
                'amount': x.amount == null ? 0 : x.amount!,
              };
            }),
          ),
        },
        'token': {
          'transfers': List<dynamic>.from(
            data!.ledger!.token!.transfers.map((TokenTransfer x) {
              return {
                'to': x.to == null ? '' : x.to!,
                'amount': x.amount == null ? 0 : x.amount!,
                'tokenAddress': x.tokenAddress,
                'tokenId': x.tokenId,
              };
            }),
          ),
        },
      },
      'recipients': List<dynamic>.from(
        data!.actionRecipients.map(
          (Recipient x) {
            return {
              'address': x.address == null ? '' : x.address!,
              'action': x.action,
              'args': x.args,
            };
          },
        ),
      ),
    },
    'previousPublicKey': previousPublicKey == null ? '' : previousPublicKey!,
    'previousSignature': previousSignature == null ? '' : previousSignature!,
    'originSignature': originSignature == null ? '' : originSignature!,
  });
  return json;
}