Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change a retun type of get_vote_info fromm BoundedVec to Vec #18

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub use frame_support::{
},
IdentityFee, Weight,
},
BoundedVec, StorageValue,
StorageValue,
};
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
Expand Down Expand Up @@ -477,8 +477,8 @@ impl_runtime_apis! {
}
}

impl proof_of_transaction_runtime_api::ProofOfTransactionAPI<Block, AccountId, <Runtime as pallet_pot::Config>::MaxVotedValidators> for Runtime {
fn get_vote_info() -> BoundedVec<(AccountId, u64), MaxVotedValidators> {
impl proof_of_transaction_runtime_api::ProofOfTransactionAPI<Block, AccountId> for Runtime {
fn get_vote_info() -> Vec<(AccountId, VoteWeight)> {
pallet_pot::Pallet::<Runtime>::get_vote_info()
}
}
Expand Down
6 changes: 2 additions & 4 deletions frame/proof-of-transaction/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@

#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::{traits::Get, BoundedVec};

sp_api::decl_runtime_apis! {
#[api_version(3)]
pub trait ProofOfTransactionAPI<AccountId, MaxVotedValidators: Get<u32>> where
pub trait ProofOfTransactionAPI<AccountId> where
AccountId: codec::Codec,
{
fn get_vote_info() -> BoundedVec<(AccountId, u64), MaxVotedValidators>;
fn get_vote_info() -> Vec<(AccountId, u64)>;
}
}
12 changes: 4 additions & 8 deletions frame/proof-of-transaction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
dispatch::{DispatchInfo, PostDispatchInfo},
pallet_prelude::*,
BoundedVec,
};

pub use pallet::*;
Expand All @@ -20,7 +19,7 @@ use sp_runtime::{
transaction_validity::{TransactionValidity, TransactionValidityError, ValidTransaction},
};

use sp_std::{convert::TryInto, prelude::*, vec::Vec};
use sp_std::{prelude::*, vec::Vec};

pub type VoteWeight = u64;

Expand Down Expand Up @@ -73,14 +72,11 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
/// Runtime-api fn to return and change the collected VoteInfo as a BoundedVec
pub fn get_vote_info() -> BoundedVec<(T::AccountId, VoteWeight), T::MaxVotedValidators> {
/// Runtime-api fn to return the collected VoteInfo as a Vec
pub fn get_vote_info() -> Vec<(T::AccountId, VoteWeight)> {
let vote_vec = VoteInfo::<T>::iter().collect::<Vec<(T::AccountId, VoteWeight)>>();

let vote_bounded: BoundedVec<(T::AccountId, VoteWeight), T::MaxVotedValidators> =
vote_vec.try_into().expect("exceeded the # of validators available to vote.");

vote_bounded
vote_vec
}

pub fn get_max_voted_validators() -> u32 {
Expand Down