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

[pallet-revive] move event topics in event's body #5640

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
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`].
pgherveou marked this conversation as resolved.
Show resolved Hide resolved
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
Loading