forked from jl777/SuperNET
-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathfor_tests.rs
3905 lines (3601 loc) · 120 KB
/
for_tests.rs
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! Helpers used in the unit and integration tests.
#![allow(missing_docs)]
use crate::electrums::qtum_electrums;
use crate::structs::*;
use common::custom_futures::repeatable::{Ready, Retry};
use common::executor::Timer;
use common::log::{debug, info};
use common::{cfg_native, now_float, now_ms, now_sec, repeatable, wait_until_ms, wait_until_sec, PagingOptionsEnum};
use common::{get_utc_timestamp, log};
use crypto::CryptoCtx;
use gstuff::{try_s, ERR, ERRL};
use http::{HeaderMap, StatusCode};
use lazy_static::lazy_static;
use mm2_core::mm_ctx::{MmArc, MmCtxBuilder};
use mm2_metrics::{MetricType, MetricsJson};
use mm2_number::BigDecimal;
use mm2_rpc::data::legacy::{BalanceResponse, ElectrumProtocol};
use rand::Rng;
use serde::{Deserialize, Serialize};
use serde_json::{self as json, json, Value as Json};
use std::collections::HashMap;
use std::convert::TryFrom;
use std::env;
use std::net::IpAddr;
use std::num::NonZeroUsize;
use std::process::Child;
use std::sync::Mutex;
use uuid::Uuid;
cfg_native! {
use common::block_on;
use common::log::dashboard_path;
use mm2_io::fs::slurp;
use mm2_net::transport::slurp_req;
use common::wio::POOL;
use chrono::{Local, TimeZone};
use bytes::Bytes;
use futures::channel::oneshot;
use futures::task::SpawnExt;
use http::Request;
use regex::Regex;
use std::fs;
use std::io::Write;
use std::net::Ipv4Addr;
use std::path::{Path, PathBuf};
use std::process::Command;
}
pub const MAKER_SUCCESS_EVENTS: [&str; 12] = [
"Started",
"Negotiated",
"MakerPaymentInstructionsReceived",
"TakerFeeValidated",
"MakerPaymentSent",
"TakerPaymentReceived",
"TakerPaymentWaitConfirmStarted",
"TakerPaymentValidatedAndConfirmed",
"TakerPaymentSpent",
"TakerPaymentSpendConfirmStarted",
"TakerPaymentSpendConfirmed",
"Finished",
];
pub const MAKER_ERROR_EVENTS: [&str; 15] = [
"StartFailed",
"NegotiateFailed",
"TakerFeeValidateFailed",
"MakerPaymentTransactionFailed",
"MakerPaymentDataSendFailed",
"MakerPaymentWaitConfirmFailed",
"TakerPaymentValidateFailed",
"TakerPaymentWaitConfirmFailed",
"TakerPaymentSpendFailed",
"TakerPaymentSpendConfirmFailed",
"MakerPaymentWaitRefundStarted",
"MakerPaymentRefundStarted",
"MakerPaymentRefunded",
"MakerPaymentRefundFailed",
"MakerPaymentRefundFinished",
];
pub const TAKER_SUCCESS_EVENTS: [&str; 12] = [
"Started",
"Negotiated",
"TakerFeeSent",
"TakerPaymentInstructionsReceived",
"MakerPaymentReceived",
"MakerPaymentWaitConfirmStarted",
"MakerPaymentValidatedAndConfirmed",
"TakerPaymentSent",
"TakerPaymentSpent",
"MakerPaymentSpent",
"MakerPaymentSpendConfirmed",
"Finished",
];
pub const TAKER_USING_WATCHERS_SUCCESS_EVENTS: [&str; 14] = [
"Started",
"Negotiated",
"TakerFeeSent",
"TakerPaymentInstructionsReceived",
"MakerPaymentReceived",
"MakerPaymentWaitConfirmStarted",
"MakerPaymentValidatedAndConfirmed",
"TakerPaymentSent",
"WatcherMessageSent",
"TakerPaymentSpent",
"MakerPaymentSpent",
"MakerPaymentSpentByWatcher",
"MakerPaymentSpendConfirmed",
"Finished",
];
// Taker using watchers and watcher spends maker payment
pub const TAKER_ACTUAL_EVENTS_WATCHER_SPENDS_MAKER_PAYMENT: [&str; 13] = [
"Started",
"Negotiated",
"TakerFeeSent",
"TakerPaymentInstructionsReceived",
"MakerPaymentReceived",
"MakerPaymentWaitConfirmStarted",
"MakerPaymentValidatedAndConfirmed",
"TakerPaymentSent",
"WatcherMessageSent",
"TakerPaymentSpent",
"MakerPaymentSpentByWatcher",
"MakerPaymentSpendConfirmed",
"Finished",
];
// Taker using watchers and spends maker payment instead of watcher
pub const TAKER_ACTUAL_EVENTS_TAKER_SPENDS_MAKER_PAYMENT: [&str; 13] = [
"Started",
"Negotiated",
"TakerFeeSent",
"TakerPaymentInstructionsReceived",
"MakerPaymentReceived",
"MakerPaymentWaitConfirmStarted",
"MakerPaymentValidatedAndConfirmed",
"TakerPaymentSent",
"WatcherMessageSent",
"TakerPaymentSpent",
"MakerPaymentSpent",
"MakerPaymentSpendConfirmed",
"Finished",
];
pub const TAKER_ERROR_EVENTS: [&str; 17] = [
"StartFailed",
"NegotiateFailed",
"TakerFeeSendFailed",
"MakerPaymentValidateFailed",
"MakerPaymentWaitConfirmFailed",
"TakerPaymentTransactionFailed",
"TakerPaymentWaitConfirmFailed",
"TakerPaymentDataSendFailed",
"TakerPaymentWaitForSpendFailed",
"MakerPaymentSpendFailed",
"MakerPaymentSpendConfirmFailed",
"TakerPaymentWaitRefundStarted",
"TakerPaymentRefundStarted",
"TakerPaymentRefunded",
"TakerPaymentRefundedByWatcher",
"TakerPaymentRefundFailed",
"TakerPaymentRefundFinished",
];
pub const RICK: &str = "RICK";
pub const RICK_ELECTRUM_ADDRS: &[&str] = &[
"electrum1.cipig.net:10017",
"electrum2.cipig.net:10017",
"electrum3.cipig.net:10017",
];
pub const MORTY: &str = "MORTY";
pub const MORTY_ELECTRUM_ADDRS: &[&str] = &[
"electrum1.cipig.net:10018",
"electrum2.cipig.net:10018",
"electrum3.cipig.net:10018",
];
pub const DOC: &str = "DOC";
#[cfg(not(target_arch = "wasm32"))]
pub const DOC_ELECTRUM_ADDRS: &[&str] = &[
"electrum1.cipig.net:10020",
"electrum2.cipig.net:10020",
"electrum3.cipig.net:10020",
];
#[cfg(target_arch = "wasm32")]
pub const DOC_ELECTRUM_ADDRS: &[&str] = &[
"electrum1.cipig.net:30020",
"electrum2.cipig.net:30020",
"electrum3.cipig.net:30020",
];
pub const MARTY: &str = "MARTY";
pub const MARTY_ELECTRUM_ADDRS: &[&str] = &[
"electrum1.cipig.net:10021",
"electrum2.cipig.net:10021",
"electrum3.cipig.net:10021",
];
pub const ZOMBIE_TICKER: &str = "ZOMBIE";
pub const ARRR: &str = "ARRR";
pub const ZOMBIE_ELECTRUMS: &[&str] = &[
"electrum1.cipig.net:10008",
"electrum2.cipig.net:10008",
"electrum3.cipig.net:10008",
];
pub const ZOMBIE_LIGHTWALLETD_URLS: &[&str] = &[
"https://lightd1.pirate.black:443",
"https://piratelightd1.cryptoforge.cc:443",
"https://piratelightd2.cryptoforge.cc:443",
"https://piratelightd3.cryptoforge.cc:443",
"https://piratelightd4.cryptoforge.cc:443",
];
#[cfg(not(target_arch = "wasm32"))]
pub const PIRATE_ELECTRUMS: &[&str] = &["node1.chainkeeper.pro:10132"];
#[cfg(target_arch = "wasm32")]
pub const PIRATE_ELECTRUMS: &[&str] = &[
"electrum3.cipig.net:30008",
"electrum1.cipig.net:30008",
"electrum2.cipig.net:30008",
];
#[cfg(not(target_arch = "wasm32"))]
pub const PIRATE_LIGHTWALLETD_URLS: &[&str] = &["http://node1.chainkeeper.pro:443"];
#[cfg(target_arch = "wasm32")]
pub const PIRATE_LIGHTWALLETD_URLS: &[&str] = &["https://pirate.battlefield.earth:8581"];
pub const DEFAULT_RPC_PASSWORD: &str = "pass";
pub const QRC20_ELECTRUMS: &[&str] = &[
"electrum1.cipig.net:10071",
"electrum2.cipig.net:10071",
"electrum3.cipig.net:10071",
];
pub const T_BCH_ELECTRUMS: &[&str] = &["tbch.loping.net:60001", "bch0.kister.net:51001"];
pub const TBTC_ELECTRUMS: &[&str] = &[
"electrum1.cipig.net:10068",
"electrum2.cipig.net:10068",
"electrum3.cipig.net:10068",
];
pub const ETH_MAINNET_NODE: &str = "https://mainnet.infura.io/v3/c01c1b4cf66642528547624e1d6d9d6b";
pub const ETH_MAINNET_CHAIN_ID: u64 = 1;
pub const ETH_MAINNET_SWAP_CONTRACT: &str = "0x24abe4c71fc658c91313b6552cd40cd808b3ea80";
pub const ETH_SEPOLIA_NODES: &[&str] = &[
"https://ethereum-sepolia-rpc.publicnode.com",
"https://rpc2.sepolia.org",
"https://1rpc.io/sepolia",
];
pub const ETH_SEPOLIA_CHAIN_ID: u64 = 11155111;
pub const ETH_SEPOLIA_SWAP_CONTRACT: &str = "0xeA6D65434A15377081495a9E7C5893543E7c32cB";
pub const ETH_SEPOLIA_TOKEN_CONTRACT: &str = "0x09d0d71FBC00D7CCF9CFf132f5E6825C88293F19";
pub const BCHD_TESTNET_URLS: &[&str] = &["https://bchd-testnet.greyh.at:18335"];
pub struct Mm2TestConf {
pub conf: Json,
pub rpc_password: String,
}
impl Mm2TestConf {
pub fn seednode(passphrase: &str, coins: &Json) -> Self {
Mm2TestConf {
conf: json!({
"gui": "nogui",
"netid": 9998,
"passphrase": passphrase,
"coins": coins,
"rpc_password": DEFAULT_RPC_PASSWORD,
"i_am_seed": true,
}),
rpc_password: DEFAULT_RPC_PASSWORD.into(),
}
}
/// Generates a seed node conf enabling use_trading_proto_v2
pub fn seednode_trade_v2(passphrase: &str, coins: &Json) -> Self {
Mm2TestConf {
conf: json!({
"gui": "nogui",
"netid": 9998,
"passphrase": passphrase,
"coins": coins,
"rpc_password": DEFAULT_RPC_PASSWORD,
"i_am_seed": true,
"use_trading_proto_v2": true,
}),
rpc_password: DEFAULT_RPC_PASSWORD.into(),
}
}
pub fn seednode_with_hd_account(passphrase: &str, coins: &Json) -> Self {
Mm2TestConf {
conf: json!({
"gui": "nogui",
"netid": 9998,
"passphrase": passphrase,
"coins": coins,
"rpc_password": DEFAULT_RPC_PASSWORD,
"i_am_seed": true,
"enable_hd": true,
}),
rpc_password: DEFAULT_RPC_PASSWORD.into(),
}
}
pub fn seednode_with_hd_account_trade_v2(passphrase: &str, coins: &Json) -> Self {
Mm2TestConf {
conf: json!({
"gui": "nogui",
"netid": 9998,
"passphrase": passphrase,
"coins": coins,
"rpc_password": DEFAULT_RPC_PASSWORD,
"i_am_seed": true,
"enable_hd": true,
"use_trading_proto_v2": true,
}),
rpc_password: DEFAULT_RPC_PASSWORD.into(),
}
}
pub fn seednode_with_wallet_name(coins: &Json, wallet_name: &str, wallet_password: &str) -> Self {
Mm2TestConf {
conf: json!({
"gui": "nogui",
"netid": 9998,
"coins": coins,
"rpc_password": DEFAULT_RPC_PASSWORD,
"i_am_seed": true,
"wallet_name": wallet_name,
"wallet_password": wallet_password,
}),
rpc_password: DEFAULT_RPC_PASSWORD.into(),
}
}
pub fn light_node(passphrase: &str, coins: &Json, seednodes: &[&str]) -> Self {
Mm2TestConf {
conf: json!({
"gui": "nogui",
"netid": 9998,
"passphrase": passphrase,
"coins": coins,
"rpc_password": DEFAULT_RPC_PASSWORD,
"seednodes": seednodes
}),
rpc_password: DEFAULT_RPC_PASSWORD.into(),
}
}
/// Generates a light node conf enabling use_trading_proto_v2
pub fn light_node_trade_v2(passphrase: &str, coins: &Json, seednodes: &[&str]) -> Self {
Mm2TestConf {
conf: json!({
"gui": "nogui",
"netid": 9998,
"passphrase": passphrase,
"coins": coins,
"rpc_password": DEFAULT_RPC_PASSWORD,
"seednodes": seednodes,
"use_trading_proto_v2": true,
}),
rpc_password: DEFAULT_RPC_PASSWORD.into(),
}
}
pub fn watcher_light_node(passphrase: &str, coins: &Json, seednodes: &[&str], conf: WatcherConf) -> Self {
Mm2TestConf {
conf: json!({
"gui": "nogui",
"netid": 9998,
"passphrase": passphrase,
"coins": coins,
"rpc_password": DEFAULT_RPC_PASSWORD,
"seednodes": seednodes,
"is_watcher": true,
"watcher_conf": conf
}),
rpc_password: DEFAULT_RPC_PASSWORD.into(),
}
}
pub fn light_node_with_hd_account(passphrase: &str, coins: &Json, seednodes: &[&str]) -> Self {
Mm2TestConf {
conf: json!({
"gui": "nogui",
"netid": 9998,
"passphrase": passphrase,
"coins": coins,
"rpc_password": DEFAULT_RPC_PASSWORD,
"seednodes": seednodes,
"enable_hd": true,
}),
rpc_password: DEFAULT_RPC_PASSWORD.into(),
}
}
pub fn light_node_with_hd_account_trade_v2(passphrase: &str, coins: &Json, seednodes: &[&str]) -> Self {
Mm2TestConf {
conf: json!({
"gui": "nogui",
"netid": 9998,
"passphrase": passphrase,
"coins": coins,
"rpc_password": DEFAULT_RPC_PASSWORD,
"seednodes": seednodes,
"enable_hd": true,
"use_trading_proto_v2": true,
}),
rpc_password: DEFAULT_RPC_PASSWORD.into(),
}
}
pub fn no_login_node(coins: &Json, seednodes: &[&str]) -> Self {
Mm2TestConf {
conf: json!({
"gui": "nogui",
"netid": 9998,
"coins": coins,
"rpc_password": DEFAULT_RPC_PASSWORD,
"seednodes": seednodes,
}),
rpc_password: DEFAULT_RPC_PASSWORD.into(),
}
}
}
pub struct Mm2TestConfForSwap;
impl Mm2TestConfForSwap {
/// TODO consider moving it to read it from a env file.
pub const BOB_HD_PASSPHRASE: &'static str =
"involve work eager scene give acoustic tooth mimic dance smoke hold foster";
/// TODO consider moving it to read it from a env file.
pub const ALICE_HD_PASSPHRASE: &'static str =
"tank abandon bind salon remove wisdom net size aspect direct source fossil";
pub fn bob_conf_with_policy(priv_key_policy: &Mm2InitPrivKeyPolicy, coins: &Json) -> Mm2TestConf {
match priv_key_policy {
Mm2InitPrivKeyPolicy::Iguana => {
let bob_passphrase = crate::get_passphrase!(".env.seed", "BOB_PASSPHRASE").unwrap();
Mm2TestConf::seednode(&bob_passphrase, coins)
},
Mm2InitPrivKeyPolicy::GlobalHDAccount => {
Mm2TestConf::seednode_with_hd_account(Self::BOB_HD_PASSPHRASE, coins)
},
}
}
pub fn alice_conf_with_policy(priv_key_policy: &Mm2InitPrivKeyPolicy, coins: &Json, bob_ip: &str) -> Mm2TestConf {
match priv_key_policy {
Mm2InitPrivKeyPolicy::Iguana => {
let alice_passphrase = crate::get_passphrase!(".env.client", "ALICE_PASSPHRASE").unwrap();
Mm2TestConf::light_node(&alice_passphrase, coins, &[bob_ip])
},
Mm2InitPrivKeyPolicy::GlobalHDAccount => {
Mm2TestConf::light_node_with_hd_account(Self::ALICE_HD_PASSPHRASE, coins, &[bob_ip])
},
}
}
}
pub enum Mm2InitPrivKeyPolicy {
Iguana,
GlobalHDAccount,
}
pub fn zombie_conf() -> Json {
json!({
"coin":"ZOMBIE",
"asset":"ZOMBIE",
"txversion":4,
"overwintered":1,
"mm2":1,
"avg_blocktime": 60,
"protocol":{
"type":"ZHTLC",
"protocol_data": {
"consensus_params": {
"overwinter_activation_height": 0,
"sapling_activation_height": 1,
"blossom_activation_height": null,
"heartwood_activation_height": null,
"canopy_activation_height": null,
"coin_type": 133,
"hrp_sapling_extended_spending_key": "secret-extended-key-main",
"hrp_sapling_extended_full_viewing_key": "zxviews",
"hrp_sapling_payment_address": "zs",
"b58_pubkey_address_prefix": [ 28, 184 ],
"b58_script_address_prefix": [ 28, 189 ]
},
"z_derivation_path": "m/32'/133'",
}
},
"required_confirmations":0,
"derivation_path": "m/44'/133'",
})
}
pub fn pirate_conf() -> Json {
json!({
"coin":"ARRR",
"asset":"PIRATE",
"txversion":4,
"overwintered":1,
"mm2":1,
"avg_blocktime": 60,
"protocol":{
"type":"ZHTLC",
"protocol_data": {
"consensus_params": {
"overwinter_activation_height": 152855,
"sapling_activation_height": 152855,
"blossom_activation_height": null,
"heartwood_activation_height": null,
"canopy_activation_height": null,
"coin_type": 133,
"hrp_sapling_extended_spending_key": "secret-extended-key-main",
"hrp_sapling_extended_full_viewing_key": "zxviews",
"hrp_sapling_payment_address": "zs",
"b58_pubkey_address_prefix": [ 28, 184 ],
"b58_script_address_prefix": [ 28, 189 ]
},
}
},
"required_confirmations":0
})
}
pub fn rick_conf() -> Json {
json!({
"coin":"RICK",
"asset":"RICK",
"required_confirmations":0,
"txversion":4,
"overwintered":1,
"derivation_path": "m/44'/141'",
"protocol":{
"type":"UTXO"
}
})
}
pub fn doc_conf() -> Json {
json!({
"coin":"DOC",
"asset":"DOC",
"required_confirmations":0,
"txversion":4,
"overwintered":1,
"derivation_path": "m/44'/141'",
"protocol":{
"type":"UTXO"
}
})
}
pub fn morty_conf() -> Json {
json!({
"coin":"MORTY",
"asset":"MORTY",
"required_confirmations":0,
"txversion":4,
"overwintered":1,
"derivation_path": "m/44'/141'",
"protocol":{
"type":"UTXO"
}
})
}
pub fn kmd_conf(tx_fee: u64) -> Json {
json!({
"coin":"KMD",
"txversion":4,
"overwintered":1,
"txfee":tx_fee,
"protocol":{
"type":"UTXO"
}
})
}
pub fn mycoin_conf(tx_fee: u64) -> Json {
json!({
"coin":"MYCOIN",
"asset":"MYCOIN",
"txversion":4,
"overwintered":1,
"txfee":tx_fee,
"protocol":{
"type":"UTXO"
}
})
}
pub fn mycoin1_conf(tx_fee: u64) -> Json {
json!({
"coin":"MYCOIN1",
"asset":"MYCOIN1",
"txversion":4,
"overwintered":1,
"txfee":tx_fee,
"protocol":{
"type":"UTXO"
}
})
}
pub fn atom_testnet_conf() -> Json {
json!({
"coin":"ATOM",
"avg_blocktime": 5,
"protocol":{
"type":"TENDERMINT",
"protocol_data": {
"decimals": 6,
"denom": "uatom",
"account_prefix": "cosmos",
"chain_id": "cosmoshub-testnet",
},
},
"derivation_path": "m/44'/118'",
})
}
pub fn btc_segwit_conf() -> Json {
json!({
"coin": "BTC-segwit",
"name": "bitcoin",
"fname": "Bitcoin",
"rpcport": 8332,
"pubtype": 0,
"p2shtype": 5,
"wiftype": 128,
"segwit": true,
"bech32_hrp": "bc",
"address_format": {
"format": "segwit"
},
"orderbook_ticker": "BTC",
"txfee": 0,
"estimate_fee_mode": "ECONOMICAL",
"mm2": 1,
"required_confirmations": 1,
"avg_blocktime": 10,
"derivation_path": "m/84'/0'",
"protocol": {
"type": "UTXO"
}
})
}
pub fn btc_with_spv_conf() -> Json {
json!({
"coin": "BTC",
"asset":"BTC",
"pubtype": 0,
"p2shtype": 5,
"wiftype": 128,
"segwit": true,
"bech32_hrp": "bc",
"txfee": 0,
"estimate_fee_mode": "ECONOMICAL",
"required_confirmations": 0,
"protocol": {
"type": "UTXO"
},
"spv_conf": {
"starting_block_header": {
"height": 0,
"hash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
"bits": 486604799,
"time": 1231006505,
},
"validation_params": {
"difficulty_check": true,
"constant_difficulty": false,
"difficulty_algorithm": "Bitcoin Mainnet"
}
}
})
}
pub fn btc_with_sync_starting_header() -> Json {
json!({
"coin": "BTC",
"asset":"BTC",
"pubtype": 0,
"p2shtype": 5,
"wiftype": 128,
"segwit": true,
"bech32_hrp": "bc",
"txfee": 0,
"estimate_fee_mode": "ECONOMICAL",
"required_confirmations": 0,
"protocol": {
"type": "UTXO"
},
"spv_conf": {
"starting_block_header": {
"height": 764064,
"hash": "00000000000000000006da48b920343944908861fa05b28824922d9e60aaa94d",
"bits": 386375189,
"time": 1668986059,
},
"max_stored_block_headers": 3000,
"validation_params": {
"difficulty_check": true,
"constant_difficulty": false,
"difficulty_algorithm": "Bitcoin Mainnet"
}
}
})
}
pub fn tbtc_conf() -> Json {
json!({
"coin": "tBTC",
"asset":"tBTC",
"pubtype": 111,
"p2shtype": 196,
"wiftype": 239,
"segwit": true,
"bech32_hrp": "tb",
"txfee": 1000,
"required_confirmations": 0,
"protocol": {
"type": "UTXO"
}
})
}
pub fn tbtc_segwit_conf() -> Json {
json!({
"coin": "tBTC-Segwit",
"asset":"tBTC-Segwit",
"pubtype": 111,
"p2shtype": 196,
"wiftype": 239,
"segwit": true,
"bech32_hrp": "tb",
"txfee": 1000,
"required_confirmations": 0,
"derivation_path": "m/84'/1'",
"address_format": {
"format": "segwit"
},
"protocol": {
"type": "UTXO"
},
"orderbook_ticker": "tBTC",
})
}
pub fn tbtc_with_spv_conf() -> Json {
json!({
"coin": "tBTC-TEST",
"asset":"tBTC-TEST",
"pubtype": 111,
"p2shtype": 196,
"wiftype": 239,
"segwit": true,
"bech32_hrp": "tb",
"txfee": 0,
"estimate_fee_mode": "ECONOMICAL",
"required_confirmations": 0,
"enable_spv_proof": true,
"protocol": {
"type": "UTXO"
},
"spv_conf": {
"starting_block_header": {
"height": 0,
"hash": "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943",
"bits": 486604799,
"time": 1296688602,
},
"validation_params": {
"difficulty_check": true,
"constant_difficulty": false,
"difficulty_algorithm": "Bitcoin Testnet"
}
}
})
}
pub fn tbtc_legacy_conf() -> Json {
json!({
"coin": "tBTC",
"asset":"tBTC",
"pubtype": 111,
"p2shtype": 196,
"wiftype": 239,
"segwit": false,
"bech32_hrp": "tb",
"txfee": 0,
"estimate_fee_mode": "ECONOMICAL",
"required_confirmations": 0,
"protocol": {
"type": "UTXO"
}
})
}
pub fn eth_testnet_conf_trezor() -> Json {
json!({
"coin": "ETH",
"name": "ethereum",
"mm2": 1,
"chain_id": 1337,
"max_eth_tx_type": 2,
"derivation_path": "m/44'/1'", // Trezor uses coin type 1 for testnet
"protocol": {
"type": "ETH"
},
"trezor_coin": "Ethereum"
})
}
/// ETH configuration used for dockerized Geth dev node
pub fn eth_dev_conf() -> Json {
json!({
"coin": "ETH",
"name": "ethereum",
"mm2": 1,
"chain_id": 1337,
"derivation_path": "m/44'/60'",
"protocol": {
"type": "ETH"
},
"max_eth_tx_type": 2
})
}
/// ERC20 token configuration used for dockerized Geth dev node
pub fn erc20_dev_conf(contract_address: &str) -> Json {
json!({
"coin": "ERC20DEV",
"name": "erc20dev",
"chain_id": 1337,
"mm2": 1,
"derivation_path": "m/44'/60'",
"protocol": {
"type": "ERC20",
"protocol_data": {
"platform": "ETH",
"contract_address": contract_address,
}
},
"max_eth_tx_type": 2
})
}
/// ERC20 token configuration used for dockerized tests on Sepolia
pub fn sepolia_erc20_dev_conf(contract_address: &str) -> Json {
let mut conf = erc20_dev_conf(contract_address);
set_chain_id(&mut conf, ETH_SEPOLIA_CHAIN_ID);
conf
}
/// global NFT configuration used for dockerized Geth dev node
pub fn nft_dev_conf() -> Json {
json!({
"coin": "NFT_ETH",
"name": "nftdev",
"chain_id": 1337,
"mm2": 1,
"derivation_path": "m/44'/60'",
"protocol": {
"type": "NFT",
"protocol_data": {
"platform": "ETH"
}
},
"max_eth_tx_type": 2
})
}
fn set_chain_id(conf: &mut Json, chain_id: u64) { conf["chain_id"] = json!(chain_id); }
pub fn eth_sepolia_conf() -> Json {
json!({
"coin": "ETH",
"name": "ethereum",
"derivation_path": "m/44'/60'",
"chain_id": ETH_SEPOLIA_CHAIN_ID,
"protocol": {
"type": "ETH"
},
"max_eth_tx_type": 2,
"trezor_coin": "Ethereum"
})
}
pub fn eth_sepolia_trezor_firmware_compat_conf() -> Json {
json!({
"coin": "tETH",
"name": "ethereum",
"derivation_path": "m/44'/1'", // Note: trezor uses coin type 1' for eth for testnet (SLIP44_TESTNET)
"chain_id": ETH_SEPOLIA_CHAIN_ID,
"protocol": {
"type": "ETH"
},
"max_eth_tx_type": 2,
"trezor_coin": "tETH"
})
}
pub fn eth_jst_testnet_conf() -> Json {
json!({
"coin": "JST",
"name": "jst",
"chain_id": 1337,
"derivation_path": "m/44'/60'",
"protocol": {
"type": "ERC20",
"protocol_data": {
"platform": "ETH",
"contract_address": ETH_SEPOLIA_TOKEN_CONTRACT
}
},
"max_eth_tx_type": 2
})
}
pub fn jst_sepolia_conf() -> Json {
json!({
"coin": "JST",
"name": "jst",
"chain_id": ETH_SEPOLIA_CHAIN_ID,
"protocol": {
"type": "ERC20",
"protocol_data": {
"platform": "ETH",
"chain_id": ETH_SEPOLIA_CHAIN_ID,
"contract_address": ETH_SEPOLIA_TOKEN_CONTRACT
}
},
"max_eth_tx_type": 2
})
}
pub fn jst_sepolia_trezor_conf() -> Json {
json!({
"coin": "tJST",
"name": "tjst",
"chain_id": ETH_SEPOLIA_CHAIN_ID,
"derivation_path": "m/44'/1'", // Note: Trezor uses 1' coin type for all testnets
"trezor_coin": "tETH",
"protocol": {
"type": "ERC20",
"protocol_data": {
"platform": "ETH",
"chain_id": ETH_SEPOLIA_CHAIN_ID,
"contract_address": ETH_SEPOLIA_TOKEN_CONTRACT
}
}
})
}
pub fn iris_testnet_conf() -> Json {
json!({
"coin": "IRIS-TEST",
"avg_blocktime": 5,
"derivation_path": "m/44'/566'",
"protocol":{
"type":"TENDERMINT",
"protocol_data": {
"decimals": 6,
"denom": "unyan",
"account_prefix": "iaa",
"chain_id": "nyancat-9",
},
}
})
}
pub fn nucleus_testnet_conf() -> Json {
json!({
"coin": "NUCLEUS-TEST",
"avg_blocktime": 5,
"derivation_path": "m/44'/566'",
"protocol":{
"type":"TENDERMINT",
"protocol_data": {
"decimals": 6,
"denom": "unucl",
"account_prefix": "nuc",
"chain_id": "nucleus-testnet",
},
}
})
}
pub fn iris_nimda_testnet_conf() -> Json {
json!({
"coin": "IRIS-NIMDA",
"derivation_path": "m/44'/566'",
"protocol": {