github.com/avahowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/api/daemon.go (about)

     1  package api
     2  
     3  import (
     4  	"math/big"
     5  	"net/http"
     6  
     7  	"github.com/NebulousLabs/Sia/build"
     8  	"github.com/NebulousLabs/Sia/types"
     9  
    10  	"github.com/julienschmidt/httprouter"
    11  )
    12  
    13  const (
    14  	// The developer key is used to sign updates and other important Sia-
    15  	// related information.
    16  	developerKey = `-----BEGIN PUBLIC KEY-----
    17  MIIEIjANBgkqhkiG9w0BAQEFAAOCBA8AMIIECgKCBAEAsoQHOEU6s/EqMDtw5HvA
    18  YPTUaBgnviMFbG3bMsRqSCD8ug4XJYh+Ik6WP0xgq+OPDehPiaXK8ghAtBiW1EJK
    19  mBRwlABXAzREZg8wRfG4l8Zj6ckAPJOgLn0jobXy6/SCQ+jZSWh4Y8DYr+LA3Mn3
    20  EOga7Jvhpc3fTZ232GBGJ1BobuNfRfYmwxSphv+T4vzIA3JUjVfa8pYZGIjh5XbJ
    21  5M8Lef0Xa9eqr6lYm5kQoOIXeOW56ImqI2BKg/I9NGw9phSPbwaFfy1V2kfHp5Xy
    22  DtKnyj/O9zDi+qUKjoIivnEoV+3DkioHUWv7Fpf7yx/9cPyckwvaBsTd9Cfp4uBx
    23  qJ5Qyv69VZQiD6DikNwgzjGbIjiLwfTObhInKZUoYl48yzgkR80ja5TW0SoidNvO
    24  4WTbWcLolOl522VarTs7wlgbq0Ad7yrNVnHzo447v2iT20ILH2oeAcZqvpcvRmTl
    25  U6uKoaVmBH3D3Y19dPluOjK53BrqfQ5L8RFli2wEJktPsi5fUTd4UI9BgnUieuDz
    26  S7h/VH9bv9ZVvyjpu/uVjdvaikT3zbIy9J6wS6uE5qPLPhI4B9HgbrQ03muDGpql
    27  gZrMiL3GdYrBiqpIbaWHfM0eMWEK3ZScUdtCgUXMMrkvaUJ4g9wEgbONFVVOMIV+
    28  YubIuzBFqug6WyxN/EAM/6Fss832AwVPcYM0NDTVGVdVplLMdN8YNjrYuaPngBCG
    29  e8QaTWtHzLujyBIkVdAHqfkRS65jp7JLLMx7jUA74/E/v+0cNew3Y1p2gt3iQH8t
    30  w93xn9IPUfQympc4h3KerP/Yn6P/qAh68jQkOiMMS+VbCq/BOn8Q3GbR+8rQ8dmk
    31  qVoGA7XrPQ6bymKBTghk2Ek+ZjxrpAoj0xYoYyzWf0kuxeOT8kAjlLLmfQ8pm75S
    32  QHLqH49FyfeETIU02rkw2oMOX/EYdJzZukHuouwbpKSElpRx+xTnaSemMJo+U7oX
    33  xVjma3Zynh9w12abnFWkZKtrxwXv7FCSzb0UZmMWUqWzCS03Rrlur21jp4q2Wl71
    34  Vt92xe5YbC/jbh386F1e/qGq6p+D1AmBynIpp/HE6fPsc9LWgJDDkREZcp7hthGW
    35  IdYPeP3CesFHnsZMueZRib0i7lNUkBSRneO1y/C9poNv1vOeTCNEE0jvhp/XOJuc
    36  yCQtrUSNALsvm7F+bnwP2F7K34k7MOlOgnTGqCqW+9WwBcjR44B0HI+YERCcRmJ8
    37  krBuVo9OBMV0cYBWpjo3UI9j3lHESCYhLnCz7SPap7C1yORc2ydJh+qjKqdLBHom
    38  t+JydcdJLbIG+kb3jB9QIIu5A4TlSGlHV6ewtxIWLS1473jEkITiVTt0Y5k+VLfW
    39  bwIDAQAB
    40  -----END PUBLIC KEY-----`
    41  )
    42  
    43  // SiaConstants is a struct listing all of the constants in use.
    44  type SiaConstants struct {
    45  	GenesisTimestamp      types.Timestamp   `json:"genesistimestamp"`
    46  	BlockSizeLimit        uint64            `json:"blocksizelimit"`
    47  	BlockFrequency        types.BlockHeight `json:"blockfrequency"`
    48  	TargetWindow          types.BlockHeight `json:"targetwindow"`
    49  	MedianTimestampWindow uint64            `json:"mediantimestampwindow"`
    50  	FutureThreshold       types.Timestamp   `json:"futurethreshold"`
    51  	SiafundCount          types.Currency    `json:"siafundcount"`
    52  	SiafundPortion        *big.Rat          `json:"siafundportion"`
    53  	MaturityDelay         types.BlockHeight `json:"maturitydelay"`
    54  
    55  	InitialCoinbase uint64 `json:"initialcoinbase"`
    56  	MinimumCoinbase uint64 `json:"minimumcoinbase"`
    57  
    58  	RootTarget types.Target `json:"roottarget"`
    59  	RootDepth  types.Target `json:"rootdepth"`
    60  
    61  	MaxAdjustmentUp   *big.Rat `json:"maxadjustmentup"`
    62  	MaxAdjustmentDown *big.Rat `json:"maxadjustmentdown"`
    63  
    64  	SiacoinPrecision types.Currency `json:"siacoinprecision"`
    65  }
    66  
    67  type DaemonVersion struct {
    68  	Version string `json:"version"`
    69  }
    70  
    71  // debugConstantsHandler prints a json file containing all of the constants.
    72  func (srv *Server) daemonConstantsHandler(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
    73  	sc := SiaConstants{
    74  		GenesisTimestamp:      types.GenesisTimestamp,
    75  		BlockSizeLimit:        types.BlockSizeLimit,
    76  		BlockFrequency:        types.BlockFrequency,
    77  		TargetWindow:          types.TargetWindow,
    78  		MedianTimestampWindow: types.MedianTimestampWindow,
    79  		FutureThreshold:       types.FutureThreshold,
    80  		SiafundCount:          types.SiafundCount,
    81  		SiafundPortion:        types.SiafundPortion,
    82  		MaturityDelay:         types.MaturityDelay,
    83  
    84  		InitialCoinbase: types.InitialCoinbase,
    85  		MinimumCoinbase: types.MinimumCoinbase,
    86  
    87  		RootTarget: types.RootTarget,
    88  		RootDepth:  types.RootDepth,
    89  
    90  		MaxAdjustmentUp:   types.MaxAdjustmentUp,
    91  		MaxAdjustmentDown: types.MaxAdjustmentDown,
    92  
    93  		SiacoinPrecision: types.SiacoinPrecision,
    94  	}
    95  
    96  	writeJSON(w, sc)
    97  }
    98  
    99  // daemonVersionHandler handles the API call that requests the daemon's version.
   100  func (srv *Server) daemonVersionHandler(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
   101  	writeJSON(w, DaemonVersion{Version: build.Version})
   102  }
   103  
   104  // daemonStopHandler handles the API call to stop the daemon cleanly.
   105  func (srv *Server) daemonStopHandler(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
   106  	// can't write after we stop the server, so lie a bit.
   107  	writeSuccess(w)
   108  
   109  	// need to flush the response before shutting down the server
   110  	f, ok := w.(http.Flusher)
   111  	if !ok {
   112  		panic("Server does not support flushing")
   113  	}
   114  	f.Flush()
   115  
   116  	if err := srv.Close(); err != nil {
   117  		build.Critical(err)
   118  	}
   119  }