[#768] adm: Return error from getContractDeployData()

Make code more idiomatic and unify in style with other error reporting.
Retain panics for code errors.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-01-24 11:02:05 +03:00 committed by Evgenii Stratonikov
parent cc2da73b20
commit c00eb7ccee

View file

@ -222,7 +222,11 @@ func (c *initializeContext) deployOrUpdateContracts(w *io2.BufBinWriter, nnsHash
invokeHash = ctrHash invokeHash = ctrHash
} }
params := getContractDeployParameters(cs, c.getContractDeployData(ctrName, keysParam, updateMethodName)) args, err := c.getContractDeployData(ctrName, keysParam, updateMethodName)
if err != nil {
return fmt.Errorf("%s: getting update params: %v", ctrName, err)
}
params := getContractDeployParameters(cs, args)
res, err := c.CommitteeAct.MakeCall(invokeHash, method, params...) res, err := c.CommitteeAct.MakeCall(invokeHash, method, params...)
if err != nil { if err != nil {
if method != updateMethodName || !strings.Contains(err.Error(), common.ErrAlreadyUpdated) { if method != updateMethodName || !strings.Contains(err.Error(), common.ErrAlreadyUpdated) {
@ -345,7 +349,11 @@ func (c *initializeContext) deployContracts() error {
return fmt.Errorf("can't sign manifest group: %v", err) return fmt.Errorf("can't sign manifest group: %v", err)
} }
params := getContractDeployParameters(cs, c.getContractDeployData(ctrName, keysParam, deployMethodName)) args, err := c.getContractDeployData(ctrName, keysParam, deployMethodName)
if err != nil {
return fmt.Errorf("%s: getting deploy params: %v", ctrName, err)
}
params := getContractDeployParameters(cs, args)
res, err := c.CommitteeAct.MakeCall(management.Hash, deployMethodName, params...) res, err := c.CommitteeAct.MakeCall(management.Hash, deployMethodName, params...)
if err != nil { if err != nil {
return fmt.Errorf("can't deploy %s contract: %w", ctrName, err) return fmt.Errorf("can't deploy %s contract: %w", ctrName, err)
@ -511,7 +519,7 @@ func getContractDeployParameters(cs *contractState, deployData []any) []any {
return []any{cs.RawNEF, cs.RawManifest, deployData} return []any{cs.RawNEF, cs.RawManifest, deployData}
} }
func (c *initializeContext) getContractDeployData(ctrName string, keysParam []any, method string) []any { func (c *initializeContext) getContractDeployData(ctrName string, keysParam []any, method string) ([]any, error) {
items := make([]any, 0, 6) items := make([]any, 0, 6)
switch ctrName { switch ctrName {
@ -522,7 +530,7 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
smartcontract.Parameter{}) smartcontract.Parameter{})
case processingContract: case processingContract:
items = append(items, c.Contracts[frostfsContract].Hash) items = append(items, c.Contracts[frostfsContract].Hash)
return items[1:] // no notary info return items[1:], nil // no notary info
case balanceContract: case balanceContract:
items = append(items, items = append(items,
c.Contracts[netmapContract].Hash, c.Contracts[netmapContract].Hash,
@ -533,7 +541,7 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
r := management.NewReader(c.ReadOnlyInvoker) r := management.NewReader(c.ReadOnlyInvoker)
nnsCs, err := r.GetContractByID(1) nnsCs, err := r.GetContractByID(1)
if err != nil { if err != nil {
panic("NNS is not yet deployed") return nil, errors.New("NNS is not yet deployed")
} }
items = append(items, items = append(items,
c.Contracts[netmapContract].Hash, c.Contracts[netmapContract].Hash,
@ -544,7 +552,7 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
case frostfsIDContract: case frostfsIDContract:
h, found, err := getFrostfsIDAdmin(viper.GetViper()) h, found, err := getFrostfsIDAdmin(viper.GetViper())
if err != nil { if err != nil {
panic(err) return nil, err
} }
if found { if found {
@ -557,11 +565,11 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
if method == updateMethodName { if method == updateMethodName {
arr, err := c.getNetConfigFromNetmapContract() arr, err := c.getNetConfigFromNetmapContract()
if err != nil { if err != nil {
panic(err) return nil, err
} }
m, err := parseConfigFromNetmapContract(arr) m, err := parseConfigFromNetmapContract(arr)
if err != nil { if err != nil {
panic(err) return nil, err
} }
for k, v := range m { for k, v := range m {
for _, key := range netmapConfigKeys { for _, key := range netmapConfigKeys {
@ -590,7 +598,7 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
default: default:
panic(fmt.Sprintf("invalid contract name: %s", ctrName)) panic(fmt.Sprintf("invalid contract name: %s", ctrName))
} }
return items return items, nil
} }
func (c *initializeContext) getNetConfigFromNetmapContract() ([]stackitem.Item, error) { func (c *initializeContext) getNetConfigFromNetmapContract() ([]stackitem.Item, error) {