Skip to content

Commit

Permalink
proto-to-block 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Neznaemov committed Oct 24, 2023
1 parent e01d0d5 commit defacdb
Show file tree
Hide file tree
Showing 66 changed files with 5,529 additions and 1,271 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GOFLAGS ?= -mod=vendor

PROTO_PACKAGES_GO := proto
PROTO_PACKAGES_GO := block
PROTO_PACKAGES_SVC := service

test:
Expand All @@ -10,6 +10,7 @@ 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
@go fmt ./...

clean:
@for pkg in $(PROTO_PACKAGES_GO); do find $$pkg \( -name '*.pb.go' -or -name '*.pb.md' \) -delete;done
Expand Down
8 changes: 4 additions & 4 deletions api/peer_deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
"github.com/hyperledger/fabric-protos-go/peer"
"google.golang.org/grpc/codes"

"github.com/s7techlab/hlf-sdk-go/proto"
"github.com/s7techlab/hlf-sdk-go/block"
)

var (
SeekFromOldest = &orderer.SeekPosition{
Type: &orderer.SeekPosition_Oldest{Oldest: &orderer.SeekOldest{}}}
SeekFromNewest = &orderer.SeekPosition{
Type: &orderer.SeekPosition_Newest{Newest: &orderer.SeekNewest{}}}
SeekToMax = proto.NewSeekSpecified(math.MaxUint64)
SeekToMax = block.NewSeekSpecified(math.MaxUint64)
)

type DeliverClient interface {
Expand Down Expand Up @@ -61,10 +61,10 @@ func SeekRange(start, end uint64) EventCCSeekOption {
if start == 0 {
seekFrom = SeekFromOldest
} else {
seekFrom = proto.NewSeekSpecified(start)
seekFrom = block.NewSeekSpecified(start)
}
return func() (*orderer.SeekPosition, *orderer.SeekPosition) {
return seekFrom, proto.NewSeekSpecified(end)
return seekFrom, block.NewSeekSpecified(end)
}
}

Expand Down
35 changes: 4 additions & 31 deletions proto/block.go → block/block.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package proto
package block

import (
"fmt"

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/protoutil"

bft "github.com/s7techlab/hlf-sdk-go/proto/smartbft"
bftcommon "github.com/s7techlab/hlf-sdk-go/proto/smartbft/common"
"github.com/s7techlab/hlf-sdk-go/proto/txflags"
bft "github.com/s7techlab/hlf-sdk-go/block/smartbft"
bftcommon "github.com/s7techlab/hlf-sdk-go/block/smartbft/common"
"github.com/s7techlab/hlf-sdk-go/block/txflags"
)

type (
Expand Down Expand Up @@ -177,28 +175,3 @@ func createConfigEnvelope(data []byte) (*common.ConfigEnvelope, error) {

return configEnvelope, nil
}

func (x *Block) ValidEnvelopes() []*Envelope {
var envs []*Envelope
for _, e := range x.Data.Envelopes {
if e.ValidationCode != peer.TxValidationCode_VALID {
continue
}

envs = append(envs, e)
}

return envs
}

func (x *Block) BlockDate() *timestamp.Timestamp {
var max *timestamp.Timestamp
for _, envelope := range x.ValidEnvelopes() {
ts := envelope.GetPayload().GetHeader().GetChannelHeader().GetTimestamp()

if ts.AsTime().After(max.AsTime()) {
max = ts
}
}
return max
}
391 changes: 196 additions & 195 deletions proto/block.pb.go → block/block.pb.go

Large diffs are not rendered by default.

Loading

0 comments on commit defacdb

Please sign in to comment.