Skip to content

Commit

Permalink
feat(api): optimize contract verification and add logging
Browse files Browse the repository at this point in the history
- Add early check to verify if address is a contract
- Abort process and return error for non-contract addresses
  • Loading branch information
portdeveloper committed Aug 8, 2024
1 parent 0cd92e5 commit 53d6e20
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ func getABI(c *gin.Context) {
return
}

// Check if the address is a contract
code, err := client.CodeAt(c.Request.Context(), common.HexToAddress(address), nil)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("Failed to check contract code: %v", err)})
return
}

if len(code) == 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "The provided address is not a contract"})
return
}

proxyInfo, err := DetectProxyTarget(c.Request.Context(), client, common.HexToAddress(address))
if err != nil {
proxyInfo = nil
Expand Down

0 comments on commit 53d6e20

Please sign in to comment.