Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement JSON-RPC method queryStakes #2437

Merged
merged 2 commits into from
Mar 21, 2024

Conversation

Tommytrg
Copy link
Member

@Tommytrg Tommytrg commented Feb 29, 2024

Implement JSON-RPC and CLI methods that allow querying the stakes of the specified address/addresses argument.
The argument can contain:

  • A validator and a withdrawer
  • A validator
  • A withdrawer
  • Empty argument, uses the node's address as validator.

close #2424
close #2423

@Tommytrg Tommytrg changed the base branch from master to 2.0-master February 29, 2024 16:44
@Tommytrg Tommytrg marked this pull request as draft February 29, 2024 16:44
@Tommytrg Tommytrg force-pushed the feat/2.0/jsonrpc/query-stakes branch 6 times, most recently from 8aa111e to 694acaf Compare March 7, 2024 15:00
@Tommytrg Tommytrg marked this pull request as ready for review March 8, 2024 10:28
@Tommytrg Tommytrg force-pushed the feat/2.0/jsonrpc/query-stakes branch from 694acaf to bdc5fe7 Compare March 8, 2024 11:22
Comment on lines 2119 to 2133
match address {
QueryStakesArgument::Validator(k) => QueryStakesParams::Validator(
PublicKeyHash::from_bech32(get_environment(), &k).map_err(internal_error)?,
),
QueryStakesArgument::Withdrawer(k) => QueryStakesParams::Withdrawer(
PublicKeyHash::from_bech32(get_environment(), &k).map_err(internal_error)?,
),
QueryStakesArgument::Key((v, w)) => QueryStakesParams::Key((
PublicKeyHash::from_bech32(get_environment(), &v).map_err(internal_error)?,
PublicKeyHash::from_bech32(get_environment(), &w).map_err(internal_error)?,
)),
}
Copy link
Member

Choose a reason for hiding this comment

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

I can imagine that you can remove all the map_err in each branch, and rather have it once in line 2130.

Copy link
Member Author

Choose a reason for hiding this comment

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

Something like the following?

        match address {
            QueryStakesArgument::Validator(validator) => QueryStakesParams::Validator(
                PublicKeyHash::from_bech32(get_environment(), &validator)
            ),
            QueryStakesArgument::Withdrawer(withdrawer) => QueryStakesParams::Withdrawer(
                PublicKeyHash::from_bech32(get_environment(), &withdrawer)
            ),
            QueryStakesArgument::Key((validator, withdrawer)) => QueryStakesParams::Key((
                PublicKeyHash::from_bech32(get_environment(), &validator),
                PublicKeyHash::from_bech32(get_environment(), &withdrawer)
            )),
        }.map_err(internal_error)?
error[E0308]: mismatched types
    --> node/src/actors/json_rpc/api.rs:2120:17
     |
2119 |             QueryStakesArgument::Validator(validator) => QueryStakesParams::Validator(
     |                                                          ---------------------------- arguments to this enum variant are incorrect
2120 |                 PublicKeyHash::from_bech32(get_environment(), &validator)
     |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `PublicKeyHash`, found `Result<PublicKeyHash, ...>`
     |
     = note: expected struct `witnet_data_structures::chain::PublicKeyHash`
                  found enum `Result<witnet_data_structures::chain::PublicKeyHash, PublicKeyHashParseError>`
note: tuple variant defined here
    --> node/src/actors/messages.rs:314:5
    
    ```

@Tommytrg Tommytrg force-pushed the feat/2.0/jsonrpc/query-stakes branch 6 times, most recently from 1f25d7a to 977b4e8 Compare March 18, 2024 17:59
This method allows to query the stakes of the specified argument.
The argument can contain:
- A validator and a withdrawer
- A validator
- A withdrawer
- Empty argument, uses the node's address as validator.

The type of the argument is an address as a string.
 Please enter the commit message for your changes. Lines starting
@Tommytrg Tommytrg force-pushed the feat/2.0/jsonrpc/query-stakes branch from 977b4e8 to ef7bf95 Compare March 18, 2024 18:25
@Tommytrg Tommytrg merged commit ef7bf95 into witnet:2.0-master Mar 21, 2024
1 check failed
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.

2 participants