Skip to content

Commit

Permalink
update to latest go mod version
Browse files Browse the repository at this point in the history
Signed-off-by: SamYuan1990 <yy19902439@126.com>
  • Loading branch information
SamYuan1990 authored and guoger committed Nov 6, 2020
1 parent 750210a commit 7b6e883
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 46 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ steps:
- task: Go@0
inputs:
command: 'test'
arguments: '-v ./...'
arguments: '-v ./... -cover'
workingDirectory: '$(System.DefaultWorkingDirectory)'

12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ module github.com/guoger/stupid
go 1.12

require (
github.com/Knetic/govaluate v3.0.0+incompatible // indirect
github.com/Shopify/sarama v1.23.1 // indirect
github.com/fsouza/go-dockerclient v1.4.4 // indirect
github.com/gogo/protobuf v1.2.1
github.com/golang/protobuf v1.3.2
github.com/hashicorp/go-version v1.2.0 // indirect
github.com/hyperledger/fabric v1.4.3
github.com/hyperledger/fabric-amcl v0.0.0-20181230093703-5ccba6eab8d6 // indirect
github.com/hyperledger/fabric v2.0.1+incompatible
github.com/hyperledger/fabric-amcl v0.0.0-20200128223036-d1aa2665426a // indirect
github.com/hyperledger/fabric-protos-go v0.0.0-20200424173316-dd554ba3746e
github.com/hyperledger/fabric-samples/commercial-paper/organization/digibank/contract-go v0.0.0-20200610124333-7b2dcbf2edc1 // indirect
github.com/hyperledger/fabric-samples/commercial-paper/organization/magnetocorp/contract-go v0.0.0-20200610124333-7b2dcbf2edc1 // indirect
github.com/hyperledger/fabric-sdk-go v1.0.0-beta1.0.20200317135226-e71412ff3db1
github.com/miekg/pkcs11 v1.0.3 // indirect
github.com/onsi/ginkgo v1.10.1 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect
github.com/pkg/errors v0.8.1
github.com/spf13/viper v1.4.0 // indirect
github.com/stretchr/testify v1.3.0
github.com/stretchr/testify v1.5.1
github.com/sykesm/zap-logfmt v0.0.2 // indirect
google.golang.org/grpc v1.23.0 // indirect
gopkg.in/jcmturner/goidentity.v3 v3.0.0 // indirect
)
161 changes: 153 additions & 8 deletions go.sum

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions infra/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package infra
import (
"sync"

"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
)

type Elements struct {
Expand All @@ -24,7 +24,6 @@ func (a *Assembler) assemble(e *Elements) *Elements {
if err != nil {
panic(err)
}

e.Envelope = env
return e
}
Expand All @@ -34,7 +33,6 @@ func (a *Assembler) sign(e *Elements) *Elements {
if err != nil {
panic(err)
}

e.SignedProp = sprop

return e
Expand Down
12 changes: 6 additions & 6 deletions infra/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"context"
"time"

"github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/core/comm"
"github.com/hyperledger/fabric/protos/orderer"
"github.com/hyperledger/fabric/protos/peer"
)

func CreateGRPCClient(certs [][]byte) (*comm.GRPCClient, error) {
config := comm.ClientConfig{}
config.Timeout = 5 * time.Second
config.SecOpts = &comm.SecureOptions{
config.SecOpts = comm.SecureOptions{
UseTLS: false,
RequireClientCert: false,
ServerRootCAs: certs,
Expand All @@ -36,7 +36,7 @@ func CreateEndorserClient(addr string, tlscacerts [][]byte) (peer.EndorserClient
return nil, err
}

conn, err := gRPCClient.NewConnection(addr, "")
conn, err := gRPCClient.NewConnection(addr)
if err != nil {
return nil, err
}
Expand All @@ -50,7 +50,7 @@ func CreateBroadcastClient(addr string, tlscacerts [][]byte) (orderer.AtomicBroa
return nil, err
}

conn, err := gRPCClient.NewConnection(addr, "")
conn, err := gRPCClient.NewConnection(addr)
if err != nil {
return nil, err
}
Expand All @@ -64,7 +64,7 @@ func CreateDeliverFilteredClient(addr string, tlscacerts [][]byte) (peer.Deliver
return nil, err
}

conn, err := gRPCClient.NewConnection(addr, "")
conn, err := gRPCClient.NewConnection(addr)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion infra/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io/ioutil"

"github.com/gogo/protobuf/proto"
"github.com/hyperledger/fabric/protos/msp"
"github.com/hyperledger/fabric-protos-go/msp"
)

type Config struct {
Expand Down
2 changes: 1 addition & 1 deletion infra/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"io/ioutil"
"math/big"

"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric/bccsp/utils"
"github.com/hyperledger/fabric/common/crypto"
"github.com/hyperledger/fabric/protos/common"
"github.com/pkg/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion infra/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric-protos-go/peer"
)

type Observer struct {
Expand Down
70 changes: 56 additions & 14 deletions infra/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"math"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/orderer"
"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/protoutil"
"github.com/pkg/errors"
)

Expand All @@ -31,7 +31,7 @@ func CreateProposal(signer *Crypto, channel, ccname, version string, args ...str
panic(err)
}

prop, _, err := utils.CreateChaincodeProposal(common.HeaderType_ENDORSER_TRANSACTION, channel, invocation, creator)
prop, _, err := protoutil.CreateChaincodeProposal(common.HeaderType_ENDORSER_TRANSACTION, channel, invocation, creator)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -59,13 +59,13 @@ func CreateSignedTx(proposal *peer.Proposal, signer *Crypto, resps []*peer.Propo
}

// the original header
hdr, err := utils.GetHeader(proposal.Header)
hdr, err := GetHeader(proposal.Header)
if err != nil {
return nil, err
}

// the original payload
pPayl, err := utils.GetChaincodeProposalPayload(proposal.Payload)
pPayl, err := GetChaincodeProposalPayload(proposal.Payload)
if err != nil {
return nil, err
}
Expand All @@ -77,7 +77,7 @@ func CreateSignedTx(proposal *peer.Proposal, signer *Crypto, resps []*peer.Propo
return nil, err
}

shdr, err := utils.GetSignatureHeader(hdr.SignatureHeader)
shdr, err := GetSignatureHeader(hdr.SignatureHeader)
if err != nil {
return nil, err
}
Expand All @@ -87,7 +87,7 @@ func CreateSignedTx(proposal *peer.Proposal, signer *Crypto, resps []*peer.Propo
}

// get header extensions so we have the visibility field
hdrExt, err := utils.GetChaincodeHeaderExtension(hdr)
_, err = GetChaincodeHeaderExtension(hdr)
if err != nil {
return nil, err
}
Expand All @@ -112,14 +112,14 @@ func CreateSignedTx(proposal *peer.Proposal, signer *Crypto, resps []*peer.Propo
cea := &peer.ChaincodeEndorsedAction{ProposalResponsePayload: a1, Endorsements: endorsements}

// obtain the bytes of the proposal payload that will go to the transaction
propPayloadBytes, err := utils.GetBytesProposalPayloadForTx(pPayl, hdrExt.PayloadVisibility)
propPayloadBytes, err := protoutil.GetBytesProposalPayloadForTx(pPayl) //, hdrExt.PayloadVisibility
if err != nil {
return nil, err
}

// serialize the chaincode action payload
cap := &peer.ChaincodeActionPayload{ChaincodeProposalPayload: propPayloadBytes, Action: cea}
capBytes, err := utils.GetBytesChaincodeActionPayload(cap)
capBytes, err := protoutil.GetBytesChaincodeActionPayload(cap)
if err != nil {
return nil, err
}
Expand All @@ -130,14 +130,14 @@ func CreateSignedTx(proposal *peer.Proposal, signer *Crypto, resps []*peer.Propo
taas[0] = taa
tx := &peer.Transaction{Actions: taas}
// serialize the tx
txBytes, err := utils.GetBytesTransaction(tx)
txBytes, err := protoutil.GetBytesTransaction(tx)
if err != nil {
return nil, err
}

// create the payload
payl := &common.Payload{Header: hdr, Data: txBytes}
paylBytes, err := utils.GetBytesPayload(payl)
paylBytes, err := protoutil.GetBytesPayload(payl)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func CreateSignedDeliverNewestEnv(ch string, signer *Crypto) (*common.Envelope,
Behavior: orderer.SeekInfo_BLOCK_UNTIL_READY,
}

return utils.CreateSignedEnvelope(
return protoutil.CreateSignedEnvelope(
common.HeaderType_DELIVER_SEEK_INFO,
ch,
signer,
Expand All @@ -181,3 +181,45 @@ func CreateSignedDeliverNewestEnv(ch string, signer *Crypto) (*common.Envelope,
0,
)
}

func GetHeader(bytes []byte) (*common.Header, error) {
hdr := &common.Header{}
err := proto.Unmarshal(bytes, hdr)
return hdr, errors.Wrap(err, "error unmarshaling Header")
}

func GetChaincodeProposalPayload(bytes []byte) (*peer.ChaincodeProposalPayload, error) {
cpp := &peer.ChaincodeProposalPayload{}
err := proto.Unmarshal(bytes, cpp)
return cpp, errors.Wrap(err, "error unmarshaling ChaincodeProposalPayload")
}

func GetSignatureHeader(bytes []byte) (*common.SignatureHeader, error) {
return UnmarshalSignatureHeader(bytes)
}

func GetChaincodeHeaderExtension(hdr *common.Header) (*peer.ChaincodeHeaderExtension, error) {
chdr, err := UnmarshalChannelHeader(hdr.ChannelHeader)
if err != nil {
return nil, err
}

chaincodeHdrExt := &peer.ChaincodeHeaderExtension{}
err = proto.Unmarshal(chdr.Extension, chaincodeHdrExt)
return chaincodeHdrExt, errors.Wrap(err, "error unmarshaling ChaincodeHeaderExtension")
}

// UnmarshalChannelHeader returns a ChannelHeader from bytes
func UnmarshalChannelHeader(bytes []byte) (*common.ChannelHeader, error) {
chdr := &common.ChannelHeader{}
err := proto.Unmarshal(bytes, chdr)
return chdr, errors.Wrap(err, "error unmarshaling ChannelHeader")
}

func UnmarshalSignatureHeader(bytes []byte) (*common.SignatureHeader, error) {
sh := &common.SignatureHeader{}
if err := proto.Unmarshal(bytes, sh); err != nil {
return nil, errors.Wrap(err, "error unmarshaling SignatureHeader")
}
return sh, nil
}
14 changes: 9 additions & 5 deletions infra/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"io"

"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/orderer"
"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric-protos-go/peer"
)

type Proposers struct {
Expand Down Expand Up @@ -60,8 +60,12 @@ func (p *Proposer) Start(signed, processed chan *Elements, done <-chan struct{},
//send sign proposal to peer for endorsement
r, err := p.e.ProcessProposal(context.Background(), s.SignedProp)
if err != nil || r.Response.Status < 200 || r.Response.Status >= 400 {
fmt.Printf("Err processing proposal: %s, status: %d, addr: %s \n", err, r.Response.Status, p.addr)
fmt.Println(r)
if r == nil {
fmt.Printf("Err processing proposal: %s, status: unknown, addr: %s \n", err, p.addr)
} else {
fmt.Printf("Err processing proposal: %s, status: %d, addr: %s \n", err, r.Response.Status, p.addr)
fmt.Println(r)
}
continue
}
s.lock.Lock()
Expand Down

0 comments on commit 7b6e883

Please sign in to comment.