2022-08-31 19:38:35 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/cli/options"
|
|
|
|
"github.com/nspcc-dev/neo-go/cli/paramcontext"
|
2023-12-28 11:58:38 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/txctx"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/waiter"
|
2024-07-09 18:24:39 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2022-08-31 19:38:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func sendTx(ctx *cli.Context) error {
|
2024-07-09 18:24:39 +00:00
|
|
|
args := ctx.Args().Slice()
|
2022-08-31 19:38:35 +00:00
|
|
|
if len(args) == 0 {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit("missing input file", 1)
|
2022-08-31 19:38:35 +00:00
|
|
|
} else if len(args) > 1 {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit("only one input file is accepted", 1)
|
2022-08-31 19:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pc, err := paramcontext.Read(args[0])
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(err, 1)
|
2022-08-31 19:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tx, err := pc.GetCompleteTransaction()
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Errorf("failed to complete transaction: %w", err), 1)
|
2022-08-31 19:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
c, err := options.GetRPCClient(gctx, ctx)
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Errorf("failed to create RPC client: %w", err), 1)
|
2022-08-31 19:38:35 +00:00
|
|
|
}
|
|
|
|
res, err := c.SendRawTransaction(tx)
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Errorf("failed to submit transaction to RPC node: %w", err), 1)
|
2022-08-31 19:38:35 +00:00
|
|
|
}
|
2023-12-28 11:58:38 +00:00
|
|
|
var aer *state.AppExecResult
|
|
|
|
if ctx.Bool("await") {
|
|
|
|
version, err := c.GetVersion()
|
|
|
|
aer, err = waiter.New(c, version).Wait(res, tx.ValidUntilBlock, err)
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(fmt.Errorf("failed to await transaction %s: %w", res.StringLE(), err), 1)
|
2023-12-28 11:58:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
txctx.DumpTransactionInfo(ctx.App.Writer, res, aer)
|
2022-08-31 19:38:35 +00:00
|
|
|
return nil
|
|
|
|
}
|