handleClick(e)}
54 | style={{ display: 'flex', alignItems: 'center' }}
55 | >
56 | {children}
57 |
58 |
59 | {icon ? : }
60 |
61 |
62 |
63 | );
64 | };
65 |
66 | export default Copy;
67 |
--------------------------------------------------------------------------------
/apps/indexer-proxy/proxy/src/mod_libp2p/mod.rs:
--------------------------------------------------------------------------------
1 | use std::time::Duration;
2 |
3 | use libp2p::identity::{self, Keypair};
4 | use tokio::time::sleep;
5 |
6 | use crate::mod_libp2p::network::EventLoop;
7 |
8 | pub mod behavior;
9 | pub mod network;
10 |
11 | pub async fn start_libp2p_process(controller_sk: &str) {
12 | let local_key = make_libp2p_keypair(controller_sk).await;
13 | tokio::spawn(async move {
14 | let mut backoff = Duration::from_secs(1);
15 | loop {
16 | match monitor_libp2p_connection(local_key.clone()).await {
17 | Ok(_) => {
18 | break;
19 | }
20 | Err(_e) => {
21 | sleep(backoff).await;
22 | backoff = (backoff * 2).min(Duration::from_secs(60)); // Cap backoff
23 | }
24 | }
25 | }
26 | });
27 | }
28 |
29 | pub async fn make_libp2p_keypair(controller_sk: &str) -> Keypair {
30 | if let Ok(private_key_bytes) = hex::decode(&controller_sk) {
31 | if let Ok(secret_key) = identity::secp256k1::SecretKey::try_from_bytes(private_key_bytes) {
32 | identity::secp256k1::Keypair::from(secret_key).into()
33 | } else {
34 | make_fake_libp2p_keypair().await
35 | }
36 | } else {
37 | make_fake_libp2p_keypair().await
38 | }
39 | }
40 |
41 | pub async fn make_fake_libp2p_keypair() -> Keypair {
42 | let private_key_bytes =
43 | hex::decode("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
44 | let secret_key = identity::secp256k1::SecretKey::try_from_bytes(private_key_bytes).unwrap();
45 | identity::secp256k1::Keypair::from(secret_key).into()
46 | }
47 |
48 | pub async fn monitor_libp2p_connection(
49 | local_key: Keypair,
50 | ) -> Result<(), Box