Skip to content

Commit

Permalink
Merge pull request #60 from llllllluc/add-prev-id-and-remove-need-for…
Browse files Browse the repository at this point in the history
…-account-for-keeper

[Chore] Add prev id and remove need for account for keeper
  • Loading branch information
simke9445 authored Sep 26, 2023
2 parents 44511ad + 66151a7 commit ba82332
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions contracts/warp-controller/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ pub fn reply(mut deps: DepsMut, env: Env, msg: Reply) -> Result<Response, Contra
&mut deps,
Job {
id: state.current_job_id,
prev_id: Some(finished_job.id),
owner: finished_job.owner.clone(),
last_update_time: Uint64::from(env.block.time.seconds()),
name: finished_job.name.clone(),
Expand Down
2 changes: 2 additions & 0 deletions contracts/warp-controller/src/execute/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pub fn migrate_pending_jobs(
job_key,
&Job {
id: v1_job.id,
prev_id: None,
owner: v1_job.owner,
last_update_time: v1_job.last_update_time,
name: v1_job.name,
Expand Down Expand Up @@ -376,6 +377,7 @@ pub fn migrate_finished_jobs(
job_key,
&Job {
id: v1_job.id,
prev_id: None,
owner: v1_job.owner,
last_update_time: v1_job.last_update_time,
name: v1_job.name,
Expand Down
13 changes: 4 additions & 9 deletions contracts/warp-controller/src/execute/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub fn create_job(
&mut deps,
Job {
id: state.current_job_id,
prev_id: None,
owner: account.owner,
last_update_time: Uint64::from(env.block.time.seconds()),
name: data.name,
Expand Down Expand Up @@ -264,12 +265,6 @@ pub fn execute_job(
let job = JobQueue::get(&deps, data.id.into())?;
let account = ACCOUNTS().load(deps.storage, job.owner.clone())?;

if !ACCOUNTS().has(deps.storage, info.sender.clone()) {
return Err(ContractError::AccountDoesNotExist {});
}

let keeper_account = ACCOUNTS().load(deps.storage, info.sender.clone())?;

if job.status != JobStatus::Pending {
return Err(ContractError::JobNotActive {});
}
Expand Down Expand Up @@ -326,8 +321,9 @@ pub fn execute_job(
});
}

//send reward to executor
let reward_msg = BankMsg::Send {
to_address: keeper_account.account.to_string(),
to_address: info.sender.to_string(),
amount: vec![Coin::new(job.reward.u128(), config.fee_denom)],
};

Expand Down Expand Up @@ -401,8 +397,7 @@ pub fn evict_job(
);
job_status = JobQueue::sync(&mut deps, env, job.clone())?.status;
} else {
job_status =
JobQueue::finalize(&mut deps, env, job.id.into(), JobStatus::Evicted)?.status;
job_status = JobQueue::finalize(&mut deps, env, job.id.into(), JobStatus::Evicted)?.status;

cosmos_msgs.append(&mut vec![
//send reward minus fee back to account
Expand Down
3 changes: 3 additions & 0 deletions contracts/warp-controller/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl JobQueue {
None => Err(ContractError::JobDoesNotExist {}),
Some(job) => Ok(Job {
id: job.id,
prev_id: job.prev_id,
owner: job.owner,
last_update_time: Uint64::new(env.block.time.seconds()),
name: job.name,
Expand All @@ -133,6 +134,7 @@ impl JobQueue {
None => Err(ContractError::JobDoesNotExist {}),
Some(job) => Ok(Job {
id: job.id,
prev_id: job.prev_id,
owner: job.owner,
last_update_time: if added_reward > config.minimum_reward {
Uint64::new(env.block.time.seconds())
Expand Down Expand Up @@ -169,6 +171,7 @@ impl JobQueue {

let new_job = Job {
id: job.id,
prev_id: job.prev_id,
owner: job.owner,
last_update_time: Uint64::new(env.block.time.seconds()),
name: job.name,
Expand Down
2 changes: 2 additions & 0 deletions packages/controller/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use strum_macros::Display;
#[cw_serde]
pub struct Job {
pub id: Uint64,
// Exist if job is the follow up job of a recurring job
pub prev_id: Option<Uint64>,
pub owner: Addr,
pub last_update_time: Uint64,
pub name: String,
Expand Down

0 comments on commit ba82332

Please sign in to comment.