Skip to content

Commit 0003a62

Browse files
committed
feat: Runtime API to retrieve evaluation/participation made by a user
1 parent a5385e6 commit 0003a62

File tree

4 files changed

+72
-31
lines changed

4 files changed

+72
-31
lines changed

justfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ default:
44

55
# Build the "Base" Runtime using srtool
66
build-polimec-polkadot-srtool:
7-
srtool build --root -p polimec-runtime --profile production --runtime-dir runtimes/polimec --build-opts="--features=on-chain-release-build" --no-wasm-std
7+
srtool build --root -p polimec-runtime --profile production --runtime-dir runtimes/polimec --build-opts="--features=on-chain-release-build"
88

99
build-polimec-paseo-srtool:
10-
srtool build --root -p polimec-runtime --profile production --runtime-dir runtimes/polimec --build-opts="--features=on-chain-release-build,fast-mode" --no-wasm-std
10+
srtool build --root -p polimec-runtime --profile production --runtime-dir runtimes/polimec --build-opts="--features=on-chain-release-build,fast-mode"
1111

1212
# Test the runtimes features
1313
test-runtime-features runtime="polimec-runtime":

pallets/funding/src/functions/runtime_api.rs

+32-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ sp_api::decl_runtime_apis! {
2323
fn top_projects_by_usd_target_percent_reached(amount: u32) -> Vec<(ProjectId, ProjectMetadataOf<T>, ProjectDetailsOf<T>)>;
2424
}
2525

26-
#[api_version(1)]
26+
#[api_version(2)]
2727
pub trait UserInformation<T: Config> {
28-
/// Get all the contribution token balances for the participated projects
28+
/// Get all the contribution token balances for the participated projects.
2929
fn contribution_tokens(account: AccountIdOf<T>) -> Vec<(ProjectId, Balance)>;
30+
31+
/// Get all the `EvaluationInfoOf` made by a single account, for a specific project if provided.
32+
fn evaluations_of(account: AccountIdOf<T>, project_id: Option<ProjectId>) -> Vec<EvaluationInfoOf<T>>;
33+
34+
/// Get all the `BidInfoOf` made by a single account, for a specific project if provided.
35+
fn participations_of(account: AccountIdOf<T>, project_id: Option<ProjectId>) -> Vec<BidInfoOf<T>>;
3036
}
3137

3238
#[api_version(1)]
@@ -82,6 +88,30 @@ impl<T: Config> Pallet<T> {
8288
.collect_vec()
8389
}
8490

91+
pub fn participations_of(account: AccountIdOf<T>, project_id: Option<ProjectId>) -> Vec<BidInfoOf<T>> {
92+
match project_id {
93+
Some(id) => Bids::<T>::iter_prefix_values(id).filter(|bid| bid.bidder == account).collect_vec(),
94+
None => Bids::<T>::iter_values().filter(|bid| bid.bidder == account).collect_vec(),
95+
}
96+
}
97+
98+
pub fn evaluations_of(account: AccountIdOf<T>, project_id: Option<ProjectId>) -> Vec<EvaluationInfoOf<T>> {
99+
match project_id {
100+
Some(id) => {
101+
// Use both project ID and account as prefix
102+
let prefix = (id, account);
103+
Evaluations::<T>::iter_prefix_values(prefix).collect_vec()
104+
},
105+
None => {
106+
// If no project is specified, iterate over all projects for this account
107+
Evaluations::<T>::iter()
108+
.filter(|((_, evaluator, _), _)| *evaluator == account)
109+
.map(|(_, value)| value)
110+
.collect_vec()
111+
},
112+
}
113+
}
114+
85115
pub fn top_projects_by_usd_raised(amount: u32) -> Vec<(ProjectId, ProjectMetadataOf<T>, ProjectDetailsOf<T>)> {
86116
ProjectsDetails::<T>::iter()
87117
.sorted_by(|a, b| b.1.funding_amount_reached_usd.cmp(&a.1.funding_amount_reached_usd))

runtimes/polimec/src/lib.rs

+37-26
Original file line numberDiff line numberDiff line change
@@ -244,29 +244,30 @@ pub struct BaseCallFilter;
244244
impl Contains<RuntimeCall> for BaseCallFilter {
245245
fn contains(c: &RuntimeCall) -> bool {
246246
match c {
247-
RuntimeCall::Funding(call) =>
247+
RuntimeCall::Funding(call) => {
248248
if cfg!(feature = "development-settings") {
249249
true
250250
} else {
251251
matches!(
252252
call,
253-
pallet_funding::Call::create_project { .. } |
254-
pallet_funding::Call::remove_project { .. } |
255-
pallet_funding::Call::edit_project { .. } |
256-
pallet_funding::Call::start_evaluation { .. } |
257-
pallet_funding::Call::evaluate { .. } |
258-
pallet_funding::Call::end_evaluation { .. } |
259-
pallet_funding::Call::bid { .. } |
260-
pallet_funding::Call::end_funding { .. } |
261-
pallet_funding::Call::start_settlement { .. } |
262-
pallet_funding::Call::settle_evaluation { .. } |
263-
pallet_funding::Call::settle_bid { .. } |
264-
pallet_funding::Call::mark_project_as_settled { .. } |
265-
pallet_funding::Call::start_offchain_migration { .. } |
266-
pallet_funding::Call::confirm_offchain_migration { .. } |
267-
pallet_funding::Call::mark_project_ct_migration_as_finished { .. }
253+
pallet_funding::Call::create_project { .. }
254+
| pallet_funding::Call::remove_project { .. }
255+
| pallet_funding::Call::edit_project { .. }
256+
| pallet_funding::Call::start_evaluation { .. }
257+
| pallet_funding::Call::evaluate { .. }
258+
| pallet_funding::Call::end_evaluation { .. }
259+
| pallet_funding::Call::bid { .. }
260+
| pallet_funding::Call::end_funding { .. }
261+
| pallet_funding::Call::start_settlement { .. }
262+
| pallet_funding::Call::settle_evaluation { .. }
263+
| pallet_funding::Call::settle_bid { .. }
264+
| pallet_funding::Call::mark_project_as_settled { .. }
265+
| pallet_funding::Call::start_offchain_migration { .. }
266+
| pallet_funding::Call::confirm_offchain_migration { .. }
267+
| pallet_funding::Call::mark_project_ct_migration_as_finished { .. }
268268
)
269-
},
269+
}
270+
},
270271
_ => true,
271272
}
272273
}
@@ -300,19 +301,20 @@ impl InstanceFilter<RuntimeCall> for Type {
300301
),
301302
proxy::Type::Governance => matches!(
302303
c,
303-
RuntimeCall::Treasury(..) |
304-
RuntimeCall::Democracy(..) |
305-
RuntimeCall::Council(..) |
306-
RuntimeCall::TechnicalCommittee(..) |
307-
RuntimeCall::Elections(..) |
308-
RuntimeCall::Preimage(..) |
309-
RuntimeCall::Scheduler(..)
304+
RuntimeCall::Treasury(..)
305+
| RuntimeCall::Democracy(..)
306+
| RuntimeCall::Council(..)
307+
| RuntimeCall::TechnicalCommittee(..)
308+
| RuntimeCall::Elections(..)
309+
| RuntimeCall::Preimage(..)
310+
| RuntimeCall::Scheduler(..)
310311
),
311312
proxy::Type::Staking => {
312313
matches!(c, RuntimeCall::ParachainStaking(..))
313314
},
314-
proxy::Type::IdentityJudgement =>
315-
matches!(c, RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })),
315+
proxy::Type::IdentityJudgement => {
316+
matches!(c, RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }))
317+
},
316318
}
317319
}
318320

@@ -1502,6 +1504,15 @@ impl_runtime_apis! {
15021504
fn contribution_tokens(account: AccountId) -> Vec<(ProjectId, Balance)> {
15031505
Funding::contribution_tokens(account)
15041506
}
1507+
1508+
fn evaluations_of(account: AccountId, project_id: Option<ProjectId>) -> Vec<EvaluationInfoOf<Runtime>> {
1509+
Funding::evaluations_of(account, project_id)
1510+
}
1511+
1512+
1513+
fn participations_of(account: AccountId, project_id: Option<ProjectId>) -> Vec<BidInfoOf<Runtime>> {
1514+
Funding::participations_of(account, project_id)
1515+
}
15051516
}
15061517

15071518
impl pallet_funding::functions::runtime_api::ProjectInformation<Block, Runtime> for Runtime {

rust-toolchain.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "1.81.0"
2+
channel = "1.84.1"
33
components = [ "rustfmt", "clippy", "rust-analyzer", "rust-src" ]
44
targets = [ "wasm32-unknown-unknown" ]

0 commit comments

Comments
 (0)