-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathwownero_wallet.dart
More file actions
179 lines (162 loc) · 5.03 KB
/
wownero_wallet.dart
File metadata and controls
179 lines (162 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import 'dart:async';
import 'package:compat/compat.dart' as lib_monero_compat;
import 'package:cs_monero/cs_monero.dart' as lib_monero;
import '../../../models/isar/models/blockchain_data/address.dart';
import '../../../utilities/amount/amount.dart';
import '../../../utilities/enums/fee_rate_type_enum.dart';
import '../../crypto_currency/crypto_currency.dart';
import '../../models/tx_data.dart';
import '../intermediate/lib_monero_wallet.dart';
class WowneroWallet extends LibMoneroWallet {
WowneroWallet(CryptoCurrencyNetwork network)
: super(Wownero(network), lib_monero_compat.WalletType.wownero);
@override
Future<Amount> estimateFeeFor(Amount amount, BigInt feeRate) async {
if (libMoneroWallet == null ||
syncStatus is! lib_monero_compat.SyncedSyncStatus) {
return Amount.zeroWith(fractionDigits: cryptoCurrency.fractionDigits);
}
lib_monero.TransactionPriority priority;
FeeRateType feeRateType = FeeRateType.slow;
switch (feeRate.toInt()) {
case 1:
priority = lib_monero.TransactionPriority.low;
feeRateType = FeeRateType.average;
break;
case 2:
priority = lib_monero.TransactionPriority.medium;
feeRateType = FeeRateType.average;
break;
case 3:
priority = lib_monero.TransactionPriority.high;
feeRateType = FeeRateType.fast;
break;
case 4:
priority = lib_monero.TransactionPriority.last;
feeRateType = FeeRateType.fast;
break;
case 0:
default:
priority = lib_monero.TransactionPriority.normal;
feeRateType = FeeRateType.slow;
break;
}
dynamic approximateFee;
await estimateFeeMutex.protect(() async {
{
try {
final data = await prepareSend(
txData: TxData(
recipients: [
// This address is only used for getting an approximate fee, never for sending
TxRecipient(
address:
"WW3iVcnoAY6K9zNdU4qmdvZELefx6xZz4PMpTwUifRkvMQckyadhSPYMVPJhBdYE8P9c27fg9RPmVaWNFx1cDaj61HnetqBiy",
amount: amount,
isChange: false,
addressType: AddressType.cryptonote,
),
],
feeRateType: feeRateType,
),
);
approximateFee = data.fee!;
// unsure why this delay?
await Future<void>.delayed(const Duration(milliseconds: 500));
} catch (e) {
approximateFee = libMoneroWallet!.estimateFee(
priority,
amount.raw.toInt(),
);
}
}
});
if (approximateFee is Amount) {
return approximateFee as Amount;
} else {
return Amount(
rawValue: BigInt.from(approximateFee as int),
fractionDigits: cryptoCurrency.fractionDigits,
);
}
}
@override
bool walletExists(String path) =>
lib_monero.WowneroWallet.isWalletExist(path);
@override
Future<void> loadWallet({
required String path,
required String password,
}) async {
libMoneroWallet = await lib_monero.WowneroWallet.loadWallet(
path: path,
password: password,
);
}
@override
Future<lib_monero.Wallet> getCreatedWallet({
required String path,
required String password,
required int wordCount,
required String seedOffset,
int? networkType,
}) async {
final lib_monero.WowneroSeedType type;
switch (wordCount) {
case 16:
type = lib_monero.WowneroSeedType.sixteen;
break;
case 25:
type = lib_monero.WowneroSeedType.twentyFive;
break;
default:
throw Exception("Invalid mnemonic word count: $wordCount");
}
return await lib_monero.WowneroWallet.create(
path: path,
password: password,
seedType: type,
overrideDeprecated14WordSeedException: true,
seedOffset: seedOffset,
networkType: networkType ?? getNetworkType(),
);
}
@override
Future<lib_monero.Wallet> getRestoredWallet({
required String path,
required String password,
required String mnemonic,
required String seedOffset,
int height = 0,
int? networkType,
}) async => await lib_monero.WowneroWallet.restoreWalletFromSeed(
path: path,
password: password,
seed: mnemonic,
restoreHeight: height,
seedOffset: seedOffset,
networkType: networkType ?? getNetworkType(),
);
@override
Future<lib_monero.Wallet> getRestoredFromViewKeyWallet({
required String path,
required String password,
required String address,
required String privateViewKey,
int height = 0,
int? networkType,
}) async => lib_monero.WowneroWallet.createViewOnlyWallet(
path: path,
password: password,
address: address,
viewKey: privateViewKey,
restoreHeight: height,
networkType: networkType ?? getNetworkType(),
);
@override
void invalidSeedLengthCheck(int length) {
if (!(length == 16 || length == 25)) {
throw Exception("Invalid wownero mnemonic length found: $length");
}
}
}