"github.com/bytom/protocol"
"github.com/bytom/protocol/bc"
"github.com/bytom/protocol/bc/legacy"
+ "github.com/bytom/protocol/validation"
"github.com/bytom/types"
)
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))
+ m.Handle("/is-mining", jsonHandler(bcr.isMining))
+ m.Handle("/gas-rate", jsonHandler(bcr.gasRate))
latencyHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if l := latency(m, req); l != nil {
func (bcr *BlockchainReactor) getBlockHeight() uint64 {
return bcr.chain.Height()
}
+
+func (bcr *BlockchainReactor) isMining() bool {
+ return bcr.mining.IsMining()
+}
+
+func (bcr *BlockchainReactor) gasRate() int64 {
+ return validation.GasRate
+}
BytomcliCmd.AddCommand(deleteKeyCmd)
BytomcliCmd.AddCommand(listKeysCmd)
+ BytomcliCmd.AddCommand(isMiningCmd)
+
BytomcliCmd.AddCommand(netInfoCmd)
BytomcliCmd.AddCommand(netListeningCmd)
BytomcliCmd.AddCommand(peerCountCmd)
BytomcliCmd.AddCommand(netSyncingCmd)
+ BytomcliCmd.AddCommand(gasRateCmd)
+
BytomcliCmd.AddCommand(createAccessTokenCmd)
BytomcliCmd.AddCommand(listAccessTokenCmd)
BytomcliCmd.AddCommand(deleteAccessTokenCmd)
--- /dev/null
+package commands
+
+import (
+ "context"
+
+ "github.com/spf13/cobra"
+ jww "github.com/spf13/jwalterweatherman"
+)
+
+var isMiningCmd = &cobra.Command{
+ Use: "is-mining",
+ Short: "If client is actively mining new blocks",
+ Run: func(cmd *cobra.Command, args []string) {
+ var response interface{}
+ client := mustRPCClient()
+ client.Call(context.Background(), "/is-mining", nil, &response)
+ jww.FEEDBACK.Printf("is mining: %v\n", response)
+ },
+}
--- /dev/null
+package commands
+
+import (
+ "context"
+
+ "github.com/spf13/cobra"
+ jww "github.com/spf13/jwalterweatherman"
+)
+
+var gasRateCmd = &cobra.Command{
+ Use: "gas-rate",
+ Short: "Print the current gas rate",
+ Run: func(cmd *cobra.Command, args []string) {
+ var response interface{}
+ client := mustRPCClient()
+ client.Call(context.Background(), "/gas-rate", nil, &response)
+ jww.FEEDBACK.Printf("gas rate: %v\n", response)
+ },
+}
const (
defaultGasLimit = int64(80000)
muxGasCost = int64(10)
- gasRate = int64(1000)
+ // GasRate indicates the current gas rate
+ GasRate = int64(1000)
)
type gasState struct {
}
g.BTMValue = BTMValue
- if gasAmount, ok := checked.DivInt64(BTMValue, gasRate); ok {
+ if gasAmount, ok := checked.DivInt64(BTMValue, GasRate); ok {
if gasAmount == 0 {
g.gasLeft = muxGasCost
} else if gasAmount < defaultGasLimit {