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

add memo and tx type indexing #97

Closed
wants to merge 9 commits into from
17 changes: 15 additions & 2 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,10 @@ impl Database {
fee_amount_per_gas_unit,
fee_token,
gas_limit_multiplier,
code_type,
code,
data,
memo,
return_code
)",
network
Expand All @@ -599,7 +601,9 @@ impl Database {
for t in txs.iter() {
let tx = Tx::try_from(t.as_slice()).map_err(|_| Error::InvalidTxData)?;

let mut code = Default::default();
let mut code: [u8; 32] = Default::default();
let mut code_type: String = "wrapper".to_string();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is redundant with tx_type which already exist in the table. You want to indicate if the tx is decrypted or wrapper... etc, right ?

Copy link
Contributor Author

@dimiandre dimiandre Feb 7, 2024

Choose a reason for hiding this comment

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

I'd like to indicate what that decrypted tx actually contains

tx_transfer
tx_ibc
etc

otherwise there is no easy way to "decode" code and query it directly from the database

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok. We use the code to indicate the tx_type but indeed you need to know it.
So just change the default value wrapper with unknown. Wrapper is another type (decrypted, wrapper, protocol,...) and it is different from what you want (aka tx_transfer, tx_ibc, ...). Just so we don't get mixed up.


let mut txid_wrapper: Vec<u8> = vec![];

let mut hash_id = tx.header_hash().to_vec();
Expand Down Expand Up @@ -633,7 +637,7 @@ impl Database {
}

// look for wrapper tx to link to
let txs = query(&format!("SELECT * FROM {0}.transactions WHERE block_id IN (SELECT block_id FROM {0}.blocks WHERE header_height = {1});", network, block_height-1))
let txs: Vec<Row> = query(&format!("SELECT * FROM {0}.transactions WHERE block_id IN (SELECT block_id FROM {0}.blocks WHERE header_height = {1});", network, block_height-1))
.fetch_all(&mut *sqlx_tx)
.await?;
txid_wrapper = txs[i].try_get("hash")?;
Expand All @@ -649,6 +653,8 @@ impl Database {

let unknown_type = "unknown".to_string();
let type_tx = checksums_map.get(&code_hex).unwrap_or(&unknown_type);
code_type = type_tx.to_string();

let data = tx.data().ok_or(Error::InvalidTxData)?;

info!("Saving {} transaction", type_tx);
Expand Down Expand Up @@ -892,6 +898,7 @@ impl Database {
// values only set if transaction type is Wrapper
let mut fee_amount_per_gas_unit: Option<String> = None;
let mut fee_token: Option<String> = None;

let mut gas_limit_multiplier: Option<i64> = None;
if let TxType::Wrapper(txw) = tx.header().tx_type {
fee_amount_per_gas_unit = Some(txw.fee.amount_per_gas_unit.to_string_precise());
Expand All @@ -910,8 +917,10 @@ impl Database {
fee_amount_per_gas_unit,
fee_token,
gas_limit_multiplier,
code_type,
code,
tx.data().map(|v| v.to_vec()),
tx.memo().map(|v| v.to_vec()),
return_code,
));
}
Expand All @@ -934,8 +943,10 @@ impl Database {
fee_amount_per_gas_unit,
fee_token,
fee_gas_limit_multiplier,
code_type,
code,
data,
memo,
return_code,
)| {
b.push_bind(hash)
Expand All @@ -945,8 +956,10 @@ impl Database {
.push_bind(fee_amount_per_gas_unit)
.push_bind(fee_token)
.push_bind(fee_gas_limit_multiplier)
.push_bind(code_type)
.push_bind(code)
.push_bind(data)
.push_bind(memo)
.push_bind(return_code);
},
)
Expand Down
2 changes: 2 additions & 0 deletions src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ pub fn get_create_transactions_table_query(network: &str) -> String {
fee_amount_per_gas_unit TEXT,
fee_token TEXT,
gas_limit_multiplier BIGINT,
code_type TEXT,
code BYTEA,
data BYTEA,
memo BYTEA,
return_code INTEGER
);",
network
Expand Down
Loading