dev
dart 73 lines 1.68 KB
Raw
1 import 'package:cw_core/unspent_transaction_output.dart';
2 import 'package:cw_core/utils/print_verbose.dart';
3 import 'package:cw_monero/api/coins_info.dart';
4
5 class MoneroUnspent extends Unspent {
6 static MoneroUnspent fromUnspent({
7 required String address,
8 required String hash,
9 required String keyImage,
10 required int value,
11 required bool isFrozen,
12 required bool isUnlocked,
13 required bool isSpent,
14 }) {
15 return MoneroUnspent(
16 address: address,
17 hash: hash,
18 keyImage: keyImage,
19 value: value,
20 isFrozen: isFrozen,
21 isUnlocked: isUnlocked,
22 isSpent: isSpent);
23 }
24
25 MoneroUnspent(
26 {required String address,
27 required String hash,
28 required String keyImage,
29 required int value,
30 required bool isFrozen,
31 required this.isUnlocked,
32 required this.isSpent})
33 : super(address, hash, value, 0, keyImage) {
34 _frozen = isFrozen;
35 }
36
37 bool _frozen = false;
38
39 @override
40 set isFrozen(bool freeze) {
41 _frozen = freeze;
42 printV("set isFrozen: $freeze ($keyImage): $freeze");
43 getCoinByKeyImage(keyImage!).then((coinId) async {
44 if (coinId == null) return;
45 if (freeze) {
46 await freezeCoin(coinId);
47 _frozen = true;
48 } else {
49 await thawCoin(coinId);
50 _frozen = false;
51 }
52 });
53 }
54
55 @override
56 bool get isFrozen => _frozen;
57
58 final bool isUnlocked;
59 final bool isSpent;
60
61 Map<String, dynamic> toJson() {
62 return {
63 'address': address,
64 'hash': hash,
65 'keyImage': keyImage,
66 'value': value,
67 'isFrozen': isFrozen,
68 'isUnlocked': isUnlocked,
69 'isChange': isChange,
70 'isSpent': isSpent,
71 };
72 }
73 }