2021-09-14 12:02:54 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/cli/options"
|
|
|
|
"github.com/nspcc-dev/neo-go/cli/paramcontext"
|
|
|
|
"github.com/nspcc-dev/neo-go/cli/query"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
2024-07-09 18:24:39 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-09-14 12:02:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func txDump(ctx *cli.Context) error {
|
2024-07-09 18:24:39 +00:00
|
|
|
args := ctx.Args().Slice()
|
2022-08-05 10:32:37 +00:00
|
|
|
if len(args) == 0 {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit("missing input file", 1)
|
2022-08-05 10:32:37 +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)
|
2021-09-14 12:02:54 +00:00
|
|
|
}
|
|
|
|
|
2022-08-05 10:32:37 +00:00
|
|
|
c, err := paramcontext.Read(args[0])
|
2021-09-14 12:02:54 +00:00
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(err, 1)
|
2021-09-14 12:02:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tx, ok := c.Verifiable.(*transaction.Transaction)
|
|
|
|
if !ok {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit("verifiable item is not a transaction", 1)
|
2021-09-14 12:02:54 +00:00
|
|
|
}
|
|
|
|
|
2023-10-12 15:07:54 +00:00
|
|
|
err = query.DumpApplicationLog(ctx, nil, tx, nil, true)
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(err, 1)
|
2023-10-12 15:07:54 +00:00
|
|
|
}
|
2021-09-14 12:02:54 +00:00
|
|
|
|
|
|
|
if ctx.String(options.RPCEndpointFlag) != "" {
|
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
var err error
|
|
|
|
cl, err := options.GetRPCClient(gctx, ctx)
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(err, 1)
|
2021-09-14 12:02:54 +00:00
|
|
|
}
|
|
|
|
res, err := cl.InvokeScript(tx.Script, tx.Signers)
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(err, 1)
|
2021-09-14 12:02:54 +00:00
|
|
|
}
|
|
|
|
resS, err := json.MarshalIndent(res, "", " ")
|
|
|
|
if err != nil {
|
2024-07-09 18:24:39 +00:00
|
|
|
return cli.Exit(err, 1)
|
2021-09-14 12:02:54 +00:00
|
|
|
}
|
|
|
|
fmt.Fprintln(ctx.App.Writer, string(resS))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|