Skip to content

Commit

Permalink
program::message::AccountKeys: Clone, Default, Debug, Eq (#33749
Browse files Browse the repository at this point in the history
)

It is a pretty standard set of traits to implement on most types.  Both `Pubkey`
and `LoadedAddresses` contained within the `AccountKeys` already implement them.
Doing the same for `AccountKeys` could simplify unit tests and/or some common
value manipulation logic.
  • Loading branch information
ilya-bobyr authored Oct 18, 2023
1 parent e96678b commit 84c2f9d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sdk/program/src/message/account_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use {
message::{v0::LoadedAddresses, CompileError},
pubkey::Pubkey,
},
std::{collections::BTreeMap, ops::Index},
std::{collections::BTreeMap, iter::zip, ops::Index},
};

/// Collection of static and dynamically loaded keys used to load accounts
/// during transaction processing.
#[derive(Clone, Default, Debug, Eq)]
pub struct AccountKeys<'a> {
static_keys: &'a [Pubkey],
dynamic_keys: Option<&'a LoadedAddresses>,
Expand Down Expand Up @@ -138,6 +139,12 @@ impl<'a> AccountKeys<'a> {
}
}

impl PartialEq for AccountKeys<'_> {
fn eq(&self, other: &Self) -> bool {
zip(self.iter(), other.iter()).all(|(a, b)| a == b)
}
}

#[cfg(test)]
mod tests {
use {super::*, crate::instruction::AccountMeta};
Expand Down

0 comments on commit 84c2f9d

Please sign in to comment.