Skip to content

Commit

Permalink
Clean up, minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Jan 17, 2020
1 parent 038ad89 commit dc7ba09
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
18 changes: 6 additions & 12 deletions blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ func (c *Client) GetBlockByHash(hash string) (blockInfo *BlockInfo, err error) {

var resp string
// https://api.whatsonchain.com/v1/bsv/<network>/block/hash/<hash>
url := fmt.Sprintf("%s%s/block/hash/%s", apiEndpoint, c.Parameters.Network, hash)
if resp, err = c.Request(url, http.MethodGet, nil); err != nil {
if resp, err = c.Request(fmt.Sprintf("%s%s/block/hash/%s", apiEndpoint, c.Parameters.Network, hash), http.MethodGet, nil); err != nil {
return
}

blockInfo = new(BlockInfo)
err = json.Unmarshal([]byte(resp), blockInfo)
err = json.Unmarshal([]byte(resp), &blockInfo)
return
}

Expand All @@ -30,13 +28,11 @@ func (c *Client) GetBlockByHeight(height int64) (blockInfo *BlockInfo, err error

var resp string
// https://api.whatsonchain.com/v1/bsv/<network>/block/height/<height>
url := fmt.Sprintf("%s%s/block/height/%d", apiEndpoint, c.Parameters.Network, height)
if resp, err = c.Request(url, http.MethodGet, nil); err != nil {
if resp, err = c.Request(fmt.Sprintf("%s%s/block/height/%d", apiEndpoint, c.Parameters.Network, height), http.MethodGet, nil); err != nil {
return
}

blockInfo = new(BlockInfo)
err = json.Unmarshal([]byte(resp), blockInfo)
err = json.Unmarshal([]byte(resp), &blockInfo)
return
}

Expand All @@ -48,12 +44,10 @@ func (c *Client) GetBlockPages(hash string, page int) (txList *BlockPagesInfo, e

var resp string
// https://api.whatsonchain.com/v1/bsv/<network>/block/hash/<hash>/page/1
url := fmt.Sprintf("%s%s/block/hash/%s/page/%d", apiEndpoint, c.Parameters.Network, hash, page)
if resp, err = c.Request(url, http.MethodGet, nil); err != nil {
if resp, err = c.Request(fmt.Sprintf("%s%s/block/hash/%s/page/%d", apiEndpoint, c.Parameters.Network, hash, page), http.MethodGet, nil); err != nil {
return
}

txList = new(BlockPagesInfo)
err = json.Unmarshal([]byte(resp), txList)
err = json.Unmarshal([]byte(resp), &txList)
return
}
6 changes: 2 additions & 4 deletions chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ func (c *Client) GetChainInfo() (chainInfo *ChainInfo, err error) {

var resp string
// https://api.whatsonchain.com/v1/bsv/<network>/chain/info
url := fmt.Sprintf("%s%s/chain/info", apiEndpoint, c.Parameters.Network)
if resp, err = c.Request(url, http.MethodGet, nil); err != nil {
if resp, err = c.Request(fmt.Sprintf("%s%s/chain/info", apiEndpoint, c.Parameters.Network), http.MethodGet, nil); err != nil {
return
}

chainInfo = new(ChainInfo)
err = json.Unmarshal([]byte(resp), chainInfo)
err = json.Unmarshal([]byte(resp), &chainInfo)
return
}
3 changes: 3 additions & 0 deletions definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type ChainInfo struct {
VerificationProgress float64 `json:"verificationprogress"`
}

// CirculatingSupply is the structure response
type CirculatingSupply float64

// BlockInfo is the response info about a returned block
type BlockInfo struct {
Bits string `json:"bits"`
Expand Down
3 changes: 1 addition & 2 deletions health.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ import (
func (c *Client) GetHealth() (status string, err error) {

// https://api.whatsonchain.com/v1/bsv/<network>/woc
url := fmt.Sprintf("%s%s/woc", apiEndpoint, c.Parameters.Network)
return c.Request(url, http.MethodGet, nil)
return c.Request(fmt.Sprintf("%s%s/woc", apiEndpoint, c.Parameters.Network), http.MethodGet, nil)
}

0 comments on commit dc7ba09

Please sign in to comment.