Skip to content

Commit

Permalink
Add signers to transaction model (#126)
Browse files Browse the repository at this point in the history
* Add signers to transaction model

* Rebuild API docs
  • Loading branch information
aopoltorzhicky authored Feb 12, 2024
1 parent 25b17e4 commit de33b49
Show file tree
Hide file tree
Showing 12 changed files with 449 additions and 311 deletions.
6 changes: 6 additions & 0 deletions cmd/api/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cmd/api/docs/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cmd/api/docs/swagger.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions cmd/api/handler/responses/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Tx struct {
Time time.Time `example:"2023-07-04T03:10:57+00:00" format:"date-time" json:"time" swaggertype:"string"`

Messages []Message `json:"messages,omitempty"`
Signers []string `json:"signers"`

MessageTypes []types.MsgType `example:"MsgSend,MsgUnjail" json:"message_types"`
Status types.Status `example:"success" json:"status"`
Expand Down Expand Up @@ -57,11 +58,15 @@ func NewTx(tx storage.Tx) Tx {
MessageTypes: tx.MessageTypes.Names(),
MsgTypeMask: tx.MessageTypes,
Messages: make([]Message, 0),
Signers: make([]string, len(tx.Signers)),
}

for i := range tx.Messages {
result.Messages = append(result.Messages, NewMessage(tx.Messages[i]))
}
for i := range tx.Signers {
result.Signers[i] = tx.Signers[i].Address
}

return result
}
Expand Down
17 changes: 17 additions & 0 deletions cmd/api/handler/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ var (
Type: types.MsgSend,
},
},
Signers: []storage.Address{
{
Address: testAddress,
},
},
}
)

Expand Down Expand Up @@ -122,6 +127,8 @@ func (s *TxTestSuite) TestGet() {
s.Require().Equal("memo", tx.Memo)
s.Require().Equal("sdk", tx.Codespace)
s.Require().Equal(types.StatusSuccess, tx.Status)
s.Require().Len(tx.Signers, 1)
s.Require().Equal(testAddress, tx.Signers[0])
}

func (s *TxTestSuite) TestGetInvalidTx() {
Expand Down Expand Up @@ -183,6 +190,8 @@ func (s *TxTestSuite) TestList() {
s.Require().Equal("memo", tx.Memo)
s.Require().Equal("sdk", tx.Codespace)
s.Require().Equal(types.StatusSuccess, tx.Status)
s.Require().Len(tx.Signers, 1)
s.Require().Equal(testAddress, tx.Signers[0])
}

func (s *TxTestSuite) TestListValidationStatusError() {
Expand Down Expand Up @@ -273,6 +282,8 @@ func (s *TxTestSuite) TestListTime() {
s.Require().Equal("memo", tx.Memo)
s.Require().Equal("sdk", tx.Codespace)
s.Require().Equal(types.StatusSuccess, tx.Status)
s.Require().Len(tx.Signers, 1)
s.Require().Equal(testAddress, tx.Signers[0])
}

func (s *TxTestSuite) TestListHeight() {
Expand Down Expand Up @@ -330,6 +341,8 @@ func (s *TxTestSuite) TestListHeight() {
s.Require().Equal(types.StatusSuccess, tx.Status)

s.Require().Len(tx.Messages, 1)
s.Require().Len(tx.Signers, 1)
s.Require().Equal(testAddress, tx.Signers[0])
}

func (s *TxTestSuite) TestListExcludedMessages() {
Expand Down Expand Up @@ -387,6 +400,8 @@ func (s *TxTestSuite) TestListExcludedMessages() {
s.Require().Equal(types.StatusSuccess, tx.Status)

s.Require().Len(tx.Messages, 1)
s.Require().Len(tx.Signers, 1)
s.Require().Equal(testAddress, tx.Signers[0])
}

func (s *TxTestSuite) TestGetEvents() {
Expand Down Expand Up @@ -532,6 +547,8 @@ func (s *TxTestSuite) TestGenesis() {
s.Require().EqualValues(1, tx.MessagesCount)
s.Require().EqualValues(types.StatusSuccess, tx.Status)
s.Require().EqualValues([]types.MsgType{types.MsgCreateValidator}, tx.MessageTypes)

s.Require().Len(tx.Signers, 0)
}

func (s *TxTestSuite) TestNamespaces() {
Expand Down
3 changes: 3 additions & 0 deletions internal/storage/postgres/blob_log_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: 2024 PK Lab AG <contact@pklab.io>
// SPDX-License-Identifier: MIT

package postgres

import (
Expand Down
1 change: 0 additions & 1 deletion internal/storage/postgres/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func initDatabase(ctx context.Context, conn *database.Bun) error {
// register many-to-many relationships
conn.DB().RegisterModel(
(*models.NamespaceMessage)(nil),
(*models.Signer)(nil),
(*models.MsgAddress)(nil),
(*models.RollupProvider)(nil),
)
Expand Down
Loading

0 comments on commit de33b49

Please sign in to comment.