Skip to content

Commit

Permalink
block-date-func
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Neznaemov committed Oct 17, 2023
1 parent 8783b30 commit 739c0af
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions proto/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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"
Expand Down Expand Up @@ -189,3 +190,15 @@ func (x *Block) ValidEnvelopes() []*Envelope {

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
}

0 comments on commit 739c0af

Please sign in to comment.