Skip to content

Commit

Permalink
[pallet-revive] move event topics in event's body (#5640)
Browse files Browse the repository at this point in the history
Fix #5629
  • Loading branch information
pgherveou committed Sep 9, 2024
1 parent d2e962f commit f3f377f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
10 changes: 10 additions & 0 deletions prdoc/pr_5640.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: "[pallet-revive] Move event's topics"

doc:
- audience: Runtime Dev
description: |
Move event's topics inside body

crates:
- name: pallet-revive
bump: major
6 changes: 1 addition & 5 deletions substrate/frame/revive/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,7 @@ mod benchmarks {

assert_eq!(
record.event,
crate::Event::ContractEmitted { contract: instance.address(), data }.into(),
);
assert_eq!(
record.topics.iter().map(|t| H256::from_slice(t.as_ref())).collect::<Vec<_>>(),
topics,
crate::Event::ContractEmitted { contract: instance.address(), data, topics }.into(),
);
}

Expand Down
10 changes: 4 additions & 6 deletions substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,13 +1487,11 @@ where
}

fn deposit_event(&mut self, topics: Vec<H256>, data: Vec<u8>) {
Contracts::<Self::T>::deposit_indexed_event(
Contracts::<Self::T>::deposit_event(Event::ContractEmitted {
contract: T::AddressMapper::to_address(self.account_id()),
data,
topics,
Event::ContractEmitted {
contract: T::AddressMapper::to_address(self.account_id()),
data,
},
);
});
}

fn block_number(&self) -> U256 {
Expand Down
11 changes: 3 additions & 8 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ pub mod pallet {
/// Data supplied by the contract. Metadata generated during contract compilation
/// is needed to decode it.
data: Vec<u8>,
/// A list of topics used to index the event.
/// Number of topics is capped by [`limits::NUM_EVENT_TOPICS`].
topics: Vec<H256>,
},

/// A code with the specified hash was removed.
Expand Down Expand Up @@ -1186,14 +1189,6 @@ where
fn deposit_event(event: Event<T>) {
<frame_system::Pallet<T>>::deposit_event(<T as Config>::RuntimeEvent::from(event))
}

/// Deposit a pallet contracts indexed event.
fn deposit_indexed_event(topics: Vec<H256>, event: Event<T>) {
<frame_system::Pallet<T>>::deposit_event_indexed(
&topics.into_iter().map(Into::into).collect::<Vec<_>>(),
<T as Config>::RuntimeEvent::from(event).into(),
)
}
}

// Set up a global reference to the boolean flag used for the re-entrancy guard.
Expand Down
5 changes: 3 additions & 2 deletions substrate/frame/revive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,10 @@ mod run_tests {
phase: Phase::Initialization,
event: RuntimeEvent::Contracts(crate::Event::ContractEmitted {
contract: addr,
data: vec![1, 2, 3, 4]
data: vec![1, 2, 3, 4],
topics: vec![H256::repeat_byte(42)],
}),
topics: vec![H256::repeat_byte(42)],
topics: vec![],
},
EventRecord {
phase: Phase::Initialization,
Expand Down

0 comments on commit f3f377f

Please sign in to comment.