Skip to content

Commit

Permalink
Update comments and remove unnecessary Result wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
jules committed Jan 26, 2022
1 parent c9168ac commit 092fb3a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/network/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl<N: Network, E: Environment> Operator<N, E> {
}

///
/// Returns all registered provers on this operator.
/// Returns a list of all provers which have submitted shares to this operator.
///
pub fn get_provers(&self) -> Vec<Address<N>> {
self.state.get_provers()
Expand Down
8 changes: 4 additions & 4 deletions src/rpc/documentation/public_endpoints/getprovers.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Get Provers
Returns the addresses of all provers that are registered on an operator.
Returns the Aleo addresses of all provers which have submitted shares to an operator.

### Arguments

None

### Response

| Parameter | Type | Description |
|:---------:|:------:|:------------------------------------------:|
| `result` | array | All of the addresses known to the operator |
| Parameter | Type | Description |
|:---------:|:------:|:---------------------------------------------------------------------:|
| `result` | array | All of the Aleo addresses which have submitted shares to the operator |

### Example Request
```ignore
Expand Down
8 changes: 4 additions & 4 deletions src/rpc/documentation/public_endpoints/getshares.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Get Shares
Returns the amount of shares submitted to an operator in total.
Returns the total number of shares submitted to an operator.

### Arguments

None

### Response

| Parameter | Type | Description |
|:---------:|:------:|:-------------------------------------------------------:|
| `result` | u64 | The amount of shares submitted to the operator in total |
| Parameter | Type | Description |
|:---------:|:------:|:----------------------------------------------------:|
| `result` | u64 | The total number of shares submitted to the operator |

### Example Request
```ignore
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/documentation/public_endpoints/getsharesforprover.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Get Shares For Prover
Returns the amount of shares submitted by a prover, given their address.
Returns the number of shares submitted by a prover, given their address.

### Arguments

| Parameter | Type | Required | Description |
|:---------:|:------:|:--------:|:------------------------------:|
| `prover` | string | Yes | The aleo address of the prover |
| `prover` | string | Yes | The Aleo address of the prover |

### Response

| Parameter | Type | Description |
|:---------:|:------:|:--------------------------------------------:|
| `result` | u64 | The amount of shares submitted by the prover |
| `result` | u64 | The number of shares submitted by the prover |

### Example Request
```ignore
Expand Down
8 changes: 4 additions & 4 deletions src/rpc/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,12 @@ async fn handle_rpc<N: Network, E: Environment>(
result_to_response(&req, result)
}
"getshares" => {
let result = rpc.get_shares().await.map_err(convert_crate_err);
result_to_response(&req, result)
let result = rpc.get_shares().await;
result_to_response(&req, Ok(result))
}
"getprovers" => {
let result = rpc.get_provers().await.map_err(convert_crate_err);
result_to_response(&req, result)
let result = rpc.get_provers().await;
result_to_response(&req, Ok(result))
}
_ => {
let err = jrt::Error::from_code(jrt::ErrorCode::MethodNotFound);
Expand Down
16 changes: 6 additions & 10 deletions src/rpc/rpc_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,19 +348,15 @@ impl<N: Network, E: Environment> RpcFunctions<N> for RpcImpl<N, E> {
Ok(self.operator.get_shares_for_prover(&prover))
}

/// Returns the amount of shares submitted to an operator in total.
async fn get_shares(&self) -> Result<u64, RpcError> {
/// Returns the amount of shares submitted to the operator in total.
async fn get_shares(&self) -> u64 {
let shares = self.operator.to_shares();
let mut res = 0;
for (_, share) in shares {
res += share.values().sum::<u64>();
}
Ok(res)
shares.iter().map(|(_, share)| share.values().sum::<u64>()).sum()
}

/// Returns a list of provers registered on an operator.
async fn get_provers(&self) -> Result<Value, RpcError> {
/// Returns a list of all provers that have submitted shares to the operator.
async fn get_provers(&self) -> Value {
let provers = self.operator.get_provers();
Ok(serde_json::json!(provers))
serde_json::json!(provers)
}
}
4 changes: 2 additions & 2 deletions src/rpc/rpc_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ pub trait RpcFunctions<N: Network> {
async fn get_shares_for_prover(&self, prover: serde_json::Value) -> Result<u64, RpcError>;

#[doc = include_str!("./documentation/public_endpoints/getshares.md")]
async fn get_shares(&self) -> Result<u64, RpcError>;
async fn get_shares(&self) -> u64;

#[doc = include_str!("./documentation/public_endpoints/getprovers.md")]
async fn get_provers(&self) -> Result<serde_json::Value, RpcError>;
async fn get_provers(&self) -> serde_json::Value;
}

// /// Definition of private RPC endpoints that require authentication.
Expand Down
2 changes: 1 addition & 1 deletion storage/src/state/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<N: Network> OperatorState<N> {
self.shares.remove_shares(block_height, coinbase_record)
}

/// Returns a list of provers registered on an operator.
/// Returns a list of provers which have submitted shares to an operator.
pub fn get_provers(&self) -> Vec<Address<N>> {
self.shares.get_provers()
}
Expand Down

0 comments on commit 092fb3a

Please sign in to comment.