process events and logs
This commit is contained in:
@@ -57,6 +57,7 @@ CREATE TABLE transaction
|
||||
gas_used BIGINT DEFAULT 0,
|
||||
raw_log TEXT,
|
||||
logs JSONB,
|
||||
events JSONB,
|
||||
|
||||
CONSTRAINT unique_tx UNIQUE (hash)
|
||||
);
|
||||
|
||||
@@ -345,6 +345,7 @@ pub(crate) async fn insert_transaction<'a, E>(
|
||||
gas_used: i64,
|
||||
raw_log: String,
|
||||
logs: JsonValue,
|
||||
events: JsonValue,
|
||||
executor: E,
|
||||
) -> Result<(), sqlx::Error>
|
||||
where
|
||||
@@ -356,8 +357,8 @@ where
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO transaction
|
||||
(hash, height, index, success, messages, memo, signatures, signer_infos, fee, gas_wanted, gas_used, raw_log, logs)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
||||
(hash, height, index, success, messages, memo, signatures, signer_infos, fee, gas_wanted, gas_used, raw_log, logs, events)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
|
||||
ON CONFLICT (hash) DO UPDATE
|
||||
SET height = excluded.height,
|
||||
index = excluded.index,
|
||||
@@ -370,7 +371,8 @@ where
|
||||
gas_wanted = excluded.gas_wanted,
|
||||
gas_used = excluded.gas_used,
|
||||
raw_log = excluded.raw_log,
|
||||
logs = excluded.logs
|
||||
logs = excluded.logs,
|
||||
events = excluded.events
|
||||
"#,
|
||||
hash,
|
||||
height,
|
||||
@@ -385,6 +387,7 @@ where
|
||||
gas_used,
|
||||
raw_log,
|
||||
logs,
|
||||
events,
|
||||
)
|
||||
.execute(executor)
|
||||
.await?;
|
||||
|
||||
@@ -23,7 +23,7 @@ use serde_json::json;
|
||||
use sqlx::types::time::{OffsetDateTime, PrimitiveDateTime};
|
||||
use sqlx::{Postgres, Transaction};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use tracing::{debug, trace, warn};
|
||||
use tracing::{debug, error, trace, warn};
|
||||
|
||||
pub struct PostgresStorageTransaction {
|
||||
pub(super) inner: Transaction<'static, Postgres>,
|
||||
@@ -167,10 +167,17 @@ impl PostgresStorageTransaction {
|
||||
.map(|info| proto::cosmos::tx::v1beta1::SignerInfo::from(info.clone()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let hash = chain_tx.hash.to_string();
|
||||
let height = chain_tx.height.into();
|
||||
let index = chain_tx.index as i32;
|
||||
|
||||
let log = serde_json::to_value(chain_tx.tx_result.log.clone()).map_err(|e| error!(hash, height, index, "Failed to parse logs: {e}")).unwrap_or_default();
|
||||
let events = &chain_tx.tx_result.events;
|
||||
|
||||
insert_transaction(
|
||||
chain_tx.hash.to_string(),
|
||||
chain_tx.height.into(),
|
||||
chain_tx.index as i32,
|
||||
hash,
|
||||
height,
|
||||
index,
|
||||
chain_tx.tx_result.code.is_ok(),
|
||||
serde_json::Value::Array(messages),
|
||||
chain_tx.tx.body.memo.clone(),
|
||||
@@ -180,7 +187,8 @@ impl PostgresStorageTransaction {
|
||||
chain_tx.tx_result.gas_wanted,
|
||||
chain_tx.tx_result.gas_used,
|
||||
chain_tx.tx_result.log.clone(),
|
||||
json!("null"),
|
||||
json!(log),
|
||||
json!(events),
|
||||
self.inner.as_mut(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -57,6 +57,7 @@ CREATE TABLE transaction
|
||||
gas_used BIGINT DEFAULT 0,
|
||||
raw_log TEXT,
|
||||
logs JSONB,
|
||||
events JSONB,
|
||||
|
||||
CONSTRAINT unique_tx UNIQUE (hash)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user