diff --git a/chainIdRpcs.json b/chainIdRpcs.json index fa20c37..a2070f4 100644 --- a/chainIdRpcs.json +++ b/chainIdRpcs.json @@ -61,5 +61,8 @@ ], "1081": [ "ws://3.144.199.9:9944" + ], + "1082": [ + "ws://127.0.0.1:9944" ] } diff --git a/flake.lock b/flake.lock index 6909ad3..a23b12e 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1685677062, - "narHash": "sha256-zoHF7+HNwNwne2XEomphbdc4Y8tdWT16EUxUTXpOKpQ=", + "lastModified": 1701040486, + "narHash": "sha256-vawYwoHA5CwvjfqaT3A5CT9V36Eq43gxdwpux32Qkjw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "95be94370d09f97f6af6a1df1eb9649b5260724e", + "rev": "45827faa2132b8eade424f6bdd48d8828754341a", "type": "github" }, "original": { @@ -51,11 +51,11 @@ ] }, "locked": { - "lastModified": 1685673048, - "narHash": "sha256-iGmamm2ykfUpekXf02SN/r4dPeU33rekwXpkQyB5L1I=", + "lastModified": 1701051362, + "narHash": "sha256-3dXjewnLylWGZKNshIV0eiabhIDjcUNXC5zRKcm0TxY=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "19fdc1c7ae8aa90ba50f044496fda6c4b6616f91", + "rev": "055d3d2ea161dfc6ca569f2f135a107f48cf483e", "type": "github" }, "original": { diff --git a/src/faucet.rs b/src/faucet.rs index 592c01e..89b9689 100644 --- a/src/faucet.rs +++ b/src/faucet.rs @@ -142,34 +142,33 @@ pub async fn handle_token_transfer( Ok(result) } -#[post("/faucet", data = "")] -#[allow(clippy::too_many_arguments)] -pub async fn faucet( +pub async fn check_twitter( app_config: &State, twitter_bearer_token: auth::TwitterBearerToken<'_>, - payload: Json, - auth_db: &State, - evm_providers: &State>, - substrate_providers: &State< - SubstrateProviders>, - >, - evm_wallet: &State>, - signer_pair: &State, - tx_sender: &State>, -) -> Result, Error> { - let faucet_data = payload.clone().into_inner().faucet; +) -> Result { + // during debug builds, we return a dummy user + if cfg!(debug_assertions) { + let token = twitter_bearer_token.token(); + return Ok(twitter_v2::User { + id: NumericId::new(token.parse().unwrap()), + username: "dummy".to_string(), + name: "dummy".to_string(), + created_at: None, + description: None, + entities: None, + location: None, + pinned_tweet_id: None, + profile_image_url: None, + protected: None, + public_metrics: None, + url: None, + verified: None, + withheld: None, + }); + } let auth = BearerToken::new(twitter_bearer_token.token()); let twitter_api = TwitterApi::new(auth); - // Extract faucet request fields - let FaucetRequest { - wallet_address, - typed_chain_id, - .. - } = faucet_data.clone(); - println!( - "Requesting faucet for (address {}, chain: {:?}", - wallet_address, typed_chain_id - ); + let twitter_user: twitter_v2::User = twitter_api .get_users_me() .send() @@ -269,11 +268,41 @@ pub async fn faucet( ); if !is_following_webb { - return Err(Error::Custom( + Err(Error::Custom( "User is not following the webb twitter account".to_string(), - )); + )) + } else { + Ok(twitter_user) } +} +#[post("/faucet", data = "")] +#[allow(clippy::too_many_arguments)] +pub async fn faucet( + app_config: &State, + twitter_bearer_token: auth::TwitterBearerToken<'_>, + payload: Json, + auth_db: &State, + evm_providers: &State>, + substrate_providers: &State< + SubstrateProviders>, + >, + evm_wallet: &State>, + signer_pair: &State, + tx_sender: &State>, +) -> Result, Error> { + let twitter_user = check_twitter(app_config, twitter_bearer_token).await?; + let faucet_data = payload.clone().into_inner().faucet; + // Extract faucet request fields + let FaucetRequest { + wallet_address, + typed_chain_id, + .. + } = faucet_data.clone(); + println!( + "Requesting faucet for (address {}, chain: {:?}", + wallet_address, typed_chain_id + ); // Check if the user's last claim date is within the last 24 hours let claim_data = auth_db .get_last_claim_data(twitter_user.id.into(), typed_chain_id) diff --git a/src/main.rs b/src/main.rs index 79a1980..37e1ef5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -219,7 +219,11 @@ fn substrate_providers_firing() -> impl Fairing { let result: Result>, Error> = match rocket.state::() { Some(_config) => { - let networks = vec![Network::Tangle]; + let networks = vec![ + Network::Tangle, + #[cfg(debug_assertions)] + Network::TangleLocal, + ]; let mut futures_unordered = FuturesUnordered::new(); diff --git a/src/txes/networks.rs b/src/txes/networks.rs index cf56dbc..add97dd 100644 --- a/src/txes/networks.rs +++ b/src/txes/networks.rs @@ -16,6 +16,7 @@ pub enum Network { // Substrate Tangle, + TangleLocal, } impl Network { @@ -34,6 +35,7 @@ impl Network { "demeter" => Some(Self::Demeter), "tangle-evm-testnet" => Some(Self::TangleEVMTestnet), "tangle" => Some(Self::Tangle), + "tangle-local" => Some(Self::TangleLocal), _ => None, } } @@ -77,6 +79,7 @@ impl Network { pub fn from_substrate_chain_id(chain_id: u64) -> Option { match chain_id { 1081 => Some(Self::Tangle), + 1082 => Some(Self::TangleLocal), _ => None, } } @@ -84,6 +87,7 @@ impl Network { pub fn to_substrate_chain_id(&self) -> Option { match self { Self::Tangle => Some(1081), + Self::TangleLocal => Some(1082), _ => None, } } @@ -103,6 +107,7 @@ impl Network { pub fn to_typed_chain_id(&self) -> Option { match self { Self::Tangle => Some(TypedChainId::Substrate(1081)), + Self::TangleLocal => Some(TypedChainId::Substrate(1082)), Self::ArbitrumGoerli => Some(TypedChainId::Evm(421613)), Self::Athena => Some(TypedChainId::Evm(3884533461)), Self::Demeter => Some(TypedChainId::Evm(3884533463)), diff --git a/src/txes/processor.rs b/src/txes/processor.rs index 46add5e..61684bf 100644 --- a/src/txes/processor.rs +++ b/src/txes/processor.rs @@ -1,4 +1,3 @@ - use std::sync::Arc; use crate::subxt::utils::H256; @@ -248,28 +247,31 @@ async fn handle_substrate_native_tx( println!("Tranasction sent with TxHash: {:?}", tx_hash); - // let events = tx_result - // .wait_for_finalized_success() - // .await - // .map_err(|e| Error::Custom(e.to_string()))?; - // let block_hash = events.block_hash(); + let tx_block = tx_result + .wait_for_in_block() + .await + .map_err(|e| Error::Custom(e.to_string()))?; + let block_hash = tx_block.block_hash(); - // // Find a Transfer event and print it. - // let transfer_event = events - // .find_first::() - // .map_err(|e| Error::Custom(e.to_string()))?; - // if let Some(event) = transfer_event { - // let from = event.from; - // let to = event.to; - // let amount = event.amount.div(10u128.pow(18)); - // println!("Transfered {amount} tokens {from} -> {to}"); - // } + // Find a Transfer event and print it. + let transfer_event = tx_block + .fetch_events() + .await + .map_err(|e| Error::Custom(e.to_string()))? + .find_first::() + .map_err(|e| Error::Custom(e.to_string()))?; + if let Some(event) = transfer_event { + let from = event.from; + let to = event.to; + let amount = event.amount / (10u128.pow(18)); + println!("Transfered {amount} tokens {from} -> {to}"); + } // Return the transaction hash. result_sender .send(Ok(TxResult::Substrate { tx_hash, - block_hash: tx_hash, + block_hash, })) .map_err(|e| { Error::Custom(format!("Failed to send tx_hash: {:?}", e))