-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathark_wallet.dart
More file actions
95 lines (81 loc) · 2.84 KB
/
Copy pathark_wallet.dart
File metadata and controls
95 lines (81 loc) · 2.84 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
import 'package:bull_sdk/ark.dart' as ark_wallet;
import 'package:bb_mobile/core/ark/ark.dart';
import 'package:bb_mobile/core/ark/entities/ark_balance.dart';
import 'package:bb_mobile/core/ark/errors.dart';
import 'package:convert/convert.dart' as convert;
import 'package:satoshifier/satoshifier.dart' as satoshifier;
class ArkWalletEntity {
final ark_wallet.ArkWallet wallet;
final List<int> _secretKey;
ArkWalletEntity({required this.wallet, required this._secretKey});
static Future<ArkWalletEntity> init({required List<int> secretKey}) async {
try {
final wallet = await ark_wallet.ArkWallet.init(
secretKey: secretKey,
network: Ark.network,
esplora: Ark.esplora,
server: Ark.server,
boltz: Ark.boltz,
);
return ArkWalletEntity(wallet: wallet, secretKey: secretKey);
} catch (e) {
throw ArkError(e.toString());
}
}
String get offchainAddress => wallet.offchainAddress();
String get boardingAddress => wallet.boardingAddress();
String get secretHex => convert.hex.encode(_secretKey);
static bool isArkAddress(String address) {
try {
return ark_wallet.Utils.isArk(address: address);
} catch (e) {
return false;
}
}
static Future<bool> isBtcAddress(String address) async {
try {
final satoshified = await satoshifier.Satoshifier.parse(address);
return satoshified is satoshifier.BitcoinAddress;
} catch (e) {
return false;
}
}
Future<ArkBalance> get balance async {
try {
final balance = await wallet.balance();
final arkBalance = ArkBalance(
preconfirmed: balance.preconfirmed,
settled: balance.settled,
available: balance.available,
recoverable: balance.recoverable,
total: balance.total,
boarding: ArkBoarding(
unconfirmed: balance.boarding.unconfirmed,
confirmed: balance.boarding.confirmed,
total: balance.boarding.total,
),
);
return arkBalance;
} catch (e) {
rethrow;
}
}
Future<List<ark_wallet.ArkTransaction>> get transactions =>
wallet.transactionHistory();
Future<void> settle(bool selectRecoverableVtxos) =>
wallet.settle(selectRecoverableVtxos: selectRecoverableVtxos);
Future<String> sendOffchain({required int amount, required String address}) =>
wallet.sendOffChain(sats: amount, address: address);
Future<String> sendOnChain({required int amount, required String address}) =>
wallet.sendOnChain(sats: amount, address: address);
Future<String> collaborativeRedeem({
required int amount,
required String address,
required bool selectRecoverableVtxos,
}) => wallet.collaborativeRedeem(
sats: amount,
address: address,
selectRecoverableVtxos: selectRecoverableVtxos,
);
ark_wallet.ServerInfo get serverInfo => wallet.serverInfo();
}