Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
feat: improvements api (#45)
Browse files Browse the repository at this point in the history
closes #37

This PR had the tx_type info to the block answer and add wrapper_id info
for decrypted tx.

---------

Co-authored-by: neithanmo <[email protected]>
  • Loading branch information
rllola and neithanmo authored Oct 31, 2023
1 parent 17d1d93 commit 555d675
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ impl Database {
/// Returns all the tx hashes for a block
pub async fn get_tx_hashes_block(&self, hash: &[u8]) -> Result<Vec<Row>, Error> {
// query for all tx hash that are in a block identified by the block_id
let str = format!("SELECT t.hash FROM {0}.{BLOCKS_TABLE_NAME} b JOIN {0}.{TX_TABLE_NAME} t ON b.block_id = t.block_id WHERE b.block_id =$1;", self.network);
let str = format!("SELECT t.hash, t.tx_type FROM {0}.{BLOCKS_TABLE_NAME} b JOIN {0}.{TX_TABLE_NAME} t ON b.block_id = t.block_id WHERE b.block_id = $1;", self.network);

query(&str)
.bind(hash)
Expand Down
8 changes: 7 additions & 1 deletion src/server/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ pub struct HashID(
#[serde(serialize_with = "serialize_hex", deserialize_with = "from_hex")] pub Vec<u8>,
);

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct TxShort {
pub tx_type: String,
pub hash_id: HashID,
}

/// Relevant information regarding blocks
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct BlockInfo {
pub block_id: HashID,
pub header: Header,
pub last_commit: Option<LastCommitInfo>,
pub tx_hashes: Vec<HashID>,
pub tx_hashes: Vec<TxShort>,
}

impl From<BlockInfo> for Header {
Expand Down
10 changes: 6 additions & 4 deletions src/server/endpoints/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sqlx::Row as TRow;
use tracing::info;

use crate::{
server::{blocks::HashID, ServerState},
server::{blocks::HashID, blocks::TxShort, ServerState},
BlockInfo, Error,
};

Expand All @@ -17,10 +17,12 @@ async fn get_tx_hashes(
) -> Result<(), Error> {
let rows = state.db.get_tx_hashes_block(hash).await?;

let mut tx_hashes: Vec<HashID> = vec![];
let mut tx_hashes: Vec<TxShort> = vec![];
for row in rows.iter() {
let hash = HashID(row.try_get("hash")?);
tx_hashes.push(hash);
println!("GET_TX_HASHES_ {:?}", row.columns());
let hash_id = HashID(row.try_get("hash")?);
let tx_type: String = row.try_get("tx_type")?;
tx_hashes.push(TxShort { tx_type, hash_id });
}

block.tx_hashes = tx_hashes;
Expand Down
7 changes: 6 additions & 1 deletion src/server/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use sqlx::Row as TRow;
// represents the number of columns
// that db must contains in order to deserialized
// transactions
const NUM_TX_COLUMNS: usize = 8;
const NUM_TX_COLUMNS: usize = 9;

// namada::ibc::applications::transfer::msgs::transfer::TYPE_URL has been made private and can't be access anymore
const MSG_TRANSFER_TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer";
Expand Down Expand Up @@ -75,6 +75,9 @@ pub struct TxInfo {
block_id: Vec<u8>,
/// The transaction type encoded as a string
tx_type: String,
/// id for the wrapper tx if the tx is decrypted. otherwise it is null.
#[serde(with = "hex::serde")]
wrapper_id: Vec<u8>,
/// The transaction fee only for tx_type Wrapper (otherwise empty)
fee_amount_per_gas_unit: String,
fee_token: String,
Expand Down Expand Up @@ -187,6 +190,7 @@ impl TryFrom<Row> for TxInfo {
let hash: Vec<u8> = row.try_get("hash")?;
let block_id: Vec<u8> = row.try_get("block_id")?;
let tx_type: String = row.try_get("tx_type")?;
let wrapper_id: Vec<u8> = row.try_get("wrapper_id")?;
let fee_amount_per_gas_unit = row.try_get("fee_amount_per_gas_unit")?;
let fee_token = row.try_get("fee_token")?;
let gas_limit_multiplier = row.try_get("gas_limit_multiplier")?;
Expand All @@ -197,6 +201,7 @@ impl TryFrom<Row> for TxInfo {
hash,
block_id,
tx_type,
wrapper_id,
fee_amount_per_gas_unit,
fee_token,
gas_limit_multiplier,
Expand Down

0 comments on commit 555d675

Please sign in to comment.