Delete services/api/internal directory

This commit is contained in:
P4vlushaaa 2025-01-23 14:32:27 +03:00 committed by GitHub
parent 96085269a4
commit 147389ff99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 0 additions and 214 deletions

View file

@ -1,81 +0,0 @@
package handlers
import (
"encoding/json"
"math/big"
"net/http"
"github.com/nspcc-dev/neo-go/pkg/util"
"web3-onlyfans/services/api/internal/neo"
"web3-onlyfans/services/api/internal/utils"
)
func MarketListHandler(w http.ResponseWriter, r *http.Request, neoCli *neo.NeoClient, logger utils.Logger, cfg *utils.Config) {
marketHash, err := util.Uint160DecodeStringLE(cfg.MarketContractHash)
if err != nil {
http.Error(w, "invalid market hash", http.StatusInternalServerError)
return
}
invRes, err := neoCli.Actor.Reader().InvokeCall(marketHash, "List", nil, nil)
if err != nil {
logger.Errorf("invoke List error: %v", err)
http.Error(w, "market list error", http.StatusInternalServerError)
return
}
tokenList, err := utils.DecodeStringArray(invRes.Stack[0])
if err != nil {
logger.Errorf("decode array error: %v", err)
http.Error(w, "decode array error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]any{
"status": "ok",
"tokens": tokenList,
})
}
type MarketBuyRequest struct {
TokenID string `json:"token_id"`
Amount int64 `json:"amount"`
}
func MarketBuyHandler(w http.ResponseWriter, r *http.Request, neoCli *neo.NeoClient, logger utils.Logger, cfg *utils.Config) {
var req MarketBuyRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, "invalid JSON", http.StatusBadRequest)
return
}
tokenHash, err := util.Uint160DecodeStringLE(cfg.TokenContractHash)
if err != nil {
http.Error(w, "invalid token contract hash", http.StatusInternalServerError)
return
}
// Вызываем transfer NEP-17: (from=Actor, to=market, amount=req.Amount, data=req.TokenID)
dataBytes := []byte(req.TokenID)
amt := big.NewInt(req.Amount)
txHash, err := neoCli.Actor.Call(tokenHash, "transfer", []any{
neoCli.Actor.Sender(), // from
cfg.MarketContractHash, // to
amt, // amount
dataBytes, // data
}, nil)
if err != nil {
logger.Errorf("market buy transfer error: %v", err)
http.Error(w, "market buy error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]any{
"status": "ok",
"txHash": txHash.StringBE(),
"tokenID": req.TokenID,
"amount": req.Amount,
})
}

View file

@ -1,89 +0,0 @@
package handlers
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"github.com/nspcc-dev/neo-go/pkg/util"
"web3-onlyfans/services/api/internal/neo"
"web3-onlyfans/services/api/internal/utils"
)
type MintNFTRequest struct {
TokenID string `json:"token_id"`
Name string `json:"name"`
BlurredRef string `json:"blurred_ref"`
FullRef string `json:"full_ref"`
Price int `json:"price"`
}
func MintNFTHandler(w http.ResponseWriter, r *http.Request, neoCli *neo.NeoClient, logger utils.Logger, cfg *utils.Config) {
var req MintNFTRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, "invalid JSON", http.StatusBadRequest)
return
}
nftHash, err := util.Uint160DecodeStringLE(cfg.NftContractHash)
if err != nil {
http.Error(w, "invalid NFT hash", http.StatusInternalServerError)
return
}
txHash, err := neoCli.Actor.Call(nftHash, "mint", []any{
req.TokenID,
req.Name,
req.BlurredRef,
req.FullRef,
req.Price,
}, nil)
if err != nil {
logger.Errorf("mint call error: %v", err)
http.Error(w, "mint call error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]any{
"status": "ok",
"txHash": txHash.StringBE(),
"tokenID": req.TokenID,
})
}
func NFTPropertiesHandler(w http.ResponseWriter, r *http.Request, neoCli *neo.NeoClient, logger utils.Logger, cfg *utils.Config) {
tokenID := r.URL.Query().Get("token_id")
if tokenID == "" {
http.Error(w, "missing token_id", http.StatusBadRequest)
return
}
nftHash, err := util.Uint160DecodeStringLE(cfg.NftContractHash)
if err != nil {
http.Error(w, "invalid NFT hash", http.StatusInternalServerError)
return
}
invRes, err := neoCli.Actor.Reader().InvokeCall(nftHash, "properties", []any{tokenID}, nil)
if err != nil {
logger.Errorf("invoke call error: %v", err)
http.Error(w, "invoke call error", http.StatusInternalServerError)
return
}
// Разбираем stackitem.Map
propsMap, err := utils.DecodeStringMap(invRes.Stack[0])
if err != nil {
logger.Errorf("decode error: %v", err)
http.Error(w, "decode error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]any{
"status": "ok",
"props": propsMap,
})
}

View file

@ -1,44 +0,0 @@
package neo
import (
"context"
"fmt"
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
"github.com/nspcc-dev/neo-go/pkg/wallet"
)
type NeoClient struct {
Actor *actor.Actor
RPC *rpcclient.Client
Context context.Context
}
func NewNeoClient(rpcEndpoint, walletPath, walletPass string) (*NeoClient, error) {
ctx := context.Background()
rpcCli, err := rpcclient.New(ctx, rpcEndpoint, rpcclient.Options{})
if err != nil {
return nil, fmt.Errorf("rpcclient new: %w", err)
}
w, err := wallet.NewWalletFromFile(walletPath)
if err != nil {
return nil, fmt.Errorf("wallet load: %w", err)
}
acc := w.GetAccount(w.GetChangeAddress())
err = acc.Decrypt(walletPass, w.Scrypt)
if err != nil {
return nil, fmt.Errorf("wallet decrypt: %w", err)
}
act, err := actor.NewSimple(rpcCli, acc)
if err != nil {
return nil, fmt.Errorf("actor new: %w", err)
}
return &NeoClient{
Actor: act,
RPC: rpcCli,
Context: ctx,
}, nil
}