Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golang Blinks Example #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 238 additions & 0 deletions examples/gin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
# Created by https://www.toptal.com/developers/gitignore/api/goland,go,macos,linux,windows,git
# Edit at https://www.toptal.com/developers/gitignore?templates=goland,go,macos,linux,windows,git

### Git ###
# Created by git for backups. To disable backups in Git:
# $ git config --global mergetool.keepBackup false
*.orig

# Created by git when using merge tools for conflicts
*.BACKUP.*
*.BASE.*
*.LOCAL.*
*.REMOTE.*
*_BACKUP_*.txt
*_BASE_*.txt
*_LOCAL_*.txt
*_REMOTE_*.txt

### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

### Go Patch ###
/vendor/
/Godeps/

### GoLand ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
.idea/

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### GoLand Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml

# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/goland,go,macos,linux,windows,git

.env
/contract/node_modules/
/tmp
22 changes: 22 additions & 0 deletions examples/gin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.22.4 as builder

WORKDIR /app

COPY go.mod .
COPY go.sum .

# Install dependencies before build
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o blink_app .

FROM alpine:latest

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*


COPY --from=builder /app/blink_app .

ENTRYPOINT ["./blink_app"]
16 changes: 16 additions & 0 deletions examples/gin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Solana Action: Mint NFT

This example includes a Solana Action built in Go using the Gin framework and Solana-Go-SDK. It
provides an API endpoint for minting an NFT.

Navigate to `./examples/gin` and start the application:

``` go
go run main.go
```

The server will start running on <http://localhost:8081>.

The endpoint for the Action is: <http://localhost:8080/api/actions/mint_nft>

You can test the Action using [Blinks Inspector](https://www.blinks.xyz/inspector)
83 changes: 83 additions & 0 deletions examples/gin/app/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package app

import (
"github.com/blocto/solana-go-sdk/types"
"github.com/gin-gonic/gin"
"log"
"net/http"
)

const (
RPC_URL = ""
)

func ActionsRulesHandler(c *gin.Context) {
payload := gin.H{
"rules": []gin.H{
{
"pathPattern": "/*",
"apiPath": "/api/actions/*",
},
{
"pathPattern": "/api/actions/**",
"apiPath": "/api/actions/**",
},
},
}

c.JSON(http.StatusOK, payload)
}

func GetActionsHandler(c *gin.Context) {
payload := ActionGetResponse{
Title: "Actions Example - Mint NFT",
// Icon: c.Request.URL.Scheme + "://" + c.Request.URL.Host + "/solana_devs.jpg",
Description: "Transfer SOL to another Solana wallet",
Label: "Transfer",
}
payload.Links.Actions = []Actions{
{"Mint NFT", "/api/actions/mint_nft", []ActionParameters{
{"name", "Enter the Name of the NFT", true},
{"symbol", "Enter the Symbol of the NFT", true},
{"uri", "Enter the Uri of the NFT", true},
}},
}

c.JSON(http.StatusOK, payload)
}

func OptionsHandler(c *gin.Context) {
for key, value := range ACTIONS_CORS_HEADERS {
c.Header(key, value)
}
c.Status(http.StatusOK)
}

func PostHandler(c *gin.Context) {
var (
qPayload MintNFTParams
request ActionPostRequest
response ActionPostResponse
)

if err := c.ShouldBindQuery(&qPayload); err != nil {
c.JSON(http.StatusBadRequest, ActionError{Message: "Invalid Query Params"})
return
}

if err := c.ShouldBindJSON(&request); err != nil {
log.Println(err)
c.JSON(http.StatusBadRequest, ActionError{Message: "Invalid request"})
return
}

account, err := types.AccountFromBase58(request.Account)
if err != nil {
log.Println(err)
c.JSON(http.StatusBadRequest, ActionError{Message: "Invalid request; Error validating account"})
return
}
response.Fields.Transaction, response.Fields.Message = mintNFT(qPayload, account)

c.JSON(http.StatusOK, response)
}
Loading