From 3bcc0204fa3e1325f48bf3992835450bf062d713 Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 22 Mar 2024 00:35:52 +0100 Subject: [PATCH] Fix: signer hash --- cmd/api/init.go | 4 ++-- internal/storage/postgres/tx.go | 11 +++++++++-- internal/storage/postgres/tx_test.go | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/api/init.go b/cmd/api/init.go index 2005472..8c7dc69 100644 --- a/cmd/api/init.go +++ b/cmd/api/init.go @@ -347,7 +347,7 @@ func initHandlers(ctx context.Context, e *echo.Echo, cfg Config, db postgres.Sto v1.GET("/swagger/*", echoSwagger.WrapHandler) if cfg.ApiConfig.Websocket { - initWebsocket(ctx, db, v1) + initWebsocket(ctx, v1) } log.Info().Msg("API routes:") @@ -381,7 +381,7 @@ var ( endpointCache *cache.Cache ) -func initWebsocket(ctx context.Context, db postgres.Storage, group *echo.Group) { +func initWebsocket(ctx context.Context, group *echo.Group) { observer := dispatcher.Observe(storage.ChannelHead, storage.ChannelBlock) wsManager = websocket.NewManager(observer) wsManager.Start(ctx) diff --git a/internal/storage/postgres/tx.go b/internal/storage/postgres/tx.go index 5f23b60..305e24e 100644 --- a/internal/storage/postgres/tx.go +++ b/internal/storage/postgres/tx.go @@ -25,9 +25,16 @@ func NewTx(db *database.Bun) *Tx { } func (tx *Tx) ByHash(ctx context.Context, hash []byte) (transaction storage.Tx, err error) { - err = tx.DB().NewSelect().Model(&transaction). + query := tx.DB().NewSelect().Model((*storage.Tx)(nil)). Where("hash = ?", hash). - Scan(ctx) + Limit(1) + + err = tx.DB().NewSelect(). + TableExpr("(?) as tx", query). + ColumnExpr("tx.*"). + ColumnExpr("address.hash as signer__hash"). + Join("left join address on address.id = tx.signer_id"). + Scan(ctx, &transaction) return } diff --git a/internal/storage/postgres/tx_test.go b/internal/storage/postgres/tx_test.go index 278acd3..3d039b6 100644 --- a/internal/storage/postgres/tx_test.go +++ b/internal/storage/postgres/tx_test.go @@ -31,6 +31,8 @@ func (s *StorageTestSuite) TestTxByHash() { s.Require().EqualValues(1, tx.SignerId) s.Require().EqualValues(types.StatusSuccess, tx.Status) s.Require().EqualValues(hash, tx.Hash) + s.Require().NotNil(tx.Signer) + s.Require().Equal("3fff1c39b9d163bfb9bcbf9dfea78675f1b4bc2c", hex.EncodeToString(tx.Signer.Hash)) } func (s *StorageTestSuite) TestTxByHeight() {