Skip to content

Commit 9c16005

Browse files
committed
♻️ Keeping is_signer and is_writable in AccountMeta
1 parent f8d20db commit 9c16005

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

crates/programs/world/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,13 @@ fn system_execute<'info>(
559559
use anchor_lang::solana_program::program::invoke;
560560

561561
let mut accounts = vec![AccountMeta::new_readonly(authority.key(), false)];
562-
accounts.extend(
563-
remaining_accounts
564-
.iter()
565-
.map(|account| AccountMeta::new_readonly(account.key(), false)),
566-
);
562+
accounts.extend(remaining_accounts.iter().map(|account| {
563+
AccountMeta {
564+
pubkey: account.key(),
565+
is_signer: account.is_signer,
566+
is_writable: account.is_writable,
567+
}
568+
}));
567569

568570
let mut account_infos = vec![authority.to_account_info()];
569571
account_infos.extend(

crates/programs/world/src/utils.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/// Computes an 8-byte discriminator for the given name.
2+
///
3+
/// The discriminator is derived by taking the first 8 bytes of the SHA-256 hash
4+
/// of the input name. This is used for discriminator-based routing in bundled
5+
/// components and systems.
6+
///
7+
/// # Collision Risk
8+
///
9+
/// Using 8 bytes (64 bits) of a hash introduces a small collision probability.
10+
/// With the birthday paradox, collisions become likely after ~2^32 different names.
11+
/// This is acceptable for component/system name spaces in practice.
12+
///
13+
/// # Examples
14+
///
15+
/// ```
16+
/// let disc = discriminator_for("Position");
17+
/// assert_eq!(disc.len(), 8);
18+
/// ```
119
pub const fn discriminator_for(name: &str) -> [u8; 8] {
220
let mut discriminator = [0u8; 8];
321

@@ -7,6 +25,7 @@ pub const fn discriminator_for(name: &str) -> [u8; 8] {
725

826
let hash_bytes = hash.as_slice();
927

28+
// Manual loop required for const fn compatibility
1029
let mut i = 0;
1130
while i < 8 {
1231
discriminator[i] = hash_bytes[i];

0 commit comments

Comments
 (0)