From c7a165b8ae04ad1d08154c4f60c336ad32dfb49f Mon Sep 17 00:00:00 2001 From: simke9445 Date: Tue, 7 Nov 2023 14:51:40 +0100 Subject: [PATCH] add last_job_id to free_accounts --- contracts/warp-controller/src/execute/job.rs | 3 +++ contracts/warp-controller/src/util/msg.rs | 2 ++ .../src/execute/account.rs | 2 +- .../src/integration_tests.rs | 23 +++++++++++-------- .../src/query/account.rs | 8 +++---- .../warp-job-account-tracker/src/state.rs | 2 +- packages/job-account-tracker/src/lib.rs | 1 + 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/contracts/warp-controller/src/execute/job.rs b/contracts/warp-controller/src/execute/job.rs index c4221352..7ec8b2ab 100644 --- a/contracts/warp-controller/src/execute/job.rs +++ b/contracts/warp-controller/src/execute/job.rs @@ -290,6 +290,7 @@ pub fn delete_job( config.job_account_tracker_address.to_string(), job.owner.to_string(), job_account_addr.to_string(), + job.id, )); } @@ -460,6 +461,7 @@ pub fn execute_job( config.job_account_tracker_address.to_string(), job.owner.to_string(), job_account_addr.to_string(), + job.id, )); } @@ -553,6 +555,7 @@ pub fn evict_job( config.job_account_tracker_address.to_string(), job.owner.to_string(), job_account_addr.to_string(), + job.id, )); } } diff --git a/contracts/warp-controller/src/util/msg.rs b/contracts/warp-controller/src/util/msg.rs index e21d05ce..2a1d05ad 100644 --- a/contracts/warp-controller/src/util/msg.rs +++ b/contracts/warp-controller/src/util/msg.rs @@ -34,6 +34,7 @@ pub fn build_free_account_msg( job_account_tracker_addr: String, account_owner_addr: String, account_addr: String, + last_job_id: Uint64, ) -> CosmosMsg { CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: job_account_tracker_addr, @@ -41,6 +42,7 @@ pub fn build_free_account_msg( FreeAccountMsg { account_owner_addr, account_addr, + last_job_id, }, )) .unwrap(), diff --git a/contracts/warp-job-account-tracker/src/execute/account.rs b/contracts/warp-job-account-tracker/src/execute/account.rs index fc460636..501bd114 100644 --- a/contracts/warp-job-account-tracker/src/execute/account.rs +++ b/contracts/warp-job-account-tracker/src/execute/account.rs @@ -30,7 +30,7 @@ pub fn free_account(deps: DepsMut, data: FreeAccountMsg) -> Result Ok(true), + None => Ok(data.last_job_id), Some(_) => Err(ContractError::AccountAlreadyFreeError {}), }, )?; diff --git a/contracts/warp-job-account-tracker/src/integration_tests.rs b/contracts/warp-job-account-tracker/src/integration_tests.rs index 78c65da4..ca29f8d2 100644 --- a/contracts/warp-job-account-tracker/src/integration_tests.rs +++ b/contracts/warp-job-account-tracker/src/integration_tests.rs @@ -138,6 +138,7 @@ mod tests { &ExecuteMsg::FreeAccount(FreeAccountMsg { account_owner_addr: USER_1.to_string(), account_addr: DUMMY_WARP_ACCOUNT_1_ADDR.to_string(), + last_job_id: DUMMY_JOB_1_ID, }), &[], ); @@ -150,6 +151,7 @@ mod tests { &ExecuteMsg::FreeAccount(FreeAccountMsg { account_owner_addr: USER_1.to_string(), account_addr: DUMMY_WARP_ACCOUNT_1_ADDR.to_string(), + last_job_id: DUMMY_JOB_1_ID, }), &[], ), @@ -163,6 +165,7 @@ mod tests { &ExecuteMsg::FreeAccount(FreeAccountMsg { account_owner_addr: USER_1.to_string(), account_addr: DUMMY_WARP_ACCOUNT_2_ADDR.to_string(), + last_job_id: DUMMY_JOB_2_ID, }), &[], ); @@ -174,6 +177,7 @@ mod tests { &ExecuteMsg::FreeAccount(FreeAccountMsg { account_owner_addr: USER_1.to_string(), account_addr: DUMMY_WARP_ACCOUNT_3_ADDR.to_string(), + last_job_id: DUMMY_JOB_1_ID, }), &[], ); @@ -189,7 +193,7 @@ mod tests { Ok(FirstFreeAccountResponse { account: Some(Account { addr: Addr::unchecked(DUMMY_WARP_ACCOUNT_1_ADDR), - taken_by_job_id: None + taken_by_job_id: Some(DUMMY_JOB_1_ID) }) }) ); @@ -208,15 +212,15 @@ mod tests { accounts: vec![ Account { addr: Addr::unchecked(DUMMY_WARP_ACCOUNT_3_ADDR), - taken_by_job_id: None + taken_by_job_id: Some(DUMMY_JOB_1_ID) }, Account { addr: Addr::unchecked(DUMMY_WARP_ACCOUNT_2_ADDR), - taken_by_job_id: None + taken_by_job_id: Some(DUMMY_JOB_2_ID) }, Account { addr: Addr::unchecked(DUMMY_WARP_ACCOUNT_1_ADDR), - taken_by_job_id: None + taken_by_job_id: Some(DUMMY_JOB_1_ID) } ], total_count: 3 @@ -280,11 +284,11 @@ mod tests { accounts: vec![ Account { addr: Addr::unchecked(DUMMY_WARP_ACCOUNT_3_ADDR), - taken_by_job_id: None + taken_by_job_id: Some(DUMMY_JOB_1_ID) }, Account { addr: Addr::unchecked(DUMMY_WARP_ACCOUNT_1_ADDR), - taken_by_job_id: None + taken_by_job_id: Some(DUMMY_JOB_1_ID) } ], total_count: 2 @@ -317,6 +321,7 @@ mod tests { &ExecuteMsg::FreeAccount(FreeAccountMsg { account_owner_addr: USER_1.to_string(), account_addr: DUMMY_WARP_ACCOUNT_2_ADDR.to_string(), + last_job_id: DUMMY_JOB_1_ID, }), &[], ); @@ -335,15 +340,15 @@ mod tests { accounts: vec![ Account { addr: Addr::unchecked(DUMMY_WARP_ACCOUNT_3_ADDR), - taken_by_job_id: None + taken_by_job_id: Some(DUMMY_JOB_1_ID) }, Account { addr: Addr::unchecked(DUMMY_WARP_ACCOUNT_2_ADDR), - taken_by_job_id: None + taken_by_job_id: Some(DUMMY_JOB_1_ID) }, Account { addr: Addr::unchecked(DUMMY_WARP_ACCOUNT_1_ADDR), - taken_by_job_id: None + taken_by_job_id: Some(DUMMY_JOB_1_ID) } ], total_count: 3 diff --git a/contracts/warp-job-account-tracker/src/query/account.rs b/contracts/warp-job-account-tracker/src/query/account.rs index f89c67af..1f6aad72 100644 --- a/contracts/warp-job-account-tracker/src/query/account.rs +++ b/contracts/warp-job-account-tracker/src/query/account.rs @@ -29,9 +29,9 @@ pub fn query_first_free_account( ) .next(); let free_account = match maybe_free_account { - Some(Ok((account, _))) => Some(Account { + Some(Ok((account, last_job_id))) => Some(Account { addr: account.1, - taken_by_job_id: None, + taken_by_job_id: Some(last_job_id), }), _ => None, }; @@ -105,9 +105,9 @@ pub fn query_free_accounts(deps: Deps, data: QueryFreeAccountsMsg) -> StdResult< let accounts = iter .take(data.limit.unwrap_or(QUERY_LIMIT) as usize) .map(|item| { - item.map(|(account, _)| Account { + item.map(|(account, last_job_id)| Account { addr: account.1, - taken_by_job_id: None, + taken_by_job_id: Some(last_job_id), }) }) .collect::>>()?; diff --git a/contracts/warp-job-account-tracker/src/state.rs b/contracts/warp-job-account-tracker/src/state.rs index 400c501f..5dca505e 100644 --- a/contracts/warp-job-account-tracker/src/state.rs +++ b/contracts/warp-job-account-tracker/src/state.rs @@ -8,4 +8,4 @@ pub const CONFIG: Item = Item::new("config"); pub const TAKEN_ACCOUNTS: Map<(&Addr, &Addr), Uint64> = Map::new("taken_accounts"); // Key is the (account owner address, account address), value is id of the last job which reserved it -pub const FREE_ACCOUNTS: Map<(&Addr, &Addr), bool> = Map::new("free_accounts"); +pub const FREE_ACCOUNTS: Map<(&Addr, &Addr), Uint64> = Map::new("free_accounts"); diff --git a/packages/job-account-tracker/src/lib.rs b/packages/job-account-tracker/src/lib.rs index 841745fc..fb265394 100644 --- a/packages/job-account-tracker/src/lib.rs +++ b/packages/job-account-tracker/src/lib.rs @@ -32,6 +32,7 @@ pub struct TakeAccountMsg { pub struct FreeAccountMsg { pub account_owner_addr: String, pub account_addr: String, + pub last_job_id: Uint64, } #[derive(QueryResponses)]