check if signer is valid and fix authorizers check
@@ -201,10 +201,38 @@ func (t *Transaction) SetSigner(account *Account) error {
return err
}
+ if !t.validSigner(account.Address()) {
+ return fmt.Errorf(
+ "not a valid signer %s, proposer: %s, payer: %s, authorizers: %s",
+ account.Address(),
+ t.tx.ProposalKey.Address,
+ t.tx.Payer,
+ t.tx.Authorizers,
+ )
+ }
+
t.signer = account
return nil
}
+// validSigner checks whether the signer is valid for transaction
+func (t *Transaction) validSigner(s flow.Address) bool {
+ return t.tx.ProposalKey.Address == s ||
+ t.tx.Payer == s ||
+ t.authorizersContains(s)
+}
+
+// authorizersContains checks whether address is in the authorizer list
+func (t *Transaction) authorizersContains(address flow.Address) bool {
+ for _, a := range t.tx.Authorizers {
+ if address == a {
+ return true
+ }
+ }
+
+ return false
+}
+
// SetProposer sets the proposer for transaction.
func (t *Transaction) SetProposer(proposer *flow.Account, keyIndex int) *Transaction {
t.proposer = proposer
@@ -262,6 +290,8 @@ func (t *Transaction) AddAuthorizers(authorizers []flow.Address) (*Transaction,
map[common.LocationID]string{},
)
+ // get authorizers param list if exists
+ if program.SoleTransactionDeclaration().Prepare != nil {
requiredAuths := program.SoleTransactionDeclaration().
Prepare.
FunctionDeclaration.
@@ -270,11 +300,12 @@ func (t *Transaction) AddAuthorizers(authorizers []flow.Address) (*Transaction,
if len(requiredAuths) != len(authorizers) {
return nil, fmt.Errorf(
- "provided authorizers length missmatch, required authorizers %d, but provided %d",
+ "provided authorizers length mismatch, required authorizers %d, but provided %d",
len(requiredAuths),
len(authorizers),
)
}
+ }
for _, authorizer := range authorizers {
t.tx.AddAuthorizer(authorizer)
