feat: obolapi #125
Conversation
emlautarom1
left a comment
There was a problem hiding this comment.
A few small things in particular regarding code reuse: we have multiple places where we're dealing with SSZ and it would be nice for them to be consistent, otherwise we end up with duplicated code and no reuse.
Some tests are not needed/are duplicates, so I would double check and remove them. The Go implementation has some HTTP tests (app/obolapi/api_internal_test.go) which are not particularly interesting so no need to port them.
| @@ -0,0 +1,78 @@ | |||
| //! Serialization helpers for hex encoding/decoding with 0x prefix. | |||
There was a problem hiding this comment.
At this point it would be nice to have a module (maybe in charon-core) with all of these utilities defined. Otherwise, each module ends up reimplementing functionality and there is little reuse.
There was a problem hiding this comment.
Since the error for each crate is different
For example:
pub fn from_0x(data: &str, expected_len: usize) -> Result<Vec<u8>> {
if data.is_empty() {
return Err(Error::EmptyHex);
}
Ok(charon_cluster::helpers::from_0x_hex_str(
data,
expected_len,
)?)
}
Where we have the quite same implementation in charon_cluster, but this accept the empty hex.
pub fn from_0x_hex_str(s: &str, len: usize) -> Result<Vec<u8>, hex::FromHexError> {
if s.is_empty() {
return Ok(vec![]);
}
let s = s.strip_prefix("0x").unwrap_or(s);
let bytes = hex::decode(s)?;
if bytes.len() != len {
return Err(hex::FromHexError::InvalidStringLength);
}
Ok(bytes)
}
I try to reuse the main logic of implementation, but for error handling, there will be different for each crates.
There was a problem hiding this comment.
Makes sense. We should still revisit this in the future with a standalone module with its own error types.
@iamquang95 Could you please create a ticket about this? Also, include references to possible duplicate functions.
|
Also create a research ticket to see if we can replace our ssz implementation with some existing crates: #128 |
Should fix: #124