Skip to content
Snippets Groups Projects
Commit 81216960 authored by vjrj's avatar vjrj
Browse files

Remove old from/to pubkeys in txs

parent 6cad9335
No related branches found
No related tags found
No related merge requests found
import 'dart:typed_data';
import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'contact.dart'; import 'contact.dart';
import 'model_utils.dart';
import 'transaction_type.dart'; import 'transaction_type.dart';
part 'transaction.g.dart'; part 'transaction.g.dart';
...@@ -15,36 +12,22 @@ part 'transaction.g.dart'; ...@@ -15,36 +12,22 @@ part 'transaction.g.dart';
class Transaction extends Equatable { class Transaction extends Equatable {
const Transaction({ const Transaction({
required this.type, required this.type,
required this.from,
required this.to,
required this.amount, required this.amount,
required this.comment, required this.comment,
required this.time, required this.time,
required this.fromC, required this.fromC,
required this.toC, required this.toC,
this.toAvatar,
this.toNick,
this.fromAvatar,
this.fromNick,
}); });
factory Transaction.fromJson(Map<String, dynamic> json) => factory Transaction.fromJson(Map<String, dynamic> json) =>
_$TransactionFromJson(json); _$TransactionFromJson(json);
final TransactionType type; final TransactionType type;
final String from;
final String to;
final Contact fromC; final Contact fromC;
final Contact toC; final Contact toC;
final double amount; final double amount;
final String comment; final String comment;
final DateTime time; final DateTime time;
@JsonKey(fromJson: uIntFromList, toJson: uIntToList)
final Uint8List? toAvatar;
final String? toNick;
@JsonKey(fromJson: uIntFromList, toJson: uIntToList)
final Uint8List? fromAvatar;
final String? fromNick;
bool get isOutgoing => bool get isOutgoing =>
type == TransactionType.sending || type == TransactionType.sent; type == TransactionType.sending || type == TransactionType.sent;
...@@ -55,16 +38,5 @@ class Transaction extends Equatable { ...@@ -55,16 +38,5 @@ class Transaction extends Equatable {
Map<String, dynamic> toJson() => _$TransactionToJson(this); Map<String, dynamic> toJson() => _$TransactionToJson(this);
@override @override
List<Object?> get props => <dynamic>[ List<Object?> get props => <dynamic>[type, fromC, toC, amount, comment, time];
type,
from,
to,
amount,
comment,
time,
toAvatar,
toNick,
fromAvatar,
fromNick
];
} }
...@@ -9,10 +9,6 @@ part of 'transaction.dart'; ...@@ -9,10 +9,6 @@ part of 'transaction.dart';
abstract class _$TransactionCWProxy { abstract class _$TransactionCWProxy {
Transaction type(TransactionType type); Transaction type(TransactionType type);
Transaction from(String from);
Transaction to(String to);
Transaction amount(double amount); Transaction amount(double amount);
Transaction comment(String comment); Transaction comment(String comment);
...@@ -23,14 +19,6 @@ abstract class _$TransactionCWProxy { ...@@ -23,14 +19,6 @@ abstract class _$TransactionCWProxy {
Transaction toC(Contact toC); Transaction toC(Contact toC);
Transaction toAvatar(Uint8List? toAvatar);
Transaction toNick(String? toNick);
Transaction fromAvatar(Uint8List? fromAvatar);
Transaction fromNick(String? fromNick);
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Transaction(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Transaction(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
/// ///
/// Usage /// Usage
...@@ -39,17 +27,11 @@ abstract class _$TransactionCWProxy { ...@@ -39,17 +27,11 @@ abstract class _$TransactionCWProxy {
/// ```` /// ````
Transaction call({ Transaction call({
TransactionType? type, TransactionType? type,
String? from,
String? to,
double? amount, double? amount,
String? comment, String? comment,
DateTime? time, DateTime? time,
Contact? fromC, Contact? fromC,
Contact? toC, Contact? toC,
Uint8List? toAvatar,
String? toNick,
Uint8List? fromAvatar,
String? fromNick,
}); });
} }
...@@ -62,12 +44,6 @@ class _$TransactionCWProxyImpl implements _$TransactionCWProxy { ...@@ -62,12 +44,6 @@ class _$TransactionCWProxyImpl implements _$TransactionCWProxy {
@override @override
Transaction type(TransactionType type) => this(type: type); Transaction type(TransactionType type) => this(type: type);
@override
Transaction from(String from) => this(from: from);
@override
Transaction to(String to) => this(to: to);
@override @override
Transaction amount(double amount) => this(amount: amount); Transaction amount(double amount) => this(amount: amount);
...@@ -83,18 +59,6 @@ class _$TransactionCWProxyImpl implements _$TransactionCWProxy { ...@@ -83,18 +59,6 @@ class _$TransactionCWProxyImpl implements _$TransactionCWProxy {
@override @override
Transaction toC(Contact toC) => this(toC: toC); Transaction toC(Contact toC) => this(toC: toC);
@override
Transaction toAvatar(Uint8List? toAvatar) => this(toAvatar: toAvatar);
@override
Transaction toNick(String? toNick) => this(toNick: toNick);
@override
Transaction fromAvatar(Uint8List? fromAvatar) => this(fromAvatar: fromAvatar);
@override
Transaction fromNick(String? fromNick) => this(fromNick: fromNick);
@override @override
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Transaction(...).copyWith.fieldName(...)` to override fields one at a time with nullification support. /// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `Transaction(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
...@@ -105,31 +69,17 @@ class _$TransactionCWProxyImpl implements _$TransactionCWProxy { ...@@ -105,31 +69,17 @@ class _$TransactionCWProxyImpl implements _$TransactionCWProxy {
/// ```` /// ````
Transaction call({ Transaction call({
Object? type = const $CopyWithPlaceholder(), Object? type = const $CopyWithPlaceholder(),
Object? from = const $CopyWithPlaceholder(),
Object? to = const $CopyWithPlaceholder(),
Object? amount = const $CopyWithPlaceholder(), Object? amount = const $CopyWithPlaceholder(),
Object? comment = const $CopyWithPlaceholder(), Object? comment = const $CopyWithPlaceholder(),
Object? time = const $CopyWithPlaceholder(), Object? time = const $CopyWithPlaceholder(),
Object? fromC = const $CopyWithPlaceholder(), Object? fromC = const $CopyWithPlaceholder(),
Object? toC = const $CopyWithPlaceholder(), Object? toC = const $CopyWithPlaceholder(),
Object? toAvatar = const $CopyWithPlaceholder(),
Object? toNick = const $CopyWithPlaceholder(),
Object? fromAvatar = const $CopyWithPlaceholder(),
Object? fromNick = const $CopyWithPlaceholder(),
}) { }) {
return Transaction( return Transaction(
type: type == const $CopyWithPlaceholder() || type == null type: type == const $CopyWithPlaceholder() || type == null
? _value.type ? _value.type
// ignore: cast_nullable_to_non_nullable // ignore: cast_nullable_to_non_nullable
: type as TransactionType, : type as TransactionType,
from: from == const $CopyWithPlaceholder() || from == null
? _value.from
// ignore: cast_nullable_to_non_nullable
: from as String,
to: to == const $CopyWithPlaceholder() || to == null
? _value.to
// ignore: cast_nullable_to_non_nullable
: to as String,
amount: amount == const $CopyWithPlaceholder() || amount == null amount: amount == const $CopyWithPlaceholder() || amount == null
? _value.amount ? _value.amount
// ignore: cast_nullable_to_non_nullable // ignore: cast_nullable_to_non_nullable
...@@ -150,22 +100,6 @@ class _$TransactionCWProxyImpl implements _$TransactionCWProxy { ...@@ -150,22 +100,6 @@ class _$TransactionCWProxyImpl implements _$TransactionCWProxy {
? _value.toC ? _value.toC
// ignore: cast_nullable_to_non_nullable // ignore: cast_nullable_to_non_nullable
: toC as Contact, : toC as Contact,
toAvatar: toAvatar == const $CopyWithPlaceholder()
? _value.toAvatar
// ignore: cast_nullable_to_non_nullable
: toAvatar as Uint8List?,
toNick: toNick == const $CopyWithPlaceholder()
? _value.toNick
// ignore: cast_nullable_to_non_nullable
: toNick as String?,
fromAvatar: fromAvatar == const $CopyWithPlaceholder()
? _value.fromAvatar
// ignore: cast_nullable_to_non_nullable
: fromAvatar as Uint8List?,
fromNick: fromNick == const $CopyWithPlaceholder()
? _value.fromNick
// ignore: cast_nullable_to_non_nullable
: fromNick as String?,
); );
} }
} }
...@@ -182,33 +116,21 @@ extension $TransactionCopyWith on Transaction { ...@@ -182,33 +116,21 @@ extension $TransactionCopyWith on Transaction {
Transaction _$TransactionFromJson(Map<String, dynamic> json) => Transaction( Transaction _$TransactionFromJson(Map<String, dynamic> json) => Transaction(
type: $enumDecode(_$TransactionTypeEnumMap, json['type']), type: $enumDecode(_$TransactionTypeEnumMap, json['type']),
from: json['from'] as String,
to: json['to'] as String,
amount: (json['amount'] as num).toDouble(), amount: (json['amount'] as num).toDouble(),
comment: json['comment'] as String, comment: json['comment'] as String,
time: DateTime.parse(json['time'] as String), time: DateTime.parse(json['time'] as String),
fromC: Contact.fromJson(json['fromC'] as Map<String, dynamic>), fromC: Contact.fromJson(json['fromC'] as Map<String, dynamic>),
toC: Contact.fromJson(json['toC'] as Map<String, dynamic>), toC: Contact.fromJson(json['toC'] as Map<String, dynamic>),
toAvatar: uIntFromList(json['toAvatar']),
toNick: json['toNick'] as String?,
fromAvatar: uIntFromList(json['fromAvatar']),
fromNick: json['fromNick'] as String?,
); );
Map<String, dynamic> _$TransactionToJson(Transaction instance) => Map<String, dynamic> _$TransactionToJson(Transaction instance) =>
<String, dynamic>{ <String, dynamic>{
'type': _$TransactionTypeEnumMap[instance.type]!, 'type': _$TransactionTypeEnumMap[instance.type]!,
'from': instance.from,
'to': instance.to,
'fromC': instance.fromC, 'fromC': instance.fromC,
'toC': instance.toC, 'toC': instance.toC,
'amount': instance.amount, 'amount': instance.amount,
'comment': instance.comment, 'comment': instance.comment,
'time': instance.time.toIso8601String(), 'time': instance.time.toIso8601String(),
'toAvatar': uIntToList(instance.toAvatar),
'toNick': instance.toNick,
'fromAvatar': uIntToList(instance.fromAvatar),
'fromNick': instance.fromNick,
}; };
const _$TransactionTypeEnumMap = { const _$TransactionTypeEnumMap = {
......
...@@ -5,7 +5,6 @@ import 'package:tuple/tuple.dart'; ...@@ -5,7 +5,6 @@ import 'package:tuple/tuple.dart';
import '../../../g1/api.dart'; import '../../../g1/api.dart';
import '../../../g1/transaction_parser.dart'; import '../../../g1/transaction_parser.dart';
import '../../shared_prefs.dart'; import '../../shared_prefs.dart';
import '../../ui/contacts_cache.dart';
import '../../ui/logger.dart'; import '../../ui/logger.dart';
import '../../ui/notification_controller.dart'; import '../../ui/notification_controller.dart';
import 'contact.dart'; import 'contact.dart';
...@@ -83,7 +82,7 @@ class TransactionsCubit extends HydratedCubit<TransactionsAndBalanceState> { ...@@ -83,7 +82,7 @@ class TransactionsCubit extends HydratedCubit<TransactionsAndBalanceState> {
if (tx.type == TransactionType.received && if (tx.type == TransactionType.received &&
newState.latestReceivedNotification.isBefore(tx.time)) { newState.latestReceivedNotification.isBefore(tx.time)) {
// Future // Future
final Contact from = await ContactsCache().getContact(tx.from); final Contact from = tx.fromC;
NotificationController.createNewNotification( NotificationController.createNewNotification(
tx.time.millisecondsSinceEpoch.toString(), tx.time.millisecondsSinceEpoch.toString(),
amount: tx.amount / 100, amount: tx.amount / 100,
...@@ -93,7 +92,7 @@ class TransactionsCubit extends HydratedCubit<TransactionsAndBalanceState> { ...@@ -93,7 +92,7 @@ class TransactionsCubit extends HydratedCubit<TransactionsAndBalanceState> {
if (tx.type == TransactionType.sent && if (tx.type == TransactionType.sent &&
newState.latestSentNotification.isBefore(tx.time)) { newState.latestSentNotification.isBefore(tx.time)) {
// Future // Future
final Contact to = await ContactsCache().getContact(tx.to); final Contact to = tx.toC;
NotificationController.createNewNotification( NotificationController.createNewNotification(
tx.time.millisecondsSinceEpoch.toString(), tx.time.millisecondsSinceEpoch.toString(),
amount: -tx.amount / 100, amount: -tx.amount / 100,
......
...@@ -48,9 +48,7 @@ Future<TransactionsAndBalanceState> transactionParser(String txData) async { ...@@ -48,9 +48,7 @@ Future<TransactionsAndBalanceState> transactionParser(String txData) async {
0, 0,
Transaction( Transaction(
type: type, type: type,
from: address2,
fromC: fromC, fromC: fromC,
to: address1,
toC: toC, toC: toC,
amount: pubKey == address2 ? -amount : amount, amount: pubKey == address2 ? -amount : amount,
comment: comment, comment: comment,
...@@ -137,9 +135,7 @@ Future<Transaction> _txGvaParse( ...@@ -137,9 +135,7 @@ Future<Transaction> _txGvaParse(
final Contact toC = await ContactsCache().getContact(to!); final Contact toC = await ContactsCache().getContact(to!);
return Transaction( return Transaction(
type: type, type: type,
from: from,
fromC: fromC, fromC: fromC,
to: to,
toC: toC, toC: toC,
amount: amount, amount: amount,
comment: comment, comment: comment,
......
...@@ -34,11 +34,14 @@ void main() { ...@@ -34,11 +34,14 @@ void main() {
expect(result.balance, equals(6700)); expect(result.balance, equals(6700));
final List<Transaction> txs = result.transactions; final List<Transaction> txs = result.transactions;
for (final Transaction tx in txs) { for (final Transaction tx in txs) {
expect(tx.from != tx.to, equals(true)); expect(tx.fromC != tx.toC, equals(true));
} }
expect(txs.first.to == '9Bcx5JV3swCQBEeH3PcuNcBVperLscWtN78hjFVx1yzG', expect(
txs.first.toC.pubKey == '9Bcx5JV3swCQBEeH3PcuNcBVperLscWtN78hjFVx1yzG',
equals(true)); equals(true));
expect(txs.first.from != '9Bcx5JV3swCQBEeH3PcuNcBVperLscWtN78hjFVx1yzG', expect(
txs.first.fromC.pubKey !=
'9Bcx5JV3swCQBEeH3PcuNcBVperLscWtN78hjFVx1yzG',
equals(true)); equals(true));
expect(txs[txs.length - 2].amount < 0, equals(true)); expect(txs[txs.length - 2].amount < 0, equals(true));
expect(txs.last.amount > 0, equals(true)); expect(txs.last.amount > 0, equals(true));
...@@ -54,22 +57,25 @@ void main() { ...@@ -54,22 +57,25 @@ void main() {
expect(result.balance, equals(3)); expect(result.balance, equals(3));
final List<Transaction> txs = result.transactions; final List<Transaction> txs = result.transactions;
for (final Transaction tx in txs) { for (final Transaction tx in txs) {
expect(tx.from != tx.to, equals(true)); expect(tx.fromC != tx.toC, equals(true));
} }
expect( expect(txs.first.fromC.pubKey,
txs.first.from, equals('BrgsSYK3xUzDyztGBHmxq69gfNxBfe2UKpxG21oZUBr5')); equals('BrgsSYK3xUzDyztGBHmxq69gfNxBfe2UKpxG21oZUBr5'));
expect( expect(txs.first.toC.pubKey,
txs.first.to, equals('6DrGg8cftpkgffv4Y4Lse9HSjgc8coEQor3yvMPHAnVH')); equals('6DrGg8cftpkgffv4Y4Lse9HSjgc8coEQor3yvMPHAnVH'));
expect(txs.first.type, equals(TransactionType.receiving)); expect(txs.first.type, equals(TransactionType.receiving));
expect(txs.first.amount, equals(100)); expect(txs.first.amount, equals(100));
expect(txs[1].to, equals('EDB7chzCBdtUCnqFZquVeto4a65FjeRkPrqcV8NwVbTx')); expect(txs[1].toC.pubKey,
expect(txs[1].from, equals('6DrGg8cftpkgffv4Y4Lse9HSjgc8coEQor3yvMPHAnVH')); equals('EDB7chzCBdtUCnqFZquVeto4a65FjeRkPrqcV8NwVbTx'));
expect(txs[1].fromC.pubKey,
equals('6DrGg8cftpkgffv4Y4Lse9HSjgc8coEQor3yvMPHAnVH'));
expect(txs[1].amount, equals(-1200)); expect(txs[1].amount, equals(-1200));
expect(txs[1].type, equals(TransactionType.sent)); expect(txs[1].type, equals(TransactionType.sent));
expect( expect(txs.last.fromC.pubKey,
txs.last.from, equals('A1Fc1VoCLKHyPYmXimYECSmjmsceqwRSZcTBXfgG9JaB')); equals('A1Fc1VoCLKHyPYmXimYECSmjmsceqwRSZcTBXfgG9JaB'));
expect(txs.last.to, equals('6DrGg8cftpkgffv4Y4Lse9HSjgc8coEQor3yvMPHAnVH')); expect(txs.last.toC.pubKey,
equals('6DrGg8cftpkgffv4Y4Lse9HSjgc8coEQor3yvMPHAnVH'));
expect(txs.last.type, equals(TransactionType.received)); expect(txs.last.type, equals(TransactionType.received));
expect(txs.last.amount, equals(10000)); expect(txs.last.amount, equals(10000));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment