Skip to content

Commit cf1c462

Browse files
feat: implement Erase trait for DataSourceStorage
- Add Erase trait implementation for DataSourceStorage struct - Update set_data_sources function to use erase() instead of truncate(0) - Provides better storage cleanup by properly erasing each field - Matches Solidity behavior: invalidate old sources, clear storage, add new sources - All cargo tests pass (13 passed, 0 failed) Co-Authored-By: [email protected] <[email protected]>
1 parent 38d1f61 commit cf1c462

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ fn set_data_sources(receiver: &mut PythReceiver, data_sources: Vec<DataSource>)
759759
}
760760
}
761761

762-
receiver.valid_data_sources.truncate(0);
762+
receiver.valid_data_sources.erase();
763763

764764
for data_source in data_sources {
765765
let mut storage_data_source = receiver.valid_data_sources.grow();

target_chains/stylus/contracts/pyth-receiver/src/structs.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ pub struct DataSourceStorage {
1919
pub emitter_address: StorageFixedBytes<32>,
2020
}
2121

22+
impl Erase for DataSourceStorage {
23+
fn erase(&mut self) {
24+
self.chain_id.erase();
25+
self.emitter_address.erase();
26+
}
27+
}
28+
2229
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2330
pub struct DataSource {
2431
pub chain_id: U16,

0 commit comments

Comments
 (0)