Skip to content

Commit

Permalink
Merge pull request #136 from s7techlab/services-refactoring
Browse files Browse the repository at this point in the history
services refactoring
  • Loading branch information
criro1 authored Oct 23, 2023
2 parents edf8e28 + 6fb4bda commit e01d0d5
Show file tree
Hide file tree
Showing 144 changed files with 9,931 additions and 2,246 deletions.
7 changes: 7 additions & 0 deletions .generators/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ package generators
import (
// proto/grpc
_ "github.com/golang/protobuf/protoc-gen-go"

// validation schema
_ "github.com/envoyproxy/protoc-gen-validate"

_ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway"

_ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger"
)
3 changes: 2 additions & 1 deletion .generators/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ pwd
for genpkg in `go list -f '{{ join .Imports "\n" }}' deps.go`
do
echo "building $genpkg..."
go build -mod=vendor -o ${GENERATOR_DIR}/bin/`basename $genpkg` -trimpath ${genpkg}
go get ${genpkg}
go build -mod=readonly -o ${GENERATOR_DIR}/bin/`basename $genpkg` -trimpath ${genpkg}
echo "installed $genpkg"
done

4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Go Quality

on: [push, pull_request]
on: [ push, pull_request ]

jobs:
test:
Expand All @@ -11,7 +11,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: '1.16'
go-version: '1.18'

- name: Check out code
uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
GOFLAGS ?= -mod=vendor

PROTO_PACKAGES_GO := proto
PROTO_PACKAGES_SVC := service

test:
@echo "go test -mod vendor ./..."
@go test ./...

proto: clean
@for pkg in $(PROTO_PACKAGES_GO) ;do echo $$pkg && buf generate --template buf.gen.go.yaml $$pkg -o ./$$(echo $$pkg | cut -d "/" -f1); done
@for pkg in $(PROTO_PACKAGES_SVC) ;do echo $$pkg && buf generate --template buf.gen.svc.yaml $$pkg -o ./$$(echo $$pkg | cut -d "/" -f1); done

clean:
@for pkg in $(PROTO_PACKAGES_GO); do find $$pkg \( -name '*.pb.go' -or -name '*.pb.md' \) -delete;done
@for pkg in $(PROTO_PACKAGES_SVC); do find $$pkg \( -name '*.pb.go' -or -name '*.pb.cc.go' -or -name '*.pb.gw.go' -or -name '*.swagger.json' -or -name '*.pb.md' \) -delete;done
43 changes: 0 additions & 43 deletions api/chaincode_lifecycle.go

This file was deleted.

19 changes: 19 additions & 0 deletions api/channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package api

import (
"context"
)

type Channel interface {
// Chaincode returns chaincode instance by chaincode name
Chaincode(ctx context.Context, name string) (Chaincode, error)
// Join channel
Join(ctx context.Context) error
}

// types which identify tx "wait'er" policy
// we don't make it as alias for preventing binding to our lib
const (
TxWaiterSelfType string = "self"
TxWaiterAllType string = "all"
)
4 changes: 3 additions & 1 deletion api/public.go → api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ type Invoker interface {
) (res *peer.Response, chaincodeTx string, err error)
}

type Public interface {
type Client interface {
EventsDeliverer
BlocksDeliverer
Invoker

FabricV2() bool
}
17 changes: 6 additions & 11 deletions api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"strconv"
"strings"
"time"

"github.com/s7techlab/hlf-sdk-go/crypto"
)

type Config struct {
Crypto CryptoConfig `yaml:"crypto"`
Crypto *crypto.Config `yaml:"crypto"`
Orderers []ConnectionConfig `yaml:"orderers"`
Discovery DiscoveryConfig `yaml:"discovery"`
// peer pool for local configuration without gossip discovery
Expand All @@ -25,9 +27,9 @@ type ConnectionConfig struct {
}

type CAConfig struct {
Crypto CryptoConfig `yaml:"crypto"`
Host string `yaml:"host"`
Tls TlsConfig `yaml:"tls"`
Crypto *crypto.Config `yaml:"crypto"`
Host string `yaml:"host"`
Tls TlsConfig `yaml:"tls"`
}

type PoolConfig struct {
Expand Down Expand Up @@ -99,13 +101,6 @@ type DiscoveryChaincode struct {
Policy string `json:"policy"`
}

type CryptoConfig struct {
Type string `yaml:"type"`
Options CryptoSuiteOpts `yaml:"options"`
}

type CryptoSuiteOpts map[string]interface{}

type Duration struct {
time.Duration
}
Expand Down
38 changes: 0 additions & 38 deletions api/core.go

This file was deleted.

41 changes: 0 additions & 41 deletions api/errors.go

This file was deleted.

18 changes: 0 additions & 18 deletions api/identity.go

This file was deleted.

8 changes: 4 additions & 4 deletions api/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ type Endorser interface {
Endorse(ctx context.Context, proposal *peer.SignedProposal) (*peer.ProposalResponse, error)
}

type ChannelsFetcher interface {
type ChannelListGetter interface {
GetChannels(ctx context.Context) (*peer.ChannelQueryResponse, error)
}

type ChannelInfo interface {
type ChainInfoGetter interface {
GetChainInfo(ctx context.Context, channel string) (*common.BlockchainInfo, error)
}

Expand All @@ -29,9 +29,9 @@ type Peer interface {

Endorser

ChannelInfo
ChannelListGetter

ChannelsFetcher
ChainInfoGetter

BlocksDeliverer

Expand Down
37 changes: 0 additions & 37 deletions api/peer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,11 @@ package api

import (
"context"
"fmt"
"time"

"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/msp"
"google.golang.org/grpc/connectivity"
)

const (
ErrNoPeersForMSP = Error(`no peers for MSP`)
ErrMSPNotFound = Error(`MSP not found`)
ErrPeerNotReady = Error(`peer not ready`)

DefaultGrpcCheckPeriod = 5 * time.Second
)

type ErrNoReadyPeers struct {
MspId string
}

func (e ErrNoReadyPeers) Error() string {
return fmt.Sprintf("no ready peers for MspId: %s", e.MspId)
}

type MSPPeerPool interface {
Peers() []Peer
FirstReadyPeer() (Peer, error)
Expand All @@ -45,21 +26,3 @@ type PeerPool interface {
}

type PeerPoolCheckStrategy func(ctx context.Context, peer Peer, alive chan bool)

func StrategyGRPC(d time.Duration) PeerPoolCheckStrategy {
return func(ctx context.Context, peer Peer, alive chan bool) {
t := time.NewTicker(d)
for {
select {
case <-ctx.Done():
return
case <-t.C:
if peer.Conn().GetState() == connectivity.Ready {
alive <- true
} else {
alive <- false
}
}
}
}
}
8 changes: 8 additions & 0 deletions buf.gen.go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ plugins:
path: .generators/bin/protoc-gen-go
out: .
opt:
- plugins=grpc
- paths=source_relative

- name: go-validate
path: .generators/bin/protoc-gen-validate
out: .
opt:
- paths=source_relative
- lang=go
30 changes: 30 additions & 0 deletions buf.gen.svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: v1

plugins:

- name: go
path: .generators/bin/protoc-gen-go
out: .
opt:
- plugins=grpc
- paths=source_relative

- name: go-validate
path: .generators/bin/protoc-gen-validate
out: .
opt:
- paths=source_relative
- lang=go

- name: swagger
path: .generators/bin/protoc-gen-swagger
out: .
opt:
- logtostderr=true

- name: grpc-gateway
path: .generators/bin/protoc-gen-grpc-gateway
out: .
opt:
- logtostderr=true
- paths=source_relative
Loading

0 comments on commit e01d0d5

Please sign in to comment.