Skip to content

feat: obolapi #125

Merged
iamquang95 merged 9 commits into
mainfrom
iamquang95/obolapi
Jan 21, 2026
Merged

feat: obolapi #125
iamquang95 merged 9 commits into
mainfrom
iamquang95/obolapi

Conversation

@iamquang95
Copy link
Copy Markdown
Collaborator

Should fix: #124

Copy link
Copy Markdown
Collaborator

@emlautarom1 emlautarom1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/charon/src/obolapi/test_api.rs Outdated
Comment thread crates/charon/src/obolapi/test_api.rs Outdated
Comment thread crates/charon/src/obolapi/client.rs
Comment thread crates/charon/src/obolapi/client.rs Outdated
Comment thread crates/charon/src/obolapi/client.rs Outdated
Comment thread crates/charon/src/obolapi/helper.rs Outdated
@@ -0,0 +1,78 @@
//! Serialization helpers for hex encoding/decoding with 0x prefix.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

@emlautarom1 emlautarom1 Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue is being tracked here: #127

Comment thread crates/charon/src/obolapi/exit.rs
Comment thread crates/charon/src/obolapi/exit.rs Outdated
Comment thread crates/charon/src/obolapi/exit.rs Outdated
Comment thread crates/charon/src/obolapi/exit.rs Outdated
@iamquang95
Copy link
Copy Markdown
Collaborator Author

Also create a research ticket to see if we can replace our ssz implementation with some existing crates: #128

@iamquang95 iamquang95 merged commit ad4f045 into main Jan 21, 2026
7 checks passed
@iamquang95 iamquang95 deleted the iamquang95/obolapi branch January 21, 2026 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement obolapi

2 participants