Skip to content

Commit

Permalink
Fix: signer hash
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Mar 21, 2024
1 parent c92644f commit 3bcc020
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/api/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions internal/storage/postgres/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions internal/storage/postgres/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 3bcc020

Please sign in to comment.