[#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:
parent
cc2da73b20
commit
c00eb7ccee
1 changed files with 17 additions and 9 deletions
|
@ -222,7 +222,11 @@ func (c *initializeContext) deployOrUpdateContracts(w *io2.BufBinWriter, nnsHash
|
|||
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...)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
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...)
|
||||
if err != nil {
|
||||
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}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
switch ctrName {
|
||||
|
@ -522,7 +530,7 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
|
|||
smartcontract.Parameter{})
|
||||
case processingContract:
|
||||
items = append(items, c.Contracts[frostfsContract].Hash)
|
||||
return items[1:] // no notary info
|
||||
return items[1:], nil // no notary info
|
||||
case balanceContract:
|
||||
items = append(items,
|
||||
c.Contracts[netmapContract].Hash,
|
||||
|
@ -533,7 +541,7 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
|
|||
r := management.NewReader(c.ReadOnlyInvoker)
|
||||
nnsCs, err := r.GetContractByID(1)
|
||||
if err != nil {
|
||||
panic("NNS is not yet deployed")
|
||||
return nil, errors.New("NNS is not yet deployed")
|
||||
}
|
||||
items = append(items,
|
||||
c.Contracts[netmapContract].Hash,
|
||||
|
@ -544,7 +552,7 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
|
|||
case frostfsIDContract:
|
||||
h, found, err := getFrostfsIDAdmin(viper.GetViper())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if found {
|
||||
|
@ -557,11 +565,11 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
|
|||
if method == updateMethodName {
|
||||
arr, err := c.getNetConfigFromNetmapContract()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
m, err := parseConfigFromNetmapContract(arr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range m {
|
||||
for _, key := range netmapConfigKeys {
|
||||
|
@ -590,7 +598,7 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
|
|||
default:
|
||||
panic(fmt.Sprintf("invalid contract name: %s", ctrName))
|
||||
}
|
||||
return items
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (c *initializeContext) getNetConfigFromNetmapContract() ([]stackitem.Item, error) {
|
||||
|
|
Loading…
Reference in a new issue