Skip to content

Commit

Permalink
update IsSponsorTx
Browse files Browse the repository at this point in the history
  • Loading branch information
linhpn99 committed Jul 9, 2024
1 parent 5408223 commit 760bc60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tm2/pkg/std/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,25 @@ func (tx Tx) ValidateBasic() error {
return nil
}

// IsSponsorTx checks if the transaction is a sponsor transaction.
// A sponsor transaction is defined as having:
// - At least one message in the transaction.
// - The first message type is "no_op".
// - More than one signer.
// - The first signer is different from all other signers.
// IsSponsorTx checks if the transaction is a valid sponsor transaction
func (tx Tx) IsSponsorTx() bool {
if len(tx.Msgs) == 0 || tx.Msgs[0].Type() != "no_op" {
// At least one message in the transaction
if len(tx.Msgs) < 1 {
return false
}

// The first message type is "no_op"
if tx.Msgs[0].Type() != "no_op" {
return false
}

// More than one signer
signers := tx.GetSigners()
if len(signers) <= 1 {
return false
}

// The first signer is different from all other signers
for i := 1; i < len(signers); i++ {
if signers[0] == signers[i] {
return false
Expand Down
10 changes: 10 additions & 0 deletions tm2/pkg/std/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ func TestIsSponsorTx(t *testing.T) {
},
expected: true,
},
{
name: "only have no_op message",
msgs: []Msg{
mockMsg{
caller: addr1,
msgType: "no_op",
},
},
expected: false,
},
{
name: "no_op message with same signers",
msgs: []Msg{
Expand Down

0 comments on commit 760bc60

Please sign in to comment.