diff --git a/src/contract.rs b/src/contract.rs index 2e2ed90..a5d9220 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -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 { + 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, @@ -86,6 +94,8 @@ pub fn instantiate( }, )?; + NOIS_JOB_LAST_ID.save(deps.storage, &0)?; + match msg.nois_proxy { None => (), Some(addr) => { @@ -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 = 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(), }; diff --git a/src/state.rs b/src/state.rs index 2b9598f..0d61572 100644 --- a/src/state.rs +++ b/src/state.rs @@ -90,6 +90,7 @@ pub enum NoiseJob { pub const FARM_PROFILES: Map<&str, FarmProfile> = Map::new("farm_profiles"); pub const INFORMATION: Item = Item::new("info"); pub const NOIS_PROXY: Item = Item::new("nois_proxy"); +pub const NOIS_JOB_LAST_ID: Item = Item::new("nois_job_last_id"); pub const NOIS_JOBS: Map<&str, NoiseJob> = Map::new("nois_jobs"); #[cw_serde]