[#404] innerring: Get GAS script hash from neo-go client

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-02-19 16:48:20 +03:00 committed by Alex Vanin
parent 883a2e3e77
commit 948823c392
3 changed files with 7 additions and 23 deletions

View file

@ -67,8 +67,6 @@ func defaultConfiguration(cfg *viper.Viper) {
cfg.SetDefault("contracts.audit", "") cfg.SetDefault("contracts.audit", "")
// alphabet contracts // alphabet contracts
cfg.SetDefault("contracts.alphabet.amount", 7) cfg.SetDefault("contracts.alphabet.amount", 7)
// gas native contract in LE
cfg.SetDefault("contracts.gas", "70e2301955bf1e74cbb31d18c2f96972abadb328")
cfg.SetDefault("timers.epoch", "0") cfg.SetDefault("timers.epoch", "0")
cfg.SetDefault("timers.emit", "0") cfg.SetDefault("timers.emit", "0")

View file

@ -88,7 +88,6 @@ type (
balance util.Uint160 // in morph balance util.Uint160 // in morph
container util.Uint160 // in morph container util.Uint160 // in morph
audit util.Uint160 // in morph audit util.Uint160 // in morph
gas util.Uint160 // native contract in both chains
alphabet alphabetContracts // in morph alphabet alphabetContracts // in morph
} }
@ -222,7 +221,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
log: log, log: log,
cfg: cfg, cfg: cfg,
key: server.key, key: server.key,
gas: server.contracts.gas,
name: morphPrefix, name: morphPrefix,
} }
@ -557,7 +555,6 @@ func createClient(ctx context.Context, p *chainParams) (*client.Client, error) {
client.WithContext(ctx), client.WithContext(ctx),
client.WithLogger(p.log), client.WithLogger(p.log),
client.WithDialTimeout(p.cfg.GetDuration(p.name+".dial_timeouts")), client.WithDialTimeout(p.cfg.GetDuration(p.name+".dial_timeouts")),
client.WithGasContract(p.gas),
) )
} }
@ -570,7 +567,6 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) {
netmapContractStr := cfg.GetString("contracts.netmap") netmapContractStr := cfg.GetString("contracts.netmap")
neofsContractStr := cfg.GetString("contracts.neofs") neofsContractStr := cfg.GetString("contracts.neofs")
balanceContractStr := cfg.GetString("contracts.balance") balanceContractStr := cfg.GetString("contracts.balance")
nativeGasContractStr := cfg.GetString("contracts.gas")
containerContractStr := cfg.GetString("contracts.container") containerContractStr := cfg.GetString("contracts.container")
auditContractStr := cfg.GetString("contracts.audit") auditContractStr := cfg.GetString("contracts.audit")
@ -589,11 +585,6 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) {
return nil, errors.Wrap(err, "ir: can't read balance script-hash") return nil, errors.Wrap(err, "ir: can't read balance script-hash")
} }
result.gas, err = util.Uint160DecodeStringLE(nativeGasContractStr)
if err != nil {
return nil, errors.Wrap(err, "ir: can't read native gas script-hash")
}
result.container, err = util.Uint160DecodeStringLE(containerContractStr) result.container, err = util.Uint160DecodeStringLE(containerContractStr)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "ir: can't read container script-hash") return nil, errors.Wrap(err, "ir: can't read container script-hash")

View file

@ -5,6 +5,7 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"time" "time"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/rpc/client" "github.com/nspcc-dev/neo-go/pkg/rpc/client"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
@ -35,7 +36,6 @@ func defaultConfig() *cfg {
ctx: context.Background(), ctx: context.Background(),
dialTimeout: defaultDialTimeout, dialTimeout: defaultDialTimeout,
logger: zap.L(), logger: zap.L(),
gas: util.Uint160{},
} }
} }
@ -89,11 +89,16 @@ func New(key *ecdsa.PrivateKey, endpoint string, opts ...Option) (*Client, error
return nil, err return nil, err
} }
gas, err := cli.GetNativeContractHash(nativenames.Gas)
if err != nil {
return nil, err
}
return &Client{ return &Client{
logger: cfg.logger, logger: cfg.logger,
client: cli, client: cli,
acc: account, acc: account,
gas: cfg.gas, gas: gas,
}, nil }, nil
} }
@ -138,13 +143,3 @@ func WithLogger(logger *logger.Logger) Option {
} }
} }
} }
// WithGasContract returns a client constructor option
// that specifies native gas contract script hash.
//
// If option not provided, empty script hash is used.
func WithGasContract(gas util.Uint160) Option {
return func(c *cfg) {
c.gas = gas
}
}