Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ezynda3 committed Sep 13, 2024
1 parent 74d7a8d commit 1ccdb85
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 50 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18.2-alpine3.14 AS builder
FROM golang:1.22.5-alpine AS builder
WORKDIR /app
RUN apk update && apk upgrade && apk add --no-cache ca-certificates
RUN update-ca-certificates
Expand All @@ -7,7 +7,6 @@ RUN go mod download
RUN CGO_ENABLED=0 go build -o pocketbase .

FROM scratch

WORKDIR /app
COPY --from=builder /app/pb_public /app/pb_public
COPY --from=builder /app/pocketbase /app/pocketbase
Expand Down
22 changes: 12 additions & 10 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ tasks:
setup:
cmds:
- go mod download
- pnpm --prefix ui install

backend_dev: air serve

frontend_dev: pnpm --prefix ui dev

frontend_build: pnpm --prefix ui build
templ:
- templ generate --watch --proxy="http://localhost:8090" --open-browser=false -v

server:
- |
go run github.com/cosmtrek/[email protected] \
--build.cmd "go build -o tmp/bin/main" --build.bin "tmp/bin/main serve" --build.delay "100" \
--build.include_ext "go" \
--build.stop_on_error "false" \
--misc.clean_on_exit true
dev:
deps: [backend_dev, frontend_dev]
deps: [server, templ]

build:
deps: [setup, frontend_build]
deps: [setup]
cmds:
- go build -o bin/anyabi

deploy: flyctl deploy
26 changes: 15 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module github.com/mark3labs/anyabi.xyz

go 1.20
go 1.21

toolchain go1.22.5

require (
github.com/a-h/templ v0.2.778
github.com/ethereum/go-ethereum v1.11.2
github.com/joho/godotenv v1.3.0
github.com/labstack/echo/v5 v5.0.0-20220201181537-ed2888cfa198
Expand Down Expand Up @@ -41,8 +44,8 @@ require (
github.com/disintegration/imaging v1.6.2 // indirect
github.com/domodwyer/mailyak/v3 v3.4.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.1 // indirect
github.com/ganigeorgiev/fexpr v0.3.0 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
Expand All @@ -59,7 +62,7 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.16 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
Expand All @@ -73,15 +76,16 @@ require (
github.com/valyala/fasttemplate v1.2.2 // indirect
go.opencensus.io v0.24.0 // indirect
gocloud.dev v0.28.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/image v0.5.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.110.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
87 changes: 66 additions & 21 deletions go.sum

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions index.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

templ Index() {
<!DOCTYPE html>
<html lang="en" class="dark">

<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.png" />
<meta name="viewport" content="width=device-width" />
<title>AnyABI - The easiest way to fetch an ABI</title>
<meta name="twitter:title" content="AnyABI - The easiest way to fetch an ABI" />
<meta name="description" content="Quickly grab the ABI for ANY EVM smart contract on ANY EVM chain." />
<meta name="twitter:description" content="Quickly grab the ABI for ANY EVM smart contract on ANY EVM chain." />
<meta name="twitter:image" content="https://anyabi.xyz/thumbnail.png" />
<meta property="og:image" content="https://anyabi.xyz/thumbnail.png" />
<meta name="twitter:card" content="summary_large_image" />
<meta http-equiv="content-security-policy" content="">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
</head>

<body>
<main class="container">
<h1>
<img src="/logo.png" width="48" />
AnyABI
</h1>
<article>The easiest way to fetch an ABI.</article>
<section>
<form role="search">
<fieldset role="group">
<select name="chain">
<option>Ethereum</option>
</select>
<input name="address" type="text" placeholder="Address" />
<input type="submit" value="Let's Go!" />
</fieldset>
</form>
</section>
</main>
<!-- 100% privacy friendly analytics -->
<script async defer src="https://scripts.simpleanalyticscdn.com/latest.js"></script>
<noscript>
<img src="https://queue.simpleanalyticscdn.com/noscript.gif" alt="" referrerpolicy="no-referrer-when-downgrade" />
</noscript>
</body>

</html>
}
35 changes: 35 additions & 0 deletions index_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions index_templ.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang=\"en\" class=\"dark\"><head><meta charset=\"utf-8\"><link rel=\"icon\" href=\"/favicon.png\"><meta name=\"viewport\" content=\"width=device-width\"><title>AnyABI - The easiest way to fetch an ABI</title><meta name=\"twitter:title\" content=\"AnyABI - The easiest way to fetch an ABI\"><meta name=\"description\" content=\"Quickly grab the ABI for ANY EVM smart contract on ANY EVM chain.\"><meta name=\"twitter:description\" content=\"Quickly grab the ABI for ANY EVM smart contract on ANY EVM chain.\"><meta name=\"twitter:image\" content=\"https://anyabi.xyz/thumbnail.png\"><meta property=\"og:image\" content=\"https://anyabi.xyz/thumbnail.png\"><meta name=\"twitter:card\" content=\"summary_large_image\"><meta http-equiv=\"content-security-policy\" content=\"\"><link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css\"></head><body><main class=\"container\"><h1><img src=\"/logo.png\" width=\"48\"> AnyABI</h1><article>The easiest way to fetch an ABI.</article><section><form role=\"search\"><fieldset role=\"group\"><select name=\"chain\"><option>Ethereum</option></select> <input name=\"address\" type=\"text\" placeholder=\"Address\"> <input type=\"submit\" value=\"Let&#39;s Go!\"></fieldset></form></section></main><!-- 100% privacy friendly analytics --><script async defer src=\"https://scripts.simpleanalyticscdn.com/latest.js\"></script><noscript><img src=\"https://queue.simpleanalyticscdn.com/noscript.gif\" alt=\"\" referrerpolicy=\"no-referrer-when-downgrade\"></noscript></body></html>
46 changes: 40 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net/http"
"os"
"strings"

"github.com/a-h/templ"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/joho/godotenv"
Expand All @@ -23,11 +30,6 @@ import (
"github.com/pocketbase/pocketbase/models"
"github.com/pocketbase/pocketbase/plugins/migratecmd"
"golang.org/x/time/rate"
"io"
"log"
"net/http"
"os"
"strings"
)

type EtherscanResponse struct {
Expand Down Expand Up @@ -92,6 +94,7 @@ var (
"104.154.76.147": true,
"34.122.246.162": true,
"34.45.228.219": true,
"35.193.6.125": true,
}
)

Expand All @@ -103,7 +106,13 @@ func main() {

e.Router.GET(
"/*",
apis.StaticDirectoryHandler(os.DirFS("./pb_public"), true),
apis.StaticDirectoryHandler(os.DirFS("./static"), false),
)
e.Router.GET(
"/",
func(c echo.Context) error {
return Render(c, http.StatusOK, Index())
},
)

rateLimiterConfig := middleware.RateLimiterConfig{
Expand All @@ -114,9 +123,14 @@ func main() {
return id, nil
},
ErrorHandler: func(context echo.Context, err error) error {
log.Println("Rate limit error: ", err)
return context.JSON(http.StatusForbidden, nil)
},
DenyHandler: func(context echo.Context, identifier string, err error) error {
log.Println(
"Rate limiting IP: ",
context.Request().Header.Get("Fly-Client-IP"),
)
return context.JSON(http.StatusTooManyRequests, nil)
},
}
Expand Down Expand Up @@ -270,6 +284,18 @@ func main() {
}
}

// This custom Render replaces Echo's echo.Context.Render() with templ's templ.Component.Render().
func Render(ctx echo.Context, statusCode int, t templ.Component) error {
buf := templ.GetBuffer()
defer templ.ReleaseBuffer(buf)

if err := t.Render(ctx.Request().Context(), buf); err != nil {
return err
}

return ctx.HTML(statusCode, buf.String())
}

func getABI(
app *pocketbase.PocketBase,
chainId, address string,
Expand Down Expand Up @@ -395,6 +421,10 @@ func getAbiFromEtherscan(
return "", nil, err
}

if result.Result[0].ContractName == "" {
return "", nil, err
}

// Extract ABI from interface{} type
var abiJson []map[string]interface{}
err = json.Unmarshal([]byte(result.Result[0].ABI), &abiJson)
Expand Down Expand Up @@ -435,6 +465,10 @@ func getAbiFromEtherscanNonStandard(
return "", nil, err
}

if result.Result.ContractName == "" {
return "", nil, err
}

// Extract ABI from interface{} type
var abiJson []map[string]interface{}
err = json.Unmarshal([]byte(result.Result.ABI), &abiJson)
Expand Down
File renamed without changes

0 comments on commit 1ccdb85

Please sign in to comment.