Skip to content

Commit

Permalink
[FAB-8049] Split txn out of channel
Browse files Browse the repository at this point in the history
This patch moves txn methods from channel and internal into its
own package.

Change-Id: If024c9ee85a423d1b6dda891eac1e3d762d656f9
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Feb 3, 2018
1 parent b8f2be7 commit d4c8e3c
Show file tree
Hide file tree
Showing 19 changed files with 1,424 additions and 1,361 deletions.
4 changes: 2 additions & 2 deletions api/apifabclient/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ type TransactionID struct {

// ChaincodeInvokeRequest contains the parameters for sending a transaction proposal.
type ChaincodeInvokeRequest struct {
Targets []ProposalProcessor
Targets []ProposalProcessor // TODO: remove
ChaincodeID string
TxnID TransactionID // TODO: does it make sense to include the TxnID in the request?
TxnID TransactionID // TODO: remove from external interface
TransientMap map[string][]byte
Fcn string
Args [][]byte
Expand Down
17 changes: 8 additions & 9 deletions pkg/fabric-client/channel/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ package channel
import (
"time"

"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/internal"

"github.com/golang/protobuf/proto"

ab "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/orderer"
Expand All @@ -19,6 +17,7 @@ import (

ccomm "github.com/hyperledger/fabric-sdk-go/pkg/config/comm"
fc "github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/internal"
"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/txn"
"github.com/pkg/errors"
)

Expand All @@ -41,7 +40,7 @@ func (c *Channel) GenesisBlock() (*common.Block, error) {
return nil, errors.WithMessage(err, "failed to get creator identity")
}

txnID, err := internal.NewTxnID(c.clientContext)
txnID, err := txn.NewID(c.clientContext)
if err != nil {
return nil, errors.WithMessage(err, "failed to calculate transaction id")
}
Expand All @@ -57,7 +56,7 @@ func (c *Channel) GenesisBlock() (*common.Block, error) {
}
protos_utils.MakeChannelHeader(common.HeaderType_DELIVER_SEEK_INFO, 1, c.Name(), 0)
tlsCertHash := ccomm.TLSCertHash(c.clientContext.Config())
seekInfoHeader, err := BuildChannelHeader(common.HeaderType_DELIVER_SEEK_INFO, c.Name(), txnID.ID, 0, "", time.Now(), tlsCertHash)
seekInfoHeader, err := txn.BuildChannelHeader(common.HeaderType_DELIVER_SEEK_INFO, c.Name(), txnID.ID, 0, "", time.Now(), tlsCertHash)
if err != nil {
return nil, errors.Wrap(err, "BuildChannelHeader failed")
}
Expand All @@ -71,12 +70,12 @@ func (c *Channel) GenesisBlock() (*common.Block, error) {
}
seekPayloadBytes := fc.MarshalOrPanic(seekPayload)

signedEnvelope, err := c.SignPayload(seekPayloadBytes)
signedEnvelope, err := txn.SignPayload(c.clientContext, seekPayloadBytes)
if err != nil {
return nil, errors.WithMessage(err, "SignPayload failed")
}

block, err := c.SendEnvelope(signedEnvelope)
block, err := txn.SendEnvelope(c.clientContext, signedEnvelope, c.Orderers())
if err != nil {
return nil, errors.WithMessage(err, "SendEnvelope failed")
}
Expand All @@ -101,7 +100,7 @@ func (c *Channel) block(pos *ab.SeekPosition) (*common.Block, error) {
}

tlsCertHash := ccomm.TLSCertHash(c.clientContext.Config())
seekInfoHeader, err := BuildChannelHeader(common.HeaderType_DELIVER_SEEK_INFO, c.Name(), txID, 0, "", time.Now(), tlsCertHash)
seekInfoHeader, err := txn.BuildChannelHeader(common.HeaderType_DELIVER_SEEK_INFO, c.Name(), txID, 0, "", time.Now(), tlsCertHash)
if err != nil {
return nil, errors.Wrap(err, "BuildChannelHeader failed")
}
Expand Down Expand Up @@ -147,10 +146,10 @@ func (c *Channel) block(pos *ab.SeekPosition) (*common.Block, error) {
return nil, err
}

signedEnvelope, err := c.SignPayload(seekPayloadBytes)
signedEnvelope, err := txn.SignPayload(c.clientContext, seekPayloadBytes)
if err != nil {
return nil, errors.WithMessage(err, "SignPayload failed")
}

return c.SendEnvelope(signedEnvelope)
return txn.SendEnvelope(c.clientContext, signedEnvelope, c.Orderers())
}
25 changes: 17 additions & 8 deletions pkg/fabric-client/channel/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/pkg/errors"

fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient"
"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/txn"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)
Expand Down Expand Up @@ -188,12 +189,17 @@ func queryByChaincode(channelID string, request fab.ChaincodeInvokeRequest, clie
return nil, err
}

transactionProposalResponses, _, err := SendTransactionProposalWithChannelID(channelID, request, clientContext)
tp, err := txn.NewProposal(clientContext, channelID, request)
if err != nil {
return nil, errors.WithMessage(err, "SendTransactionProposalWithChannelID failed")
return nil, errors.WithMessage(err, "NewProposal failed")
}

return filterProposalResponses(transactionProposalResponses)
tpr, err := txn.SendProposal(tp, request.Targets)
if err != nil {
return nil, errors.WithMessage(err, "SendProposal failed")
}

return filterProposalResponses(tpr)
}

// queryBySystemChaincodeByTarget is an internal helper function that queries system chaincode.
Expand Down Expand Up @@ -250,16 +256,19 @@ func (c *Channel) QueryConfigBlock(peers []fab.Peer, minResponses int) (*common.
ChaincodeID: "cscc",
Fcn: "GetConfigBlock",
Args: [][]byte{[]byte(c.Name())},
Targets: peersToTxnProcessors(peers),
}

// we are using system channel here (query to system cc)
transactionProposalResponses, _, err := SendTransactionProposalWithChannelID(systemChannel, request, c.clientContext)
tp, err := txn.NewProposal(c.clientContext, systemChannel, request)
if err != nil {
return nil, errors.WithMessage(err, "NewProposal failed")
}

tpr, err := txn.SendProposal(tp, peersToTxnProcessors(peers))
if err != nil {
return nil, errors.WithMessage(err, "SendTransactionProposalWithChannelID failed")
return nil, errors.WithMessage(err, "SendProposal failed")
}

responses, err := filterProposalResponses(transactionProposalResponses)
responses, err := filterProposalResponses(tpr)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit d4c8e3c

Please sign in to comment.