nft coming soon

This commit is contained in:
Asim Aslam
2021-11-26 12:26:13 +00:00
parent 2209b9e081
commit 274575d92b
13 changed files with 464 additions and 0 deletions

2
nft/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
nft

3
nft/Dockerfile Normal file
View File

@@ -0,0 +1,3 @@
FROM alpine
ADD nft /nft
ENTRYPOINT [ "/nft" ]

28
nft/Makefile Normal file
View File

@@ -0,0 +1,28 @@
GOPATH:=$(shell go env GOPATH)
.PHONY: init
init:
go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go
go get github.com/micro/micro/v3/cmd/protoc-gen-micro
go get github.com/micro/micro/v3/cmd/protoc-gen-openapi
.PHONY: api
api:
protoc --openapi_out=. --proto_path=. proto/nft.proto
.PHONY: proto
proto:
protoc --proto_path=. --micro_out=. --go_out=:. proto/nft.proto
.PHONY: build
build:
go build -o nft *.go
.PHONY: test
test:
go test -v ./... -cover
.PHONY: docker
docker:
docker build . -t nft:latest

7
nft/README.md Normal file
View File

@@ -0,0 +1,7 @@
Explore, buy and sell NFTs (coming soon)
# NFT Service
Explore, buy and sell NFTs with a simple API. Powered by OpenSea.
Create your own unique NFT now and launch it when the API is ready.

15
nft/examples.json Normal file
View File

@@ -0,0 +1,15 @@
{
"vote": [
{
"title": "Vote for the API",
"run_check": false,
"request": {
"message": "Launch it!"
},
"response": {
"message": "Thanks for the vote!"
}
}
}
]
}

2
nft/generate.go Normal file
View File

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

50
nft/handler/nft.go Normal file
View File

@@ -0,0 +1,50 @@
package handler
import (
"context"
"sync"
"time"
"github.com/micro/services/pkg/tenant"
"github.com/micro/micro/v3/service/store"
pb "github.com/micro/services/nft/proto"
)
type Nft struct{}
var (
mtx sync.RWMutex
voteKey = "votes/"
)
type Vote struct {
Id string `json:"id"`
Message string `json:"message"`
VotedAt time.Time `json:"voted_at"`
}
func (n *Nft) Vote(ctx context.Context, req *pb.VoteRequest, rsp *pb.VoteResponse) error {
mtx.Lock()
defer mtx.Unlock()
id, ok := tenant.FromContext(ctx)
if !ok {
id = "micro"
}
rec := store.NewRecord(voteKey + id, &Vote{
Id: id,
Message: req.Message,
VotedAt: time.Now(),
})
// we don't need to check the error
store.Write(rec)
rsp.Message = "Thanks for the vote!"
return nil
}

24
nft/main.go Normal file
View File

@@ -0,0 +1,24 @@
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"
)
func main() {
// Create service
srv := service.New(
service.Name("nft"),
service.Version("latest"),
)
// Register handler
pb.RegisterNftHandler(srv.Server(), new(handler.Nft))
// Run service
if err := srv.Run(); err != nil {
logger.Fatal(err)
}
}

1
nft/micro.mu Normal file
View File

@@ -0,0 +1 @@
service nft

213
nft/proto/nft.pb.go Normal file
View File

@@ -0,0 +1,213 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.15.6
// source: proto/nft.proto
package nft
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// Vote to have the NFT api launched faster!
type VoteRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// optional message
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
}
func (x *VoteRequest) Reset() {
*x = VoteRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_nft_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *VoteRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*VoteRequest) ProtoMessage() {}
func (x *VoteRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_nft_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use VoteRequest.ProtoReflect.Descriptor instead.
func (*VoteRequest) Descriptor() ([]byte, []int) {
return file_proto_nft_proto_rawDescGZIP(), []int{0}
}
func (x *VoteRequest) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
type VoteResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// response message
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
}
func (x *VoteResponse) Reset() {
*x = VoteResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_nft_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *VoteResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*VoteResponse) ProtoMessage() {}
func (x *VoteResponse) ProtoReflect() protoreflect.Message {
mi := &file_proto_nft_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use VoteResponse.ProtoReflect.Descriptor instead.
func (*VoteResponse) Descriptor() ([]byte, []int) {
return file_proto_nft_proto_rawDescGZIP(), []int{1}
}
func (x *VoteResponse) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
var File_proto_nft_proto protoreflect.FileDescriptor
var file_proto_nft_proto_rawDesc = []byte{
0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6e, 0x66, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x03, 0x6e, 0x66, 0x74, 0x22, 0x27, 0x0a, 0x0b, 0x56, 0x6f, 0x74, 0x65, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22,
0x28, 0x0a, 0x0c, 0x56, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x34, 0x0a, 0x03, 0x4e, 0x66, 0x74,
0x12, 0x2d, 0x0a, 0x04, 0x56, 0x6f, 0x74, 0x65, 0x12, 0x10, 0x2e, 0x6e, 0x66, 0x74, 0x2e, 0x56,
0x6f, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x6e, 0x66, 0x74,
0x2e, 0x56, 0x6f, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42,
0x0d, 0x5a, 0x0b, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x6e, 0x66, 0x74, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_proto_nft_proto_rawDescOnce sync.Once
file_proto_nft_proto_rawDescData = file_proto_nft_proto_rawDesc
)
func file_proto_nft_proto_rawDescGZIP() []byte {
file_proto_nft_proto_rawDescOnce.Do(func() {
file_proto_nft_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_nft_proto_rawDescData)
})
return file_proto_nft_proto_rawDescData
}
var file_proto_nft_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_proto_nft_proto_goTypes = []interface{}{
(*VoteRequest)(nil), // 0: nft.VoteRequest
(*VoteResponse)(nil), // 1: nft.VoteResponse
}
var file_proto_nft_proto_depIdxs = []int32{
0, // 0: nft.Nft.Vote:input_type -> nft.VoteRequest
1, // 1: nft.Nft.Vote:output_type -> nft.VoteResponse
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_proto_nft_proto_init() }
func file_proto_nft_proto_init() {
if File_proto_nft_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_proto_nft_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*VoteRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_nft_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*VoteResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_nft_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_proto_nft_proto_goTypes,
DependencyIndexes: file_proto_nft_proto_depIdxs,
MessageInfos: file_proto_nft_proto_msgTypes,
}.Build()
File_proto_nft_proto = out.File
file_proto_nft_proto_rawDesc = nil
file_proto_nft_proto_goTypes = nil
file_proto_nft_proto_depIdxs = nil
}

93
nft/proto/nft.pb.micro.go Normal file
View File

@@ -0,0 +1,93 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: proto/nft.proto
package nft
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
import (
context "context"
api "github.com/micro/micro/v3/service/api"
client "github.com/micro/micro/v3/service/client"
server "github.com/micro/micro/v3/service/server"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// Reference imports to suppress errors if they are not otherwise used.
var _ api.Endpoint
var _ context.Context
var _ client.Option
var _ server.Option
// Api Endpoints for Nft service
func NewNftEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for Nft service
type NftService interface {
Vote(ctx context.Context, in *VoteRequest, opts ...client.CallOption) (*VoteResponse, error)
}
type nftService struct {
c client.Client
name string
}
func NewNftService(name string, c client.Client) NftService {
return &nftService{
c: c,
name: name,
}
}
func (c *nftService) Vote(ctx context.Context, in *VoteRequest, opts ...client.CallOption) (*VoteResponse, error) {
req := c.c.NewRequest(c.name, "Nft.Vote", in)
out := new(VoteResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Nft service
type NftHandler interface {
Vote(context.Context, *VoteRequest, *VoteResponse) error
}
func RegisterNftHandler(s server.Server, hdlr NftHandler, opts ...server.HandlerOption) error {
type nft interface {
Vote(ctx context.Context, in *VoteRequest, out *VoteResponse) error
}
type Nft struct {
nft
}
h := &nftHandler{hdlr}
return s.Handle(s.NewHandler(&Nft{h}, opts...))
}
type nftHandler struct {
NftHandler
}
func (h *nftHandler) Vote(ctx context.Context, in *VoteRequest, out *VoteResponse) error {
return h.NftHandler.Vote(ctx, in, out)
}

20
nft/proto/nft.proto Normal file
View File

@@ -0,0 +1,20 @@
syntax = "proto3";
package nft;
option go_package = "./proto;nft";
service Nft {
rpc Vote(VoteRequest) returns (VoteResponse) {}
}
// Vote to have the NFT api launched faster!
message VoteRequest {
// optional message
string message = 1;
}
message VoteResponse {
// response message
string message = 2;
}

6
nft/publicapi.json Normal file
View File

@@ -0,0 +1,6 @@
{
"name": "nft",
"icon": "🪙",
"category": "coming soon",
"display_name": "NFT (Coming Soon)"
}