-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lifecycle interface to system cc (#60)
* 1 * add Lifecycle interface to core SystemCC and implement it * add Lifecycle interface to core SystemCC and implement it * add Lifecycle interface to core SystemCC and implement it * add Lifecycle interface to core SystemCC and implement it * add Lifecycle interface to core SystemCC and implement it * add Lifecycle interface to core SystemCC and implement it * add Lifecycle interface to core SystemCC and implement it Co-authored-by: n.neznaemov <n.neznaemov@s7.ru>
- Loading branch information
Showing
4 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
lb "github.com/hyperledger/fabric-protos-go/peer/lifecycle" | ||
) | ||
|
||
type Lifecycle interface { | ||
QueryInstalledChaincodes(ctx context.Context) (*lb.QueryInstalledChaincodesResult, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,5 @@ type SystemCC interface { | |
CSCC() CSCC | ||
QSCC() QSCC | ||
LSCC() LSCC | ||
Lifecycle() Lifecycle | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package system | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/golang/protobuf/proto" | ||
lb "github.com/hyperledger/fabric-protos-go/peer/lifecycle" | ||
"github.com/hyperledger/fabric/common/util" | ||
"github.com/hyperledger/fabric/core/chaincode/lifecycle" | ||
"github.com/hyperledger/fabric/msp" | ||
"github.com/pkg/errors" | ||
"github.com/s7techlab/hlf-sdk-go/api" | ||
peerSDK "github.com/s7techlab/hlf-sdk-go/peer" | ||
) | ||
|
||
type lifecycleCC struct { | ||
peerPool api.PeerPool | ||
identity msp.SigningIdentity | ||
processor api.PeerProcessor | ||
} | ||
|
||
func (c *lifecycleCC) QueryInstalledChaincodes(ctx context.Context) (*lb.QueryInstalledChaincodesResult, error) { | ||
resp, err := c.endorse(ctx, lifecycle.QueryInstalledChaincodesFuncName, ``) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ccData := new(lb.QueryInstalledChaincodesResult) | ||
if err = proto.Unmarshal(resp, ccData); err != nil { | ||
return nil, errors.Wrap(err, `failed to unmarshal protobuf`) | ||
} | ||
return ccData, nil | ||
} | ||
|
||
func (c *lifecycleCC) endorse(ctx context.Context, fn string, args ...string) ([]byte, error) { | ||
prop, _, err := c.processor.CreateProposal(&api.DiscoveryChaincode{Name: lifecycleName, Type: api.CCTypeGoLang}, c.identity, fn, util.ToChaincodeArgs(args...), nil) | ||
if err != nil { | ||
return nil, errors.Wrap(err, `failed to create proposal`) | ||
} | ||
|
||
resp, err := c.peerPool.Process(ctx, c.identity.GetMSPIdentifier(), prop) | ||
if err != nil { | ||
return nil, errors.Wrap(err, `failed to endorse proposal`) | ||
} | ||
return resp.Response.Payload, nil | ||
} | ||
|
||
func NewLifecycle(peerPool api.PeerPool, identity msp.SigningIdentity) api.Lifecycle { | ||
return &lifecycleCC{peerPool: peerPool, identity: identity, processor: peerSDK.NewProcessor(``)} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters