Merge pull request #2033 from nspcc-dev/sysgas
cli/sc: add sysgas option to add some gas
This commit is contained in:
commit
e5d26a5df1
3 changed files with 24 additions and 8 deletions
|
@ -54,7 +54,11 @@ var (
|
||||||
}
|
}
|
||||||
gasFlag = flags.Fixed8Flag{
|
gasFlag = flags.Fixed8Flag{
|
||||||
Name: "gas, g",
|
Name: "gas, g",
|
||||||
Usage: "gas to add to the transaction",
|
Usage: "network fee to add to the transaction (prioritizing it)",
|
||||||
|
}
|
||||||
|
sysGasFlag = flags.Fixed8Flag{
|
||||||
|
Name: "sysgas, e",
|
||||||
|
Usage: "system fee to add to transaction (compensating for execution)",
|
||||||
}
|
}
|
||||||
outFlag = cli.StringFlag{
|
outFlag = cli.StringFlag{
|
||||||
Name: "out",
|
Name: "out",
|
||||||
|
@ -99,6 +103,7 @@ func NewCommands() []cli.Command {
|
||||||
walletFlag,
|
walletFlag,
|
||||||
addressFlag,
|
addressFlag,
|
||||||
gasFlag,
|
gasFlag,
|
||||||
|
sysGasFlag,
|
||||||
outFlag,
|
outFlag,
|
||||||
forceFlag,
|
forceFlag,
|
||||||
}
|
}
|
||||||
|
@ -163,7 +168,7 @@ func NewCommands() []cli.Command {
|
||||||
{
|
{
|
||||||
Name: "deploy",
|
Name: "deploy",
|
||||||
Usage: "deploy a smart contract (.nef with description)",
|
Usage: "deploy a smart contract (.nef with description)",
|
||||||
UsageText: "neo-go contract deploy -r endpoint -w wallet [-a address] [-g gas] --in contract.nef --manifest contract.manifest.json [--out file] [--force] [data]",
|
UsageText: "neo-go contract deploy -r endpoint -w wallet [-a address] [-g gas] [-e sysgas] --in contract.nef --manifest contract.manifest.json [--out file] [--force] [data]",
|
||||||
Description: `Deploys given contract into the chain. The gas parameter is for additional
|
Description: `Deploys given contract into the chain. The gas parameter is for additional
|
||||||
gas to be added as a network fee to prioritize the transaction. The data
|
gas to be added as a network fee to prioritize the transaction. The data
|
||||||
parameter is an optional parameter to be passed to '_deploy' method.
|
parameter is an optional parameter to be passed to '_deploy' method.
|
||||||
|
@ -174,7 +179,7 @@ func NewCommands() []cli.Command {
|
||||||
{
|
{
|
||||||
Name: "invokefunction",
|
Name: "invokefunction",
|
||||||
Usage: "invoke deployed contract on the blockchain",
|
Usage: "invoke deployed contract on the blockchain",
|
||||||
UsageText: "neo-go contract invokefunction -r endpoint -w wallet [-a address] [-g gas] [--out file] [--force] scripthash [method] [arguments...] [--] [signers...]",
|
UsageText: "neo-go contract invokefunction -r endpoint -w wallet [-a address] [-g gas] [-e sysgas] [--out file] [--force] scripthash [method] [arguments...] [--] [signers...]",
|
||||||
Description: `Executes given (as a script hash) deployed script with the given method,
|
Description: `Executes given (as a script hash) deployed script with the given method,
|
||||||
arguments and signers. Sender is included in the list of signers by default
|
arguments and signers. Sender is included in the list of signers by default
|
||||||
with None witness scope. If you'd like to change default sender's scope,
|
with None witness scope. If you'd like to change default sender's scope,
|
||||||
|
@ -562,7 +567,7 @@ func invokeInternal(ctx *cli.Context, signAndPush bool) error {
|
||||||
func invokeWithArgs(ctx *cli.Context, signAndPush bool, script util.Uint160, operation string, params []smartcontract.Parameter, cosigners []transaction.Signer) (util.Uint160, error) {
|
func invokeWithArgs(ctx *cli.Context, signAndPush bool, script util.Uint160, operation string, params []smartcontract.Parameter, cosigners []transaction.Signer) (util.Uint160, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
gas fixedn.Fixed8
|
gas, sysgas fixedn.Fixed8
|
||||||
cosignersAccounts []client.SignerAccount
|
cosignersAccounts []client.SignerAccount
|
||||||
resp *result.Invoke
|
resp *result.Invoke
|
||||||
acc *wallet.Account
|
acc *wallet.Account
|
||||||
|
@ -571,6 +576,7 @@ func invokeWithArgs(ctx *cli.Context, signAndPush bool, script util.Uint160, ope
|
||||||
)
|
)
|
||||||
if signAndPush {
|
if signAndPush {
|
||||||
gas = flags.Fixed8FromContext(ctx, "gas")
|
gas = flags.Fixed8FromContext(ctx, "gas")
|
||||||
|
sysgas = flags.Fixed8FromContext(ctx, "sysgas")
|
||||||
acc, wall, err = getAccFromContext(ctx)
|
acc, wall, err = getAccFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sender, err
|
return sender, err
|
||||||
|
@ -604,7 +610,7 @@ func invokeWithArgs(ctx *cli.Context, signAndPush bool, script util.Uint160, ope
|
||||||
fmt.Fprintln(ctx.App.Writer, errText+". Sending transaction...")
|
fmt.Fprintln(ctx.App.Writer, errText+". Sending transaction...")
|
||||||
}
|
}
|
||||||
if out := ctx.String("out"); out != "" {
|
if out := ctx.String("out"); out != "" {
|
||||||
tx, err := c.CreateTxFromScript(resp.Script, acc, resp.GasConsumed, int64(gas), cosignersAccounts)
|
tx, err := c.CreateTxFromScript(resp.Script, acc, resp.GasConsumed+int64(sysgas), int64(gas), cosignersAccounts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sender, cli.NewExitError(fmt.Errorf("failed to create tx: %w", err), 1)
|
return sender, cli.NewExitError(fmt.Errorf("failed to create tx: %w", err), 1)
|
||||||
}
|
}
|
||||||
|
@ -618,7 +624,7 @@ func invokeWithArgs(ctx *cli.Context, signAndPush bool, script util.Uint160, ope
|
||||||
if len(resp.Script) == 0 {
|
if len(resp.Script) == 0 {
|
||||||
return sender, cli.NewExitError(errors.New("no script returned from the RPC node"), 1)
|
return sender, cli.NewExitError(errors.New("no script returned from the RPC node"), 1)
|
||||||
}
|
}
|
||||||
txHash, err := c.SignAndPushInvocationTx(resp.Script, acc, resp.GasConsumed, gas, cosignersAccounts)
|
txHash, err := c.SignAndPushInvocationTx(resp.Script, acc, resp.GasConsumed+int64(sysgas), gas, cosignersAccounts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sender, cli.NewExitError(fmt.Errorf("failed to push invocation tx: %w", err), 1)
|
return sender, cli.NewExitError(fmt.Errorf("failed to push invocation tx: %w", err), 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,6 +235,7 @@ func transferNEP11(ctx *cli.Context) error {
|
||||||
|
|
||||||
func signAndSendNEP11Transfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, token, to util.Uint160, tokenID string, amount *big.Int, data interface{}, cosigners []client.SignerAccount) error {
|
func signAndSendNEP11Transfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, token, to util.Uint160, tokenID string, amount *big.Int, data interface{}, cosigners []client.SignerAccount) error {
|
||||||
gas := flags.Fixed8FromContext(ctx, "gas")
|
gas := flags.Fixed8FromContext(ctx, "gas")
|
||||||
|
sysgas := flags.Fixed8FromContext(ctx, "sysgas")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tx *transaction.Transaction
|
tx *transaction.Transaction
|
||||||
|
@ -254,6 +255,7 @@ func signAndSendNEP11Transfer(ctx *cli.Context, c *client.Client, acc *wallet.Ac
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
tx.SystemFee += int64(sysgas)
|
||||||
|
|
||||||
if outFile := ctx.String("out"); outFile != "" {
|
if outFile := ctx.String("out"); outFile != "" {
|
||||||
if err := paramcontext.InitAndSave(c.GetNetwork(), tx, acc, outFile); err != nil {
|
if err := paramcontext.InitAndSave(c.GetNetwork(), tx, acc, outFile); err != nil {
|
||||||
|
|
|
@ -25,8 +25,12 @@ var (
|
||||||
Usage: "Token to use (hash or name (for NEO/GAS or imported tokens))",
|
Usage: "Token to use (hash or name (for NEO/GAS or imported tokens))",
|
||||||
}
|
}
|
||||||
gasFlag = flags.Fixed8Flag{
|
gasFlag = flags.Fixed8Flag{
|
||||||
Name: "gas",
|
Name: "gas, g",
|
||||||
Usage: "Amount of GAS to attach to a tx",
|
Usage: "network fee to add to the transaction (prioritizing it)",
|
||||||
|
}
|
||||||
|
sysGasFlag = flags.Fixed8Flag{
|
||||||
|
Name: "sysgas, e",
|
||||||
|
Usage: "system fee to add to transaction (compensating for execution)",
|
||||||
}
|
}
|
||||||
baseBalanceFlags = []cli.Flag{
|
baseBalanceFlags = []cli.Flag{
|
||||||
walletPathFlag,
|
walletPathFlag,
|
||||||
|
@ -50,6 +54,7 @@ var (
|
||||||
toAddrFlag,
|
toAddrFlag,
|
||||||
tokenFlag,
|
tokenFlag,
|
||||||
gasFlag,
|
gasFlag,
|
||||||
|
sysGasFlag,
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "amount",
|
Name: "amount",
|
||||||
Usage: "Amount of asset to send",
|
Usage: "Amount of asset to send",
|
||||||
|
@ -60,6 +65,7 @@ var (
|
||||||
outFlag,
|
outFlag,
|
||||||
fromAddrFlag,
|
fromAddrFlag,
|
||||||
gasFlag,
|
gasFlag,
|
||||||
|
sysGasFlag,
|
||||||
}, options.RPC...)
|
}, options.RPC...)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -561,11 +567,13 @@ func transferNEP(ctx *cli.Context, standard string) error {
|
||||||
|
|
||||||
func signAndSendNEP17Transfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, recipients []client.TransferTarget, cosigners []client.SignerAccount) error {
|
func signAndSendNEP17Transfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, recipients []client.TransferTarget, cosigners []client.SignerAccount) error {
|
||||||
gas := flags.Fixed8FromContext(ctx, "gas")
|
gas := flags.Fixed8FromContext(ctx, "gas")
|
||||||
|
sysgas := flags.Fixed8FromContext(ctx, "sysgas")
|
||||||
|
|
||||||
tx, err := c.CreateNEP17MultiTransferTx(acc, int64(gas), recipients, cosigners)
|
tx, err := c.CreateNEP17MultiTransferTx(acc, int64(gas), recipients, cosigners)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
tx.SystemFee += int64(sysgas)
|
||||||
|
|
||||||
if outFile := ctx.String("out"); outFile != "" {
|
if outFile := ctx.String("out"); outFile != "" {
|
||||||
if err := paramcontext.InitAndSave(c.GetNetwork(), tx, acc, outFile); err != nil {
|
if err := paramcontext.InitAndSave(c.GetNetwork(), tx, acc, outFile); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue