Skip to content

Commit

Permalink
Record claims only once tokens got claimed
Browse files Browse the repository at this point in the history
  • Loading branch information
shekohex committed Dec 1, 2023
1 parent b64b76b commit 5e6f790
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions src/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,27 +335,10 @@ pub async fn faucet(
}
}

let claim: ClaimsData = ClaimsData {
identity: twitter_user.id.into(),
address: wallet_address.clone().into(),
last_claimed_date: now,
};

auth_db
.put_last_claim_data(twitter_user.id.into(), typed_chain_id, claim)
.await?;
// Process the claim and build the response
println!(
"{:?} Claiming for user: {:?}",
Utc::now().to_rfc3339(),
"Paying {} ({wallet_address}) on chain: {typed_chain_id:?}",
twitter_user.username,
);
println!(
"{:?} Paying {} on chain: {:?}",
Utc::now().to_rfc3339(),
wallet_address,
typed_chain_id
);

match handle_token_transfer(
faucet_data,
Expand All @@ -368,17 +351,38 @@ pub async fn faucet(
)
.await
{
Ok(tx_result) => Ok(status::Custom(
Status::Ok,
json!({
"wallet": wallet_address,
"typed_chain_id": typed_chain_id,
"last_claimed_date": now,
"user": twitter_user,
"tx_result": tx_result,
})
.to_string(),
)),
Ok(tx_result) => {
let claim: ClaimsData = ClaimsData {
identity: twitter_user.id.into(),
address: wallet_address.clone().into(),
last_claimed_date: now,
};

auth_db
.put_last_claim_data(
twitter_user.id.into(),
typed_chain_id,
claim,
)
.await?;
println!(
"{:?} Paid {} on chain: {:?}",
Utc::now().to_rfc3339(),
wallet_address,
typed_chain_id
);
Ok(status::Custom(
Status::Ok,
json!({
"wallet": wallet_address,
"typed_chain_id": typed_chain_id,
"last_claimed_date": now,
"user": twitter_user,
"tx_result": tx_result,
})
.to_string(),
))
}
Err(e) => {
rocket::log::private::error!("Error transferring tokens: {e:?}");
Ok(status::Custom(
Expand Down

0 comments on commit 5e6f790

Please sign in to comment.