Skip to content

Instantly share code, notes, and snippets.

@guillemcordoba
Last active November 12, 2020 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillemcordoba/442e0b1f58d2c2c3b96cfe9e06bff60f to your computer and use it in GitHub Desktop.
Save guillemcordoba/442e0b1f58d2c2c3b96cfe9e06bff60f to your computer and use it in GitHub Desktop.
fn get_entry_type_index(entry_type: String) -> ExternResult<EntryDefIndex> {
match entry_type.as_str() {
"association" => Ok(EntryDefIndex::from(0)),
"encrypted_data_wrapper" => Ok(EntryDefIndex::from(1)),
"bid_commitment" => Ok(EntryDefIndex::from(2)),
"market_plan" => Ok(EntryDefIndex::from(3)),
_ => Err(crate::err("Wrong entry type")),
}
}
entry_defs![
MarketBidderAssociation::entry_def(),
EncryptedDataWrapper::entry_def(),
BidCommitment::entry_def(),
MarketPlan::entry_def(),
Path::entry_def()
];
pub fn query_elements(entry_type: String, time_range: TimeRange) -> ExternResult<Vec<Element>> {
let filter = ChainQueryFilter::new()
.entry_type(EntryType::App(AppEntryType::new(
crate::get_entry_type_index(entry_type)?,
zome_info!()?.zome_id,
EntryVisibility::Private,
)))
.header_type(HeaderType::Create)
.include_entries(true);
let query_result: ElementVec = query!(filter)?;
Ok(query_result.0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment