Skip to content

Commit

Permalink
Scarb fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
b-j-roberts committed Mar 11, 2024
1 parent 63dd245 commit 6fec8ea
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
23 changes: 12 additions & 11 deletions src/bytes/src/bytes.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,18 @@ impl BytesImpl of BytesTrait {
fn to_byte_array(self: Bytes) -> ByteArray {
let mut res: ByteArray = Default::default();
let mut offset = 0;
while offset < self.size() {
if offset + 31 <= self.size() {
let (new_offset, value) = self.read_bytes31(offset);
res.append_word(value.into(), 31);
offset = new_offset;
} else {
let (new_offset, value) = self.read_u8(offset);
res.append_byte(value);
offset = new_offset;
}
};
while offset < self
.size() {
if offset + 31 <= self.size() {
let (new_offset, value) = self.read_bytes31(offset);
res.append_word(value.into(), 31);
offset = new_offset;
} else {
let (new_offset, value) = self.read_u8(offset);
res.append_byte(value);
offset = new_offset;
}
};
res
}

Expand Down
34 changes: 18 additions & 16 deletions src/bytes/src/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ impl BytesDebug of Debug<Bytes> {
let prefix: ByteArray = "0x";
Display::fmt(@prefix, ref f)?;
let mut res: Result<(), Error> = Result::Ok(());
while i < self.size() {
let (new_i, value) = self.read_u8(i);
res = format_byte_hex(value, ref f);
if res.is_err() {
break;
}
i = new_i;
};
while i < self
.size() {
let (new_i, value) = self.read_u8(i);
res = format_byte_hex(value, ref f);
if res.is_err() {
break;
}
i = new_i;
};
res
}
}
Expand All @@ -39,14 +40,15 @@ impl BytesDisplay of Display<Bytes> {
let prefix: ByteArray = "0x";
Display::fmt(@prefix, ref f)?;
let mut res: Result<(), Error> = Result::Ok(());
while i < self.size() {
let (new_i, value) = self.read_u8(i);
res = format_byte_hex(value, ref f);
if res.is_err() {
break;
}
i = new_i;
};
while i < self
.size() {
let (new_i, value) = self.read_u8(i);
res = format_byte_hex(value, ref f);
if res.is_err() {
break;
}
i = new_i;
};
res
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/encoding/src/tests/sol_abi.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ fn compare_bytes(actual: @Bytes, expected: @Bytes) -> bool {
return false;
}
let mut i: usize = 0;
while i < actual.size() {
let (_, actual_val) = actual.read_u8(i);
let (_, expected_val) = expected.read_u8(i);
if actual_val != expected_val {
break;
}
i += 1;
};
while i < actual
.size() {
let (_, actual_val) = actual.read_u8(i);
let (_, expected_val) = expected.read_u8(i);
if actual_val != expected_val {
break;
}
i += 1;
};
if i < actual.size() {
return false;
}
Expand Down

0 comments on commit 6fec8ea

Please sign in to comment.