Feature Request
Area: Smart Contract
File: contracts/solar_grid/src/lib.rs
Description
The provider dashboard uses hardcoded mock data because there is no on-chain function to list all registered meters. Add a paginated get_all_meters so the frontend can fetch real data.
Implementation Guide
Step 1 - Track meter IDs in instance storage. Update register_meter to append each new ID:
const METER_IDS: Symbol = symbol_short!("MIDS");
// inside register_meter after storing the meter:
let mut ids: Vec<Symbol> = env.storage().instance().get(&METER_IDS).unwrap_or(vec![]);
ids.push_back(meter_id.clone());
env.storage().instance().set(&METER_IDS, &ids);
Step 2 - Add the paginated query:
pub fn get_all_meters(env: Env, page: u32, page_size: u32) -> Vec<Meter> {
let ids: Vec<Symbol> = env.storage().instance().get(&METER_IDS).unwrap_or(vec![]);
let start = (page * page_size) as usize;
ids.iter().skip(start).take(page_size as usize)
.filter_map(|id| env.storage().persistent().get(&DataKey::Meter(id.clone())))
.collect()
}
Step 3 - Wire up in ProviderDashboard.tsx:
const result = await contractQuery('get_all_meters', [
nativeToScVal(0, { type: 'u32' }),
nativeToScVal(20, { type: 'u32' }),
]);
Definition of Done
Feature Request
Area: Smart Contract
File: contracts/solar_grid/src/lib.rs
Description
The provider dashboard uses hardcoded mock data because there is no on-chain function to list all registered meters. Add a paginated get_all_meters so the frontend can fetch real data.
Implementation Guide
Step 1 - Track meter IDs in instance storage. Update register_meter to append each new ID:
Step 2 - Add the paginated query:
Step 3 - Wire up in ProviderDashboard.tsx:
Definition of Done