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

delegate review: take site ipfs from request #113

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 3 additions & 4 deletions api/v1/delegateReviewCreation/delegateReviewCreation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"

"github.com/NetSepio/gateway/api/middleware/auth/paseto"
"github.com/NetSepio/gateway/app/routines/webreview"
"github.com/NetSepio/gateway/config/dbconfig"
"github.com/NetSepio/gateway/models"
"github.com/NetSepio/gateway/util/pkg/aptos"
Expand Down Expand Up @@ -35,7 +34,7 @@ func deletegateReviewCreation(c *gin.Context) {
}

walletAddr := c.GetString(paseto.CTX_WALLET_ADDRES)
txResult, err := aptos.DelegateReview(aptos.DelegateReviewParams{Voter: walletAddr, MetaDataUri: request.MetaDataUri, Category: request.Category, DomainAddress: request.DomainAddress, SiteUrl: request.SiteUrl, SiteType: request.SiteType, SiteTag: request.SiteTag, SiteSafety: request.SiteSafety})
txResult, err := aptos.DelegateReview(aptos.DelegateReviewParams{Voter: walletAddr, MetaDataUri: request.MetaDataUri, Category: request.Category, DomainAddress: request.DomainAddress, SiteUrl: request.SiteUrl, SiteType: request.SiteType, SiteTag: request.SiteTag, SiteSafety: request.SiteSafety, SiteIpfsHash: request.SiteIpfsHash})
if err != nil {
if errors.Is(err, aptos.ErrMetadataDuplicated) {
httpo.NewErrorResponse(http.StatusConflict, "Metadata already exist").SendD(c)
Expand All @@ -59,11 +58,11 @@ func deletegateReviewCreation(c *gin.Context) {
SiteType: request.SiteType,
SiteTag: request.SiteTag,
SiteSafety: request.SiteSafety,
SiteIpfsHash: "",
SiteIpfsHash: request.SiteIpfsHash,
TransactionHash: txResult.Result.TransactionHash,
TransactionVersion: txResult.Result.Version,
}
go webreview.Publish(request.MetaDataUri, request.SiteUrl)

if err := db.Create(newReview).Error; err != nil {
httpo.NewSuccessResponseP(httpo.TXDbFailed, "transaction is successful but failed to store tx in db", payload).Send(c, 200)
return
Expand Down
1 change: 1 addition & 0 deletions api/v1/delegateReviewCreation/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type DelegateReviewCreationRequest struct {
SiteType string `json:"siteType" binding:"required"`
SiteTag string `json:"siteTag" binding:"required"`
SiteSafety string `json:"siteSafety" binding:"required"`
SiteIpfsHash string `json:"siteIpfsHash" binding:"required"`
}

type DelegateReviewCreationPayload struct {
Expand Down
3 changes: 2 additions & 1 deletion util/pkg/aptos/smartcontract.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ type DelegateReviewParams struct {
SiteType string
SiteTag string
SiteSafety string
SiteIpfsHash string
}

var ErrMetadataDuplicated = errors.New("metadata already exist")

func DelegateReview(p DelegateReviewParams) (*TxResult, error) {
command := fmt.Sprintf("move run --function-id %s::netsepio::delegate_submit_review --max-gas %d --gas-unit-price %d --args", envconfig.EnvVars.FUNCTION_ID, envconfig.EnvVars.GAS_UNITS, envconfig.EnvVars.GAS_PRICE)
args := append(strings.Split(command, " "),
argA(p.Voter), argS(p.MetaDataUri), argS(p.Category), argS(p.DomainAddress), argS(p.SiteUrl), argS(p.SiteType), argS(p.SiteTag), argS(p.SiteSafety), argS(""))
argA(p.Voter), argS(p.MetaDataUri), argS(p.Category), argS(p.DomainAddress), argS(p.SiteUrl), argS(p.SiteType), argS(p.SiteTag), argS(p.SiteSafety), argS(p.SiteIpfsHash))
cmd := exec.Command("aptos", args...)
fmt.Println(strings.Join(args, " "))

Expand Down
Loading