From: Ian Jackson Date: Wed, 28 Oct 2020 22:37:57 +0000 (+0000) Subject: for revert: daft AccountName recovery X-Git-Tag: otter-0.2.0~587 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=1a643415fe3580cd13719f3ff19e0cd378a9d66e;p=otter.git for revert: daft AccountName recovery Signed-off-by: Ian Jackson --- diff --git a/src/accounts.rs b/src/accounts.rs index 4ba85afc..ccfc0836 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -168,14 +168,33 @@ pub fn save_accounts_now() -> Result<(), InternalError> { panic!("xxx") } +pub type Mut<'l> = ( + MappedRwLockWriteGuard<'l, AccountRecord>, + MappedRwLockWriteGuard<'l, AccountName>, + AccountId, +); + +trait AccountNameOrId { + fn initial_lookup(Self, accounts: &Accounts) -> Option; +} + +impl<'n> AccountNameOrId for &'n AccountName { + #[throws(as Option)] + fn lookup_mut(self, accounts: &RwLockWriteGuard) -> AccountLookupMut { + let acctid = *accounts.names.get(self)?; + +} + #[derive(Default,Debug)] -struct LookupHelper { +struct LookupHelper<'d> { acctid_r: Option, } -impl LookupHelper { +impl<'d, K:AccountNameOrId> LookupHelper<'d, K> { #[throws(as Option)] - fn get(&mut self, accounts: &Accounts, account: &AccountName) -> AccountId { + fn get(&mut self, accounts: &Accounts, key: K) -> AccountId { + let acctid = key.initial_lookup(accounts)?; + let name = *accounts.records. let acctid = *accounts.names.get(account)?; self.acctid_r = Some(acctid); acctid @@ -199,7 +218,7 @@ impl AccountRecord { }).collect() } - pub fn lookup(account: &AccountName, _: Authorisation) + pub fn lookup(key: K, _: Authorisation) -> Option<(MappedRwLockReadGuard<'static, AccountRecord>, AccountId)> { @@ -213,10 +232,9 @@ impl AccountRecord { ) } - pub fn lookup_mut_caller_must_save - ( account: &AccountName, _auth: Authorisation) - -> Option<(MappedRwLockWriteGuard<'static, AccountRecord>, - AccountId)> + pub fn lookup_mut_caller_must_save + ( key: &K, _auth: Authorisation) + -> Option { let mut helper : LookupHelper = default(); helper.wrap(