Commit f1623460 authored by David Vorick's avatar David Vorick

switch constants endpoint to being a part of consensusGET

parent 4649ff57
Pipeline #40811239 failed with stages
in 2 minutes and 30 seconds
......@@ -15,11 +15,35 @@ import (
// ConsensusGET contains general information about the consensus set, with tags
// to support idiomatic json encodings.
type ConsensusGET struct {
// Consensus status values.
Synced bool `json:"synced"`
Height types.BlockHeight `json:"height"`
CurrentBlock types.BlockID `json:"currentblock"`
Target types.Target `json:"target"`
Difficulty types.Currency `json:"difficulty"`
// Consensus code constants.
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"`
}
// ConsensusHeadersGET contains information from a blocks header.
......@@ -86,31 +110,6 @@ 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 {
......@@ -204,6 +203,28 @@ func (api *API) consensusHandler(w http.ResponseWriter, req *http.Request, _ htt
CurrentBlock: cbid,
Target: currentTarget,
Difficulty: currentTarget.Difficulty(),
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,
})
}
......@@ -249,34 +270,6 @@ 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) {
......
......@@ -34,6 +34,16 @@ func TestIntegrationConsensusGET(t *testing.T) {
if cg.Target != expectedTarget {
t.Error("wrong target returned in consensus GET call")
}
if cg.BlockFrequency != types.BlockFrequency {
t.Error("constant mismatch")
}
if cg.SiafundCount != types.SiafundCount {
t.Error("constant mismatch")
}
if cg.InitialCoinbase != types.InitialCoinbase {
t.Error("constant mismatch")
}
}
// TestConsensusValidateTransactionSet probes the POST call to
......
......@@ -22,7 +22,6 @@ 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