Skip to content

Commit

Permalink
fix(web-server): change account_attempts to an Option<u32> (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
billguo99 authored Aug 2, 2023
1 parent c3e9249 commit f38b816
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion web-server/sgx-wallet-impl/src/schema/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct WalletStorable {
pub phone_number: Option<String>,
pub otp_phone_number: Option<String>,

pub account_attempts: u32,
pub account_attempts: Option<u32>,

pub algorand_account: AlgorandAccount,
pub xrpl_account: XrplAccount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn create_wallet(request: &CreateWallet) -> Result {
phone_number: request.phone_number.clone(),
otp_phone_number: request.phone_number.clone(),

account_attempts: 0,
account_attempts: Some(0),
algorand_account: new_algorand_account,
xrpl_account: new_xrpl_account,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn open_wallet(request: &OpenWallet) -> OpenWalletResult {
match unlock_wallet(&request.wallet_id, &request.auth_pin) {
Ok(_) => {
return match mutate_wallet(&request.wallet_id, |mut stored| {
stored.account_attempts = 0;
stored.account_attempts = Some(0);
stored
}) {
Ok(Some(stored)) => OpenWalletResult::Opened(WalletDisplay::from(stored)),
Expand All @@ -19,7 +19,9 @@ pub fn open_wallet(request: &OpenWallet) -> OpenWalletResult {
Err(err) => match err {
UnlockWalletError::InvalidAuthPin => {
match mutate_wallet(&request.wallet_id, |mut stored| {
stored.account_attempts = stored.account_attempts + 1;
stored.account_attempts = stored
.account_attempts
.map_or(Some(1), |attempts| Some(attempts + 1));
stored
}) {
_ => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn reset_wallet_pin(request: &PinReset) -> PinResetResult {
StartPinResetResult::Success => {
match mutate_wallet(&request.wallet_id, |mut stored| {
stored.auth_pin = request.new_pin.clone();
stored.account_attempts = 0;
stored.account_attempts = Some(0);
stored
}) {
Ok(Some(_)) => PinResetResult::Reset,
Expand Down
2 changes: 1 addition & 1 deletion web-server/sgx-wallet-impl/src/wallet_operations/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn unlock_wallet(wallet_id: &str, auth_pin: &str) -> Result<WalletStorable,
let stored: WalletStorable =
load_wallet(wallet_id)?.ok_or(UnlockWalletError::InvalidWalletId)?;

if stored.account_attempts >= 3 {
if stored.account_attempts >= Some(3) {
return Err(UnlockWalletError::AccountLocked);
}

Expand Down

0 comments on commit f38b816

Please sign in to comment.