provwasm_stdv1/
query.rs

1use cosmwasm_std::{Addr, CustomQuery};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5use crate::types::ProvenanceRoute;
6
7/// Represents a request to query a custom provenance module.
8#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
9#[serde(rename_all = "snake_case")]
10pub struct ProvenanceQuery {
11    pub route: ProvenanceRoute,        // The module router key
12    pub params: ProvenanceQueryParams, // The module-specific params
13    pub version: String,               // The data format version
14}
15
16// Indicate that ProvenanceQuery is a custom query to avoid conflicts with other types such as
17// BankQuery and WasmQuery.
18impl CustomQuery for ProvenanceQuery {}
19
20/// Input params for custom provenance queriers.
21#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
22#[serde(rename_all = "snake_case")]
23pub enum ProvenanceQueryParams {
24    Name(NameQueryParams),
25    Attribute(AttributeQueryParams),
26    Marker(MarkerQueryParams),
27    Metadata(MetadataQueryParams),
28}
29
30/// Params for name queries.
31#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
32#[serde(rename_all = "snake_case")]
33pub enum NameQueryParams {
34    Resolve { name: String },
35    Lookup { address: Addr },
36}
37
38/// Params for attribute queries.
39#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
40#[serde(rename_all = "snake_case")]
41pub enum AttributeQueryParams {
42    GetAttributes { address: Addr, name: String },
43    GetAllAttributes { address: Addr },
44}
45
46/// Params for marker queries.
47#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
48#[serde(rename_all = "snake_case")]
49pub enum MarkerQueryParams {
50    GetMarkerByAddress { address: Addr },
51    GetMarkerByDenom { denom: String },
52}
53
54/// Params for metadata queries
55#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
56#[serde(rename_all = "snake_case")]
57pub enum MetadataQueryParams {
58    GetScope {
59        scope_id: String,
60    },
61    GetSessions {
62        scope_id: String,
63    },
64    GetRecords {
65        scope_id: String,
66        name: Option<String>,
67    },
68}