WIPL:Epic transactions model

This commit is contained in:
likho 2023-10-03 16:20:44 +02:00
parent 8705340880
commit 540c8b5c5d
2 changed files with 94 additions and 82 deletions

View file

@ -1,48 +1,47 @@
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
import 'dart:convert';
import 'dart:math';
import 'package:isar/isar.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/address.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/input.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/output.dart';
import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:tuple/tuple.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart';
@Collection()
class EpicTransaction {
String parentKeyId;
int id;
String txSlateId;
String txType;
String creationTs;
String confirmationTs;
bool confirmed;
int numInputs;
int numOutputs;
String amountCredited;
String amountDebited;
String fee;
int? ttlCutoffHeight; // Use int? for nullable fields
List<MessageDto> messages;
String storedTx;
String kernelExcess;
int kernelLookupMinHeight;
String? paymentProof; // Use String? for nullable fields
Id isarId = Isar.autoIncrement;
@Index()
late final String walletId;
@Index()
final String parentKeyId;
@Index(unique: true, composite: [CompositeIndex("walletId")])
late final int id;
final String? txSlateId;
@enumerated
final TransactionType txType;
final String creationTs;
final String confirmationTs;
final bool confirmed;
final int numInputs;
final int numOutputs;
final String amountCredited;
final String amountDebited;
final String? fee;
final String? ttlCutoffHeight;
final Messages? messages;
final String? storedTx;
final String? kernelExcess;
final int? kernelLookupMinHeight;
final String? paymentProof;
@Backlink(to: "transactions")
final address = IsarLink<Address>();
EpicTransaction({
required this.walletId,
required this.parentKeyId,
required this.id,
required this.txSlateId,
this.txSlateId,
required this.txType,
required this.creationTs,
required this.confirmationTs,
@ -51,61 +50,66 @@ class EpicTransaction {
required this.numOutputs,
required this.amountCredited,
required this.amountDebited,
required this.fee,
this.fee,
this.ttlCutoffHeight,
required this.messages,
required this.storedTx,
required this.kernelExcess,
required this.kernelLookupMinHeight,
this.messages,
this.storedTx,
this.kernelExcess,
this.kernelLookupMinHeight,
this.paymentProof,
});
Tuple2
// factory EpicTransaction.fromJson(Map<String, dynamic> json) {
// return EpicTransaction(
// parentKeyId: json['parent_key_id'] as String,
// id: json['id'] as int,
// txSlateId: json['tx_slate_id'] as String,
// txType: json['tx_type'] as TransactionType,
// creationTs: json['creation_ts'] as String,
// confirmationTs: json['confirmation_ts'] as String,
// confirmed: json['confirmed'] as bool,
// numInputs: json['num_inputs'] as int,
// numOutputs: json['num_outputs'] as int,
// amountCredited: json['amount_credited'] as String,
// amountDebited: json['amount_debited'] as String,
// fee: json['fee'] as String,
// ttlCutoffHeight: json['ttl_cutoff_height'] as String,
// messages: json['messages'] != null ? Messages.fromJson(json['messages'] as Map<String, dynamic>) : null,
// storedTx: json['stored_tx'] as String,
// kernelExcess: json['kernel_excess'] as String,
// kernelLookupMinHeight: json['kernel_lookup_min_height'] as int,
// paymentProof: json['payment_proof'] as String,
// );
// }
}
factory EpicTransaction.fromJson(Map<String, dynamic> json) {
final messagesJson = json['messages']['messages'] as List;
final messagesList = messagesJson
.map((messageJson) => MessageDto.fromJson(messageJson))
.toList();
class Messages {
final List<Message> messages;
return EpicTransaction(
parentKeyId: json['parent_key_id'] as String,
id: int.parse(json['id'] as String),
txSlateId: json['tx_slate_id'] as String,
txType: json['tx_type'] as String,
creationTs: json['creation_ts'] as String,
confirmationTs: json['confirmation_ts'] as String,
confirmed: json['confirmed'] as bool,
numInputs: int.parse(json['num_inputs'] as String),
numOutputs: int.parse(json['num_outputs'] as String),
amountCredited: json['amount_credited'] as String,
amountDebited: json['amount_debited'] as String,
fee: json['fee'] as String,
ttlCutoffHeight: int.parse(json['ttl_cutoff_height'] as String),
messages: messagesList,
storedTx: json['stored_tx'] as String,
kernelExcess: json['kernel_excess'] as String,
kernelLookupMinHeight: int.parse(json['kernel_lookup_min_height'] as String),
paymentProof: json['payment_proof'] as String,
);
Messages({required this.messages});
factory Messages.fromJson(Map<String, dynamic> json) {
final messageList = json['messages'] as List<dynamic>;
final messages = messageList.map((message) => Message.fromJson(message as Map<String, dynamic>)).toList();
return Messages(messages: messages);
}
}
class MessageDto {
String id;
String publicKey;
String message;
String messageSig;
class Message {
final String id;
final String publicKey;
final String? message;
final String? messageSig;
MessageDto({
Message({
required this.id,
required this.publicKey,
required this.message,
required this.messageSig,
this.message,
this.messageSig,
});
factory MessageDto.fromJson(Map<String, dynamic> json) {
return MessageDto(
factory Message.fromJson(Map<String, dynamic> json) {
return Message(
id: json['id'] as String,
publicKey: json['public_key'] as String,
message: json['message'] as String,
@ -114,5 +118,12 @@ class MessageDto {
}
}
// Used in Isar db and stored there as int indexes so adding/removing values
// in this definition should be done extremely carefully in production
enum TransactionType {
// TODO: add more types before prod release?
outgoing,
incoming,
sentToSelf, // should we keep this?
unknown;
}

View file

@ -1408,6 +1408,8 @@ class EpicCashWallet extends CoinServiceAPI
});
// return message;
final String transactions = message['result'] as String;
print("RETURNED TRANSACTIONS IS $transactions");
final jsonTransactions = json.decode(transactions) as List;
final List<Tuple2<isar_models.Transaction, isar_models.Address?>> txnsData =
@ -1472,7 +1474,6 @@ class EpicCashWallet extends CoinServiceAPI
isLelantus: false,
slateId: slateId,
nonce: null,
// otherData: tx["id"].toString(),
otherData: tx['onChainNote'].toString(),
inputs: [],
outputs: [],