diff --git a/pkg/core/transaction/transaction.go b/pkg/core/transaction/transaction.go index 2b26be5c1..d9c23b906 100644 --- a/pkg/core/transaction/transaction.go +++ b/pkg/core/transaction/transaction.go @@ -407,3 +407,13 @@ func (t *Transaction) isValid() error { } return nil } + +// HasSigner returns true in case if hash is present in the list of signers. +func (t *Transaction) HasSigner(hash util.Uint160) bool { + for _, h := range t.Signers { + if h.Account.Equals(hash) { + return true + } + } + return false +} diff --git a/pkg/core/transaction/transaction_test.go b/pkg/core/transaction/transaction_test.go index fd213accd..510351639 100644 --- a/pkg/core/transaction/transaction_test.go +++ b/pkg/core/transaction/transaction_test.go @@ -12,6 +12,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/encoding/address" + "github.com/nspcc-dev/neo-go/pkg/internal/random" "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/util" ) @@ -248,3 +249,14 @@ func TestTransaction_GetAttributes(t *testing.T) { require.Equal(t, conflictsAttrs, tx.GetAttributes(typ)) }) } + +func TestTransaction_HasSigner(t *testing.T) { + u1, u2 := random.Uint160(), random.Uint160() + tx := Transaction{ + Signers: []Signer{ + {Account: u1}, {Account: u2}, + }, + } + require.True(t, tx.HasSigner(u1)) + require.False(t, tx.HasSigner(util.Uint160{})) +}