Skip to content

Commit

Permalink
FABGW-21: Realtime implementation of ChaincodeEvents service (#2604)
Browse files Browse the repository at this point in the history
* FABGW-21: Realtime implementation of ChaincodeEvents service

Initial implementation of Fabric Gateway's ChaincodeEvents service, allowing only listening for realtime chaincode events.

Also add block number into CommitStatus response.

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>

* Refactor to minimise visibility of implementation outside package

Previously node.serve() accessed a lot of implementation detail within the gateway package to create structs of the appropriate abstraction for the gateway internals. Refactored to move the translation between external structs and internal abstractions to the gateway.CreateServer() function, and moved the old implementation to an newServer() function that is used by unit tests to create a Gateway server that is agnostic to whether it is an embedded or standalone implementation.

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
  • Loading branch information
bestbeforetoday authored Jun 4, 2021
1 parent 34a4186 commit 1f89be9
Show file tree
Hide file tree
Showing 37 changed files with 2,571 additions and 687 deletions.
1 change: 1 addition & 0 deletions core/aclmgmt/defaultaclprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func newDefaultACLProvider(policyChecker policy.PolicyChecker) defaultACLProvide

// Gateway resources
d.cResourcePolicyMap[resources.Gateway_CommitStatus] = CHANNELREADERS
d.cResourcePolicyMap[resources.Gateway_ChaincodeEvents] = CHANNELREADERS

return d
}
Expand Down
3 changes: 2 additions & 1 deletion core/aclmgmt/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ const (
Event_FilteredBlock = "event/FilteredBlock"

// Gateway resources
Gateway_CommitStatus = "gateway/CommitStatus"
Gateway_CommitStatus = "gateway/CommitStatus"
Gateway_ChaincodeEvents = "gateway/ChaincodeEvents"
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/hyperledger/fabric-chaincode-go v0.0.0-20201119163726-f8ef75b17719
github.com/hyperledger/fabric-config v0.1.0
github.com/hyperledger/fabric-lib-go v1.0.0
github.com/hyperledger/fabric-protos-go v0.0.0-20210505131505-0ac7fd605762
github.com/hyperledger/fabric-protos-go v0.0.0-20210520141515-88b9de28f790
github.com/kr/pretty v0.2.1
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ github.com/hyperledger/fabric-lib-go v1.0.0 h1:UL1w7c9LvHZUSkIvHTDGklxFv2kTeva1Q
github.com/hyperledger/fabric-lib-go v1.0.0/go.mod h1:H362nMlunurmHwkYqR5uHL2UDWbQdbfz74n8kbCFsqc=
github.com/hyperledger/fabric-protos-go v0.0.0-20190919234611-2a87503ac7c9/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/hyperledger/fabric-protos-go v0.0.0-20200424173316-dd554ba3746e/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/hyperledger/fabric-protos-go v0.0.0-20210505131505-0ac7fd605762 h1:7eZyv7Ly+AY8y0e/8WCitouShlWcjBT9QJGf/8DGqHQ=
github.com/hyperledger/fabric-protos-go v0.0.0-20210505131505-0ac7fd605762/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/hyperledger/fabric-protos-go v0.0.0-20210520141515-88b9de28f790 h1:TB5A4O5MviIjLPtM0UjQFitHtxitKqMyk0BGJKbGqyw=
github.com/hyperledger/fabric-protos-go v0.0.0-20210520141515-88b9de28f790/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
Expand Down
17 changes: 16 additions & 1 deletion integration/chaincode/simple/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
case "mspid":
// Checks the shim's GetMSPID() API
return t.mspid(args)
case "event":
return t.event(stub, args)
default:
return shim.Error(`Invalid invoke function name. Expecting "invoke", "delete", "query", "respond", or "mspid"`)
return shim.Error(`Invalid invoke function name. Expecting "invoke", "delete", "query", "respond", "mspid", or "event"`)
}
}

Expand Down Expand Up @@ -228,3 +230,16 @@ func (t *SimpleChaincode) mspid(args []string) pb.Response {
fmt.Printf("MSPID:%s\n", mspid)
return shim.Success([]byte(mspid))
}

// event emits a chaincode event
func (t *SimpleChaincode) event(stub shim.ChaincodeStubInterface, args []string) pb.Response {
if len(args) != 2 {
return shim.Error("Incorrect number of arguments. Expecting 2")
}

if err := stub.SetEvent(args[0], []byte(args[1])); err != nil {
return shim.Error(err.Error())
}

return shim.Success(nil)
}
Loading

0 comments on commit 1f89be9

Please sign in to comment.