Skip to content

Commit

Permalink
add user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
davidzhangg committed Mar 20, 2024
1 parent e17732c commit b2c218a
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 80 deletions.
22 changes: 14 additions & 8 deletions services/balance_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ func (s *balanceServiceImpl) GetTokenBalancesForWalletAddress(chainName chains.C
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -618,7 +619,7 @@ func (s *balanceServiceImpl) GetTokenBalancesForWalletAddress(chainName chains.C
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[BalancesResponse]
Expand Down Expand Up @@ -699,6 +700,7 @@ func (s *balanceServiceImpl) GetHistoricalPortfolioForWalletAddress(chainName ch
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -716,7 +718,7 @@ func (s *balanceServiceImpl) GetHistoricalPortfolioForWalletAddress(chainName ch
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[PortfolioResponse]
Expand Down Expand Up @@ -821,7 +823,7 @@ func (s *balanceServiceImpl) GetErc20TransfersForWalletAddress(chainName chains.
var data utils.Response[Erc20TransfersResponse]
for hasNext {

res, err := utils.PaginateEndpoint(apiURL, s.APIKey, params, page, s.Debug, s.ThreadCount)
res, err := utils.PaginateEndpoint(apiURL, s.APIKey, params, page, s.Debug, s.ThreadCount, utils.UserAgent)
if err != nil {
blockTransactionWithContractTransfersChannel <- BlockTransactionWithContractTransfersResult{Err: err}
hasNext = false
Expand Down Expand Up @@ -918,6 +920,7 @@ func (s *balanceServiceImpl) GetErc20TransfersForWalletAddressByPage(chainName c
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -935,7 +938,7 @@ func (s *balanceServiceImpl) GetErc20TransfersForWalletAddressByPage(chainName c
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[Erc20TransfersResponse]
Expand Down Expand Up @@ -1032,7 +1035,7 @@ func (s *balanceServiceImpl) GetTokenHoldersV2ForTokenAddress(chainName chains.C
var data utils.Response[TokenHoldersResponse]
for hasNext {

res, err := utils.PaginateEndpoint(apiURL, s.APIKey, params, page, s.Debug, s.ThreadCount)
res, err := utils.PaginateEndpoint(apiURL, s.APIKey, params, page, s.Debug, s.ThreadCount, utils.UserAgent)
if err != nil {
tokenHolderChannel <- TokenHolderResult{Err: err}
hasNext = false
Expand Down Expand Up @@ -1121,6 +1124,7 @@ func (s *balanceServiceImpl) GetTokenHoldersV2ForTokenAddressByPage(chainName ch
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -1138,7 +1142,7 @@ func (s *balanceServiceImpl) GetTokenHoldersV2ForTokenAddressByPage(chainName ch
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[TokenHoldersResponse]
Expand Down Expand Up @@ -1239,6 +1243,7 @@ func (s *balanceServiceImpl) GetHistoricalTokenBalancesForWalletAddress(chainNam
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -1256,7 +1261,7 @@ func (s *balanceServiceImpl) GetHistoricalTokenBalancesForWalletAddress(chainNam
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[HistoricalBalancesResponse]
Expand Down Expand Up @@ -1337,6 +1342,7 @@ func (s *balanceServiceImpl) GetNativeTokenBalance(chainName chains.Chain, walle
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -1354,7 +1360,7 @@ func (s *balanceServiceImpl) GetNativeTokenBalance(chainName chains.Chain, walle
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[TokenBalanceNativeResponse]
Expand Down
36 changes: 23 additions & 13 deletions services/base_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ func (s *baseServiceImpl) GetBlock(chainName chains.Chain, blockHeight string) (
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -475,7 +476,7 @@ func (s *baseServiceImpl) GetBlock(chainName chains.Chain, blockHeight string) (
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[BlockResponse]
Expand Down Expand Up @@ -544,6 +545,7 @@ func (s *baseServiceImpl) GetResolvedAddress(chainName chains.Chain, walletAddre
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -561,7 +563,7 @@ func (s *baseServiceImpl) GetResolvedAddress(chainName chains.Chain, walletAddre
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[ResolvedAddress]
Expand Down Expand Up @@ -650,7 +652,7 @@ func (s *baseServiceImpl) GetBlockHeights(chainName chains.Chain, startDate stri
var data utils.Response[BlockHeightsResponse]
for hasNext {

res, err := utils.PaginateEndpoint(apiURL, s.APIKey, params, page, s.Debug, s.ThreadCount)
res, err := utils.PaginateEndpoint(apiURL, s.APIKey, params, page, s.Debug, s.ThreadCount, utils.UserAgent)
if err != nil {
blockHeightsChannel <- BlockHeightsResult{Err: err}
hasNext = false
Expand Down Expand Up @@ -731,6 +733,7 @@ func (s *baseServiceImpl) GetBlockHeightsByPage(chainName chains.Chain, startDat
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -748,7 +751,7 @@ func (s *baseServiceImpl) GetBlockHeightsByPage(chainName chains.Chain, startDat
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[BlockHeightsResponse]
Expand Down Expand Up @@ -845,6 +848,7 @@ func (s *baseServiceImpl) GetLogs(chainName chains.Chain, queryParamOpts ...GetL
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -862,7 +866,7 @@ func (s *baseServiceImpl) GetLogs(chainName chains.Chain, queryParamOpts ...GetL
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[GetLogsResponse]
Expand Down Expand Up @@ -959,7 +963,7 @@ func (s *baseServiceImpl) GetLogEventsByAddress(chainName chains.Chain, contract
var data utils.Response[LogEventsByAddressResponse]
for hasNext {

res, err := utils.PaginateEndpoint(apiURL, s.APIKey, params, page, s.Debug, s.ThreadCount)
res, err := utils.PaginateEndpoint(apiURL, s.APIKey, params, page, s.Debug, s.ThreadCount, utils.UserAgent)
if err != nil {
logEventChannel <- LogEventResult{Err: err}
hasNext = false
Expand Down Expand Up @@ -1048,6 +1052,7 @@ func (s *baseServiceImpl) GetLogEventsByAddressByPage(chainName chains.Chain, co
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -1065,7 +1070,7 @@ func (s *baseServiceImpl) GetLogEventsByAddressByPage(chainName chains.Chain, co
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[LogEventsByAddressResponse]
Expand Down Expand Up @@ -1166,7 +1171,7 @@ func (s *baseServiceImpl) GetLogEventsByTopicHash(chainName chains.Chain, topicH
var data utils.Response[LogEventsByTopicHashResponse]
for hasNext {

res, err := utils.PaginateEndpoint(apiURL, s.APIKey, params, page, s.Debug, s.ThreadCount)
res, err := utils.PaginateEndpoint(apiURL, s.APIKey, params, page, s.Debug, s.ThreadCount, utils.UserAgent)
if err != nil {
logEventChannel <- LogEventResult{Err: err}
hasNext = false
Expand Down Expand Up @@ -1259,6 +1264,7 @@ func (s *baseServiceImpl) GetLogEventsByTopicHashByPage(chainName chains.Chain,
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -1276,7 +1282,7 @@ func (s *baseServiceImpl) GetLogEventsByTopicHashByPage(chainName chains.Chain,
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[LogEventsByTopicHashResponse]
Expand Down Expand Up @@ -1345,6 +1351,7 @@ func (s *baseServiceImpl) GetAllChains() (*utils.Response[AllChainsResponse], er
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -1362,7 +1369,7 @@ func (s *baseServiceImpl) GetAllChains() (*utils.Response[AllChainsResponse], er
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[AllChainsResponse]
Expand Down Expand Up @@ -1431,6 +1438,7 @@ func (s *baseServiceImpl) GetAllChainStatus() (*utils.Response[AllChainsStatusRe
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -1448,7 +1456,7 @@ func (s *baseServiceImpl) GetAllChainStatus() (*utils.Response[AllChainsStatusRe
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[AllChainsStatusResponse]
Expand Down Expand Up @@ -1525,6 +1533,7 @@ func (s *baseServiceImpl) GetAddressActivity(walletAddress string, queryParamOpt
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -1542,7 +1551,7 @@ func (s *baseServiceImpl) GetAddressActivity(walletAddress string, queryParamOpt
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[ChainActivityResponse]
Expand Down Expand Up @@ -1619,6 +1628,7 @@ func (s *baseServiceImpl) GetGasPrices(chainName chains.Chain, eventType string,
}

req.Header.Set("Authorization", `Bearer `+s.APIKey)
req.Header.Set("X-Requested-With", utils.UserAgent)

var startTime time.Time // Declares startTime, initially set to zero value of time.Time

Expand All @@ -1636,7 +1646,7 @@ func (s *baseServiceImpl) GetGasPrices(chainName chains.Chain, eventType string,
defer resp.Body.Close()

utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0)
backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0, utils.UserAgent)

// // Read the response body
var data utils.Response[GasPricesResponse]
Expand Down
Loading

0 comments on commit b2c218a

Please sign in to comment.