Skip to content

Commit

Permalink
Fix job id
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadalm committed Aug 1, 2023
1 parent 542ea87 commit 315c952
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ use crate::helpers::throw_err;
use crate::receive::receive;
use crate::state::{
farm_profile_dto, points, FarmProfile, NoiseJob, Points, FARM_PROFILES, INFORMATION, NOIS_JOBS,
NOIS_PROXY,
NOIS_JOB_LAST_ID, NOIS_PROXY,
};

const CONTRACT_NAME: &str = "crates.io:farm_template";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

fn next_job_id(store: &mut dyn Storage) -> StdResult<String> {
let last_id = (NOIS_JOB_LAST_ID.may_load(store)?).unwrap_or(0);
let next_id = last_id + 1;
NOIS_JOB_LAST_ID.save(store, &next_id)?;

Ok(next_id.to_string())
}

fn mint_seeds(
plant: KomplePlant,
recipient: String,
Expand Down Expand Up @@ -86,6 +94,8 @@ pub fn instantiate(
},
)?;

NOIS_JOB_LAST_ID.save(deps.storage, &0)?;

match msg.nois_proxy {
None => (),
Some(addr) => {
Expand Down Expand Up @@ -232,15 +242,14 @@ pub fn execute(
plant: komple,
recipient: info.sender.into_string(),
};
NOIS_JOBS.save(deps.storage, "val", &job)?;
let job_id = next_job_id(deps.storage)?;
NOIS_JOBS.save(deps.storage, &job_id, &job)?;

let mut messages: Vec<CosmosMsg> = vec![];
let msg = WasmMsg::Execute {
contract_addr: nois_proxy.into(),
msg: to_binary(
&ProxyExecuteMsg::GetNextRandomness {
job_id: "val".into(), // todo: uuid?
},
&ProxyExecuteMsg::GetNextRandomness { job_id },
)?,
funds: info.funds.clone(),
};
Expand Down
1 change: 1 addition & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub enum NoiseJob {
pub const FARM_PROFILES: Map<&str, FarmProfile> = Map::new("farm_profiles");
pub const INFORMATION: Item<ContractInformation> = Item::new("info");
pub const NOIS_PROXY: Item<Addr> = Item::new("nois_proxy");
pub const NOIS_JOB_LAST_ID: Item<u64> = Item::new("nois_job_last_id");
pub const NOIS_JOBS: Map<&str, NoiseJob> = Map::new("nois_jobs");

#[cw_serde]
Expand Down

0 comments on commit 315c952

Please sign in to comment.