update go mod (#334)

This commit is contained in:
Asim Aslam
2021-12-16 12:31:04 +00:00
committed by GitHub
parent f9e539ad88
commit 527dcc12c3
16 changed files with 164 additions and 165 deletions

View File

@@ -9,58 +9,58 @@ type CollectionsResponse struct {
}
type Asset struct {
Id int32 `json:"id"`
TokenId string `json:"token_id"`
Sales int32 `json:"num_sales"`
ImageUrl string `json:"image_url"`
Name string `json:"name"`
Description string `json:"description"`
Permalink string `json:"permalink"`
Contract *Contract `json:"asset_contract"`
Collection *Collection `json:"collection"`
Creator *User `json:"creator"`
Owner *User `json:"owner"`
LastSale *Sale `json:"last_sale,omitempty"`
Presale bool `json:"is_presale"`
ListingDate string `json:"listing_date,omitempty"`
Id int32 `json:"id"`
TokenId string `json:"token_id"`
Sales int32 `json:"num_sales"`
ImageUrl string `json:"image_url"`
Name string `json:"name"`
Description string `json:"description"`
Permalink string `json:"permalink"`
Contract *Contract `json:"asset_contract"`
Collection *Collection `json:"collection"`
Creator *User `json:"creator"`
Owner *User `json:"owner"`
LastSale *Sale `json:"last_sale,omitempty"`
Presale bool `json:"is_presale"`
ListingDate string `json:"listing_date,omitempty"`
}
type Contract struct {
// name of contract
Name string `json:"name,omitempty"`
// ethereum address
Address string `json:"address,omitempty"`
// type of contract e.g "semi-fungible"
Type string `json:"asset_contract_type,omitempty"`
// timestamp of creation
CreatedAt string `json:"created_date,omitempty"`
// owner id
Owner int32 `json:"owner,omitempty"`
// aka "ERC1155"
Schema string `json:"schema_name,omitempty"`
// related symbol
Symbol string `json:"symbol,omitempty"`
// description of contract
Description string `json:"description,omitempty"`
// payout address
PayoutAddress string `json:"payout_address,omitempty"`
// seller fees
SellerFees string `json:"seller_fees_basis_points,omitempty"`
// name of contract
Name string `json:"name,omitempty"`
// ethereum address
Address string `json:"address,omitempty"`
// type of contract e.g "semi-fungible"
Type string `json:"asset_contract_type,omitempty"`
// timestamp of creation
CreatedAt string `json:"created_date,omitempty"`
// owner id
Owner int32 `json:"owner,omitempty"`
// aka "ERC1155"
Schema string `json:"schema_name,omitempty"`
// related symbol
Symbol string `json:"symbol,omitempty"`
// description of contract
Description string `json:"description,omitempty"`
// payout address
PayoutAddress string `json:"payout_address,omitempty"`
// seller fees
SellerFees string `json:"seller_fees_basis_points,omitempty"`
}
type Collection struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Slug string `json:"slug,omitempty"`
ImageUrl string `json:"image_url,omitempty"`
CreatedAt string `json:"created_date,omitempty"`
PayoutAddress string `json:"payout_address,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Slug string `json:"slug,omitempty"`
ImageUrl string `json:"image_url,omitempty"`
CreatedAt string `json:"created_date,omitempty"`
PayoutAddress string `json:"payout_address,omitempty"`
}
type User struct {
User *Username `json:"user"`
ProfileUrl string `json:"profile_img_url,omitempty"`
Address string `json:"address,omitempty"`
User *Username `json:"user"`
ProfileUrl string `json:"profile_img_url,omitempty"`
Address string `json:"address,omitempty"`
}
type Username struct {
@@ -68,40 +68,39 @@ type Username struct {
}
type SaleAsset struct {
TokenId string `json:"token_id"`
TokenId string `json:"token_id"`
Decimals int32 `json:"decimals"`
}
type Sale struct {
Asset *SaleAsset `json:"asset"`
EventType string `json:"event_type,omitempty"`
EventTimestamp string `json:"event_timestamp,omitempty"`
TotalPrice string `json:"total_price,omitempty"`
Quantity string `json:"quantity,omitempty"`
CreatedAt string `json:"created_date,omitempty"`
Transaction *Transaction `json:"transaction,omitempty"`
PaymentToken *Token `json:"payment_token,omitempty"`
Asset *SaleAsset `json:"asset"`
EventType string `json:"event_type,omitempty"`
EventTimestamp string `json:"event_timestamp,omitempty"`
TotalPrice string `json:"total_price,omitempty"`
Quantity string `json:"quantity,omitempty"`
CreatedAt string `json:"created_date,omitempty"`
Transaction *Transaction `json:"transaction,omitempty"`
PaymentToken *Token `json:"payment_token,omitempty"`
}
type Transaction struct {
Id int32 `json:"id,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
BlockHash string `json:"block_hash,omitempty"`
BlockNumber string `json:"block_number,omitempty"`
FromAccount *User `json:"from_account,omitempty"`
ToAccount *User `json:"to_account,omitempty"`
TransactionHash string `json:"transaction_hash,omitempty"`
TransactionIndex string `json:"transaction_index,omitempty"`
Id int32 `json:"id,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
BlockHash string `json:"block_hash,omitempty"`
BlockNumber string `json:"block_number,omitempty"`
FromAccount *User `json:"from_account,omitempty"`
ToAccount *User `json:"to_account,omitempty"`
TransactionHash string `json:"transaction_hash,omitempty"`
TransactionIndex string `json:"transaction_index,omitempty"`
}
type Token struct {
Id int32 `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Symbol string `json:"symbol,omitempty"`
Address string `json:"address,omitempty"`
ImageUrl string `json:"image_url,omitempty"`
Decimals int32 `json:"decimals,omitempty"`
EthPrice string `json:"eth_price,omitempty"`
UsdPrice string `json:"usd_price,omitempty"`
Id int32 `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Symbol string `json:"symbol,omitempty"`
Address string `json:"address,omitempty"`
ImageUrl string `json:"image_url,omitempty"`
Decimals int32 `json:"decimals,omitempty"`
EthPrice string `json:"eth_price,omitempty"`
UsdPrice string `json:"usd_price,omitempty"`
}

View File

@@ -1,2 +1,3 @@
package main
//go:generate make proto

View File

@@ -3,13 +3,11 @@ package handler
import (
"context"
pb "github.com/micro/services/nft/proto"
)
type Nft struct{}
func (n *Nft) Assets(ctx context.Context, req *pb.AssetsRequest, rsp *pb.AssetsResponse) error {
return nil
}

View File

@@ -4,12 +4,12 @@ import (
"context"
"fmt"
"github.com/micro/services/pkg/api"
"github.com/micro/services/nft/domain"
"github.com/micro/micro/v3/service/config"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/micro/v3/service/errors"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/services/nft/domain"
pb "github.com/micro/services/nft/proto"
"github.com/micro/services/pkg/api"
)
// OpenSea handler
@@ -23,24 +23,23 @@ var (
openseaURL = "https://api.opensea.io/api/v1"
)
func New() *OpenSea {
v, err := config.Get("nft.key")
if err != nil {
logger.Fatal("nft.key config not found: %v", err)
}
v, err := config.Get("nft.key")
if err != nil {
logger.Fatal("nft.key config not found: %v", err)
}
key := v.String("")
if len(key) == 0 {
logger.Fatal("nft.key config not found")
}
key := v.String("")
if len(key) == 0 {
logger.Fatal("nft.key config not found")
}
// set the api key
api.SetKey("X-API-KEY", key)
return &OpenSea {
return &OpenSea{
apiKey: key,
Nft: new(Nft),
Nft: new(Nft),
}
}
@@ -83,7 +82,7 @@ func (o *OpenSea) Assets(ctx context.Context, req *pb.AssetsRequest, rsp *pb.Ass
var resp domain.AssetsResponse
if err := api.Get(uri + params, &resp); err != nil {
if err := api.Get(uri+params, &resp); err != nil {
return errors.InternalServerError("nft.assets", "failed to get assets: %v", err)
}
@@ -117,7 +116,7 @@ func (o *OpenSea) Assets(ctx context.Context, req *pb.AssetsRequest, rsp *pb.Ass
if asset.LastSale.Transaction == nil {
asset.LastSale.Transaction = &domain.Transaction{
FromAccount: &domain.User{User: new(domain.Username)},
ToAccount: &domain.User{User: new(domain.Username)},
ToAccount: &domain.User{User: new(domain.Username)},
}
}
if asset.LastSale.Transaction.FromAccount == nil {
@@ -137,36 +136,36 @@ func (o *OpenSea) Assets(ctx context.Context, req *pb.AssetsRequest, rsp *pb.Ass
}
lastSale = &pb.Sale{
AssetTokenId: asset.LastSale.Asset.TokenId,
AssetDecimals: asset.LastSale.Asset.Decimals,
EventType: asset.LastSale.EventType,
AssetTokenId: asset.LastSale.Asset.TokenId,
AssetDecimals: asset.LastSale.Asset.Decimals,
EventType: asset.LastSale.EventType,
EventTimestamp: asset.LastSale.EventTimestamp,
TotalPrice: asset.LastSale.TotalPrice,
Quantity: asset.LastSale.Quantity,
CreatedAt: asset.LastSale.CreatedAt,
TotalPrice: asset.LastSale.TotalPrice,
Quantity: asset.LastSale.Quantity,
CreatedAt: asset.LastSale.CreatedAt,
Transaction: &pb.Transaction{
Id: asset.LastSale.Transaction.Id,
Timestamp: asset.LastSale.Transaction.Timestamp,
BlockHash: asset.LastSale.Transaction.BlockHash,
Id: asset.LastSale.Transaction.Id,
Timestamp: asset.LastSale.Transaction.Timestamp,
BlockHash: asset.LastSale.Transaction.BlockHash,
BlockNumber: asset.LastSale.Transaction.BlockNumber,
FromAccount: &pb.User{
Username: asset.LastSale.Transaction.FromAccount.User.Username,
Username: asset.LastSale.Transaction.FromAccount.User.Username,
ProfileUrl: asset.LastSale.Transaction.FromAccount.ProfileUrl,
Address: asset.LastSale.Transaction.FromAccount.Address,
Address: asset.LastSale.Transaction.FromAccount.Address,
},
ToAccount: &pb.User{
Username: asset.LastSale.Transaction.ToAccount.User.Username,
Username: asset.LastSale.Transaction.ToAccount.User.Username,
ProfileUrl: asset.LastSale.Transaction.ToAccount.ProfileUrl,
Address: asset.LastSale.Transaction.ToAccount.Address,
Address: asset.LastSale.Transaction.ToAccount.Address,
},
TransactionHash: asset.LastSale.Transaction.TransactionHash,
TransactionHash: asset.LastSale.Transaction.TransactionHash,
TransactionIndex: asset.LastSale.Transaction.TransactionIndex,
},
PaymentToken: &pb.Token{
Id: asset.LastSale.PaymentToken.Id,
Name: asset.LastSale.PaymentToken.Name,
Symbol: asset.LastSale.PaymentToken.Symbol,
Address: asset.LastSale.PaymentToken.Address,
Id: asset.LastSale.PaymentToken.Id,
Name: asset.LastSale.PaymentToken.Name,
Symbol: asset.LastSale.PaymentToken.Symbol,
Address: asset.LastSale.PaymentToken.Address,
ImageUrl: asset.LastSale.PaymentToken.ImageUrl,
Decimals: asset.LastSale.PaymentToken.Decimals,
EthPrice: asset.LastSale.PaymentToken.EthPrice,
@@ -176,45 +175,45 @@ func (o *OpenSea) Assets(ctx context.Context, req *pb.AssetsRequest, rsp *pb.Ass
}
rsp.Assets = append(rsp.Assets, &pb.Asset{
Name: asset.Name,
Name: asset.Name,
Description: asset.Description,
Id: asset.Id,
TokenId: asset.TokenId,
ImageUrl: asset.ImageUrl,
Sales: asset.Sales,
Permalink: asset.Permalink,
Id: asset.Id,
TokenId: asset.TokenId,
ImageUrl: asset.ImageUrl,
Sales: asset.Sales,
Permalink: asset.Permalink,
Contract: &pb.Contract{
Name: asset.Contract.Name,
Description: asset.Contract.Description,
Address: asset.Contract.Address,
Type: asset.Contract.Type,
CreatedAt: asset.Contract.CreatedAt,
Owner: asset.Contract.Owner,
Schema: asset.Contract.Schema,
Symbol: asset.Contract.Symbol,
Name: asset.Contract.Name,
Description: asset.Contract.Description,
Address: asset.Contract.Address,
Type: asset.Contract.Type,
CreatedAt: asset.Contract.CreatedAt,
Owner: asset.Contract.Owner,
Schema: asset.Contract.Schema,
Symbol: asset.Contract.Symbol,
PayoutAddress: asset.Contract.PayoutAddress,
SellerFees: asset.Contract.SellerFees,
SellerFees: asset.Contract.SellerFees,
},
Collection: &pb.Collection{
Name: asset.Collection.Name,
Description: asset.Collection.Description,
Slug: asset.Collection.Slug,
ImageUrl: asset.Collection.ImageUrl,
CreatedAt: asset.Collection.CreatedAt,
Name: asset.Collection.Name,
Description: asset.Collection.Description,
Slug: asset.Collection.Slug,
ImageUrl: asset.Collection.ImageUrl,
CreatedAt: asset.Collection.CreatedAt,
PayoutAddress: asset.Collection.PayoutAddress,
},
Owner: &pb.User{
Username: asset.Owner.User.Username,
Username: asset.Owner.User.Username,
ProfileUrl: asset.Owner.ProfileUrl,
Address: asset.Owner.Address,
Address: asset.Owner.Address,
},
Creator: &pb.User{
Username: asset.Creator.User.Username,
Username: asset.Creator.User.Username,
ProfileUrl: asset.Creator.ProfileUrl,
Address: asset.Creator.Address,
Address: asset.Creator.Address,
},
LastSale: lastSale,
Presale: asset.Presale,
LastSale: lastSale,
Presale: asset.Presale,
ListingDate: asset.ListingDate,
})
}
@@ -241,25 +240,24 @@ func (o *OpenSea) Collections(ctx context.Context, req *pb.CollectionsRequest, r
offset = req.Offset
}
params += fmt.Sprintf("limit=%d&offset=%d",limit, offset)
params += fmt.Sprintf("limit=%d&offset=%d", limit, offset)
var resp domain.CollectionsResponse
if err := api.Get(uri + params, &resp); err != nil {
if err := api.Get(uri+params, &resp); err != nil {
return errors.InternalServerError("nft.collections", "failed to get collections: %v", err)
}
for _, collection := range resp.Collections {
rsp.Collections = append(rsp.Collections, &pb.Collection{
Name: collection.Name,
Description: collection.Description,
Slug: collection.Slug,
ImageUrl: collection.ImageUrl,
CreatedAt: collection.CreatedAt,
Name: collection.Name,
Description: collection.Description,
Slug: collection.Slug,
ImageUrl: collection.ImageUrl,
CreatedAt: collection.CreatedAt,
PayoutAddress: collection.PayoutAddress,
})
}
return nil
}

View File

@@ -1,10 +1,10 @@
package main
import (
"github.com/micro/services/nft/handler"
pb "github.com/micro/services/nft/proto"
"github.com/micro/micro/v3/service"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/services/nft/handler"
pb "github.com/micro/services/nft/proto"
)
func main() {