[#888] neofs-adm: set contract hashes on read
Non-alphabet contract are always deployed from committee so it makes sense to calculate hashes in one place. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
6bcd4811e2
commit
8ddd0aab55
3 changed files with 17 additions and 19 deletions
|
@ -74,8 +74,7 @@ func (c *initializeContext) deployNNS(method string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
h := state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name)
|
||||
if _, err := c.Client.GetContractStateByHash(h); err == nil && method != "update" {
|
||||
if _, err := c.Client.GetContractStateByHash(cs.Hash); err == nil && method != "update" {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -123,13 +122,11 @@ func (c *initializeContext) deployNNS(method string) error {
|
|||
|
||||
func (c *initializeContext) deployContracts(method string) error {
|
||||
mgmtHash := c.nativeHash(nativenames.Management)
|
||||
sender := c.CommitteeAcc.Contract.ScriptHash()
|
||||
for _, ctrName := range contractList {
|
||||
cs, err := c.readContract(ctrName)
|
||||
_, err := c.readContract(ctrName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cs.Hash = state.CreateContractHash(sender, cs.NEF.Checksum, cs.Manifest.Name)
|
||||
}
|
||||
|
||||
alphaCs, err := c.readContract(alphabetContract)
|
||||
|
@ -264,13 +261,18 @@ func (c *initializeContext) readContract(ctrName string) (*contractState, error)
|
|||
return nil, fmt.Errorf("can't parse manifest file: %w", err)
|
||||
}
|
||||
|
||||
c.Contracts[ctrName] = &contractState{
|
||||
cs := &contractState{
|
||||
NEF: &nf,
|
||||
RawNEF: rawNef,
|
||||
Manifest: m,
|
||||
RawManifest: rawManif,
|
||||
}
|
||||
return c.Contracts[ctrName], nil
|
||||
if ctrName != alphabetContract {
|
||||
cs.Hash = state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(),
|
||||
cs.NEF.Checksum, cs.Manifest.Name)
|
||||
}
|
||||
c.Contracts[ctrName] = cs
|
||||
return cs, nil
|
||||
}
|
||||
|
||||
func getContractDeployParameters(rawNef, rawManif []byte, deployData []smartcontract.Parameter) []smartcontract.Parameter {
|
||||
|
|
|
@ -24,18 +24,17 @@ const defaultNameServiceSysfee = 4000_0000
|
|||
const defaultRegisterSysfee = 10_0000_0000 + defaultNameServiceDomainPrice
|
||||
|
||||
func (c *initializeContext) setNNS() error {
|
||||
cs, err := c.readContract(nnsContract)
|
||||
nnsCs, err := c.readContract(nnsContract)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h := state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name)
|
||||
ok, err := c.nnsRootRegistered(h)
|
||||
ok, err := c.nnsRootRegistered(nnsCs.Hash)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !ok {
|
||||
bw := io.NewBufBinWriter()
|
||||
emit.AppCall(bw.BinWriter, h, "addRoot", callflag.All, "neofs")
|
||||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRoot", callflag.All, "neofs")
|
||||
if err := c.sendCommitteeTx(bw.Bytes(), -1); err != nil {
|
||||
return fmt.Errorf("can't add domain root to NNS: %w", err)
|
||||
}
|
||||
|
@ -52,7 +51,7 @@ func (c *initializeContext) setNNS() error {
|
|||
alphaCs.Hash = state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name)
|
||||
|
||||
domain := getAlphabetNNSDomain(i)
|
||||
if err := c.nnsRegisterDomain(h, alphaCs.Hash, domain); err != nil {
|
||||
if err := c.nnsRegisterDomain(nnsCs.Hash, alphaCs.Hash, domain); err != nil {
|
||||
return err
|
||||
}
|
||||
c.Command.Printf("NNS: Set %s -> %s\n", domain, alphaCs.Hash.StringLE())
|
||||
|
@ -63,10 +62,9 @@ func (c *initializeContext) setNNS() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cs.Hash = state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name)
|
||||
|
||||
domain := ctrName + ".neofs"
|
||||
if err := c.nnsRegisterDomain(h, cs.Hash, domain); err != nil {
|
||||
if err := c.nnsRegisterDomain(nnsCs.Hash, cs.Hash, domain); err != nil {
|
||||
return err
|
||||
}
|
||||
c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE())
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
||||
scContext "github.com/nspcc-dev/neo-go/pkg/smartcontract/context"
|
||||
|
@ -133,18 +132,17 @@ func (c *initializeContext) multiSign(tx *transaction.Transaction, accType strin
|
|||
|
||||
func (c *initializeContext) transferGASToProxy() error {
|
||||
gasHash := c.nativeHash(nativenames.Gas)
|
||||
cs, err := c.readContract(proxyContract)
|
||||
proxyCs, err := c.readContract(proxyContract)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h := state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name)
|
||||
bal, err := c.Client.NEP17BalanceOf(gasHash, h)
|
||||
bal, err := c.Client.NEP17BalanceOf(gasHash, proxyCs.Hash)
|
||||
if err != nil || bal > 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
tx, err := c.Client.CreateNEP17TransferTx(c.CommitteeAcc, h, gasHash, initialProxyGASAmount, 0, nil, nil)
|
||||
tx, err := c.Client.CreateNEP17TransferTx(c.CommitteeAcc, proxyCs.Hash, gasHash, initialProxyGASAmount, 0, nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue