Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC-Tools 1.0 #66

Merged
merged 73 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
6db2b30
Startup check on invoke
andremacedopv Sep 1, 2023
b684e08
Add DCO.yml
samuelvenzi Sep 11, 2023
e32e1a5
Pass different identities via gateway
mikaellafs Sep 6, 2023
5d53a85
Update tx callers format
mikaellafs Sep 11, 2023
9026270
Pass different identities via fabric sdk
mikaellafs Sep 11, 2023
327aec3
Fix tests
mikaellafs Sep 12, 2023
b929705
User admin cert as default
mikaellafs Sep 13, 2023
bcd393c
Remove unused code
AlineLermen Sep 14, 2023
57c55a1
Add call to InitFunc in Init
AlineLermen Sep 15, 2023
2efbf4c
Merge pull request #51 from GoLedgerDev/refactor/init-on-invoke
andremacedopv Sep 15, 2023
d15b94b
Automatic collection generation
andremacedopv Sep 20, 2023
f2e63b2
Remove fabric binaries
AlineLermen Sep 22, 2023
5162eae
Add script to verify and download fabric binaries
AlineLermen Sep 22, 2023
7da3e9e
Remove install script after its done
AlineLermen Sep 22, 2023
4241506
Inlcude binaries in gitignore
andremacedopv Sep 22, 2023
5d13f86
Merge pull request #53 from hyperledger-labs/refactor/remove-binaries
samuelvenzi Sep 23, 2023
3d6a21b
Merge branch 'main' into develop
andremacedopv Sep 25, 2023
fc350de
Merge branch 'develop' into feature/permissioning
andremacedopv Sep 25, 2023
69352e6
Merge branch 'develop' into feature/collection-generation
andremacedopv Sep 25, 2023
1116799
Fix CCAPI waiting for inexistant Custom Event response
andremacedopv Dec 12, 2023
e5e0455
Merge pull request #52 from hyperledger-labs/feature/collection-gener…
andremacedopv Dec 12, 2023
1de9739
Merge pull request #56 from hyperledger-labs/fix/custom-event-reception
andremacedopv Dec 12, 2023
9661747
Add test module to go.work
samuelvenzi Jan 10, 2024
da5f743
Start fixing online testing suite
samuelvenzi Jan 10, 2024
d78b1f2
Remove test functions dependend on cc-tools built-in transactions
samuelvenzi Jan 10, 2024
5ceb371
Merge branch 'develop' into feature/permissioning
andremacedopv Jan 12, 2024
aa584dc
Remove tryout.go tests
samuelvenzi Jan 12, 2024
9027910
Remove /test from go.work
samuelvenzi Jan 12, 2024
cbf76e2
Merge pull request #57 from hyperledger-labs/fix/online-testing
andremacedopv Jan 12, 2024
e708f7e
Check for binaries on the system
AlineLermen Jan 30, 2024
44edf10
Still check for repo bin directory
AlineLermen Jan 30, 2024
40421c3
Automatic collection generation
andremacedopv Sep 20, 2023
c44cf38
I, Samuel Venzi hereby sign-off-by all of my past commits and commits…
samuelvenzi Sep 11, 2023
6359b3b
Add LICENSE and NOTICE
samuelvenzi Sep 13, 2023
71c2868
Update dependencies to new repo
andremacedopv Sep 25, 2023
d914104
Update CCAPI dependencies to new repo
andremacedopv Sep 25, 2023
67b619a
Fix CCAPI waiting for inexistant Custom Event response
andremacedopv Dec 12, 2023
848e4b1
Add test module to go.work
samuelvenzi Jan 10, 2024
1df6530
Start fixing online testing suite
samuelvenzi Jan 10, 2024
3c2d2f9
Remove test functions dependend on cc-tools built-in transactions
samuelvenzi Jan 10, 2024
fcb27b2
Remove tryout.go tests
samuelvenzi Jan 12, 2024
91d7599
Remove /test from go.work
samuelvenzi Jan 12, 2024
fa24332
WIP: Use godog package for tests
andremacedopv Jan 15, 2024
ff08f59
Fix chaincode to return the error status correctly
mikaellafs Jan 30, 2024
62daab9
Fix ccapi to get status code from error message
mikaellafs Jan 30, 2024
242678c
Fix godog test to verify running network on correct port
mikaellafs Jan 30, 2024
1661223
Reenable network creation on godog
andremacedopv Jan 30, 2024
61b53bd
Remove unecessary test run from godog
andremacedopv Jan 30, 2024
489725d
Merge pull request #59 from hyperledger-labs/refactor/search-binaries
samuelvenzi Feb 1, 2024
edeac76
Define startDev folder on godog
andremacedopv Feb 5, 2024
e43ae2c
Add verbose verification for godog tests
samuelvenzi Feb 5, 2024
a027288
Add godog tests to actions
samuelvenzi Feb 5, 2024
b29a0cb
Merge branch 'develop' into fix/godog
samuelvenzi Feb 5, 2024
63bffc2
Fix test path
samuelvenzi Feb 5, 2024
c26deec
Merge pull request #58 from hyperledger-labs/fix/godog
samuelvenzi Feb 5, 2024
a1fd3ee
Update swagger to use gateway endpoints
samuelvenzi Mar 7, 2024
6106497
Add channel and chaincode examples on swagger endpoints
andremacedopv Mar 7, 2024
94a866d
Merge pull request #60 from hyperledger-labs/refactor/swagger
andremacedopv Mar 7, 2024
cffdb4f
Bump go version to 1.21
andremacedopv May 8, 2024
66fde9c
Update cc-tools-version
andremacedopv May 9, 2024
9bf51c1
Merge branch 'develop' into feature/permissioning
andremacedopv May 9, 2024
ad986ff
Update createNewLibrary callers
andremacedopv May 9, 2024
a5ca4dd
Update test certificate
andremacedopv May 9, 2024
8131911
Fix eventHandler invoke
andremacedopv May 9, 2024
4251a55
Merge pull request #49 from hyperledger-labs/feature/permissioning
samuelvenzi May 10, 2024
1539aa6
Add example index
samuelvenzi Jun 12, 2024
b7690b8
Implement qscc endpoints
samuelvenzi Jun 27, 2024
90343aa
Merge pull request #62 from hyperledger-labs/feature/qscc
andremacedopv Jun 27, 2024
48098cd
Bump CC-Tools Version to 1.0
andremacedopv Jul 1, 2024
40a0789
Updateccapi dependencies
andremacedopv Jul 1, 2024
580da76
Fix typo on Readme
andremacedopv Jul 1, 2024
abdf0bf
Merge pull request #65 from hyperledger-labs/bump/cc-tools-1.0
samuelvenzi Jul 1, 2024
78fde59
Merge branch 'main' into develop
samuelvenzi Jul 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.21

- name: Build
run: go build -v github.com/hyperledger-labs/cc-tools-demo/chaincode

- name: Test
run: go test github.com/hyperledger-labs/cc-tools-demo/chaincode -coverpkg=./... -v
- name: Unit tests
run: go test github.com/hyperledger-labs/cc-tools-demo/chaincode -coverpkg=./... -v

- name: Integration tests
run: go test -v ./tests
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ node_modules
fabric/crypto-config
fabric/channel-artifacts
fabric/ca
fabric/bin
fabric/builders
chaincode/vendor/*
chaincode/collections.json
ccapi/vendor/*
cc-tools-demo.tar.gz
package-lock.json
Expand Down
93 changes: 93 additions & 0 deletions DCO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Probot: DCO

a GitHub Integration built with [probot](https://github.com/probot/probot) that enforces the [Developer Certificate of Origin](https://developercertificate.org/) (DCO) on Pull Requests. It requires all commit messages to contain the `Signed-off-by` line with an email address that matches the commit author.

## Usage

[Configure the integration](https://github.com/apps/dco) for your organization or repositories. Enable [required status checks](docs/required-statuses.md) if you want to enforce the DCO on all commits.

See [docs/deploy.md](docs/deploy.md) if you would like to run your own instance of this plugin.

## Modes of operations

### Default

By default, Probot DCO enforces the presence of [valid DCO signoffs](#how-it-works) on all commits (excluding bots and merges). If a PRs contains commits that lack a valid Signed-off-by line, they are blocked until a correctly signed-off revision of the commit is pushed. This closely mirrors the upstream Linux kernel process.

### Individual remediation commit support

Optionally, a project can allow individual remediation commit support, where the failing commit's author can push an additional properly signed-off commit with additional text in the commit log that indicates they apply their signoff retroactively.

To enable this, place the following configuration file in `.github/dco.yml` on the default branch:

```yaml
allowRemediationCommits:
individual: true
```

### Third-party remediation support

Additionally, a project can allow third-parties to sign off on an author's behalf by pushing an additional properly signed-off commit with additional text in the commit log that indicates they sign off on behalf of the author. Third-party remediation requires individual remediation to be enabled.

To enable this, place the following configuration file in `.github/dco.yml` on the default branch:

```yaml
allowRemediationCommits:
individual: true
thirdParty: true
```

### Skipping sign-off for organization members

It is possible to disable the check for commits authored and [signed](https://help.github.com/articles/signing-commits-using-gpg/) by members of the organization the repository belongs to. To do this, place the following configuration file in `.github/dco.yml` on the default branch:

```yaml
require:
members: false
```

When this setting is present on a repository that belongs to a GitHub user (instead of an organization), only the repository owner is allowed to push commits without sign-off.

## How it works

The Developer Certificate of Origin (DCO) is a lightweight way for contributors to certify that they wrote or otherwise have the right to submit the code they are contributing to the project. Here is the full [text of the DCO](https://developercertificate.org/), reformatted for readability:

> By making a contribution to this project, I certify that:
>
> a. The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
>
> b. The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
>
> c. The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
>
> d. I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.

Contributors _sign-off_ that they adhere to these requirements by adding a `Signed-off-by` line to commit messages.

```
This is my commit message

Signed-off-by: Random J Developer <[email protected]>
```

Git even has a `-s` command line option to append this automatically to your commit message:

```
$ git commit -s -m 'This is my commit message'
```

Once [installed](#usage), this integration will create a [check](https://developer.github.com/v3/checks/runs/) indicating whether or not commits in a Pull Request do not contain a valid `Signed-off-by` line.

![DCO success](https://user-images.githubusercontent.com/13410355/42352738-35f4e690-8071-11e8-9c8c-260e5868bfc8.png)
![DCO failure](https://user-images.githubusercontent.com/13410355/42352794-85fe1c9c-8071-11e8-834a-05a4aeb8cc90.png)

Additionally, the DCO creates an override button accessible to only those with write access to the repository to create a successful check.

![DCO button](https://user-images.githubusercontent.com/13410355/42353254-3bfa266a-8074-11e8-80b4-18760c5efeee.png)

## Further Reading

If you want to learn more about the DCO and why it might be necessary, here are some good resources:

- [Developer Certificate of Origin versus Contributor License Agreements](https://julien.ponge.org/blog/developer-certificate-of-origin-versus-contributor-license-agreements/)
- [The most powerful contributor agreement](https://lwn.net/Articles/592503/)
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

## Directory Structure

- `/fabric`: Fabric network v2.2 used as a test environment
- `/fabric`: Fabric network v2.5 used as a test environment
- `/chaincode`: chaincode-related files
- `/ccapi`: chaincode REST API in Golang project

## Development

The `cc-tools` library has been tested in Fabric v1.4, v2.2 and v2.4 networks.
The `cc-tools` library has been tested in Fabric v2.2, v2.4 and v2.5 networks.

Dependencies for chaincode and chaincode API:

- Go 1.14 or higher
- Go 1.21 or higher

Dependencies for test environment:

Expand All @@ -27,14 +27,14 @@ $ cd ccapi; go mod vendor; cd ..
```


## Deploying test env in v2.2
## Deploying test environment

After installing, use the script `./startDev.sh` in the root folder to start the development environment. It will
start all components of the project with 3 organizations.

If you want to deploy with 1 organization, run the command `./startDev.sh -n 1`.

To apply chaincode changes, run `$ ./upgradeCC2.sh <version> <sequence>` with a version higher than the current one (starts with 0.1). Append `-n 1` to the command if running with 1 organization.
To apply chaincode changes, run `$ ./upgradeCC.sh <version> <sequence>` with a version higher than the current one (starts with 0.1). Append `-n 1` to the command if running with 1 organization.

To apply CC API changes, run `$ ./reloadCCAPI.sh`.

Expand All @@ -44,10 +44,23 @@ To test transactions after starting all components, run `$ ./tryout.sh`.

To test transactions using the godog tool, run `$ ./godog.sh`.


## Generate TAR archive for the chaincode

The `generateTar.sh` script is available to generate a `tar.gz` archive of the chaincode.

By running `$ ./generateTar.sh` without any option, the script generates a `collections.json` file for the private data on the chaincode with all the organizations defined on the readers section of private asset types, and then archives the code without the CCAPI.

By using the `--org/-o` option along the script, it's possible to specify the organizations to be considered when generating the `collections.json` file. This option may be used multiple times to add all the organizations, ex: `$ ./generateTar.sh -o org1MSP -o org2MSP`.

To also archive the the CCAPI alongside the chaincode, the `--ccapi/-c` flag may be used. Example: `$ ./generateTar.sh -c`.

By standard the archive is created using the project name with *1.0* label, to change it the `--name/-n` and `--label/-l` flags may be used. Example: `$ ./generateTar.sh -n my-project -l 2.0`

## More

You can reach GoLedger developers and `cc-tools` maintainers at our Discord - [Join us!](https://discord.gg/GndkYHxNyQ)

More documentation and details on `cc-tools` can be found at [https://goledger-cc-tools.readthedocs.io/en/latest/](https://goledger-cc-tools.readthedocs.io/en/latest/)

For production deployment please consider using GoFabric - [https://gofabric.io](https://gofabric.io)
For production deployment please consider using GoFabric - [https://gofabric.io](https://gofabric.io)
2 changes: 1 addition & 1 deletion ccapi/chaincode/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func HandleEvent(channelName, ccName string, event EventHandler) {

func RegisterForEvents() {
// Get registered events on the chaincode
res, _, err := Invoke(os.Getenv("CHANNEL"), os.Getenv("CCNAME"), "getEvents", nil, nil)
res, _, err := Invoke(os.Getenv("CHANNEL"), os.Getenv("CCNAME"), "getEvents", os.Getenv("USER"), nil, nil)
if err != nil {
fmt.Println("error registering for events: ", err)
return
Expand Down
28 changes: 7 additions & 21 deletions ccapi/chaincode/eventHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"os"

"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
)

Expand Down Expand Up @@ -55,7 +54,7 @@ func (event EventHandler) Execute(ccEvent *fab.CCEvent) {
cc = event.Chaincode
}

res, _, err := Invoke(ch, cc, event.Transaction, [][]byte{ccEvent.Payload}, nil)
res, _, err := Invoke(ch, cc, event.Transaction, os.Getenv("USER"), [][]byte{ccEvent.Payload}, nil)
if err != nil {
fmt.Println("error invoking transaction: ", err)
return
Expand All @@ -81,30 +80,17 @@ func (event EventHandler) Execute(ccEvent *fab.CCEvent) {
return
}

// Invoke executeEvent tx
var res *channel.Response
var err error
// Invoke tx
txName := "executeEvent"
if event.ReadOnly {
res, _, err = Invoke(os.Getenv("CHANNEL"), os.Getenv("CCNAME"), "runEvent", [][]byte{args}, nil)
if err != nil {
fmt.Println("error invoking transaction: ", err)
return
}
} else {
res, _, err = Invoke(os.Getenv("CHANNEL"), os.Getenv("CCNAME"), "executeEvent", [][]byte{args}, nil)
if err != nil {
fmt.Println("error invoking transaction: ", err)
return
}
txName = "runEvent"
}

var response map[string]interface{}
nerr := json.Unmarshal(res.Payload, &response)
if nerr != nil {
fmt.Println("error unmarshalling response: ", nerr)
_, _, err := Invoke(os.Getenv("CHANNEL"), os.Getenv("CCNAME"), txName, os.Getenv("USER"), [][]byte{args}, nil)
if err != nil {
fmt.Println("error invoking transaction: ", err)
return
}
fmt.Println("Response: ", response)
} else {
fmt.Println("Event type not supported")
}
Expand Down
9 changes: 4 additions & 5 deletions ccapi/chaincode/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
)

func Invoke(channelName, ccName, txName string, txArgs [][]byte, transientRequest []byte) (*channel.Response, int, error) {
func Invoke(channelName, ccName, txName, user string, txArgs [][]byte, transientRequest []byte) (*channel.Response, int, error) {
// create channel manager
fabMngr, err := common.NewFabricChClient(channelName, os.Getenv("USER"), os.Getenv("ORG"))
fabMngr, err := common.NewFabricChClient(channelName, user, os.Getenv("ORG"))
if err != nil {
return nil, http.StatusInternalServerError, err
}
Expand All @@ -29,10 +29,9 @@ func Invoke(channelName, ccName, txName string, txArgs [][]byte, transientReques
}

res, err := fabMngr.Client.Execute(rq, channel.WithRetry(retry.DefaultChannelOpts))

if err != nil {
return nil, http.StatusInternalServerError, err
return nil, extractStatusCode(err.Error()), err
}

return &res, http.StatusInternalServerError, nil
return &res, http.StatusOK, nil
}
12 changes: 6 additions & 6 deletions ccapi/chaincode/invokeGateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
)

func InvokeGateway(channelName, chaincodeName, txName, args string, transientArgs []byte, endorsingOrgs []string) ([]byte, error) {
func InvokeGateway(channelName, chaincodeName, txName, user string, args []string, transientArgs []byte, endorsingOrgs []string) ([]byte, error) {
// Gateway endpoint
endpoint := os.Getenv("FABRIC_GATEWAY_ENDPOINT")

Expand All @@ -20,7 +20,7 @@ func InvokeGateway(channelName, chaincodeName, txName, args string, transientArg
defer grpcConn.Close()

// Create gateway connection
gw, err := common.CreateGatewayConnection(grpcConn)
gw, err := common.CreateGatewayConnection(grpcConn, user)
if err != nil {
return nil, errors.Wrap(err, "failed to create gateway connection")
}
Expand All @@ -37,25 +37,25 @@ func InvokeGateway(channelName, chaincodeName, txName, args string, transientArg
// Invoke transaction
if transientArgs != nil && len(endorsingOrgs) > 0 {
return contract.Submit(txName,
client.WithArguments(args),
client.WithArguments(args...),
client.WithTransient(transientMap),
client.WithEndorsingOrganizations(endorsingOrgs...),
)
}

if transientArgs != nil {
return contract.Submit(txName,
client.WithArguments(args),
client.WithArguments(args...),
client.WithTransient(transientMap),
)
}

if len(endorsingOrgs) > 0 {
return contract.Submit(txName,
client.WithArguments(args),
client.WithArguments(args...),
client.WithEndorsingOrganizations(endorsingOrgs...),
)
}

return contract.SubmitTransaction(txName, args)
return contract.SubmitTransaction(txName, args...)
}
10 changes: 5 additions & 5 deletions ccapi/chaincode/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
)

func Query(channelName, ccName, txName string, txArgs [][]byte) (*channel.Response, int, error) {
func Query(channelName, ccName, txName, user string, txArgs [][]byte) (*channel.Response, int, error) {
// create channel manager
fabMngr, err := common.NewFabricChClient(channelName, os.Getenv("USER"), os.Getenv("ORG"))
fabMngr, err := common.NewFabricChClient(channelName, user, os.Getenv("ORG"))
if err != nil {
return nil, http.StatusInternalServerError, err
}
Expand All @@ -23,10 +23,10 @@ func Query(channelName, ccName, txName string, txArgs [][]byte) (*channel.Respon
}

res, err := fabMngr.Client.Query(rq, channel.WithRetry(retry.DefaultChannelOpts))

if err != nil {
return nil, http.StatusInternalServerError, err
status := extractStatusCode(err.Error())
return nil, status, err
}

return &res, http.StatusInternalServerError, nil
return &res, http.StatusOK, nil
}
6 changes: 3 additions & 3 deletions ccapi/chaincode/queryGateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/pkg/errors"
)

func QueryGateway(channelName, chaincodeName, txName, args string) ([]byte, error) {
func QueryGateway(channelName, chaincodeName, txName, user string, args []string) ([]byte, error) {
// Gateway endpoint
endpoint := os.Getenv("FABRIC_GATEWAY_ENDPOINT")

Expand All @@ -19,7 +19,7 @@ func QueryGateway(channelName, chaincodeName, txName, args string) ([]byte, erro
defer grpcConn.Close()

// Create gateway connection
gw, err := common.CreateGatewayConnection(grpcConn)
gw, err := common.CreateGatewayConnection(grpcConn, user)
if err != nil {
return nil, errors.Wrap(err, "failed to create gateway connection")
}
Expand All @@ -34,5 +34,5 @@ func QueryGateway(channelName, chaincodeName, txName, args string) ([]byte, erro
return contract.EvaluateTransaction(txName)
}

return contract.EvaluateTransaction(txName, args)
return contract.EvaluateTransaction(txName, args...)
}
Loading
Loading