From c8244f2339b042d7845acd3872f2a048a314e175 Mon Sep 17 00:00:00 2001 From: Luca Palla Date: Thu, 24 Apr 2025 12:22:43 +0200 Subject: [PATCH 1/2] Add events on db --- database/postgresql/postgresql.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/database/postgresql/postgresql.go b/database/postgresql/postgresql.go index 6d184156..0b918eb8 100644 --- a/database/postgresql/postgresql.go +++ b/database/postgresql/postgresql.go @@ -166,8 +166,8 @@ func (db *Database) SaveTx(tx *types.Transaction) error { func (db *Database) saveTxInsidePartition(tx *types.Transaction, partitionID int64) error { sqlStatement := ` INSERT INTO transaction -(hash, height, success, messages, memo, signatures, signer_infos, fee, gas_wanted, gas_used, raw_log, logs, partition_id) -VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) +(hash, height, success, messages, memo, signatures, signer_infos, fee, gas_wanted, gas_used, raw_log, logs, partition_id, events) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) ON CONFLICT (hash, partition_id) DO UPDATE SET height = excluded.height, success = excluded.success, @@ -179,7 +179,8 @@ ON CONFLICT (hash, partition_id) DO UPDATE gas_wanted = excluded.gas_wanted, gas_used = excluded.gas_used, raw_log = excluded.raw_log, - logs = excluded.logs` + logs = excluded.logs, + events = excluded.events` var sigs = make([]string, len(tx.Signatures)) for index, sig := range tx.Signatures { @@ -212,12 +213,17 @@ ON CONFLICT (hash, partition_id) DO UPDATE return err } + eventsBz, err := json.Marshal(tx.Events) + if err != nil { + return err + } + _, err = db.SQL.Exec(sqlStatement, tx.TxHash, tx.Height, tx.Successful(), msgsBz, tx.Body.Memo, pq.Array(sigs), sigInfoBz, string(feeBz), tx.GasWanted, tx.GasUsed, tx.RawLog, string(logsBz), - partitionID, + partitionID, string(eventsBz), ) return err } From e269ba9b38f01b532810c18e44fc9b6fa37d7510 Mon Sep 17 00:00:00 2001 From: dimiandre Date: Wed, 30 Apr 2025 10:49:30 +0200 Subject: [PATCH 2/2] add schema --- database/postgresql/schema.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/database/postgresql/schema.sql b/database/postgresql/schema.sql index cace2530..2c4c0365 100644 --- a/database/postgresql/schema.sql +++ b/database/postgresql/schema.sql @@ -49,6 +49,7 @@ CREATE TABLE transaction gas_used BIGINT DEFAULT 0, raw_log TEXT, logs JSONB, + events JSONB NOT NULL DEFAULT '[]'::JSONB, /* PSQL partition */ partition_id BIGINT NOT NULL DEFAULT 0,