Do not export when not required
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
parent
7d52632af6
commit
92a6246052
@ -5,7 +5,7 @@ import (
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type Address struct {
|
||||
type addressData struct {
|
||||
Address string `json:"address"`
|
||||
ChainStats struct {
|
||||
FundedTxoCount int `json:"funded_txo_count"`
|
||||
@ -25,8 +25,8 @@ type Address struct {
|
||||
|
||||
// GetAddress returns an Address struct populated with data from blockstream.info
|
||||
// for a given BTC address
|
||||
func (c *client) getAddress(address string) (*Address, error) {
|
||||
addressResponse := &Address{}
|
||||
func (c *client) getAddress(address string) (*addressData, error) {
|
||||
addressResponse := &addressData{}
|
||||
|
||||
err := c.get(fmt.Sprintf("address/%s", address), addressResponse, url.Values{})
|
||||
if err != nil {
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
const fiatConvertURL = "https://api.coingecko.com/api/v3/coins/bitcoin?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false"
|
||||
|
||||
type FiatConversion struct {
|
||||
type coinGeckoResponse struct {
|
||||
MarketData struct {
|
||||
CurrentPrice struct {
|
||||
CAD int `json:"cad"`
|
||||
@ -15,8 +15,8 @@ type FiatConversion struct {
|
||||
} `json:"market_data"`
|
||||
}
|
||||
|
||||
func (c *client) ConvertBTCToCAD(amount int) (int, error) {
|
||||
fiatConversion := &FiatConversion{}
|
||||
func (c *client) convertBTCToCAD(amount int) (int, error) {
|
||||
coinGeckoData := &coinGeckoResponse{}
|
||||
|
||||
req, err := http.NewRequest("GET", fiatConvertURL, nil)
|
||||
if err != nil {
|
||||
@ -28,10 +28,10 @@ func (c *client) ConvertBTCToCAD(amount int) (int, error) {
|
||||
return 0, fmt.Errorf("http GET request failed: %v", err)
|
||||
}
|
||||
|
||||
err = c.processResponse(res, fiatConversion)
|
||||
err = c.processResponse(res, coinGeckoData)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to process response: %v", err)
|
||||
}
|
||||
|
||||
return (amount * int(fiatConversion.MarketData.CurrentPrice.CAD*1000)) / 100000000, nil // one BTC = one hundred million satoshi's
|
||||
return (amount * int(coinGeckoData.MarketData.CurrentPrice.CAD*1000)) / 100000000, nil // one BTC = one hundred million satoshi's
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func (p *Provider) GetBalances() ([]int, []string, error) {
|
||||
satoshiBalance += addressResponse.ChainStats.FundedTxoSum - addressResponse.ChainStats.SpentTxoSum
|
||||
}
|
||||
|
||||
fiatBalance, err := p.client.ConvertBTCToCAD(satoshiBalance)
|
||||
fiatBalance, err := p.client.convertBTCToCAD(satoshiBalance)
|
||||
if err != nil {
|
||||
return balances, ynabAccountIDs, fmt.Errorf("failed to convert satoshi balance to fiat balance: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user