rpcsrv: simplify calculatenetworkfee

We're dealing with a transaction here and it can't be decoded successfully
unless it has an appropriate number of witness scripts (matching the number of
signers) with appropriate hashes (matching signers). So this iterations make
no sense at all, we know exactly where to look for the
verification/invocation scripts.
This commit is contained in:
Roman Khimov 2022-08-22 14:47:30 +03:00
parent 9916832e2e
commit 98dfe66466

View file

@ -763,15 +763,8 @@ func (s *Server) calculateNetworkFee(reqParams params.Params) (interface{}, *neo
netFee int64
)
for i, signer := range tx.Signers {
var verificationScript []byte
for _, w := range tx.Scripts {
if w.VerificationScript != nil && hash.Hash160(w.VerificationScript).Equals(signer.Account) {
// then it's a standard sig/multisig witness
verificationScript = w.VerificationScript
break
}
}
if verificationScript == nil { // then it still might be a contract-based verification
w := tx.Scripts[i]
if len(w.VerificationScript) == 0 { // then it still might be a contract-based verification
gasConsumed, err := s.chain.VerifyWitness(signer.Account, tx, &tx.Scripts[i], int64(s.config.MaxGasInvoke))
if err != nil {
return 0, neorpc.NewRPCError("Invalid signature", fmt.Sprintf("contract verification for signer #%d failed: %s", i, err))
@ -785,7 +778,7 @@ func (s *Server) calculateNetworkFee(reqParams params.Params) (interface{}, *neo
if ef == 0 {
ef = s.chain.GetBaseExecFee()
}
fee, sizeDelta := fee.Calculate(ef, verificationScript)
fee, sizeDelta := fee.Calculate(ef, w.VerificationScript)
netFee += fee
size += sizeDelta
}