/
actionsendraw.go
57 lines (49 loc) · 1.91 KB
/
actionsendraw.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2022 IoTeX Foundation
// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
package action
import (
"encoding/hex"
"github.com/iotexproject/iotex-proto/golang/iotextypes"
"github.com/spf13/cobra"
"google.golang.org/protobuf/proto"
"github.com/iotexproject/iotex-core/ioctl/config"
"github.com/iotexproject/iotex-core/ioctl/output"
)
// Multi-language support
var (
_sendRawCmdShorts = map[config.Language]string{
config.English: "Send raw action on IoTeX blokchain",
config.Chinese: "在IoTeX区块链上发送原始行为",
}
_sendRawCmdUses = map[config.Language]string{
config.English: "sendraw DATA [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
config.Chinese: "sendraw 数据 [-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
}
)
// _actionSendRawCmd represents the action send raw transaction command
var _actionSendRawCmd = &cobra.Command{
Use: config.TranslateInLang(_sendRawCmdUses, config.UILanguage),
Short: config.TranslateInLang(_sendRawCmdShorts, config.UILanguage),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
err := sendRaw(args[0])
return output.PrintError(err)
},
}
func init() {
RegisterWriteCommand(_actionSendRawCmd)
}
func sendRaw(arg string) error {
actBytes, err := hex.DecodeString(arg)
if err != nil {
return output.NewError(output.ConvertError, "failed to decode data", err)
}
act := &iotextypes.Action{}
if err := proto.Unmarshal(actBytes, act); err != nil {
return output.NewError(output.SerializationError, "failed to unmarshal data bytes", err)
}
return SendRaw(act)
}