m.Handle("/net-syncing", jsonHandler(bcr.isNetSyncing))
m.Handle("/peer-count", jsonHandler(bcr.peerCount))
m.Handle("/get-block-by-height", jsonHandler(bcr.getBlockByHeight))
+ m.Handle("/get-block-transactions-count-by-height", jsonHandler(bcr.getBlockTransactionsCountByHeight))
+ m.Handle("/block-height", jsonHandler(bcr.getBlockHeight))
latencyHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if l := latency(m, req); l != nil {
func (bcr *BlockchainReactor) isNetSyncing() bool {
return bcr.blockKeeper.IsCaughtUp()
}
+
+func (bcr *BlockchainReactor) getBlockTransactionsCountByHeight(height uint64) (int, error) {
+ legacyBlock, err := bcr.chain.GetBlockByHeight(height)
+ if err != nil {
+ log.WithField("error", err).Error("Fail to get block by hash")
+ return -1, err
+ }
+ return len(legacyBlock.Transactions), nil
+}
+
+func (bcr *BlockchainReactor) getBlockHeight() uint64 {
+ return bcr.chain.Height()
+}
coreURL = env.String("BYTOM_URL", "http://localhost:1999")
)
-var getBestBlockHashCmd = &cobra.Command{
- Use: "get-best-block-hash",
- Short: "Get the most recent block hash",
+var blockHashCmd = &cobra.Command{
+ Use: "block-hash",
+ Short: "Get the hash of most recent block",
Run: func(cmd *cobra.Command, args []string) {
var response interface{}
client := mustRPCClient()
},
}
+var blockHeightCmd = &cobra.Command{
+ Use: "block-height",
+ Short: "Get the number of most recent block",
+ Run: func(cmd *cobra.Command, args []string) {
+ var response interface{}
+ client := mustRPCClient()
+ client.Call(context.Background(), "/block-height", nil, &response)
+ jww.FEEDBACK.Printf("block height: %v\n", response)
+ },
+}
+
var getBlockByHashCmd = &cobra.Command{
Use: "get-block-by-hash",
Short: "Get a whole block matching the given hash",
jww.FEEDBACK.Printf("%v\n", response)
},
}
+
+var getBlockTransactionsCountByHeightCmd = &cobra.Command{
+ Use: "get-block-transactions-count-by-height",
+ Short: "Get the transactions count of a block matching the given height",
+ Run: func(cmd *cobra.Command, args []string) {
+ if len(args) != 1 {
+ jww.ERROR.Println("get-block-header-by-height args not valid\nUsage: get-block-transactions-count-by-height [height]")
+ return
+ }
+
+ ui64, err := strconv.ParseUint(args[0], 10, 64)
+ if err != nil {
+ jww.ERROR.Printf("Invalid height value")
+ return
+ }
+ var response interface{}
+ client := mustRPCClient()
+ client.Call(context.Background(), "/get-block-transactions-count-by-height", ui64, &response)
+ jww.FEEDBACK.Printf("transactions count: %v\n", response)
+ },
+}
BytomcliCmd.AddCommand(bindAssetCmd)
BytomcliCmd.AddCommand(listAssetsCmd)
- BytomcliCmd.AddCommand(getBestBlockHashCmd)
+ BytomcliCmd.AddCommand(blockHeightCmd)
+ BytomcliCmd.AddCommand(blockHashCmd)
BytomcliCmd.AddCommand(getBlockByHashCmd)
BytomcliCmd.AddCommand(getBlockHeaderByHashCmd)
BytomcliCmd.AddCommand(getBlockTransactionsCountByHashCmd)
BytomcliCmd.AddCommand(getBlockByHeightCmd)
+ BytomcliCmd.AddCommand(getBlockTransactionsCountByHeightCmd)
BytomcliCmd.AddCommand(createKeyCmd)
BytomcliCmd.AddCommand(deleteKeyCmd)