Skip to content

Commit

Permalink
"Added new API endpoint for delegate ticket creation for base network…
Browse files Browse the repository at this point in the history
… and updated gin mode configuration"
  • Loading branch information
p-shubh committed Sep 21, 2024
1 parent 549c405 commit bf865cb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
func ApplyRoutes(r *gin.RouterGroup) {
g := r.Group("/delegateTicketCreation")
{

g.POST("", delegateTicketCreation)
g.POST("/base", delegateTicketCreationForBase)
}
}

Expand Down Expand Up @@ -72,6 +72,54 @@ func delegateTicketCreation(c *gin.Context) {
}
sendSuccessResponse(c, hash, req.UserId)
}
func delegateTicketCreationForBase(c *gin.Context) {
network := "base"
var req DelegateTicketCreationRequest
if err := c.ShouldBindJSON(&req); err != nil {
logo.Errorf("invalid request %s", err)
httpo.NewErrorResponse(http.StatusBadRequest, "body is invalid").SendD(c)
return
}
mnemonic, err := user.GetMnemonic(req.UserId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
httpo.NewErrorResponse(httpo.UserNotFound, "user not found").Send(c, 404)

return
}

httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch user").SendD(c)
logo.Errorf("failed to fetch user mnemonic for userId: %v, error: %s",
req.UserId, err)
return
}

contractDetails, err := contracts.GetContract(req.ContractAddress)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
httpo.NewErrorResponse(404, "contract not found in database").SendD(c)
return
}
httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch contract details from database").SendD(c)
logo.Errorf("failed to fetch contract details from database, error: %s", err)
return
}
if contractDetails.ContractType != contracts.ERC721 {
httpo.NewErrorResponse(http.StatusBadRequest, "contract is not ERC721").SendD(c)
return
}

flexableNFTContractAddr := common.HexToAddress(req.ContractAddress)
var hash string
hash, err = polygon.DelegateNFTCreation(mnemonic, flexableNFTContractAddr, req.MetadataURI)
if err != nil {
httpo.NewErrorResponse(http.StatusInternalServerError, "failed to tranfer").SendD(c)
logo.Errorf("failed to delegate erc721 to wallet of userId: %v , network: %v, contractAddr: %v, error: %s",
req.UserId, network, req.ContractAddress, err)
return
}
sendSuccessResponse(c, hash, req.UserId)
}

func sendSuccessResponse(c *gin.Context, hash string, userId string) {
payload := DelegateTicketCreationPayload{
Expand Down
5 changes: 5 additions & 0 deletions app/stage/apprun/apprun.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (

func Run() {
ginApp := gin.Default()
if envconfig.EnvVars.GIN_MODE == "debug" {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
}

corsM := cors.New(cors.Config{AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type", "Authorization"},
Expand Down

0 comments on commit bf865cb

Please sign in to comment.