stack_wallet/lib/dto/ethereum/eth_tx_dto.dart

144 lines
4.2 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* 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';
2023-04-06 21:24:56 +00:00
import 'package:stackwallet/utilities/amount/amount.dart';
2023-03-27 14:41:59 +00:00
import 'package:stackwallet/utilities/enums/coin_enum.dart';
class EthTxDTO {
EthTxDTO({
required this.hash,
required this.blockHash,
required this.blockNumber,
required this.transactionIndex,
required this.timestamp,
required this.from,
required this.to,
required this.value,
required this.gas,
required this.gasPrice,
required this.maxFeePerGas,
required this.maxPriorityFeePerGas,
required this.isError,
required this.hasToken,
required this.gasCost,
required this.gasUsed,
});
factory EthTxDTO.fromMap(Map<String, dynamic> map) => EthTxDTO(
hash: map['hash'] as String,
blockHash: map['blockHash'] as String,
blockNumber: map['blockNumber'] as int,
transactionIndex: map['transactionIndex'] as int,
timestamp: map['timestamp'] as int,
from: map['from'] as String,
to: map['to'] as String,
2023-10-28 16:20:17 +00:00
value: _amountFromJsonNum(map['value'])!,
gas: _amountFromJsonNum(map['gas'])!,
gasPrice: _amountFromJsonNum(map['gasPrice'])!,
2023-03-27 14:41:59 +00:00
maxFeePerGas: _amountFromJsonNum(map['maxFeePerGas']),
maxPriorityFeePerGas: _amountFromJsonNum(map['maxPriorityFeePerGas']),
2023-10-28 16:20:17 +00:00
isError: map['isError'] as bool? ?? false,
hasToken: map['hasToken'] as bool? ?? false,
gasCost: _amountFromJsonNum(map['gasCost'])!,
gasUsed: _amountFromJsonNum(map['gasUsed'])!,
);
final String hash;
final String blockHash;
final int blockNumber;
final int transactionIndex;
final int timestamp;
final String from;
final String to;
2023-03-27 14:41:59 +00:00
final Amount value;
final Amount gas;
final Amount gasPrice;
2023-10-28 16:20:17 +00:00
final Amount? maxFeePerGas;
final Amount? maxPriorityFeePerGas;
final bool isError;
final bool hasToken;
2023-03-27 14:41:59 +00:00
final Amount gasCost;
final Amount gasUsed;
2023-10-28 16:20:17 +00:00
static Amount? _amountFromJsonNum(dynamic json) {
if (json == null) {
return null;
}
2023-03-27 14:41:59 +00:00
return Amount(
2023-10-28 16:20:17 +00:00
rawValue: BigInt.parse(json.toString()),
2023-03-27 14:41:59 +00:00
fractionDigits: Coin.ethereum.decimals,
);
}
EthTxDTO copyWith({
String? hash,
String? blockHash,
int? blockNumber,
int? transactionIndex,
int? timestamp,
String? from,
String? to,
2023-03-27 14:41:59 +00:00
Amount? value,
Amount? gas,
Amount? gasPrice,
Amount? maxFeePerGas,
Amount? maxPriorityFeePerGas,
2023-10-28 16:20:17 +00:00
bool? isError,
bool? hasToken,
String? compressedTx,
2023-03-27 14:41:59 +00:00
Amount? gasCost,
Amount? gasUsed,
}) =>
EthTxDTO(
hash: hash ?? this.hash,
blockHash: blockHash ?? this.blockHash,
blockNumber: blockNumber ?? this.blockNumber,
transactionIndex: transactionIndex ?? this.transactionIndex,
timestamp: timestamp ?? this.timestamp,
from: from ?? this.from,
to: to ?? this.to,
value: value ?? this.value,
gas: gas ?? this.gas,
gasPrice: gasPrice ?? this.gasPrice,
maxFeePerGas: maxFeePerGas ?? this.maxFeePerGas,
maxPriorityFeePerGas: maxPriorityFeePerGas ?? this.maxPriorityFeePerGas,
isError: isError ?? this.isError,
hasToken: hasToken ?? this.hasToken,
gasCost: gasCost ?? this.gasCost,
gasUsed: gasUsed ?? this.gasUsed,
);
Map<String, dynamic> toMap() {
final map = <String, dynamic>{};
map['hash'] = hash;
map['blockHash'] = blockHash;
map['blockNumber'] = blockNumber;
map['transactionIndex'] = transactionIndex;
map['timestamp'] = timestamp;
map['from'] = from;
map['to'] = to;
2023-07-20 17:36:30 +00:00
map['value'] = value.toString();
map['gas'] = gas.toString();
map['gasPrice'] = gasPrice.toString();
map['maxFeePerGas'] = maxFeePerGas.toString();
map['maxPriorityFeePerGas'] = maxPriorityFeePerGas.toString();
map['isError'] = isError;
map['hasToken'] = hasToken;
2023-07-20 17:36:30 +00:00
map['gasCost'] = gasCost.toString();
map['gasUsed'] = gasUsed.toString();
return map;
}
@override
String toString() => jsonEncode(toMap());
}