Commit 4649ff57 authored by David Vorick's avatar David Vorick

add /consensus/constants endpoint, replica of /daemon/constants

parent 40f0ab37
Pipeline #40810365 failed with stages
in 27 minutes and 41 seconds
......@@ -3,6 +3,7 @@ package api
import (
"encoding/json"
"fmt"
"math/big"
"net/http"
"gitlab.com/NebulousLabs/Sia/crypto"
......@@ -85,6 +86,31 @@ type ConsensusBlocksGetSiafundOutput struct {
UnlockHash types.UnlockHash `json:"unlockhash"`
}
// SiaConstants is a struct listing all of the constants in use.
type ConsensusConstants struct {
BlockFrequency types.BlockHeight `json:"blockfrequency"`
BlockSizeLimit uint64 `json:"blocksizelimit"`
ExtremeFutureThreshold types.Timestamp `json:"extremefuturethreshold"`
FutureThreshold types.Timestamp `json:"futurethreshold"`
GenesisTimestamp types.Timestamp `json:"genesistimestamp"`
MaturityDelay types.BlockHeight `json:"maturitydelay"`
MedianTimestampWindow uint64 `json:"mediantimestampwindow"`
SiafundCount types.Currency `json:"siafundcount"`
SiafundPortion *big.Rat `json:"siafundportion"`
TargetWindow types.BlockHeight `json:"targetwindow"`
InitialCoinbase uint64 `json:"initialcoinbase"`
MinimumCoinbase uint64 `json:"minimumcoinbase"`
RootTarget types.Target `json:"roottarget"`
RootDepth types.Target `json:"rootdepth"`
MaxTargetAdjustmentUp *big.Rat `json:"maxtargetadjustmentup"`
MaxTargetAdjustmentDown *big.Rat `json:"maxtargetadjustmentdown"`
SiacoinPrecision types.Currency `json:"siacoinprecision"`
}
// ConsensusBlocksGetFromBlock is a helper method that uses a types.Block and
// types.BlockHeight to create a ConsensusBlocksGet object.
func consensusBlocksGetFromBlock(b types.Block, h types.BlockHeight) ConsensusBlocksGet {
......@@ -223,6 +249,34 @@ func (api *API) consensusBlocksHandler(w http.ResponseWriter, req *http.Request,
WriteJSON(w, consensusBlocksGetFromBlock(b, h))
}
// consensusConstatnsHandler returns the list of constants that are driving the
// consensus code.
func (api *API) consensusConstantsHandler(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
WriteJSON(w, ConsensusConstants{
BlockFrequency: types.BlockFrequency,
BlockSizeLimit: types.BlockSizeLimit,
ExtremeFutureThreshold: types.ExtremeFutureThreshold,
FutureThreshold: types.FutureThreshold,
GenesisTimestamp: types.GenesisTimestamp,
MaturityDelay: types.MaturityDelay,
MedianTimestampWindow: types.MedianTimestampWindow,
SiafundCount: types.SiafundCount,
SiafundPortion: types.SiafundPortion,
TargetWindow: types.TargetWindow,
InitialCoinbase: types.InitialCoinbase,
MinimumCoinbase: types.MinimumCoinbase,
RootTarget: types.RootTarget,
RootDepth: types.RootDepth,
MaxTargetAdjustmentUp: types.MaxTargetAdjustmentUp,
MaxTargetAdjustmentDown: types.MaxTargetAdjustmentDown,
SiacoinPrecision: types.SiacoinPrecision,
})
}
// consensusValidateTransactionsetHandler handles the API calls to
// /consensus/validate/transactionset.
func (api *API) consensusValidateTransactionsetHandler(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
......
......@@ -22,6 +22,7 @@ func (api *API) buildHTTPRoutes(requiredUserAgent string, requiredPassword strin
if api.cs != nil {
router.GET("/consensus", api.consensusHandler)
router.GET("/consensus/blocks", api.consensusBlocksHandler)
router.GET("/consensus/constants", api.consensusConstantsHandler)
router.POST("/consensus/validate/transactionset", api.consensusValidateTransactionsetHandler)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment