Skip to content

Commit

Permalink
FABG-943 Enhance documentation and add examples (hyperledger#75)
Browse files Browse the repository at this point in the history
Add parameter/return details to the GoDoc comments in pkg/gateway
Add usage examples to the GoDoc documentation
Add reference to pkg/gateway in doc.go and README.md
Remove unused option to disable discovery

Signed-off-by: andrew-coleman <[email protected]>
  • Loading branch information
andrew-coleman authored Jun 1, 2020
1 parent 219a09a commit ad7b043
Show file tree
Hide file tree
Showing 13 changed files with 644 additions and 53 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ SDK documentation can be viewed at [GoDoc](https://godoc.org/github.com/hyperled

The packages intended for end developer usage are within the pkg/client folder along with the main SDK package (pkg/fabsdk).

If you wish to use the Fabric 'Gateway' programming model, then the API is in the pkg/gateway folder.

### Examples

- [E2E Test](test/integration/e2e/end_to_end.go): Basic example that uses SDK to query and execute transaction
Expand Down
10 changes: 10 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ SPDX-License-Identifier: Apache-2.0
// Note: you create a new client instance for each context you need.
// 4) Use the funcs provided by each client to create your solution!
// 5) Call fabsdk.Close() to release resources and caches.
//
// Support for Hyperledger Fabric programming model
//
// In order to support the 'Gateway' programming model, the following package is provided:
//
// pkg/gateway: Enables Go developers to build client applications using the Hyperledger
// Fabric programming model as described in the 'Developing Applications' chapter of the Fabric
// documentation.
// Reference: https://godoc.org/github.com/hyperledger/fabric-sdk-go/pkg/gateway
//
package fabricsdk
22 changes: 20 additions & 2 deletions pkg/gateway/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func (c *Contract) Name() string {
// will be evaluated on the endorsing peers but the responses will not be sent to
// the ordering service and hence will not be committed to the ledger.
// This can be used for querying the world state.
// Parameters:
// name is the name of the transaction function to be invoked in the smart contract.
// args are the arguments to be sent to the transaction function.
//
// Returns:
// The return value of the transaction function in the smart contract.
func (c *Contract) EvaluateTransaction(name string, args ...string) ([]byte, error) {
txn, err := c.CreateTransaction(name)

Expand All @@ -47,6 +53,12 @@ func (c *Contract) EvaluateTransaction(name string, args ...string) ([]byte, err
// SubmitTransaction will submit a transaction to the ledger. The transaction function 'name'
// will be evaluated on the endorsing peers and then submitted to the ordering service
// for committing to the ledger.
// Parameters:
// name is the name of the transaction function to be invoked in the smart contract.
// args are the arguments to be sent to the transaction function.
//
// Returns:
// The return value of the transaction function in the smart contract.
func (c *Contract) SubmitTransaction(name string, args ...string) ([]byte, error) {
txn, err := c.CreateTransaction(name)

Expand All @@ -61,8 +73,14 @@ func (c *Contract) SubmitTransaction(name string, args ...string) ([]byte, error
// function implemented by this contract, and provides more control over
// the transaction invocation using the optional arguments. A new transaction object must
// be created for each transaction invocation.
func (c *Contract) CreateTransaction(name string, args ...TransactionOption) (*Transaction, error) {
return newTransaction(name, c, args...)
// Parameters:
// name is the name of the transaction function to be invoked in the smart contract.
// opts are the options to be associated with the transaction.
//
// Returns:
// A Transaction object for subsequent evaluation or submission.
func (c *Contract) CreateTransaction(name string, opts ...TransactionOption) (*Transaction, error) {
return newTransaction(name, c, opts...)
}

// RegisterEvent registers for chaincode events. Unregister must be called when the registration is no longer needed.
Expand Down
3 changes: 0 additions & 3 deletions pkg/gateway/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func TestSubmitTransaction(t *testing.T) {

gw := &Gateway{
options: &gatewayOptions{
Discovery: defaultDiscovery,
Timeout: defaultTimeout,
},
}
Expand Down Expand Up @@ -69,7 +68,6 @@ func TestEvaluateTransaction(t *testing.T) {

gw := &Gateway{
options: &gatewayOptions{
Discovery: defaultDiscovery,
Timeout: defaultTimeout,
},
}
Expand Down Expand Up @@ -98,7 +96,6 @@ func TestContractEvent(t *testing.T) {

gw := &Gateway{
options: &gatewayOptions{
Discovery: defaultDiscovery,
Timeout: defaultTimeout,
},
}
Expand Down
Loading

0 comments on commit ad7b043

Please sign in to comment.