github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/cli/util/send.go (about) 1 package util 2 3 import ( 4 "fmt" 5 6 "github.com/nspcc-dev/neo-go/cli/options" 7 "github.com/nspcc-dev/neo-go/cli/paramcontext" 8 "github.com/nspcc-dev/neo-go/cli/txctx" 9 "github.com/nspcc-dev/neo-go/pkg/core/state" 10 "github.com/nspcc-dev/neo-go/pkg/rpcclient/waiter" 11 "github.com/urfave/cli" 12 ) 13 14 func sendTx(ctx *cli.Context) error { 15 args := ctx.Args() 16 if len(args) == 0 { 17 return cli.NewExitError("missing input file", 1) 18 } else if len(args) > 1 { 19 return cli.NewExitError("only one input file is accepted", 1) 20 } 21 22 pc, err := paramcontext.Read(args[0]) 23 if err != nil { 24 return cli.NewExitError(err, 1) 25 } 26 27 tx, err := pc.GetCompleteTransaction() 28 if err != nil { 29 return cli.NewExitError(fmt.Errorf("failed to complete transaction: %w", err), 1) 30 } 31 32 gctx, cancel := options.GetTimeoutContext(ctx) 33 defer cancel() 34 35 c, err := options.GetRPCClient(gctx, ctx) 36 if err != nil { 37 return cli.NewExitError(fmt.Errorf("failed to create RPC client: %w", err), 1) 38 } 39 res, err := c.SendRawTransaction(tx) 40 if err != nil { 41 return cli.NewExitError(fmt.Errorf("failed to submit transaction to RPC node: %w", err), 1) 42 } 43 var aer *state.AppExecResult 44 if ctx.Bool("await") { 45 version, err := c.GetVersion() 46 aer, err = waiter.New(c, version).Wait(res, tx.ValidUntilBlock, err) 47 if err != nil { 48 return cli.NewExitError(fmt.Errorf("failed to await transaction %s: %w", res.StringLE(), err), 1) 49 } 50 } 51 txctx.DumpTransactionInfo(ctx.App.Writer, res, aer) 52 return nil 53 }