Skip to content

Commit

Permalink
fix: minor fixes (#85)
Browse files Browse the repository at this point in the history
* bug: incorrect next proposal id

* refactor: rename data to results in paginated endpoints
  • Loading branch information
mateuszjasiuk authored Jul 24, 2024
1 parent d72152c commit ff40594
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
8 changes: 8 additions & 0 deletions chain/src/services/namada.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ pub async fn query_next_governance_id(
client: &HttpClient,
block_height: BlockHeight,
) -> anyhow::Result<u64> {
// For block_height 0 the next id is always 0
if block_height == 0 {
return Ok(0);
}
// For all other block heights we need to subtract 1
// as namada already saved current block and bumped next proposal id
let block_height = block_height - 1;

let proposal_counter_key =
namada_sdk::governance::storage::keys::get_counter_key();
let block_height = to_block_height(block_height);
Expand Down
3 changes: 1 addition & 2 deletions shared/src/ser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use serde::{Deserialize, Serialize};

use std::collections::{BTreeMap, HashMap};
use std::str::FromStr;

Expand All @@ -9,6 +7,7 @@ use namada_sdk::token::{
Account as NamadaAccount, DenominatedAmount as NamadaDenominatedAmount,
Transfer as NamadaTransfer,
};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone)]
pub struct AccountsMap(pub BTreeMap<NamadaAccount, NamadaDenominatedAmount>);
Expand Down
2 changes: 1 addition & 1 deletion swagger-codegen.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"npmName": "@anomaorg/namada-indexer-client",
"npmVersion": "0.0.19"
"npmVersion": "0.0.20"
}

36 changes: 19 additions & 17 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ paths:
application/json:
schema:
type: object
required: [data, pagination]
required: [results, pagination]
properties:
data:
results:
type: array
items:
$ref: '#/components/schemas/Validator'
Expand Down Expand Up @@ -108,9 +108,9 @@ paths:
application/json:
schema:
type: object
required: [data, pagination]
required: [results, pagination]
properties:
data:
results:
type: array
items:
$ref: '#/components/schemas/Bond'
Expand Down Expand Up @@ -139,9 +139,9 @@ paths:
application/json:
schema:
type: object
required: [data, pagination]
required: [results, pagination]
properties:
data:
results:
type: array
items:
$ref: '#/components/schemas/MergedBond'
Expand Down Expand Up @@ -170,9 +170,9 @@ paths:
application/json:
schema:
type: object
required: [data, pagination]
required: [results, pagination]
properties:
data:
results:
type: array
items:
$ref: '#/components/schemas/Unbond'
Expand Down Expand Up @@ -201,9 +201,9 @@ paths:
application/json:
schema:
type: object
required: [data, pagination]
required: [results, pagination]
properties:
data:
results:
type: array
items:
$ref: '#/components/schemas/Unbond'
Expand Down Expand Up @@ -237,9 +237,9 @@ paths:
application/json:
schema:
type: object
required: [data, pagination]
required: [results, pagination]
properties:
data:
results:
type: array
items:
$ref: '#/components/schemas/Withdraw'
Expand Down Expand Up @@ -289,9 +289,9 @@ paths:
application/json:
schema:
type: object
required: [data, pagination]
required: [results, pagination]
properties:
data:
results:
type: array
items:
$ref: '#/components/schemas/Proposal'
Expand Down Expand Up @@ -363,9 +363,9 @@ paths:
application/json:
schema:
type: object
required: [data, pagination]
required: [results, pagination]
properties:
data:
results:
type: array
items:
$ref: '#/components/schemas/Vote'
Expand Down Expand Up @@ -604,7 +604,7 @@ components:
enum: [consensus, belowCapacity, belowThreshold, inactive, jailed, unknown]
Proposal:
type: object
required: [id, content, type, author, startEpoch, endEpoch, activationEpoch, startTime, endTime, currentTime, status, yayVotes, nayVotes, abstainVotes, tallyType]
required: [id, content, type, author, startEpoch, endEpoch, activationEpoch, startTime, endTime, currentTime, activationTime, status, yayVotes, nayVotes, abstainVotes, tallyType]
properties:
id:
type: string
Expand Down Expand Up @@ -632,6 +632,8 @@ components:
type: string
currentTime:
type: string
activationTime:
type: string
status:
type: string
enum: [pending, voting, passed, rejected]
Expand Down
11 changes: 11 additions & 0 deletions webserver/src/response/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub struct Proposal {
pub start_time: String,
pub end_time: String,
pub current_time: String,
pub activation_time: String,
pub status: ProposalStatus,
pub yay_votes: String,
pub nay_votes: String,
Expand Down Expand Up @@ -140,9 +141,18 @@ impl Proposal {
min_duration,
);

let to_activation = time_between_epochs(
min_num_of_blocks,
epoch_progress,
chain_state.last_processed_epoch,
value.activation_epoch,
min_duration,
);

let time_now = chain_state.timestamp.and_utc().timestamp();
let start_time = time_now + i64::from(to_start);
let end_time = time_now + i64::from(to_end);
let activation_time = time_now + i64::from(to_activation);

Self {
id: value.id.to_string(),
Expand Down Expand Up @@ -179,6 +189,7 @@ impl Proposal {
start_time: start_time.to_string(),
end_time: end_time.to_string(),
current_time: time_now.to_string(),
activation_time: activation_time.to_string(),

status: match value.result {
GovernanceProposalResultDb::Passed => ProposalStatus::Passed,
Expand Down
11 changes: 8 additions & 3 deletions webserver/src/response/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::constant::ITEM_PER_PAGE;

#[derive(Clone, Debug, Serialize)]
pub struct PaginatedResponse<T: Serialize> {
pub data: T,
pub results: T,
pub pagination: Pagination,
}

Expand All @@ -22,9 +22,14 @@ impl<T> PaginatedResponse<T>
where
T: Serialize,
{
pub fn new(data: T, page: u64, total_pages: u64, total_items: u64) -> Self {
pub fn new(
results: T,
page: u64,
total_pages: u64,
total_items: u64,
) -> Self {
Self {
data,
results,
pagination: Pagination {
page,
per_page: ITEM_PER_PAGE,
Expand Down

0 comments on commit ff40594

Please sign in to comment.