github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/integration/raft/client.go (about) 1 /* 2 Copyright hechain All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package raft 8 9 import ( 10 "github.com/hechain20/hechain/integration/nwo" 11 "github.com/hechain20/hechain/integration/ordererclient" 12 "github.com/hechain20/hechain/protoutil" 13 "github.com/hyperledger/fabric-protos-go/common" 14 "github.com/hyperledger/fabric-protos-go/orderer" 15 . "github.com/onsi/gomega" 16 ) 17 18 func FetchBlock(n *nwo.Network, o *nwo.Orderer, seq uint64, channel string) *common.Block { 19 denv := CreateDeliverEnvelope(n, o, seq, channel) 20 Expect(denv).NotTo(BeNil()) 21 22 var blk *common.Block 23 Eventually(func() error { 24 var err error 25 blk, err = ordererclient.Deliver(n, o, denv) 26 return err 27 }, n.EventuallyTimeout).ShouldNot(HaveOccurred()) 28 29 return blk 30 } 31 32 func CreateBroadcastEnvelope(n *nwo.Network, entity interface{}, channel string, data []byte) *common.Envelope { 33 var signer *nwo.SigningIdentity 34 switch creator := entity.(type) { 35 case *nwo.Peer: 36 signer = n.PeerUserSigner(creator, "Admin") 37 case *nwo.Orderer: 38 signer = n.OrdererUserSigner(creator, "Admin") 39 } 40 Expect(signer).NotTo(BeNil()) 41 42 env, err := protoutil.CreateSignedEnvelope( 43 common.HeaderType_MESSAGE, 44 channel, 45 signer, 46 &common.Envelope{Payload: data}, 47 0, 48 0, 49 ) 50 Expect(err).NotTo(HaveOccurred()) 51 52 return env 53 } 54 55 // CreateDeliverEnvelope creates a deliver env to seek for specified block. 56 func CreateDeliverEnvelope(n *nwo.Network, o *nwo.Orderer, blkNum uint64, channel string) *common.Envelope { 57 specified := &orderer.SeekPosition{ 58 Type: &orderer.SeekPosition_Specified{ 59 Specified: &orderer.SeekSpecified{Number: blkNum}, 60 }, 61 } 62 env, err := protoutil.CreateSignedEnvelope( 63 common.HeaderType_DELIVER_SEEK_INFO, 64 channel, 65 n.OrdererUserSigner(o, "Admin"), 66 &orderer.SeekInfo{ 67 Start: specified, 68 Stop: specified, 69 Behavior: orderer.SeekInfo_BLOCK_UNTIL_READY, 70 }, 71 0, 72 0, 73 ) 74 Expect(err).NotTo(HaveOccurred()) 75 76 return env 77 }