Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

add wallet balance endpoint #56

Merged
merged 11 commits into from
Feb 12, 2024
Merged

Conversation

tsachiherman
Copy link
Contributor

@tsachiherman tsachiherman commented Feb 5, 2024

What ?

This PR adds the balance endpoint for the xps-gateway.

Implementation

Quite straight-forward; just query the provider for the wallet balance.

Closes

Closes #23.

Open question

While this implementation would work just fine, it might be adventitious to change the

pub struct WalletBalance {
    /// The balance for the wallet; formatted as "5.32 ETH"
    #[serde(rename = "balance")]
    pub balance: String,
    /// The unit used for the balance; formatted as "ETH"
    #[serde(rename = "unit")]
    pub unit: String,
}

into something like this:

pub struct WalletBalance {
    /// The balance for the wallet; just the number itself.
    #[serde(rename = "balance")]
    pub balance: U256,
    /// The unit used for the balance; formatted as "ETH"
    #[serde(rename = "unit")]
    pub unit: String,
    /// The balance, formatted for display ; formatted as "5.32 ETH"
    #[serde(rename = "display_balance")]
    pub display_balance: String,
}

This would allow us to make the RPC more friendly for code-oriented users while retaining the user-facing formatter.

@tsachiherman tsachiherman self-assigned this Feb 5, 2024
@tsachiherman tsachiherman linked an issue Feb 5, 2024 that may be closed by this pull request
Copy link

codecov bot commented Feb 5, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (470c257) 89.85% compared to head (0a79650) 91.16%.

Files Patch % Lines
xps-gateway/src/rpc/methods.rs 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #56      +/-   ##
==========================================
+ Coverage   89.85%   91.16%   +1.31%     
==========================================
  Files          12       12              
  Lines         355      419      +64     
==========================================
+ Hits          319      382      +63     
- Misses         36       37       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tsachiherman tsachiherman requested a review from insipx February 5, 2024 17:59
@tsachiherman tsachiherman marked this pull request as ready for review February 5, 2024 17:59
@insipx
Copy link
Contributor

insipx commented Feb 6, 2024

I think the more idiomatic way would be doing something like this:

pub struct WalletBalance {
    /// The balance for the wallet; just the number itself.
    #[serde(rename = "balance")]
    pub balance: U256,
    /// The unit used for the balance; formatted as "ETH"
    #[serde(rename = "unit")]
    pub unit: String,
}

with a custom display implementation:

impl Display for WalletBalance {
// ...
}

I would also be in favor of turning unit into an enum,

pub struct Unit {
    Eth,
    Other(String),
}

Since we are mostly going to be using Eth, and down the line we can add other chains we use

@insipx
Copy link
Contributor

insipx commented Feb 8, 2024

just a small nit, if we unwrap in a method used by the RPC our server will go down

Otherwise looking good! Ready to approve after that is turned into an error

Copy link
Contributor

@jac18281828 jac18281828 left a comment

Choose a reason for hiding this comment

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

This looks like a good start. Make sure to address those codecov warnings about lack of tests.

@jac18281828 jac18281828 self-requested a review February 9, 2024 20:37
@tsachiherman tsachiherman requested a review from insipx February 12, 2024 13:18
@tsachiherman tsachiherman merged commit d2393a7 into xmtp:main Feb 12, 2024
5 checks passed
@tsachiherman tsachiherman deleted the tsachi/balance branch February 12, 2024 14:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

JSON RPC Endpoint: balance
3 participants