github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/action/actionsendraw.go (about) 1 // Copyright (c) 2022 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package action 7 8 import ( 9 "encoding/hex" 10 11 "github.com/iotexproject/iotex-proto/golang/iotextypes" 12 "github.com/pkg/errors" 13 "github.com/spf13/cobra" 14 "google.golang.org/protobuf/proto" 15 16 "github.com/iotexproject/iotex-core/ioctl" 17 "github.com/iotexproject/iotex-core/ioctl/config" 18 ) 19 20 // Multi-language support 21 var ( 22 _sendRawCmdShorts = map[config.Language]string{ 23 config.English: "Send raw action on IoTeX blokchain", 24 config.Chinese: "在IoTeX区块链上发送原始行为", 25 } 26 _sendRawCmdUses = map[config.Language]string{ 27 config.English: "sendraw DATA", 28 config.Chinese: "sendraw 数据", 29 } 30 ) 31 32 // NewActionSendRawCmd represents the action send raw transaction command 33 func NewActionSendRawCmd(client ioctl.Client) *cobra.Command { 34 use, _ := client.SelectTranslation(_sendRawCmdUses) 35 short, _ := client.SelectTranslation(_sendRawCmdShorts) 36 37 return &cobra.Command{ 38 Use: use, 39 Short: short, 40 Args: cobra.ExactArgs(1), 41 RunE: func(cmd *cobra.Command, args []string) error { 42 cmd.SilenceUsage = true 43 actBytes, err := hex.DecodeString(args[0]) 44 if err != nil { 45 return errors.Wrap(err, "failed to decode data") 46 } 47 act := &iotextypes.Action{} 48 if err := proto.Unmarshal(actBytes, act); err != nil { 49 return errors.Wrap(err, "failed to unmarshal data bytes") 50 } 51 return SendRaw(client, cmd, act) 52 }, 53 } 54 }