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

Fix: 'Invalid Transaction data' error #130

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "src/bin/indexer.rs"
[dependencies]
getrandom = { version = "0.2" }
async-trait = "0.1.51"
namada_sdk = { git = "https://github.com/anoma/namada", rev = "v0.31.0" }
namada_sdk = { git = "https://github.com/anoma/namada", rev = "v0.31.4" }
rand = { version = "0.8", default-features = false }
rand_core = { version = "0.6", default-features = false }
tokio = { version = "1.26.0", features = ["rt-multi-thread"] }
Expand Down
79 changes: 44 additions & 35 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Database {

/// Inner implementation that uses a postgres-transaction
/// to ensure database coherence.
#[instrument(skip(block, checksums_map, sqlx_tx))]
#[instrument(skip(block, block_results, checksums_map, sqlx_tx))]
async fn save_block_impl<'a>(
block: &Block,
block_results: &block_results::Response,
Expand Down Expand Up @@ -275,7 +275,7 @@ impl Database {
}

/// Save a block and commit database
#[instrument(skip(self, block, checksums_map))]
#[instrument(skip(self, block, block_results, checksums_map))]
pub async fn save_block(
&self,
block: &Block,
Expand Down Expand Up @@ -423,7 +423,7 @@ impl Database {
/// It is up to the caller to commit the operation.
/// this method is meant to be used when caller is saving
/// many blocks, and can commit after it.
#[instrument(skip(block, checksums_map, sqlx_tx, network))]
#[instrument(skip(block, block_results, checksums_map, sqlx_tx, network))]
pub async fn save_block_tx<'a>(
block: &Block,
block_results: &block_results::Response,
Expand Down Expand Up @@ -543,7 +543,7 @@ impl Database {
/// Save all the transactions in txs, it is up to the caller to
/// call sqlx_tx.commit().await?; for the changes to take place in
/// database.
#[instrument(skip(txs, block_id, sqlx_tx, checksums_map, network))]
#[instrument(skip(txs, block_id, sqlx_tx, checksums_map, block_results, network))]
async fn save_transactions<'a>(
txs: &[Vec<u8>],
block_id: &[u8],
Expand Down Expand Up @@ -647,9 +647,18 @@ impl Database {

let code_hex = hex::encode(code.as_slice());

dbg!(hex::encode(&hash_id));
dbg!(hex::encode(&code));
dbg!(&tx.sections[0].data());

let unknown_type = "unknown".to_string();
let type_tx = checksums_map.get(&code_hex).unwrap_or(&unknown_type);
let data = tx.data().ok_or(Error::InvalidTxData)?;
dbg!(&type_tx);
let mut data: Vec<u8> = vec![];
if type_tx != "tx_bridge_pool" {
// "tx_bridge_pool" doesn't have their data in the data section anymore ?
data = tx.data().ok_or(Error::InvalidTxData)?;
}

info!("Saving {} transaction", type_tx);

Expand Down Expand Up @@ -740,36 +749,36 @@ impl Database {
query.execute(&mut *sqlx_tx).await?;
}
// this is an ethereum transaction
"tx_bridge_pool" => {
// Only TransferToEthereum type is supported at the moment by namada and us.
let tx_bridge = PendingTransfer::try_from_slice(&data[..])?;

let mut query_builder: QueryBuilder<_> = QueryBuilder::new(format!(
"INSERT INTO {}.tx_bridge_pool(
tx_id,
asset,
recipient,
sender,
amount,
gas_amount,
payer
)",
network
));

let query = query_builder
.push_values(std::iter::once(0), |mut b, _| {
b.push_bind(&hash_id)
.push_bind(tx_bridge.transfer.asset.to_string())
.push_bind(tx_bridge.transfer.recipient.to_string())
.push_bind(tx_bridge.transfer.sender.to_string())
.push_bind(tx_bridge.transfer.amount.to_string_native())
.push_bind(tx_bridge.gas_fee.amount.to_string_native())
.push_bind(tx_bridge.gas_fee.payer.to_string());
})
.build();
query.execute(&mut *sqlx_tx).await?;
}
// "tx_bridge_pool" => {
// // Only TransferToEthereum type is supported at the moment by namada and us.
// let tx_bridge = PendingTransfer::try_from_slice(&data[..])?;

// let mut query_builder: QueryBuilder<_> = QueryBuilder::new(format!(
// "INSERT INTO {}.tx_bridge_pool(
// tx_id,
// asset,
// recipient,
// sender,
// amount,
// gas_amount,
// payer
// )",
// network
// ));

// let query = query_builder
// .push_values(std::iter::once(0), |mut b, _| {
// b.push_bind(&hash_id)
// .push_bind(tx_bridge.transfer.asset.to_string())
// .push_bind(tx_bridge.transfer.recipient.to_string())
// .push_bind(tx_bridge.transfer.sender.to_string())
// .push_bind(tx_bridge.transfer.amount.to_string_native())
// .push_bind(tx_bridge.gas_fee.amount.to_string_native())
// .push_bind(tx_bridge.gas_fee.payer.to_string());
// })
// .build();
// query.execute(&mut *sqlx_tx).await?;
// }
"tx_vote_proposal" => {
let mut query_builder: QueryBuilder<_> = QueryBuilder::new(format!(
"INSERT INTO {}.vote_proposal(
Expand Down
Loading