-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathmonero_wallet.dart
More file actions
140 lines (124 loc) · 3.65 KB
/
monero_wallet.dart
File metadata and controls
140 lines (124 loc) · 3.65 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
import 'dart:async';
import 'package:compat/compat.dart' as lib_monero_compat;
import 'package:cs_monero/cs_monero.dart' as lib_monero;
import '../../../utilities/amount/amount.dart';
import '../../crypto_currency/crypto_currency.dart';
import '../intermediate/lib_monero_wallet.dart';
class MoneroWallet extends LibMoneroWallet {
MoneroWallet(CryptoCurrencyNetwork network)
: super(Monero(network), lib_monero_compat.WalletType.monero);
@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;
switch (feeRate.toInt()) {
case 1:
priority = lib_monero.TransactionPriority.low;
break;
case 2:
priority = lib_monero.TransactionPriority.medium;
break;
case 3:
priority = lib_monero.TransactionPriority.high;
break;
case 4:
priority = lib_monero.TransactionPriority.last;
break;
case 0:
default:
priority = lib_monero.TransactionPriority.normal;
break;
}
int approximateFee = 0;
await estimateFeeMutex.protect(() async {
approximateFee = await libMoneroWallet!.estimateFee(
priority,
amount.raw.toInt(),
);
});
return Amount(
rawValue: BigInt.from(approximateFee),
fractionDigits: cryptoCurrency.fractionDigits,
);
}
@override
bool walletExists(String path) => lib_monero.MoneroWallet.isWalletExist(path);
@override
Future<void> loadWallet({
required String path,
required String password,
}) async {
libMoneroWallet = await lib_monero.MoneroWallet.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.MoneroSeedType type;
switch (wordCount) {
case 16:
type = lib_monero.MoneroSeedType.sixteen;
break;
case 25:
type = lib_monero.MoneroSeedType.twentyFive;
break;
default:
throw Exception("Invalid mnemonic word count: $wordCount");
}
return await lib_monero.MoneroWallet.create(
path: path,
password: password,
seedType: type,
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.MoneroWallet.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.MoneroWallet.createViewOnlyWallet(
path: path,
password: password,
address: address,
viewKey: privateViewKey,
restoreHeight: height,
networkType: networkType ?? getNetworkType(),
);
@override
void invalidSeedLengthCheck(int length) {
if (length != 25 && length != 16) {
throw Exception("Invalid monero mnemonic length found: $length");
}
}
}