@@ -105,6 +105,7 @@ func EcdsaPrivateKeyToAddress(privateKey *ecdsa.PrivateKey) (gethcommon.Address,
105
105
return crypto .PubkeyToAddress (* publicKeyECDSA ), nil
106
106
}
107
107
108
+ // RoundUpDivideBig divides two positive big.Int numbers and rounds up the result.
108
109
func RoundUpDivideBig (a , b * big.Int ) * big.Int {
109
110
one := new (big.Int ).SetUint64 (1 )
110
111
res := new (big.Int )
@@ -118,14 +119,13 @@ func IsValidEthereumAddress(address string) bool {
118
119
return ethAddrPattern .MatchString (address )
119
120
}
120
121
121
- func ReadPublicURL (url string ) ([]byte , error ) {
122
- // allow no redirects
123
- httpClient := http.Client {
124
- CheckRedirect : func (req * http.Request , via []* http.Request ) error {
125
- return http .ErrUseLastResponse
126
- },
127
- Timeout : 3 * time .Second ,
122
+ func ReadPublicURL (url string , httpClient * http.Client ) ([]byte , error ) {
123
+ // Allow no redirects
124
+ httpClient .CheckRedirect = func (req * http.Request , via []* http.Request ) error {
125
+ return http .ErrUseLastResponse
128
126
}
127
+ httpClient .Timeout = 3 * time .Second
128
+
129
129
resp , err := httpClient .Get (url )
130
130
if err != nil {
131
131
return []byte {}, err
@@ -213,7 +213,7 @@ func CheckIfUrlIsValid(rawUrl string) error {
213
213
return nil
214
214
}
215
215
216
- func IsImageURL (urlString string ) error {
216
+ func IsImageURL (urlString string , httpClient * http. Client ) error {
217
217
// Parse the URL
218
218
parsedURL , err := url .Parse (urlString )
219
219
if err != nil {
@@ -229,7 +229,7 @@ func IsImageURL(urlString string) error {
229
229
// Check if the extension is in the list of image extensions
230
230
for _ , imgExt := range ImageExtensions {
231
231
if strings .EqualFold (extension , imgExt ) {
232
- imageBytes , err := ReadPublicURL (urlString )
232
+ imageBytes , err := ReadPublicURL (urlString , httpClient )
233
233
if err != nil {
234
234
return err
235
235
}
0 commit comments