-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathparticl.dart
More file actions
240 lines (205 loc) · 6.79 KB
/
particl.dart
File metadata and controls
240 lines (205 loc) · 6.79 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import 'package:coinlib_flutter/coinlib_flutter.dart' as coinlib;
import '../../../models/isar/models/blockchain_data/address.dart';
import '../../../models/node_model.dart';
import '../../../utilities/amount/amount.dart';
import '../../../utilities/default_nodes.dart';
import '../../../utilities/enums/derive_path_type_enum.dart';
import '../crypto_currency.dart';
import '../interfaces/electrumx_currency_interface.dart';
import '../intermediate/bip39_hd_currency.dart';
class Particl extends Bip39HDCurrency with ElectrumXCurrencyInterface {
Particl(super.network) {
_idMain = "particl";
_uriScheme = "particl";
switch (network) {
case CryptoCurrencyNetwork.main:
_id = _idMain;
_name = "Particl";
_ticker = "PART";
default:
throw Exception("Unsupported network: $network");
}
}
late final String _id;
@override
String get identifier => _id;
late final String _idMain;
@override
String get mainNetId => _idMain;
late final String _name;
@override
String get prettyName => _name;
late final String _uriScheme;
@override
String get uriScheme => _uriScheme;
late final String _ticker;
@override
String get ticker => _ticker;
@override
// See https://github.com/cypherstack/stack_wallet/blob/d08b5c9b22b58db800ad07b2ceeb44c6d05f9cf3/lib/services/coins/particl/particl_wallet.dart#L57
int get minConfirms => 1;
@override
bool get torSupport => true;
@override
// See https://github.com/cypherstack/stack_wallet/blob/d08b5c9b22b58db800ad07b2ceeb44c6d05f9cf3/lib/services/coins/particl/particl_wallet.dart#L68
String constructDerivePath({
required DerivePathType derivePathType,
int account = 0,
required int chain,
required int index,
}) {
String coinType;
switch (networkParams.wifPrefix) {
case 0x6c: // PART mainnet wif.
coinType = "44"; // PART mainnet.
break;
// TODO: [prio=low] Add testnet.
default:
throw Exception("Invalid Particl network wif used!");
}
int purpose;
switch (derivePathType) {
case DerivePathType.bip44:
purpose = 44;
break;
case DerivePathType.bip84:
purpose = 84;
break;
default:
throw Exception("DerivePathType $derivePathType not supported");
}
return "m/$purpose'/$coinType'/$account'/$chain/$index";
}
@override
NodeModel defaultNode({required bool isPrimary}) {
switch (network) {
case CryptoCurrencyNetwork.main:
return NodeModel(
host: "particl.stackwallet.com",
port: 58002,
name: DefaultNodes.defaultName,
id: DefaultNodes.buildId(this),
useSSL: true,
enabled: true,
coinName: identifier,
isFailover: true,
isDown: false,
torEnabled: true,
clearnetEnabled: true,
isPrimary: isPrimary,
);
// case CryptoCurrencyNetwork.test:
// TODO: [prio=low] Add testnet.
default:
throw UnimplementedError();
}
}
@override
// See https://github.com/cypherstack/stack_wallet/blob/d08b5c9b22b58db800ad07b2ceeb44c6d05f9cf3/lib/services/coins/particl/particl_wallet.dart#L58
Amount get dustLimit =>
Amount(rawValue: BigInt.from(294), fractionDigits: fractionDigits);
@override
// See https://github.com/cypherstack/stack_wallet/blob/d08b5c9b22b58db800ad07b2ceeb44c6d05f9cf3/lib/services/coins/particl/particl_wallet.dart#L63
String get genesisHash {
switch (network) {
case CryptoCurrencyNetwork.main:
return "0000ee0784c195317ac95623e22fddb8c7b8825dc3998e0bb924d66866eccf4c";
case CryptoCurrencyNetwork.test:
return "0000594ada5310b367443ee0afd4fa3d0bbd5850ea4e33cdc7d6a904a7ec7c90";
default:
throw Exception("Unsupported network: $network");
}
}
@override
({coinlib.Address address, AddressType addressType}) getAddressForPublicKey({
required coinlib.ECPublicKey publicKey,
required DerivePathType derivePathType,
}) {
switch (derivePathType) {
case DerivePathType.bip44:
final addr = coinlib.P2PKHAddress.fromPublicKey(
publicKey,
version: networkParams.p2pkhPrefix,
);
return (address: addr, addressType: AddressType.p2pkh);
case DerivePathType.bip84:
final addr = coinlib.P2WPKHAddress.fromPublicKey(
publicKey,
hrp: networkParams.bech32Hrp,
);
return (address: addr, addressType: AddressType.p2wpkh);
default:
throw Exception("DerivePathType $derivePathType not supported");
}
}
@override
// See https://github.com/cypherstack/stack_wallet/blob/d08b5c9b22b58db800ad07b2ceeb44c6d05f9cf3/lib/services/coins/particl/particl_wallet.dart#L3532
coinlib.Network get networkParams {
switch (network) {
case CryptoCurrencyNetwork.main:
return coinlib.Network(
wifPrefix: 0x6c,
p2pkhPrefix: 0x38,
p2shPrefix: 0x3c,
privHDPrefix: 0x8f1daeb8,
pubHDPrefix: 0x696e82d1,
bech32Hrp: "pw",
messagePrefix: '\x18Bitcoin Signed Message:\n',
minFee: BigInt.from(1), // Not used in stack wallet currently
minOutput: dustLimit.raw, // Not used in stack wallet currently
feePerKb: BigInt.from(1), // Not used in stack wallet currently
);
// case CryptoCurrencyNetwork.test:
// TODO: [prio=low] Add testnet.
default:
throw Exception("Unsupported network: $network");
}
}
@override
List<DerivePathType> get supportedDerivationPathTypes => [
DerivePathType.bip44,
DerivePathType.bip84,
];
@override
bool validateAddress(String address) {
try {
coinlib.Address.fromString(address, networkParams);
return true;
} catch (_) {
return false;
}
}
@override
int get defaultSeedPhraseLength => 12;
@override
int get fractionDigits => 8;
@override
bool get hasBuySupport => false;
@override
bool get hasMnemonicPassphraseSupport => true;
@override
List<int> get possibleMnemonicLengths => [defaultSeedPhraseLength, 24];
@override
AddressType get defaultAddressType => defaultDerivePathType.getAddressType();
@override
BigInt get satsPerCoin => BigInt.from(100000000);
@override
int get targetBlockTimeSeconds => 600;
@override
DerivePathType get defaultDerivePathType => DerivePathType.bip44;
@override
Uri defaultBlockExplorer(String txid) {
switch (network) {
case CryptoCurrencyNetwork.main:
return Uri.parse("https://chainz.cryptoid.info/part/tx.dws?$txid.htm");
default:
throw Exception(
"Unsupported network for defaultBlockExplorer(): $network",
);
}
}
@override
int get transactionVersion => 160;
@override
BigInt get defaultFeeRate => BigInt.from(20000);
}