2024-02-02 07:25:04 +00:00
|
|
|
package initialize
|
2021-07-21 10:09:59 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2024-02-02 12:26:57 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
2024-02-02 12:36:14 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper"
|
2021-07-21 10:09:59 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2022-08-29 19:31:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
2022-11-23 14:44:03 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
2021-07-21 10:09:59 +00:00
|
|
|
)
|
|
|
|
|
2024-02-02 12:36:14 +00:00
|
|
|
func deployContracts(c *helper.InitializeContext) error {
|
2024-02-02 12:26:57 +00:00
|
|
|
alphaCs := c.GetContract(constants.AlphabetContract)
|
2021-12-27 10:26:22 +00:00
|
|
|
|
2023-02-21 11:42:45 +00:00
|
|
|
var keysParam []any
|
2021-12-27 10:26:22 +00:00
|
|
|
|
2022-06-07 14:32:58 +00:00
|
|
|
baseGroups := alphaCs.Manifest.Groups
|
|
|
|
|
2021-12-27 10:26:22 +00:00
|
|
|
// alphabet contracts should be deployed by individual nodes to get different hashes.
|
|
|
|
for i, acc := range c.Accounts {
|
|
|
|
ctrHash := state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name)
|
2024-02-01 11:30:59 +00:00
|
|
|
if c.IsUpdated(ctrHash, alphaCs) {
|
2021-08-06 11:28:07 +00:00
|
|
|
c.Command.Printf("Alphabet contract #%d is already deployed.\n", i)
|
2021-07-21 10:09:59 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-06-07 14:32:58 +00:00
|
|
|
alphaCs.Manifest.Groups = baseGroups
|
2024-02-02 12:36:14 +00:00
|
|
|
err := helper.AddManifestGroup(c.ContractWallet, ctrHash, alphaCs)
|
2022-06-07 14:32:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't sign manifest group: %v", err)
|
|
|
|
}
|
|
|
|
|
2022-04-07 12:47:13 +00:00
|
|
|
keysParam = append(keysParam, acc.PrivateKey().PublicKey().Bytes())
|
2024-02-02 12:36:14 +00:00
|
|
|
params := helper.GetContractDeployParameters(alphaCs, c.GetAlphabetDeployItems(i, len(c.Wallets)))
|
2021-07-21 10:09:59 +00:00
|
|
|
|
2022-08-29 19:31:32 +00:00
|
|
|
act, err := actor.NewSimple(c.Client, acc)
|
2021-07-21 10:09:59 +00:00
|
|
|
if err != nil {
|
2022-08-29 19:31:32 +00:00
|
|
|
return fmt.Errorf("could not create actor: %w", err)
|
2021-09-21 12:15:20 +00:00
|
|
|
}
|
|
|
|
|
2024-02-02 12:26:57 +00:00
|
|
|
txHash, vub, err := act.SendCall(management.Hash, constants.DeployMethodName, params...)
|
2022-08-29 19:31:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't deploy alphabet #%d contract: %w", i, err)
|
2021-09-21 12:19:22 +00:00
|
|
|
}
|
2022-08-29 19:31:32 +00:00
|
|
|
|
2024-02-02 12:36:14 +00:00
|
|
|
c.SentTxs = append(c.SentTxs, helper.HashVUBPair{Hash: txHash, Vub: vub})
|
2021-07-21 10:09:59 +00:00
|
|
|
}
|
|
|
|
|
2024-02-02 12:26:57 +00:00
|
|
|
for _, ctrName := range constants.ContractList {
|
2024-02-01 11:30:59 +00:00
|
|
|
cs := c.GetContract(ctrName)
|
2021-11-24 06:19:39 +00:00
|
|
|
|
|
|
|
ctrHash := cs.Hash
|
2024-02-01 11:30:59 +00:00
|
|
|
if c.IsUpdated(ctrHash, cs) {
|
2021-08-06 11:28:07 +00:00
|
|
|
c.Command.Printf("%s contract is already deployed.\n", ctrName)
|
2021-07-21 10:09:59 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-02-02 12:36:14 +00:00
|
|
|
err := helper.AddManifestGroup(c.ContractWallet, ctrHash, cs)
|
2021-11-29 12:33:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't sign manifest group: %v", err)
|
|
|
|
}
|
|
|
|
|
2024-02-02 12:36:14 +00:00
|
|
|
args, err := helper.GetContractDeployData(c, ctrName, keysParam, constants.DeployMethodName)
|
2024-01-24 08:02:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("%s: getting deploy params: %v", ctrName, err)
|
|
|
|
}
|
2024-02-02 12:36:14 +00:00
|
|
|
params := helper.GetContractDeployParameters(cs, args)
|
2024-02-02 12:26:57 +00:00
|
|
|
res, err := c.CommitteeAct.MakeCall(management.Hash, constants.DeployMethodName, params...)
|
2021-07-21 10:09:59 +00:00
|
|
|
if err != nil {
|
2021-09-21 12:15:20 +00:00
|
|
|
return fmt.Errorf("can't deploy %s contract: %w", ctrName, err)
|
|
|
|
}
|
2021-07-21 10:09:59 +00:00
|
|
|
|
2024-02-01 11:30:59 +00:00
|
|
|
if err := c.SendCommitteeTx(res.Script, false); err != nil {
|
2021-07-21 10:09:59 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-01 11:30:59 +00:00
|
|
|
return c.AwaitTx()
|
2021-07-21 10:09:59 +00:00
|
|
|
}
|