core: add transaction.HasSigner method

This commit is contained in:
Anna Shaleva 2020-10-23 15:12:36 +03:00
parent 1956f2c079
commit f259a614de
2 changed files with 22 additions and 0 deletions

View file

@ -407,3 +407,13 @@ func (t *Transaction) isValid() error {
} }
return nil 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
}

View file

@ -12,6 +12,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/config/netmode" "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/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/internal/testserdes"
"github.com/nspcc-dev/neo-go/pkg/util" "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)) 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{}))
}