generated from okp4/template-rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from okp4/feat/faucet-harassing
😵 Limit faucet harassing
- Loading branch information
Showing
18 changed files
with
118 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,42 @@ | ||
//! Register transaction handler | ||
|
||
use crate::cosmos::tx::error::Error::{DuplicateUser, Lock, QueueFull}; | ||
use crate::cosmos::tx::messages::register_msg::{RegisterMsg, RegisterMsgResult}; | ||
use crate::cosmos::tx::messages::response::TxResult; | ||
use crate::cosmos::tx::TxHandler; | ||
use actix::dev::ToEnvelope; | ||
use actix::{Actor, Handler}; | ||
use cosmrs::tx::Msg; | ||
use tracing::info; | ||
use tracing::log::warn; | ||
|
||
impl<T, R> Handler<RegisterMsg<T>> for TxHandler<T, R> | ||
where | ||
T: Msg + Unpin + 'static, | ||
T: Msg + Unpin + 'static + PartialEq, | ||
R: Actor + Handler<TxResult>, | ||
R::Context: ToEnvelope<R, TxResult>, | ||
{ | ||
type Result = RegisterMsgResult; | ||
|
||
fn handle(&mut self, msg: RegisterMsg<T>, _: &mut Self::Context) -> Self::Result { | ||
if msg.subscriber.is_some() { | ||
self.subscribers.push(msg.subscriber.unwrap()) | ||
let mut msgs = self.msgs_queue.lock().map_err(|_| Lock)?; | ||
|
||
if msgs.len() >= self.queue_limit { | ||
warn!( | ||
"❌ Could not register funds for {}, the queue is full.", | ||
msg.subscriber.name | ||
); | ||
Err(QueueFull) | ||
} else if msgs.iter().any(|f| f.0.id == msg.subscriber.id) { | ||
info!( | ||
"👮 The user {} already register transaction, skip this one.", | ||
msg.subscriber.name | ||
); | ||
Err(DuplicateUser) | ||
} else { | ||
info!("🤑 Register transaction for {}", msg.subscriber.name); | ||
msgs.push_back((msg.subscriber, msg.msg)); | ||
Ok(()) | ||
} | ||
self.msgs.push(msg.msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.