[#161] morph: Refactor invokeNotary method

Resolve funlen linter

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-03-23 11:01:30 +03:00 committed by Gitea
parent 512b72591a
commit 93cb9e3a94

View file

@ -892,7 +892,6 @@ func invokeNonNotary(c Client, key keys.PrivateKey, method string, args ...any)
return nil return nil
} }
// nolint: funlen
func invokeNotary(c Client, key keys.PrivateKey, method string, notaryHash util.Uint160, args ...any) error { func invokeNotary(c Client, key keys.PrivateKey, method string, notaryHash util.Uint160, args ...any) error {
nnsCs, err := c.GetContractStateByID(1) nnsCs, err := c.GetContractStateByID(1)
if err != nil { if err != nil {
@ -921,13 +920,7 @@ func invokeNotary(c Client, key keys.PrivateKey, method string, notaryHash util.
return fmt.Errorf("subnet hash resolving: %w", err) return fmt.Errorf("subnet hash resolving: %w", err)
} }
// make test invocation of the method test, err := makeTestInvocation(inv, subnetHash, method, args)
test, err := inv.Call(subnetHash, method, args...)
if err != nil {
return fmt.Errorf("test invocation: %w", err)
}
err = checkInvocationResults(test)
if err != nil { if err != nil {
return err return err
} }
@ -943,7 +936,26 @@ func invokeNotary(c Client, key keys.PrivateKey, method string, notaryHash util.
return fmt.Errorf("blockchain height: %w", err) return fmt.Errorf("blockchain height: %w", err)
} }
signersNumber := uint8(smartcontract.GetDefaultHonestNodeCount(len(alphabet)) + 1) // alphabet multisig + key signature return createAndPushTransaction(alphabet, test, bc, cosigners, c, key, multisigAccount)
}
func makeTestInvocation(inv *invoker.Invoker, subnetHash util.Uint160, method string, args []any) (*result.Invoke, error) {
test, err := inv.Call(subnetHash, method, args...)
if err != nil {
return nil, fmt.Errorf("test invocation: %w", err)
}
err = checkInvocationResults(test)
if err != nil {
return nil, err
}
return test, nil
}
func createAndPushTransaction(alphabet keys.PublicKeys, test *result.Invoke, blockCount uint32, cosigners []transaction.Signer,
client Client, key keys.PrivateKey, multisigAccount *wallet.Account) error {
// alphabet multisig + key signature
signersNumber := uint8(smartcontract.GetDefaultHonestNodeCount(len(alphabet)) + 1)
// notaryRequestValidity is number of blocks during // notaryRequestValidity is number of blocks during
// witch notary request is considered valid // witch notary request is considered valid
@ -952,7 +964,7 @@ func invokeNotary(c Client, key keys.PrivateKey, method string, notaryHash util.
mainTx := &transaction.Transaction{ mainTx := &transaction.Transaction{
Nonce: rand.Uint32(), Nonce: rand.Uint32(),
SystemFee: test.GasConsumed, SystemFee: test.GasConsumed,
ValidUntilBlock: bc + notaryRequestValidity, ValidUntilBlock: blockCount + notaryRequestValidity,
Script: test.Script, Script: test.Script,
Attributes: []transaction.Attribute{ Attributes: []transaction.Attribute{
{ {
@ -963,7 +975,7 @@ func invokeNotary(c Client, key keys.PrivateKey, method string, notaryHash util.
Signers: cosigners, Signers: cosigners,
} }
notaryFee, err := c.CalculateNotaryFee(signersNumber) notaryFee, err := client.CalculateNotaryFee(signersNumber)
if err != nil { if err != nil {
return err return err
} }
@ -971,14 +983,14 @@ func invokeNotary(c Client, key keys.PrivateKey, method string, notaryHash util.
acc := wallet.NewAccountFromPrivateKey(&key) acc := wallet.NewAccountFromPrivateKey(&key)
aa := notaryAccounts(multisigAccount, acc) aa := notaryAccounts(multisigAccount, acc)
err = c.AddNetworkFee(mainTx, notaryFee, aa...) err = client.AddNetworkFee(mainTx, notaryFee, aa...)
if err != nil { if err != nil {
return fmt.Errorf("notary network fee adding: %w", err) return fmt.Errorf("notary network fee adding: %w", err)
} }
mainTx.Scripts = notaryWitnesses(c, multisigAccount, acc, mainTx) mainTx.Scripts = notaryWitnesses(client, multisigAccount, acc, mainTx)
_, err = c.SignAndPushP2PNotaryRequest(mainTx, _, err = client.SignAndPushP2PNotaryRequest(mainTx,
[]byte{byte(opcode.RET)}, []byte{byte(opcode.RET)},
-1, -1,
0, 0,