diff --git a/services/balance_service.go b/services/balance_service.go index ca3d055..481adcb 100644 --- a/services/balance_service.go +++ b/services/balance_service.go @@ -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 @@ -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] @@ -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 @@ -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] @@ -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 @@ -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 @@ -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] @@ -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 @@ -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 @@ -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] @@ -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 @@ -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] @@ -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 @@ -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] diff --git a/services/base_service.go b/services/base_service.go index 2133e6f..a06b84c 100644 --- a/services/base_service.go +++ b/services/base_service.go @@ -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 @@ -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] @@ -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 @@ -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] @@ -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 @@ -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 @@ -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] @@ -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 @@ -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] @@ -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 @@ -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 @@ -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] @@ -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 @@ -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 @@ -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] @@ -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 @@ -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] @@ -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 @@ -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] @@ -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 @@ -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] @@ -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 @@ -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] diff --git a/services/nft_service.go b/services/nft_service.go index 3dd15b7..5bf5cca 100644 --- a/services/nft_service.go +++ b/services/nft_service.go @@ -587,7 +587,7 @@ func (s *nftServiceImpl) GetChainCollections(chainName chains.Chain, queryParamO var data utils.Response[ChainCollectionResponse] 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 { chainCollectionItemChannel <- ChainCollectionItemResult{Err: err} hasNext = false @@ -672,6 +672,7 @@ func (s *nftServiceImpl) GetChainCollectionsByPage(chainName chains.Chain, query } 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 @@ -689,7 +690,7 @@ func (s *nftServiceImpl) GetChainCollectionsByPage(chainName chains.Chain, query 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[ChainCollectionResponse] @@ -774,6 +775,7 @@ func (s *nftServiceImpl) GetNftsForAddress(chainName chains.Chain, walletAddress } 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 @@ -791,7 +793,7 @@ func (s *nftServiceImpl) GetNftsForAddress(chainName chains.Chain, walletAddress 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[NftAddressBalanceNftResponse] @@ -896,7 +898,7 @@ func (s *nftServiceImpl) GetTokenIdsForContractWithMetadata(chainName chains.Cha var data utils.Response[NftMetadataResponse] 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 { nftTokenContractChannel <- NftTokenContractResult{Err: err} hasNext = false @@ -993,6 +995,7 @@ func (s *nftServiceImpl) GetTokenIdsForContractWithMetadataByPage(chainName chai } 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 @@ -1010,7 +1013,7 @@ func (s *nftServiceImpl) GetTokenIdsForContractWithMetadataByPage(chainName chai 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[NftMetadataResponse] @@ -1091,6 +1094,7 @@ func (s *nftServiceImpl) GetNftMetadataForGivenTokenIdForContract(chainName chai } 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 @@ -1108,7 +1112,7 @@ func (s *nftServiceImpl) GetNftMetadataForGivenTokenIdForContract(chainName chai 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[NftMetadataResponse] @@ -1185,6 +1189,7 @@ func (s *nftServiceImpl) GetNftTransactionsForContractTokenId(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 @@ -1202,7 +1207,7 @@ func (s *nftServiceImpl) GetNftTransactionsForContractTokenId(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[NftTransactionsResponse] @@ -1271,6 +1276,7 @@ func (s *nftServiceImpl) GetTraitsForCollection(chainName chains.Chain, collecti } 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 @@ -1288,7 +1294,7 @@ func (s *nftServiceImpl) GetTraitsForCollection(chainName chains.Chain, collecti 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[NftCollectionTraitsResponse] @@ -1357,6 +1363,7 @@ func (s *nftServiceImpl) GetAttributesForTraitInCollection(chainName chains.Chai } 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 @@ -1374,7 +1381,7 @@ func (s *nftServiceImpl) GetAttributesForTraitInCollection(chainName chains.Chai 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[NftCollectionAttributesForTraitResponse] @@ -1443,6 +1450,7 @@ func (s *nftServiceImpl) GetCollectionTraitsSummary(chainName chains.Chain, coll } 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 @@ -1460,7 +1468,7 @@ func (s *nftServiceImpl) GetCollectionTraitsSummary(chainName chains.Chain, coll 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[NftCollectionTraitSummaryResponse] @@ -1541,6 +1549,7 @@ func (s *nftServiceImpl) CheckOwnershipInNft(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 @@ -1558,7 +1567,7 @@ func (s *nftServiceImpl) CheckOwnershipInNft(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[NftOwnershipForCollectionResponse] @@ -1627,6 +1636,7 @@ func (s *nftServiceImpl) CheckOwnershipInNftForSpecificTokenId(chainName chains. } 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 @@ -1644,7 +1654,7 @@ func (s *nftServiceImpl) CheckOwnershipInNftForSpecificTokenId(chainName chains. 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[NftOwnershipForCollectionResponse] @@ -1725,6 +1735,7 @@ func (s *nftServiceImpl) GetNftMarketSaleCount(chainName chains.Chain, contractA } 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 @@ -1742,7 +1753,7 @@ func (s *nftServiceImpl) GetNftMarketSaleCount(chainName chains.Chain, contractA 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[NftMarketSaleCountResponse] @@ -1823,6 +1834,7 @@ func (s *nftServiceImpl) GetNftMarketVolume(chainName chains.Chain, contractAddr } 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 @@ -1840,7 +1852,7 @@ func (s *nftServiceImpl) GetNftMarketVolume(chainName chains.Chain, contractAddr 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[NftMarketVolumeResponse] @@ -1921,6 +1933,7 @@ func (s *nftServiceImpl) GetNftMarketFloorPrice(chainName chains.Chain, contract } 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 @@ -1938,7 +1951,7 @@ func (s *nftServiceImpl) GetNftMarketFloorPrice(chainName chains.Chain, contract 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[NftMarketFloorPriceResponse] diff --git a/services/pricing_service.go b/services/pricing_service.go index ad662d6..e34b81f 100644 --- a/services/pricing_service.go +++ b/services/pricing_service.go @@ -162,6 +162,7 @@ func (s *pricingServiceImpl) GetTokenPrices(chainName chains.Chain, quoteCurrenc } 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 @@ -179,7 +180,7 @@ func (s *pricingServiceImpl) GetTokenPrices(chainName chains.Chain, quoteCurrenc 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 Response[TokenPricesResponse] diff --git a/services/security_service.go b/services/security_service.go index 6a474cc..3ebf717 100644 --- a/services/security_service.go +++ b/services/security_service.go @@ -193,6 +193,7 @@ func (s *securityServiceImpl) GetApprovals(chainName chains.Chain, walletAddress } 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 @@ -210,7 +211,7 @@ func (s *securityServiceImpl) GetApprovals(chainName chains.Chain, walletAddress 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[ApprovalsResponse] @@ -279,6 +280,7 @@ func (s *securityServiceImpl) GetNftApprovals(chainName chains.Chain, walletAddr } 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 @@ -296,7 +298,7 @@ func (s *securityServiceImpl) GetNftApprovals(chainName chains.Chain, walletAddr 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[NftApprovalsResponse] diff --git a/services/transaction_service.go b/services/transaction_service.go index c46dcfa..f5e11da 100644 --- a/services/transaction_service.go +++ b/services/transaction_service.go @@ -460,7 +460,7 @@ func (t *RecentTransactionsResponse) Prev() (*utils.Response[RecentTransactionsR defer resp.Body.Close() utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime) - backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0) + backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[RecentTransactionsResponse] @@ -544,7 +544,7 @@ func (t *RecentTransactionsResponse) Next() (*utils.Response[RecentTransactionsR defer resp.Body.Close() utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime) - backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0) + backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[RecentTransactionsResponse] @@ -628,7 +628,7 @@ func (t *TransactionsResponse) Prev() (*utils.Response[TransactionsResponse], er defer resp.Body.Close() utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime) - backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0) + backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsResponse] @@ -712,7 +712,7 @@ func (t *TransactionsResponse) Next() (*utils.Response[TransactionsResponse], er defer resp.Body.Close() utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime) - backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0) + backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsResponse] @@ -796,7 +796,7 @@ func (t *TransactionsTimeBucketResponse) Prev() (*utils.Response[TransactionsTim defer resp.Body.Close() utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime) - backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0) + backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsTimeBucketResponse] @@ -880,7 +880,7 @@ func (t *TransactionsTimeBucketResponse) Next() (*utils.Response[TransactionsTim defer resp.Body.Close() utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime) - backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0) + backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsTimeBucketResponse] @@ -964,7 +964,7 @@ func (t *TransactionsBlockPageResponse) Prev() (*utils.Response[TransactionsBloc defer resp.Body.Close() utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime) - backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0) + backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsBlockPageResponse] @@ -1048,7 +1048,7 @@ func (t *TransactionsBlockPageResponse) Next() (*utils.Response[TransactionsBloc defer resp.Body.Close() utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime) - backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0) + backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsBlockPageResponse] @@ -1320,6 +1320,7 @@ func (s *transactionServiceImpl) GetTransaction(chainName chains.Chain, txHash s } 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 @@ -1337,7 +1338,7 @@ func (s *transactionServiceImpl) GetTransaction(chainName chains.Chain, txHash s defer resp.Body.Close() utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime) - backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0) + backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionResponse] @@ -1423,7 +1424,7 @@ func (s *transactionServiceImpl) GetAllTransactionsForAddress(chainName chains.C var data utils.Response[RecentTransactionsResponse] for hasNext { - res, err := utils.PaginateEndpointUsingLinks(apiURL, s.APIKey, params, s.Debug, s.ThreadCount) + res, err := utils.PaginateEndpointUsingLinks(apiURL, s.APIKey, params, s.Debug, s.ThreadCount, utils.UserAgent) if err != nil { transactionChannel <- TransactionResult{Err: err} hasNext = false @@ -1516,6 +1517,7 @@ func (s *transactionServiceImpl) GetAllTransactionsForAddressByPage(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 @@ -1533,7 +1535,7 @@ func (s *transactionServiceImpl) GetAllTransactionsForAddressByPage(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(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[RecentTransactionsResponse] @@ -1621,6 +1623,7 @@ func (s *transactionServiceImpl) GetTransactionsForAddressV3(chainName chains.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 @@ -1638,7 +1641,7 @@ func (s *transactionServiceImpl) GetTransactionsForAddressV3(chainName chains.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(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsResponse] @@ -1722,6 +1725,7 @@ func (s *transactionServiceImpl) GetTimeBucketTransactionsForAddress(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 @@ -1739,7 +1743,7 @@ func (s *transactionServiceImpl) GetTimeBucketTransactionsForAddress(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(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsTimeBucketResponse] @@ -1824,6 +1828,7 @@ func (s *transactionServiceImpl) GetTransactionsForBlock(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 @@ -1841,7 +1846,7 @@ func (s *transactionServiceImpl) GetTransactionsForBlock(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(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsBlockResponse] @@ -1925,6 +1930,7 @@ func (s *transactionServiceImpl) GetTransactionsForBlockHashByPage(chainName cha } 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 @@ -1942,7 +1948,7 @@ func (s *transactionServiceImpl) GetTransactionsForBlockHashByPage(chainName cha defer resp.Body.Close() utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime) - backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0) + backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsBlockPageResponse] @@ -2027,6 +2033,7 @@ func (s *transactionServiceImpl) GetTransactionsForBlockHash(chainName chains.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 @@ -2044,7 +2051,7 @@ func (s *transactionServiceImpl) GetTransactionsForBlockHash(chainName chains.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(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsBlockResponse] @@ -2125,6 +2132,7 @@ func (s *transactionServiceImpl) GetTransactionSummary(chainName chains.Chain, w } 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 @@ -2142,7 +2150,7 @@ func (s *transactionServiceImpl) GetTransactionSummary(chainName chains.Chain, w defer resp.Body.Close() utils.DebugOutput(resp.Request.URL.String(), resp.StatusCode, startTime) - backoff := utils.NewExponentialBackoff(s.APIKey, s.Debug, 0) + backoff := utils.NewExponentialBackoff(clientKey, debugOutput, 0, utils.UserAgent) // // Read the response body var data utils.Response[TransactionsSummaryResponse] diff --git a/services/xyk_service.go b/services/xyk_service.go index 6926695..24a5b3d 100644 --- a/services/xyk_service.go +++ b/services/xyk_service.go @@ -932,6 +932,7 @@ func (s *xykServiceImpl) GetPools(chainName chains.Chain, dexName string, queryP } 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 @@ -949,7 +950,7 @@ func (s *xykServiceImpl) GetPools(chainName chains.Chain, dexName string, queryP 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[PoolResponse] @@ -1018,6 +1019,7 @@ func (s *xykServiceImpl) GetDexForPoolAddress(chainName chains.Chain, poolAddres } 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 @@ -1035,7 +1037,7 @@ func (s *xykServiceImpl) GetDexForPoolAddress(chainName chains.Chain, poolAddres 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[PoolToDexResponse] @@ -1104,6 +1106,7 @@ func (s *xykServiceImpl) GetPoolByAddress(chainName chains.Chain, dexName 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 @@ -1121,7 +1124,7 @@ func (s *xykServiceImpl) GetPoolByAddress(chainName chains.Chain, dexName 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[PoolByAddressResponse] @@ -1206,6 +1209,7 @@ func (s *xykServiceImpl) GetPoolsForTokenAddress(chainName chains.Chain, tokenAd } 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 @@ -1223,7 +1227,7 @@ func (s *xykServiceImpl) GetPoolsForTokenAddress(chainName chains.Chain, tokenAd 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[PoolsDexDataResponse] @@ -1292,6 +1296,7 @@ func (s *xykServiceImpl) GetAddressExchangeBalances(chainName chains.Chain, dexN } 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 @@ -1309,7 +1314,7 @@ func (s *xykServiceImpl) GetAddressExchangeBalances(chainName chains.Chain, dexN 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[AddressExchangeBalancesResponse] @@ -1398,6 +1403,7 @@ func (s *xykServiceImpl) GetPoolsForWalletAddress(chainName chains.Chain, wallet } 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 @@ -1415,7 +1421,7 @@ func (s *xykServiceImpl) GetPoolsForWalletAddress(chainName chains.Chain, wallet 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[PoolsDexDataResponse] @@ -1496,6 +1502,7 @@ func (s *xykServiceImpl) GetNetworkExchangeTokens(chainName chains.Chain, dexNam } 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 @@ -1513,7 +1520,7 @@ func (s *xykServiceImpl) GetNetworkExchangeTokens(chainName chains.Chain, dexNam 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[NetworkExchangeTokensResponse] @@ -1590,6 +1597,7 @@ func (s *xykServiceImpl) GetLpTokenView(chainName chains.Chain, dexName 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 @@ -1607,7 +1615,7 @@ func (s *xykServiceImpl) GetLpTokenView(chainName chains.Chain, dexName 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[NetworkExchangeTokenViewResponse] @@ -1676,6 +1684,7 @@ func (s *xykServiceImpl) GetSupportedDEXes() (*utils.Response[SupportedDexesResp } 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 @@ -1693,7 +1702,7 @@ func (s *xykServiceImpl) GetSupportedDEXes() (*utils.Response[SupportedDexesResp 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[SupportedDexesResponse] @@ -1774,6 +1783,7 @@ func (s *xykServiceImpl) GetSingleNetworkExchangeToken(chainName chains.Chain, d } 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 @@ -1791,7 +1801,7 @@ func (s *xykServiceImpl) GetSingleNetworkExchangeToken(chainName chains.Chain, d 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[SingleNetworkExchangeTokenResponse] @@ -1860,6 +1870,7 @@ func (s *xykServiceImpl) GetTransactionsForAccountAddress(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 @@ -1877,7 +1888,7 @@ func (s *xykServiceImpl) GetTransactionsForAccountAddress(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[TransactionsForAccountAddressResponse] @@ -1958,6 +1969,7 @@ func (s *xykServiceImpl) GetTransactionsForTokenAddress(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 @@ -1975,7 +1987,7 @@ func (s *xykServiceImpl) GetTransactionsForTokenAddress(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[TransactionsForTokenAddressResponse] @@ -2056,6 +2068,7 @@ func (s *xykServiceImpl) GetTransactionsForExchange(chainName chains.Chain, dexN } 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 @@ -2073,7 +2086,7 @@ func (s *xykServiceImpl) GetTransactionsForExchange(chainName chains.Chain, dexN 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[TransactionsForExchangeResponse] @@ -2158,6 +2171,7 @@ func (s *xykServiceImpl) GetTransactionsForDex(chainName chains.Chain, dexName s } 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 @@ -2175,7 +2189,7 @@ func (s *xykServiceImpl) GetTransactionsForDex(chainName chains.Chain, dexName s 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[NetworkTransactionsResponse] @@ -2244,6 +2258,7 @@ func (s *xykServiceImpl) GetEcosystemChartData(chainName chains.Chain, dexName s } 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 @@ -2261,7 +2276,7 @@ func (s *xykServiceImpl) GetEcosystemChartData(chainName chains.Chain, dexName s 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[EcosystemChartDataResponse] @@ -2330,6 +2345,7 @@ func (s *xykServiceImpl) GetHealthData(chainName chains.Chain, dexName 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 @@ -2347,7 +2363,7 @@ func (s *xykServiceImpl) GetHealthData(chainName chains.Chain, dexName 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[HealthDataResponse] diff --git a/tests/back_off_test.go b/tests/back_off_test.go index 5df3aa2..19623f8 100644 --- a/tests/back_off_test.go +++ b/tests/back_off_test.go @@ -17,7 +17,7 @@ func TestExponentialBackoff_BackOff(t *testing.T) { defer server.Close() // Create a new ExponentialBackoff instance for testing - backoff := utils.NewExponentialBackoff("API_KEY", true, 3) + backoff := utils.NewExponentialBackoff("API_KEY", true, 3, "") // Call the BackOff method with the test server URL response, err := backoff.BackOff(server.URL) @@ -38,7 +38,7 @@ func TestExponentialBackoff_BackOffSuccess(t *testing.T) { defer server.Close() // Create a new ExponentialBackoff instance for testing - backoff := utils.NewExponentialBackoff("API_KEY", true, 3) + backoff := utils.NewExponentialBackoff("API_KEY", true, 3, "") // Call the BackOff method with the test server URL response, err := backoff.BackOff(server.URL) @@ -59,7 +59,7 @@ func TestExponentialBackoff_BackOffMaxRetriesExceeded(t *testing.T) { defer server.Close() // Create a new ExponentialBackoff instance for testing - backoff := utils.NewExponentialBackoff("API_KEY", true, 5) + backoff := utils.NewExponentialBackoff("API_KEY", true, 5, "") // Call the BackOff method with the test server URL _, err := backoff.BackOff(server.URL) diff --git a/utils/backoff.go b/utils/backoff.go index 1246f10..32efaaf 100644 --- a/utils/backoff.go +++ b/utils/backoff.go @@ -15,9 +15,10 @@ type ExponentialBackoff struct { APIKey string Debug bool MaxRetries int + UserAgent string } -func NewExponentialBackoff(apiKey string, debug bool, maxRetries int) *ExponentialBackoff { +func NewExponentialBackoff(apiKey string, debug bool, maxRetries int, userAgent string) *ExponentialBackoff { if maxRetries == 0 { maxRetries = DefaultBackoffMaxRetries } @@ -26,6 +27,7 @@ func NewExponentialBackoff(apiKey string, debug bool, maxRetries int) *Exponenti Debug: debug, MaxRetries: maxRetries, RetryCount: 1, + UserAgent: userAgent, } } @@ -66,6 +68,8 @@ func (e *ExponentialBackoff) makeRequest(url string) (*http.Response, error) { return nil, err } req.Header.Add("Authorization", "Bearer "+e.APIKey) + req.Header.Set("X-Requested-With", e.UserAgent) + response, err := client.Do(req) if err != nil { return nil, err diff --git a/utils/pagination.go b/utils/pagination.go index 7d63172..ee4355e 100644 --- a/utils/pagination.go +++ b/utils/pagination.go @@ -7,7 +7,7 @@ import ( "time" ) -func PaginateEndpoint(urlStr, apiKey string, urlParams url.Values, page int, debug bool, threadCount int) (*http.Response, error) { +func PaginateEndpoint(urlStr, apiKey string, urlParams url.Values, page int, debug bool, threadCount int, userAgent string) (*http.Response, error) { parsedURL, err := url.Parse(urlStr) if err != nil { @@ -33,6 +33,7 @@ func PaginateEndpoint(urlStr, apiKey string, urlParams url.Values, page int, deb } req.Header.Set("Authorization", `Bearer `+apiKey) + req.Header.Set("X-Requested-With", userAgent) var startTime time.Time // Declares startTime, initially set to zero value of time.Time @@ -40,7 +41,7 @@ func PaginateEndpoint(urlStr, apiKey string, urlParams url.Values, page int, deb startTime = time.Now() // Initialize startTime with the current time } - backoff := NewExponentialBackoff(apiKey, debug, 0) + backoff := NewExponentialBackoff(apiKey, debug, 0, userAgent) // Perform the request resp, err := client.Do(req) @@ -61,7 +62,7 @@ func PaginateEndpoint(urlStr, apiKey string, urlParams url.Values, page int, deb } } -func PaginateEndpointUsingLinks(urlStr, apiKey string, urlParams url.Values, debug bool, threadCount int) (*http.Response, error) { +func PaginateEndpointUsingLinks(urlStr, apiKey string, urlParams url.Values, debug bool, threadCount int, userAgent string) (*http.Response, error) { parsedURL, err := url.Parse(urlStr) if err != nil { return nil, err @@ -79,6 +80,7 @@ func PaginateEndpointUsingLinks(urlStr, apiKey string, urlParams url.Values, deb } req.Header.Set("Authorization", `Bearer `+apiKey) + req.Header.Set("X-Requested-With", userAgent) var startTime time.Time // Declares startTime, initially set to zero value of time.Time @@ -86,7 +88,7 @@ func PaginateEndpointUsingLinks(urlStr, apiKey string, urlParams url.Values, deb startTime = time.Now() // Initialize startTime with the current time } - backoff := NewExponentialBackoff(apiKey, debug, 0) + backoff := NewExponentialBackoff(apiKey, debug, 0, userAgent) // Perform the request resp, err := client.Do(req) diff --git a/utils/user_agent.go b/utils/user_agent.go new file mode 100644 index 0000000..0a67ed6 --- /dev/null +++ b/utils/user_agent.go @@ -0,0 +1,3 @@ +package utils + +var UserAgent = "com.covalenthq.sdk.golang/0.0.2"