Skip to content

Commit

Permalink
feat: remove path parameter from gas endpoint + prepare gas limits fo…
Browse files Browse the repository at this point in the history
…r 0.45.1 (#140)

* feat: remove path parameter from gas endpoint

* feat: gas limits for 0.45.1
  • Loading branch information
mateuszjasiuk authored Nov 12, 2024
1 parent 9ba6ea9 commit a62af3d
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 68 deletions.
5 changes: 3 additions & 2 deletions chain/src/repository/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ mod tests {
let token = Token::Native(Id::Account(
"tnam1q87wtaqqtlwkw927gaff34hgda36huk0kgry692a".to_string(),
));
let fake_balances =
(0..10000).map(|_| Balance::fake_with_token(token.clone())).collect::<Vec<_>>();
let fake_balances = (0..10000)
.map(|_| Balance::fake_with_token(token.clone()))
.collect::<Vec<_>>();

seed_tokens_from_balance(conn, fake_balances.clone())?;

Expand Down
71 changes: 35 additions & 36 deletions orm/migrations/2024-06-12-140948_gas/up.sql
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
CREATE TABLE gas (
id SERIAL PRIMARY KEY,
tx_kind TRANSACTION_KIND NOT NULL,
token VARCHAR NOT NULL,
gas_limit INT NOT NULL
);

ALTER TABLE gas ADD UNIQUE (tx_kind, token);
ALTER TABLE gas ADD UNIQUE (tx_kind);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('transparent_transfer', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('transparent_transfer', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('shielded_transfer', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('shielded_transfer', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('shielding_transfer', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('shielding_transfer', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('unshielding_transfer', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('unshielding_transfer', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('bond', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('bond', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('redelegation', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('redelegation', 250_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('unbond', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('unbond', 150_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('withdraw', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('withdraw', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('claim_rewards', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('claim_rewards', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('vote_proposal', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('vote_proposal', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('init_proposal', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('init_proposal', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('change_metadata', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('change_metadata', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('change_commission', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('change_commission', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('reveal_pk', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('reveal_pk', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('become_validator', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('become_validator', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('ibc_msg_transfer', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('ibc_msg_transfer', 50_000);

INSERT INTO gas (tx_kind, token, gas_limit)
VALUES ('unknown', 'native', 250_000);
INSERT INTO gas (tx_kind, gas_limit)
VALUES ('unknown', 50_000);
1 change: 0 additions & 1 deletion orm/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::transactions::TransactionKindDb;
#[diesel(table_name = gas)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct GasDb {
pub token: String,
pub tx_kind: TransactionKindDb,
pub gas_limit: i32,
}
Expand Down
1 change: 0 additions & 1 deletion orm/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ diesel::table! {
gas (id) {
id -> Int4,
tx_kind -> TransactionKind,
token -> Varchar,
gas_limit -> Int4,
}
}
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": "@namada/indexer-client",
"npmVersion": "0.0.28"
"npmVersion": "0.0.29"
}

11 changes: 2 additions & 9 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,9 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/RevealedPk'
/api/v1/gas/{token}:
/api/v1/gas:
get:
parameters:
- in: path
name: token
schema:
type: string
required: true
description: The gas token. For native token use `native`.
summary: Get the gas limit per tx kind per token. Native token gas can be queried by using `native` as {token} parameter
summary: Get the gas limit per tx kind.
responses:
'200':
description: Gas limit table
Expand Down
2 changes: 1 addition & 1 deletion webserver/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl ApplicationServer {
"/revealed-public-key/:address",
get(pk_handlers::get_revealed_pk),
)
.route("/gas/:token", get(gas_handlers::get_gas_by_token))
.route("/gas", get(gas_handlers::get_gas))
.route(
"/gas-price/:token",
get(gas_handlers::get_gas_price_by_token),
Expand Down
5 changes: 2 additions & 3 deletions webserver/src/handler/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ use crate::response::gas::{Gas, GasPrice};
use crate::state::common::CommonState;

#[debug_handler]
pub async fn get_gas_by_token(
pub async fn get_gas(
_headers: HeaderMap,
Path(token): Path<String>,
State(state): State<CommonState>,
) -> Result<Json<Vec<Gas>>, ApiError> {
let gas = state.gas_service.get_gas_by_token(token).await;
let gas = state.gas_service.get_gas().await;

Ok(Json(gas))
}
Expand Down
15 changes: 3 additions & 12 deletions webserver/src/repository/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ pub struct GasRepository {
pub trait GasRepositoryTrait {
fn new(app_state: AppState) -> Self;

async fn find_gas_by_token(
&self,
token: String,
) -> Result<Vec<GasDb>, String>;
async fn get_gas(&self) -> Result<Vec<GasDb>, String>;

async fn find_gas_price_by_token(
&self,
Expand All @@ -31,17 +28,11 @@ impl GasRepositoryTrait for GasRepository {
Self { app_state }
}

async fn find_gas_by_token(
&self,
token: String,
) -> Result<Vec<GasDb>, String> {
async fn get_gas(&self) -> Result<Vec<GasDb>, String> {
let conn = self.app_state.get_db_connection().await;

conn.interact(move |conn| {
gas::table
.filter(gas::dsl::token.eq(token))
.select(GasDb::as_select())
.get_results(conn)
gas::table.select(GasDb::as_select()).get_results(conn)
})
.await
.map_err(|e| e.to_string())?
Expand Down
4 changes: 2 additions & 2 deletions webserver/src/service/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ impl GasService {
}
}

pub async fn get_gas_by_token(&self, token: String) -> Vec<Gas> {
pub async fn get_gas(&self) -> Vec<Gas> {
self.gas_repo
.find_gas_by_token(token)
.get_gas()
.await
.unwrap_or_default()
.into_iter()
Expand Down

0 comments on commit a62af3d

Please sign in to comment.