toNodeRPC method

String toNodeRPC()

Convert the transaction in JSON

Implementation

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