Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gitofdeepanshu committed Aug 11, 2023
1 parent a34e00d commit 75c6db4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
9 changes: 2 additions & 7 deletions precompiles/utils/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,7 @@ impl<K: Kind, S: Get<u32>> EvmData for BoundedBytesString<K, S> {
return Err(revert("length, value too large").into());
}

// Get valid range over the bytes data.
let range = inner_reader.move_cursor(array_size)?;

let data = inner_reader
.get_input_from_range(range)
.ok_or_else(|| revert(K::signature()))?;
let data = inner_reader.read_raw_bytes(array_size)?;

let bytes = Self {
data: data.to_owned(),
Expand Down Expand Up @@ -140,7 +135,7 @@ impl<K: Kind, S: Get<u32>> EvmData for BoundedBytesString<K, S> {
writer.write_pointer(
EvmDataWriter::new()
.write(U256::from(length))
.write_raw_bytes(&value)
.write(value)
.build(),
);
}
Expand Down
8 changes: 2 additions & 6 deletions precompiles/utils/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,11 @@ impl<'a> EvmDataReader<'a> {
Ok(data)
}

/// Return Option<&[u8]> from a given range for EvmDataReader
pub fn get_input_from_range(&self, range: Range<usize>) -> Option<&[u8]> {
self.input.get(range)
}

/// Move the reading cursor with provided length, and return a range from the previous cursor
/// location to the new one.
/// Checks cursor overflows.
pub fn move_cursor(&mut self, len: usize) -> EvmResult<Range<usize>> {
fn move_cursor(&mut self, len: usize) -> EvmResult<Range<usize>> {
let start = self.cursor;
let end = self
.cursor
Expand Down Expand Up @@ -290,7 +286,7 @@ impl EvmDataWriter {

/// Write arbitrary bytes.
/// Doesn't handle any alignement checks, prefer using `write` instead if possible.
pub fn write_raw_bytes(mut self, value: &[u8]) -> Self {
fn write_raw_bytes(mut self, value: &[u8]) -> Self {
self.data.extend_from_slice(value);
self
}
Expand Down

0 comments on commit 75c6db4

Please sign in to comment.