代码拉取完成,页面将自动刷新
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package chaincode
import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/common/ccprovider"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/pkg/errors"
"golang.org/x/net/context"
)
// Executor is used to invoke chaincode.
type Executor interface {
Execute(ctxt context.Context, cccid *ccprovider.CCContext, cis ccprovider.ChaincodeSpecGetter) (*pb.Response, *pb.ChaincodeEvent, error)
}
// Lifecycle provides methods to invoke the lifecycle system chaincode.
type Lifecycle struct {
Executor Executor
}
// GetChaincodeDeploymentSpec retrieves a chaincode deployment spec for the specified chaincode.
func (l *Lifecycle) GetChaincodeDeploymentSpec(
ctx context.Context,
txid string,
signedProp *pb.SignedProposal,
prop *pb.Proposal,
chainID string,
chaincodeID string,
) (*pb.ChaincodeDeploymentSpec, error) {
version := util.GetSysCCVersion()
cccid := ccprovider.NewCCContext(chainID, "lscc", version, txid, true, signedProp, prop)
invocationSpec := &pb.ChaincodeInvocationSpec{
ChaincodeSpec: &pb.ChaincodeSpec{
Type: pb.ChaincodeSpec_GOLANG,
ChaincodeId: &pb.ChaincodeID{Name: cccid.Name},
Input: &pb.ChaincodeInput{
Args: util.ToChaincodeArgs("getdepspec", chainID, chaincodeID),
},
},
}
res, _, err := l.Executor.Execute(ctx, cccid, invocationSpec)
if err != nil {
return nil, errors.Wrapf(err, "getdepspec %s/%s failed", chainID, chaincodeID)
}
if res.Status != shim.OK {
return nil, errors.Errorf("getdepspec %s/%s responded with error: %s", chainID, chaincodeID, res.Message)
}
if res.Payload == nil {
return nil, errors.Errorf("getdepspec %s/%s failed: payload is nil", chainID, chaincodeID)
}
cds := &pb.ChaincodeDeploymentSpec{}
err = proto.Unmarshal(res.Payload, cds)
if err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal deployment spec payload for %s/%s", chainID, chaincodeID)
}
return cds, nil
}
// GetChaincodeDefinition returns a ccprovider.ChaincodeDefinition for the chaincode
// associated with the provided channel and name.
func (l *Lifecycle) GetChaincodeDefinition(
ctx context.Context,
txid string,
signedProp *pb.SignedProposal,
prop *pb.Proposal,
chainID string,
chaincodeID string,
) (ccprovider.ChaincodeDefinition, error) {
version := util.GetSysCCVersion()
cccid := ccprovider.NewCCContext(chainID, "lscc", version, txid, true, signedProp, prop)
invocationSpec := &pb.ChaincodeInvocationSpec{
ChaincodeSpec: &pb.ChaincodeSpec{
Type: pb.ChaincodeSpec_GOLANG,
ChaincodeId: &pb.ChaincodeID{Name: cccid.Name},
Input: &pb.ChaincodeInput{
Args: util.ToChaincodeArgs("getccdata", chainID, chaincodeID),
},
},
}
res, _, err := l.Executor.Execute(ctx, cccid, invocationSpec)
if err != nil {
return nil, errors.Wrapf(err, "getccdata %s/%s failed", chainID, chaincodeID)
}
if res.Status != shim.OK {
return nil, errors.Errorf("getccdata %s/%s responded with error: %s", chainID, chaincodeID, res.Message)
}
cd := &ccprovider.ChaincodeData{}
err = proto.Unmarshal(res.Payload, cd)
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal chaincode definition")
}
return cd, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。