Skip to content

Commit

Permalink
migrate to fabric v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Zhvakin committed Jan 21, 2021
1 parent 049de97 commit 032f2c5
Show file tree
Hide file tree
Showing 43 changed files with 605 additions and 391 deletions.
16 changes: 2 additions & 14 deletions api/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package api

import (
"context"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
)

type ChaincodeTx string
Expand Down Expand Up @@ -83,18 +83,6 @@ type ChaincodeQueryBuilder interface {
AsProposalResponse(ctx context.Context) (*peer.ProposalResponse, error)
}

// CSCC describes Configuration System Chaincode (CSCC)
type CSCC interface {
// JoinChain allows to join channel using presented genesis block
JoinChain(ctx context.Context, channelName string, genesisBlock *common.Block) error
// GetConfigBlock returns genesis block of channel
GetConfigBlock(ctx context.Context, channelName string) (*common.Block, error)
// GetConfigTree returns configuration tree of channel
GetConfigTree(ctx context.Context, channelName string) (*peer.ConfigTree, error)
// Channels returns list of joined channels
Channels(ctx context.Context) (*peer.ChannelQueryResponse, error)
}

// QSCC describes Query System Chaincode (QSCC)
type QSCC interface {
// GetChainInfo allows to get common info about channel blockchain
Expand Down
21 changes: 21 additions & 0 deletions api/chaincode_cscc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// +build !fabric2

package api

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

// CSCC describes Configuration System Chaincode (CSCC)
type CSCC interface {
// JoinChain allows to join channel using presented genesis block
JoinChain(ctx context.Context, channelName string, genesisBlock *common.Block) error
// GetConfigBlock returns genesis block of channel
GetConfigBlock(ctx context.Context, channelName string) (*common.Block, error)
// GetConfigTree returns configuration tree of channel
GetConfigTree(ctx context.Context, channelName string) (*peer.ConfigTree, error)
// Channels returns list of joined channels
Channels(ctx context.Context) (*peer.ChannelQueryResponse, error)
}
21 changes: 21 additions & 0 deletions api/chaincode_cscc_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// +build fabric2

package api

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

// CSCC describes Configuration System Chaincode (CSCC)
type CSCC interface {
// JoinChain allows to join channel using presented genesis block
JoinChain(ctx context.Context, channelName string, genesisBlock *common.Block) error
// GetConfigBlock returns genesis block of channel
GetConfigBlock(ctx context.Context, channelName string) (*common.Block, error)
// GetChannelConfig returns channel configuration
GetChannelConfig(ctx context.Context, channelName string) (*common.Config, error)
// GetChannels returns list of joined channels
GetChannels(ctx context.Context) (*peer.ChannelQueryResponse, error)
}
4 changes: 2 additions & 2 deletions api/chaincode_lscc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package api
import (
"context"

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

type LSCCDeployOptions struct {
Expand Down
2 changes: 1 addition & 1 deletion api/discovery.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package api

import (
"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric-protos-go/peer"

"github.com/s7techlab/hlf-sdk-go/api/config"
)
Expand Down
2 changes: 1 addition & 1 deletion api/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package api

import (
"context"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/peer"
)

// Invoker interface describes common operations for chaincode
Expand Down
4 changes: 2 additions & 2 deletions api/orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package api
import (
"context"

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

type Orderer interface {
Expand Down
2 changes: 1 addition & 1 deletion api/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package api
import (
"context"
"fmt"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/peer"
"google.golang.org/grpc"
)

Expand Down
6 changes: 3 additions & 3 deletions api/peer_deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"google.golang.org/grpc/codes"

"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"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion api/peer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

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

Expand Down
2 changes: 1 addition & 1 deletion ca/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"net/http"

"github.com/golang/protobuf/proto"
mspPb "github.com/hyperledger/fabric-protos-go/msp"
"github.com/hyperledger/fabric/msp"
mspPb "github.com/hyperledger/fabric/protos/msp"
"github.com/pkg/errors"
"github.com/s7techlab/hlf-sdk-go/api"
"github.com/s7techlab/hlf-sdk-go/api/ca"
Expand Down
10 changes: 5 additions & 5 deletions client/chaincode/core_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package chaincode

import (
"context"
"github.com/hyperledger/fabric/common/policydsl"
"github.com/hyperledger/fabric/protoutil"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/cauthdsl"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/utils"
"github.com/pkg/errors"

"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/s7techlab/hlf-sdk-go/api"
)

Expand Down Expand Up @@ -44,7 +44,7 @@ func (c *corePackage) Install(ctx context.Context, path, version string) error {
}

func (c *corePackage) Instantiate(ctx context.Context, channelName, path, version, policy string, args [][]byte, transArgs api.TransArgs) error {
ePolicy, err := cauthdsl.FromString(policy)
ePolicy, err := policydsl.FromString(policy)
if err != nil {
return errors.Wrap(err, `failed to parse endorsement policy`)
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func (c *corePackage) Instantiate(ctx context.Context, channelName, path, versio
return errors.Wrap(err, `failed to pnmarshal proposal for make peer.Proposal`)
}

env, err := utils.CreateSignedTx(peerProp, c.identity, resp)
env, err := protoutil.CreateSignedTx(peerProp, c.identity, resp)
if err != nil {
return errors.Wrap(err, "could not assemble transaction")
}
Expand Down
8 changes: 4 additions & 4 deletions client/chaincode/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"encoding/json"
"fmt"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
fabricPeer "github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/common"
fabricPeer "github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
"github.com/hyperledger/fabric/protoutil"
"github.com/pkg/errors"

"github.com/s7techlab/hlf-sdk-go/api"
Expand Down Expand Up @@ -116,7 +116,7 @@ func (b *invokeBuilder) getTransaction(proposal *fabricPeer.SignedProposal, peer
return nil, errors.Wrap(err, `failed to unmarshal `)
}

return utils.CreateSignedTx(prop, b.identity, peerResponses...)
return protoutil.CreateSignedTx(prop, b.identity, peerResponses...)
}

func (b *invokeBuilder) ArgJSON(in ...interface{}) api.ChaincodeInvokeBuilder {
Expand Down
22 changes: 9 additions & 13 deletions client/chaincode/invoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ package chaincode_test
import (
"context"
"fmt"
"github.com/hyperledger/fabric/protoutil"
"strings"
"testing"

"github.com/golang/protobuf/proto"
"github.com/pkg/errors"
"google.golang.org/grpc"

"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/msp"
"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/pkg/errors"
"github.com/s7techlab/hlf-sdk-go/api"
"github.com/s7techlab/hlf-sdk-go/api/config"
"github.com/s7techlab/hlf-sdk-go/client"
Expand All @@ -28,6 +25,7 @@ import (
"github.com/s7techlab/hlf-sdk-go/identity"
"github.com/s7techlab/hlf-sdk-go/logger"
"github.com/s7techlab/hlf-sdk-go/peer/pool"
"google.golang.org/grpc"
)

var (
Expand Down Expand Up @@ -121,12 +119,11 @@ func (p *mockPeer) Endorse(ctx context.Context, proposal *peer.SignedProposal, o
if err := proto.Unmarshal(proposal.ProposalBytes, prop); err != nil {
return nil, errors.Wrap(err, `failed to unmarshal ProposalBytes`)
}

header, err := utils.GetHeader(prop.Header)
header, err := protoutil.UnmarshalHeader(prop.Header)
if err != nil {
return nil, errors.Wrap(err, `failed to unmarshal Header`)
}
chheader, err := utils.UnmarshalChannelHeader(header.ChannelHeader)
chheader, err := protoutil.UnmarshalChannelHeader(header.ChannelHeader)
if err != nil {
return nil, errors.Wrap(err, `failed to unmarshal`)
}
Expand All @@ -145,14 +142,13 @@ func (p *mockPeer) Endorse(ctx context.Context, proposal *peer.SignedProposal, o
Version: `0.1`,
}

return utils.CreateProposalResponse(
return protoutil.CreateProposalResponse(
prop.Header,
prop.Payload,
peerResp,
result,
event,
ccid,
[]byte(`{"message": "OK"}`),
p.endorser,
)
}
Expand Down
2 changes: 1 addition & 1 deletion client/chaincode/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"encoding/json"

fabricPeer "github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/msp"
fabricPeer "github.com/hyperledger/fabric/protos/peer"
"github.com/pkg/errors"
"github.com/s7techlab/hlf-sdk-go/api"
"github.com/s7techlab/hlf-sdk-go/peer"
Expand Down
23 changes: 16 additions & 7 deletions client/chaincode/system/cscc.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
// +build !fabric2

package system

import (
"context"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/util"
csccPkg "github.com/hyperledger/fabric/core/scc/cscc"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
"github.com/pkg/errors"
"github.com/s7techlab/hlf-sdk-go/api"
peerSDK "github.com/s7techlab/hlf-sdk-go/peer"
)

// These are function names from Invoke first parameter
const (
JoinChain string = "JoinChain"
GetConfigBlock string = "GetConfigBlock"
GetChannels string = "GetChannels"
GetConfigTree string = `GetConfigTree`
)

type cscc struct {
peerPool api.PeerPool
identity msp.SigningIdentity
Expand All @@ -26,12 +35,12 @@ func (c *cscc) JoinChain(ctx context.Context, channelName string, genesisBlock *
return errors.Wrapf(err, "failed to marshal block %s", channelName)
}

_, err = c.endorse(ctx, csccPkg.JoinChain, string(blockBytes))
_, err = c.endorse(ctx, JoinChain, string(blockBytes))
return err
}

func (c *cscc) GetConfigBlock(ctx context.Context, channelName string) (*common.Block, error) {
resp, err := c.endorse(ctx, csccPkg.GetConfigBlock, channelName)
resp, err := c.endorse(ctx, GetConfigBlock, channelName)
if err != nil {
return nil, err
}
Expand All @@ -43,7 +52,7 @@ func (c *cscc) GetConfigBlock(ctx context.Context, channelName string) (*common.
}

func (c *cscc) GetConfigTree(ctx context.Context, channelName string) (*peer.ConfigTree, error) {
resp, err := c.endorse(ctx, csccPkg.GetConfigTree, channelName)
resp, err := c.endorse(ctx, GetConfigTree, channelName)
if err != nil {
return nil, err
}
Expand All @@ -55,7 +64,7 @@ func (c *cscc) GetConfigTree(ctx context.Context, channelName string) (*peer.Con
}

func (c *cscc) Channels(ctx context.Context) (*peer.ChannelQueryResponse, error) {
resp, err := c.endorse(ctx, csccPkg.GetChannels)
resp, err := c.endorse(ctx, GetChannels)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 032f2c5

Please sign in to comment.