gitlab.com/SiaPrime/SiaPrime@v1.4.1/node/api/client/host.go (about)

     1  package client
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  	"strconv"
     7  
     8  	"gitlab.com/SiaPrime/SiaPrime/crypto"
     9  	"gitlab.com/SiaPrime/SiaPrime/modules"
    10  	"gitlab.com/SiaPrime/SiaPrime/node/api"
    11  )
    12  
    13  // HostParam is a parameter in the host's settings that can be changed via the
    14  // API. It is primarily used as a helper struct to ensure type safety.
    15  type HostParam string
    16  
    17  const (
    18  	// HostParamCollateralBudget is the collateral budget of the host in
    19  	// hastings.
    20  	HostParamCollateralBudget = HostParam("collateralbudget")
    21  	// HostParamMaxCollateral is the max collateral of the host in hastings.
    22  	HostParamMaxCollateral = HostParam("maxcollateral")
    23  	// HostParamMinContractPrice is the min contract price in hastings.
    24  	HostParamMinContractPrice = HostParam("mincontractprice")
    25  	// HostParamMinDownloadBandwidthPrice is the min download bandwidth price
    26  	// in hastings/byte.
    27  	HostParamMinDownloadBandwidthPrice = HostParam("mindownloadbandwidthprice")
    28  	// HostParamMinUploadBandwidthPrice is the min upload bandwidth price in
    29  	// hastings/byte.
    30  	HostParamMinUploadBandwidthPrice = HostParam("minuploadbandwidthprice")
    31  	// HostParamCollateral is the host's collateral in hastings/byte/block.
    32  	HostParamCollateral = HostParam("collateral")
    33  	// HostParamMinBaseRPCPrice is the minimum base RPC price in hastings.
    34  	HostParamMinBaseRPCPrice = HostParam("minbaserpcprice")
    35  	// HostParamMinSectorAccessPrice is the minimum sector access price in
    36  	// hastings.
    37  	HostParamMinSectorAccessPrice = HostParam("minsectoraccessprice")
    38  	// HostParamMinStoragePrice is the minimum storage price in
    39  	// hastings/byte/block.
    40  	HostParamMinStoragePrice = HostParam("minstorageprice")
    41  	// HostParamAcceptingContracts indicates if the host is accepting new
    42  	// contracts.
    43  	HostParamAcceptingContracts = HostParam("acceptingcontracts")
    44  	// HostParamMaxDuration is the max duration of a contract in blocks.
    45  	HostParamMaxDuration = HostParam("maxduration")
    46  	// HostParamWindowSize is the size of the proof window in blocks.
    47  	HostParamWindowSize = HostParam("windowsize")
    48  	// HostParamMaxDownloadBatchSize is the maximum size of the download batch
    49  	// size in bytes.
    50  	HostParamMaxDownloadBatchSize = HostParam("maxdownloadbatchsize")
    51  	// HostParamMaxReviseBatchSize is the maximum size of the revise batch size.
    52  	HostParamMaxReviseBatchSize = HostParam("maxrevisebatchsize")
    53  	// HostParamNetAddress is the announced netaddress of the host.
    54  	HostParamNetAddress = HostParam("netaddress")
    55  )
    56  
    57  // HostAnnouncePost uses the /host/announce endpoint to announce the host to
    58  // the network
    59  func (c *Client) HostAnnouncePost() (err error) {
    60  	err = c.post("/host/announce", "", nil)
    61  	return
    62  }
    63  
    64  // HostAnnounceAddrPost uses the /host/anounce endpoint to announce the host to
    65  // the network using the provided address.
    66  func (c *Client) HostAnnounceAddrPost(address modules.NetAddress) (err error) {
    67  	err = c.post("/host/announce", "netaddress="+string(address), nil)
    68  	return
    69  }
    70  
    71  // HostContractInfoGet uses the /host/contracts endpoint to get information
    72  // about contracts on the host.
    73  func (c *Client) HostContractInfoGet() (cg api.ContractInfoGET, err error) {
    74  	err = c.get("/host/contracts", &cg)
    75  	return
    76  }
    77  
    78  // HostEstimateScoreGet requests the /host/estimatescore endpoint.
    79  func (c *Client) HostEstimateScoreGet(param, value string) (eg api.HostEstimateScoreGET, err error) {
    80  	err = c.get(fmt.Sprintf("/host/estimatescore?%v=%v", param, value), &eg)
    81  	return
    82  }
    83  
    84  // HostGet requests the /host endpoint.
    85  func (c *Client) HostGet() (hg api.HostGET, err error) {
    86  	err = c.get("/host", &hg)
    87  	return
    88  }
    89  
    90  // HostModifySettingPost uses the /host endpoint to change a param of the host
    91  // settings to a certain value.
    92  func (c *Client) HostModifySettingPost(param HostParam, value interface{}) (err error) {
    93  	err = c.post("/host", string(param)+"="+fmt.Sprint(value), nil)
    94  	return
    95  }
    96  
    97  // HostStorageFoldersAddPost uses the /host/storage/folders/add api endpoint to
    98  // add a storage folder to a host
    99  func (c *Client) HostStorageFoldersAddPost(path string, size uint64) (err error) {
   100  	values := url.Values{}
   101  	values.Set("path", path)
   102  	values.Set("size", strconv.FormatUint(size, 10))
   103  	err = c.post("/host/storage/folders/add", values.Encode(), nil)
   104  	return
   105  }
   106  
   107  // HostStorageFoldersRemovePost uses the /host/storage/folders/remove api
   108  // endpoint to remove a storage folder from a host.
   109  func (c *Client) HostStorageFoldersRemovePost(path string) (err error) {
   110  	values := url.Values{}
   111  	values.Set("path", path)
   112  	err = c.post("/host/storage/folders/remove", values.Encode(), nil)
   113  	return
   114  }
   115  
   116  // HostStorageFoldersResizePost uses the /host/storage/folders/resize api
   117  // endpoint to resize an existing storage folder.
   118  func (c *Client) HostStorageFoldersResizePost(path string, size uint64) (err error) {
   119  	values := url.Values{}
   120  	values.Set("path", path)
   121  	values.Set("newsize", strconv.FormatUint(size, 10))
   122  	err = c.post("/host/storage/folders/resize", values.Encode(), nil)
   123  	return
   124  }
   125  
   126  // HostStorageGet requests the /host/storage endpoint.
   127  func (c *Client) HostStorageGet() (sg api.StorageGET, err error) {
   128  	err = c.get("/host/storage", &sg)
   129  	return
   130  }
   131  
   132  // HostStorageSectorsDeletePost uses the /host/storage/sectors/delete endpoint
   133  // to delete a sector from the host.
   134  func (c *Client) HostStorageSectorsDeletePost(root crypto.Hash) (err error) {
   135  	err = c.post("/host/storage/sectors/delete/"+root.String(), "", nil)
   136  	return
   137  }