[#732] neofs-adm: fetch native hashes once
Retrieve list of native contracts during initialization in a single query. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
6a40adcfca
commit
c81008764a
6 changed files with 26 additions and 37 deletions
|
@ -159,10 +159,7 @@ func generateStorageCreds(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gasHash, err := wCtx.Client.GetNativeContractHash(nativenames.Gas)
|
gasHash := wCtx.nativeHash(nativenames.Gas)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
bw := io.NewBufBinWriter()
|
bw := io.NewBufBinWriter()
|
||||||
emit.AppCall(bw.BinWriter, gasHash, "transfer", callflag.All,
|
emit.AppCall(bw.BinWriter, gasHash, "transfer", callflag.All,
|
||||||
|
|
|
@ -32,6 +32,7 @@ type initializeContext struct {
|
||||||
Contracts map[string]*contractState
|
Contracts map[string]*contractState
|
||||||
Command *cobra.Command
|
Command *cobra.Command
|
||||||
ContractPath string
|
ContractPath string
|
||||||
|
Natives map[string]util.Uint160
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeSideChainCmd(cmd *cobra.Command, args []string) error {
|
func initializeSideChainCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
@ -129,6 +130,16 @@ func newInitializeContext(cmd *cobra.Command, v *viper.Viper) (*initializeContex
|
||||||
return nil, fmt.Errorf("missing contracts path: %w", err)
|
return nil, fmt.Errorf("missing contracts path: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ns, err := c.GetNativeContracts()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't get native contract hashes: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
nativeHashes := make(map[string]util.Uint160, len(ns))
|
||||||
|
for i := range ns {
|
||||||
|
nativeHashes[ns[i].Manifest.Name] = ns[i].Hash
|
||||||
|
}
|
||||||
|
|
||||||
initCtx := &initializeContext{
|
initCtx := &initializeContext{
|
||||||
Client: c,
|
Client: c,
|
||||||
ConsensusAcc: consensusAcc,
|
ConsensusAcc: consensusAcc,
|
||||||
|
@ -139,11 +150,16 @@ func newInitializeContext(cmd *cobra.Command, v *viper.Viper) (*initializeContex
|
||||||
Command: cmd,
|
Command: cmd,
|
||||||
Contracts: make(map[string]*contractState),
|
Contracts: make(map[string]*contractState),
|
||||||
ContractPath: ctrPath,
|
ContractPath: ctrPath,
|
||||||
|
Natives: nativeHashes,
|
||||||
}
|
}
|
||||||
|
|
||||||
return initCtx, nil
|
return initCtx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *initializeContext) nativeHash(name string) util.Uint160 {
|
||||||
|
return c.Natives[name]
|
||||||
|
}
|
||||||
|
|
||||||
func openAlphabetWallets(walletDir string) ([]*wallet.Wallet, error) {
|
func openAlphabetWallets(walletDir string) ([]*wallet.Wallet, error) {
|
||||||
walletFiles, err := ioutil.ReadDir(walletDir)
|
walletFiles, err := ioutil.ReadDir(walletDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (c *initializeContext) deployNNS() error {
|
||||||
Scopes: transaction.CalledByEntry,
|
Scopes: transaction.CalledByEntry,
|
||||||
}
|
}
|
||||||
|
|
||||||
mgmtHash, _ := c.Client.GetNativeContractHash(nativenames.Management)
|
mgmtHash := c.nativeHash(nativenames.Management)
|
||||||
res, err := c.Client.InvokeFunction(mgmtHash, "deploy", params, []transaction.Signer{signer})
|
res, err := c.Client.InvokeFunction(mgmtHash, "deploy", params, []transaction.Signer{signer})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't deploy contract: %w", err)
|
return fmt.Errorf("can't deploy contract: %w", err)
|
||||||
|
@ -109,7 +109,7 @@ func (c *initializeContext) deployNNS() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) deployContracts() error {
|
func (c *initializeContext) deployContracts() error {
|
||||||
mgmtHash, _ := c.Client.GetNativeContractHash(nativenames.Management)
|
mgmtHash := c.nativeHash(nativenames.Management)
|
||||||
sender := c.CommitteeAcc.Contract.ScriptHash()
|
sender := c.CommitteeAcc.Contract.ScriptHash()
|
||||||
for _, ctrName := range contractList {
|
for _, ctrName := range contractList {
|
||||||
cs, err := c.readContract(ctrName)
|
cs, err := c.readContract(ctrName)
|
||||||
|
|
|
@ -22,10 +22,7 @@ import (
|
||||||
const initialAlphabetNEOAmount = native.NEOTotalSupply
|
const initialAlphabetNEOAmount = native.NEOTotalSupply
|
||||||
|
|
||||||
func (c *initializeContext) registerCandidates() error {
|
func (c *initializeContext) registerCandidates() error {
|
||||||
neoHash, err := c.Client.GetNativeContractHash(nativenames.Neo)
|
neoHash := c.nativeHash(nativenames.Neo)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := c.Client.InvokeFunction(neoHash, "getCandidates", []smartcontract.Parameter{}, nil)
|
res, err := c.Client.InvokeFunction(neoHash, "getCandidates", []smartcontract.Parameter{}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -72,10 +69,7 @@ func (c *initializeContext) registerCandidates() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) transferNEOToAlphabetContracts() error {
|
func (c *initializeContext) transferNEOToAlphabetContracts() error {
|
||||||
neoHash, err := c.Client.GetNativeContractHash(nativenames.Neo)
|
neoHash := c.nativeHash(nativenames.Neo)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ok, err := c.transferNEOFinished(neoHash)
|
ok, err := c.transferNEOFinished(neoHash)
|
||||||
if ok || err != nil {
|
if ok || err != nil {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package morph
|
package morph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
@ -18,10 +16,7 @@ func (c *initializeContext) setNotaryAndAlphabetNodes() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
designateHash, err := c.Client.GetNativeContractHash(nativenames.Designation)
|
designateHash := c.nativeHash(nativenames.Designation)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't fetch %s hash: %w", nativenames.Designation, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var pubs []interface{}
|
var pubs []interface{}
|
||||||
for _, w := range c.Wallets {
|
for _, w := range c.Wallets {
|
||||||
|
|
|
@ -28,14 +28,8 @@ func (c *initializeContext) transferFunds() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gasHash, err := c.Client.GetNativeContractHash(nativenames.Gas)
|
gasHash := c.nativeHash(nativenames.Gas)
|
||||||
if err != nil {
|
neoHash := c.nativeHash(nativenames.Neo)
|
||||||
return fmt.Errorf("can't fetch %s hash: %w", nativenames.Gas, err)
|
|
||||||
}
|
|
||||||
neoHash, err := c.Client.GetNativeContractHash(nativenames.Neo)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't fetch %s hash: %w", nativenames.Neo, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var transfers []client.TransferTarget
|
var transfers []client.TransferTarget
|
||||||
for _, w := range c.Wallets {
|
for _, w := range c.Wallets {
|
||||||
|
@ -87,10 +81,7 @@ func (c *initializeContext) transferFunds() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) transferFundsFinished() (bool, error) {
|
func (c *initializeContext) transferFundsFinished() (bool, error) {
|
||||||
gasHash, err := c.Client.GetNativeContractHash(nativenames.Gas)
|
gasHash := c.nativeHash(nativenames.Gas)
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
acc, err := getWalletAccount(c.Wallets[0], singleAccountName)
|
acc, err := getWalletAccount(c.Wallets[0], singleAccountName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -150,11 +141,7 @@ func (c *initializeContext) multiSign(tx *transaction.Transaction, accType strin
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) transferGASToProxy() error {
|
func (c *initializeContext) transferGASToProxy() error {
|
||||||
gasHash, err := c.Client.GetNativeContractHash(nativenames.Gas)
|
gasHash := c.nativeHash(nativenames.Gas)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't fetch %s hash: %w", nativenames.Gas, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cs, err := c.readContract(proxyContract)
|
cs, err := c.readContract(proxyContract)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue