Skip to content

Commit

Permalink
Merge pull request #4 from celenium-io/fix/tx-signer-hash
Browse files Browse the repository at this point in the history
Fix: signer hash
  • Loading branch information
aopoltorzhicky authored Mar 21, 2024
2 parents c92644f + 8e97baa commit 4d01e87
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 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
4 changes: 2 additions & 2 deletions internal/storage/postgres/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ func (s *StatsTestSuite) TestSummary() {
s.Require().EqualValues(0.0038194444444444443, summary.BPS)
s.Require().EqualValues(2327, summary.BlockTime)
s.Require().EqualValues(330, summary.BytesInBlock)
s.Require().EqualValues(0, summary.DataSize)
s.Require().EqualValues(202, summary.DataSize)
s.Require().EqualValues("0", summary.Fee.String())
s.Require().EqualValues(0, summary.RBPS)
s.Require().EqualValues(0.002337962962962963, summary.RBPS)
s.Require().EqualValues("0", summary.Supply.String())
s.Require().EqualValues(1, summary.TxCount)
}
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
2 changes: 2 additions & 0 deletions test/data/block_stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
supply_change: 0
fee: 0
bytes_in_block: 64
data_size: 0
- id: 7966
height: 7965
time: '2023-12-01T00:18:07.575Z'
Expand All @@ -18,3 +19,4 @@
supply_change: 0
fee: 0
bytes_in_block: 266
data_size: 202

0 comments on commit 4d01e87

Please sign in to comment.