return nil, errors.Wrapf(err, "tx %s", tpl.Transaction.ID.String())
}
- return map[string]string{"txid": tpl.Transaction.ID.String()}, nil
+ return map[string]string{"tx_id": tpl.Transaction.ID.String()}, nil
}
// finalizeTxWait calls FinalizeTx and then waits for confirmation of
return NewErrorResponse(err)
}
- log.WithField("txid", txID["txid"]).Info("submit single tx")
+ log.WithField("tx_id", txID["tx_id"]).Info("submit single tx")
return NewSuccessResponse(txID)
}
return NewErrorResponse(err)
}
- log.WithField("txid", txID["txid"]).Info("submit single tx")
+ log.WithField("tx_id", txID["tx_id"]).Info("submit single tx")
return NewSuccessResponse(txID)
}
package commands
import (
+ "encoding/hex"
"os"
"strconv"
+ "unicode"
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
+
+ chainjson "github.com/bytom/encoding/json"
"github.com/bytom/util"
)
},
}
-var getBlockByHashCmd = &cobra.Command{
- Use: "get-block-by-hash <hash>",
- Short: "Get a whole block matching the given hash",
+var getBlockCmd = &cobra.Command{
+ Use: "get-block <hash> | <height>",
+ Short: "Get a whole block matching the given hash or height",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
- data, exitCode := util.ClientCall("/get-block-by-hash", args[0])
+ var hash chainjson.HexBytes
+ var height uint64
+ var err error
+ isNumber := false
+
+ for _, ch := range args[0] {
+ // check whether the char is hex digit
+ if !(unicode.IsNumber(ch) || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) {
+ jww.ERROR.Printf("Invalid value for hash or height")
+ os.Exit(util.ErrLocalExe)
+ }
+
+ if !unicode.IsNumber(ch) {
+ isNumber = true
+ }
+ }
+
+ if isNumber {
+ if len(args[0]) != 64 {
+ jww.ERROR.Printf("Invalid hash length")
+ os.Exit(util.ErrLocalExe)
+ }
+
+ hash, err = hex.DecodeString(args[0])
+ if err != nil {
+ jww.ERROR.Println(err)
+ os.Exit(util.ErrLocalExe)
+ }
+ } else {
+ height, err = strconv.ParseUint(args[0], 10, 64)
+ if err != nil {
+ jww.ERROR.Printf("Invalid height value")
+ os.Exit(util.ErrLocalExe)
+ }
+ }
+
+ blockReq := &struct {
+ BlockHeight uint64 `json:"block_height"`
+ BlockHash chainjson.HexBytes `json:"block_hash"`
+ }{BlockHeight: height, BlockHash: hash}
+
+ data, exitCode := util.ClientCall("/get-block", blockReq)
if exitCode != util.Success {
os.Exit(exitCode)
}
},
}
-var getBlockByHeightCmd = &cobra.Command{
- Use: "get-block-by-height <height>",
- Short: "Get a whole block matching the given height",
- Args: cobra.ExactArgs(1),
- Run: func(cmd *cobra.Command, args []string) {
- height, err := strconv.ParseUint(args[0], 10, 64)
- if err != nil {
- jww.ERROR.Printf("Invalid height value")
- os.Exit(util.ErrLocalExe)
- }
-
- data, exitCode := util.ClientCall("/get-block-by-height", height)
- if exitCode != util.Success {
- os.Exit(exitCode)
- }
-
- printJSON(data)
- },
-}
-
var getBlockTransactionsCountByHeightCmd = &cobra.Command{
Use: "get-block-transactions-count-by-height",
Short: "Get the transactions count of a block matching the given height",