Commit graph

1167 commits

Author SHA1 Message Date
Sarsilmaz
8c77c0bafb
Update asset_transfer_ledger_chaincode.go
/*
 SPDX-License-Identifier: Apache-2.0
*/

/*
====CHAINCODE EXECUTION SAMPLES (CLI) ==================

==== Invoke assets ====

peer chaincode invoke -C myc1 -n asset_transfer -c '{"Args":["CreateAsset","asset1","blue","5","tom","35"]}'
peer chaincode invoke -C myc1 -n asset_transfer -c '{"Args":["CreateAsset","asset2","red","4","tom","50"]}'
peer chaincode invoke -C myc1 -n asset_transfer -c '{"Args":["CreateAsset","asset3","blue","6","tom","70"]}'
peer chaincode invoke -C myc1 -n asset_transfer -c '{"Args":["TransferAsset","asset2","jerry"]}'
peer chaincode invoke -C myc1 -n asset_transfer -c '{"Args":["TransferAssetByColor","blue","jerry"]}'
peer chaincode invoke -C myc1 -n asset_transfer -c '{"Args":["DeleteAsset","asset1"]}'

==== Query assets ====
peer chaincode query -C myc1 -n asset_transfer -c '{"Args":["ReadAsset","asset1"]}'
peer chaincode query -C myc1 -n asset_transfer -c '{"Args":["GetAssetsByRange","asset1","asset3"]}'
peer chaincode query -C myc1 -n asset_transfer -c '{"Args":["GetAssetHistory","asset1"]}'

Rich Query (Only supported if CouchDB is used as state database):
peer chaincode query -C myc1 -n asset_transfer -c '{"Args":["QueryAssetsByOwner","tom"]}'
peer chaincode query -C myc1 -n asset_transfer -c '{"Args":["QueryAssets","{\"selector\":{\"owner\":\"tom\"}}"]}'

Rich Query with Pagination (Only supported if CouchDB is used as state database):
peer chaincode query -C myc1 -n asset_transfer -c '{"Args":["QueryAssetsWithPagination","{\"selector\":{\"owner\":\"tom\"}}","3",""]}'

INDEXES TO SUPPORT COUCHDB RICH QUERIES

Indexes in CouchDB are required in order to make JSON queries efficient and are required for
any JSON query with a sort. Indexes may be packaged alongside
chaincode in a META-INF/statedb/couchdb/indexes directory. Each index must be defined in its own
text file with extension *.json with the index definition formatted in JSON following the
CouchDB index JSON syntax as documented at:
http://docs.couchdb.org/en/2.3.1/api/database/find.html#db-index

This asset transfer ledger example chaincode demonstrates a packaged
index which you can find in META-INF/statedb/couchdb/indexes/indexOwner.json.

If you have access to the your peer's CouchDB state database in a development environment,
you may want to iteratively test various indexes in support of your chaincode queries.  You
can use the CouchDB Fauxton interface ork a command line curl utility to create and update
indexes. Then once you finalize an index, include the index definition alongside your
chaincode in the META-INF/statedb/couchdb/indexes directory, for packaging and deployment
to managed environments.

In the examples below you can find index definitions that support asset transfer ledger
chaincode queries, along with the syntax that you can use in development environments
to create the indexes in the CouchDB Fauxton interface or a curl command line utility.


Index for docType, owner.

Example curl command line to define index in the CouchDB channel_chaincode database
curl -i -X POST -H "Content-Type: application/json" -d "{\"index\":{\"fields\":[\"docType\",\"owner\"]},\"name\":\"indexOwner\",\"ddoc\":\"indexOwnerDoc\",\"type\":\"json\"}" http://hostname:port/myc1_assets/_index


Index for docType, owner, size (descending order).

Example curl command line to define index in the CouchDB channel_chaincode database:
curl -i -X POST -H "Content-Type: application/json" -d "{\"index\":{\"fields\":[{\"size\":\"desc\"},{\"docType\":\"desc\"},{\"owner\":\"desc\"}]},\"ddoc\":\"indexSizeSortDoc\", \"name\":\"indexSizeSortDesc\",\"type\":\"json\"}" http://hostname:port/myc1_assets/_index

Rich Query with index design doc and index name specified (Only supported if CouchDB is used as state database):
peer chaincode query -C myc1 -n asset_transfer -c '{"Args":["QueryAssets","{\"selector\":{\"docType\":\"asset\",\"owner\":\"tom\"}, \"use_index\":[\"_design/indexOwnerDoc\", \"indexOwner\"]}"]}'

Rich Query with index design doc specified only (Only supported if CouchDB is used as state database):
peer chaincode query -C myc1 -n asset_transfer -c '{"Args":["QueryAssets","{\"selector\":{\"docType\":{\"$eq\":\"asset\"},\"owner\":{\"$eq\":\"tom\"},\"size\":{\"$gt\":0}},\"fields\":[\"docType\",\"owner\",\"size\"],\"sort\":[{\"size\":\"desc\"}],\"use_index\":\"_design/indexSizeSortDoc\"}"]}'
*/

package main

import (
	"encoding/json"
	"fmt"
	"log"
	"time"

	"github.com/hyperledger/fabric-chaincode-go/v2/shim"
	"github.com/hyperledger/fabric-contract-api-go/v2/contractapi"
)

const index = "color~name"

// SimpleChaincode implements the fabric-contract-api-go programming model
type SimpleChaincode struct {
	contractapi.Contract
}

type Asset struct {
	DocType        string `json:"docType"` //docType is used to distinguish the various types of objects in state database
	ID             string `json:"ID"`      //the field tags are needed to keep case from bouncing around
	Color          string `json:"color"`
	Size           int    `json:"size"`
	Owner          string `json:"owner"`
	AppraisedValue int    `json:"appraisedValue"`
}

// HistoryQueryResult structure used for returning result of history query
type HistoryQueryResult struct {
	Record    *Asset    `json:"record"`
	TxId      string    `json:"txId"`
	Timestamp time.Time `json:"timestamp"`
	IsDelete  bool      `json:"isDelete"`
}

// PaginatedQueryResult structure used for returning paginated query results and metadata
type PaginatedQueryResult struct {
	Records             []*Asset `json:"records"`
	FetchedRecordsCount int32    `json:"fetchedRecordsCount"`
	Bookmark            string   `json:"bookmark"`
}

// CreateAsset initializes a new asset in the ledger
func (t *SimpleChaincode) CreateAsset(ctx contractapi.TransactionContextInterface, assetID, color string, size int, owner string, appraisedValue int) error {
	exists, err := t.AssetExists(ctx, assetID)
	if err != nil {
		return fmt.Errorf("failed to get asset: %v", err)
	}
	if exists {
		return fmt.Errorf("asset already exists: %s", assetID)
	}

	asset := &Asset{
		DocType:        "asset",
		ID:             assetID,
		Color:          color,
		Size:           size,
		Owner:          owner,
		AppraisedValue: appraisedValue,
	}
	assetBytes, err := json.Marshal(asset)
	if err != nil {
		return err
	}

	err = ctx.GetStub().PutState(assetID, assetBytes)
	if err != nil {
		return err
	}

	//  Create an index to enable color-based range queries, e.g. return all blue assets.
	//  An 'index' is a normal key-value entry in the ledger.
	//  The key is a composite key, with the elements that you want to range query on listed first.
	//  In our case, the composite key is based on indexName~color~name.
	//  This will enable very efficient state range queries based on composite keys matching indexName~color~*
	colorNameIndexKey, err := ctx.GetStub().CreateCompositeKey(index, []string{asset.Color, asset.ID})
	if err != nil {
		return err
	}
	//  Save index entry to world state. Only the key name is needed, no need to store a duplicate copy of the asset.
	//  Note - passing a 'nil' value will effectively delete the key from state, therefore we pass null character as value
	value := []byte{0x00}
	return ctx.GetStub().PutState(colorNameIndexKey, value)
}

// ReadAsset retrieves an asset from the ledger
func (t *SimpleChaincode) ReadAsset(ctx contractapi.TransactionContextInterface, assetID string) (*Asset, error) {
	assetBytes, err := ctx.GetStub().GetState(assetID)
	if err != nil {
		return nil, fmt.Errorf("failed to get asset %s: %v", assetID, err)
	}
	if assetBytes == nil {
		return nil, fmt.Errorf("asset %s does not exist", assetID)
	}

	var asset Asset
	err = json.Unmarshal(assetBytes, &asset)
	if err != nil {
		return nil, err
	}

	return &asset, nil
}

// DeleteAsset removes an asset key-value pair from the ledger
func (t *SimpleChaincode) DeleteAsset(ctx contractapi.TransactionContextInterface, assetID string) error {
	asset, err := t.ReadAsset(ctx, assetID)
	if err != nil {
		return err
	}

	err = ctx.GetStub().DelState(assetID)
	if err != nil {
		return fmt.Errorf("failed to delete asset %s: %v", assetID, err)
	}

	colorNameIndexKey, err := ctx.GetStub().CreateCompositeKey(index, []string{asset.Color, asset.ID})
	if err != nil {
		return err
	}

	// Delete index entry
	return ctx.GetStub().DelState(colorNameIndexKey)
}

// TransferAsset transfers an asset by setting a new owner name on the asset
func (t *SimpleChaincode) TransferAsset(ctx contractapi.TransactionContextInterface, assetID, newOwner string) error {
	asset, err := t.ReadAsset(ctx, assetID)
	if err != nil {
		return err
	}

	asset.Owner = newOwner
	assetBytes, err := json.Marshal(asset)
	if err != nil {
		return err
	}

	return ctx.GetStub().PutState(assetID, assetBytes)
}

// constructQueryResponseFromIterator constructs a slice of assets from the resultsIterator
func constructQueryResponseFromIterator(resultsIterator shim.StateQueryIteratorInterface) ([]*Asset, error) {
	var assets []*Asset
	for resultsIterator.HasNext() {
		queryResult, err := resultsIterator.Next()
		if err != nil {
			return nil, err
		}
		var asset Asset
		err = json.Unmarshal(queryResult.Value, &asset)
		if err != nil {
			return nil, err
		}
		assets = append(assets, &asset)
	}

	return assets, nil
}

// GetAssetsByRange performs a range query based on the start and end keys provided.
// Read-only function results are not typically submitted to ordering. If the read-only
// results are submitted to ordering, or if the query is used in an update transaction
// and submitted to ordering, then the committing peers will re-execute to guarantee that
// result sets are stable between endorsement time and commit time. The transaction is
// invalidated by the committing peers if the result set has changed between endorsement
// time and commit time.
// Therefore, range queries are a safe option for performing update transactions based on query results.
func (t *SimpleChaincode) GetAssetsByRange(ctx contractapi.TransactionContextInterface, startKey, endKey string) ([]*Asset, error) {
	resultsIterator, err := ctx.GetStub().GetStateByRange(startKey, endKey)
	if err != nil {
		return nil, err
	}
	defer resultsIterator.Close()

	return constructQueryResponseFromIterator(resultsIterator)
}

// TransferAssetByColor will transfer assets of a given color to a certain new owner.
// Uses GetStateByPartialCompositeKey (range query) against color~name 'index'.
// Committing peers will re-execute range queries to guarantee that result sets are stable
// between endorsement time and commit time. The transaction is invalidated by the
// committing peers if the result set has changed between endorsement time and commit time.
// Therefore, range queries are a safe option for performing update transactions based on query results.
// Example: GetStateByPartialCompositeKey/RangeQuery
func (t *SimpleChaincode) TransferAssetByColor(ctx contractapi.TransactionContextInterface, color, newOwner string) error {
	// Execute a key range query on all keys starting with 'color'
	coloredAssetResultsIterator, err := ctx.GetStub().GetStateByPartialCompositeKey(index, []string{color})
	if err != nil {
		return err
	}
	defer coloredAssetResultsIterator.Close()

	for coloredAssetResultsIterator.HasNext() {
		responseRange, err := coloredAssetResultsIterator.Next()
		if err != nil {
			return err
		}

		_, compositeKeyParts, err := ctx.GetStub().SplitCompositeKey(responseRange.Key)
		if err != nil {
			return err
		}

		if len(compositeKeyParts) > 1 {
			returnedAssetID := compositeKeyParts[1]
			asset, err := t.ReadAsset(ctx, returnedAssetID)
			if err != nil {
				return err
			}
			asset.Owner = newOwner
			assetBytes, err := json.Marshal(asset)
			if err != nil {
				return err
			}
			err = ctx.GetStub().PutState(returnedAssetID, assetBytes)
			if err != nil {
				return fmt.Errorf("transfer failed for asset %s: %v", returnedAssetID, err)
			}
		}
	}

	return nil
}

// QueryAssetsByOwner queries for assets based on the owners name.
// This is an example of a parameterized query where the query logic is baked into the chaincode,
// and accepting a single query parameter (owner).
// Only available on state databases that support rich query (e.g. CouchDB)
// Example: Parameterized rich query
func (t *SimpleChaincode) QueryAssetsByOwner(ctx contractapi.TransactionContextInterface, owner string) ([]*Asset, error) {
	queryString := fmt.Sprintf(`{"selector":{"docType":"asset","owner":"%s"}}`, owner)
	return getQueryResultForQueryString(ctx, queryString)
}

// QueryAssets uses a query string to perform a query for assets.
// Query string matching state database syntax is passed in and executed as is.
// Supports ad hoc queries that can be defined at runtime by the client.
// If this is not desired, follow the QueryAssetsForOwner example for parameterized queries.
// Only available on state databases that support rich query (e.g. CouchDB)
// Example: Ad hoc rich query
func (t *SimpleChaincode) QueryAssets(ctx contractapi.TransactionContextInterface, queryString string) ([]*Asset, error) {
	return getQueryResultForQueryString(ctx, queryString)
}

// getQueryResultForQueryString executes the passed in query string.
// The result set is built and returned as a byte array containing the JSON results.
func getQueryResultForQueryString(ctx contractapi.TransactionContextInterface, queryString string) ([]*Asset, error) {
	resultsIterator, err := ctx.GetStub().GetQueryResult(queryString)
	if err != nil {
		return nil, err
	}
	defer resultsIterator.Close()

	return constructQueryResponseFromIterator(resultsIterator)
}

// GetAssetsByRangeWithPagination performs a range query based on the start and end key,
// page size and a bookmark.
// The number of fetched records will be equal to or lesser than the page size.
// Paginated range queries are only valid for read only transactions.
// Example: Pagination with Range Query
func (t *SimpleChaincode) GetAssetsByRangeWithPagination(ctx contractapi.TransactionContextInterface, startKey string, endKey string, pageSize int, bookmark string) (*PaginatedQueryResult, error) {

	resultsIterator, responseMetadata, err := ctx.GetStub().GetStateByRangeWithPagination(startKey, endKey, int32(pageSize), bookmark)
	if err != nil {
		return nil, err
	}
	defer resultsIterator.Close()

	assets, err := constructQueryResponseFromIterator(resultsIterator)
	if err != nil {
		return nil, err
	}

	return &PaginatedQueryResult{
		Records:             assets,
		FetchedRecordsCount: responseMetadata.FetchedRecordsCount,
		Bookmark:            responseMetadata.Bookmark,
	}, nil
}

// QueryAssetsWithPagination uses a query string, page size and a bookmark to perform a query
// for assets. Query string matching state database syntax is passed in and executed as is.
// The number of fetched records would be equal to or lesser than the specified page size.
// Supports ad hoc queries that can be defined at runtime by the client.
// If this is not desired, follow the QueryAssetsForOwner example for parameterized queries.
// Only available on state databases that support rich query (e.g. CouchDB)
// Paginated queries are only valid for read only transactions.
// Example: Pagination with Ad hoc Rich Query
func (t *SimpleChaincode) QueryAssetsWithPagination(ctx contractapi.TransactionContextInterface, queryString string, pageSize int, bookmark string) (*PaginatedQueryResult, error) {

	return getQueryResultForQueryStringWithPagination(ctx, queryString, int32(pageSize), bookmark)
}

// getQueryResultForQueryStringWithPagination executes the passed in query string with
// pagination info. The result set is built and returned as a byte array containing the JSON results.
func getQueryResultForQueryStringWithPagination(ctx contractapi.TransactionContextInterface, queryString string, pageSize int32, bookmark string) (*PaginatedQueryResult, error) {

	resultsIterator, responseMetadata, err := ctx.GetStub().GetQueryResultWithPagination(queryString, pageSize, bookmark)
	if err != nil {
		return nil, err
	}
	defer resultsIterator.Close()

	assets, err := constructQueryResponseFromIterator(resultsIterator)
	if err != nil {
		return nil, err
	}

	return &PaginatedQueryResult{
		Records:             assets,
		FetchedRecordsCount: responseMetadata.FetchedRecordsCount,
		Bookmark:            responseMetadata.Bookmark,
	}, nil
}

// GetAssetHistory returns the chain of custody for an asset since issuance.
func (t *SimpleChaincode) GetAssetHistory(ctx contractapi.TransactionContextInterface, assetID string) ([]HistoryQueryResult, error) {
	log.Printf("GetAssetHistory: ID %v", assetID)

	resultsIterator, err := ctx.GetStub().GetHistoryForKey(assetID)
	if err != nil {
		return nil, err
	}
	defer resultsIterator.Close()

	var records []HistoryQueryResult
	for resultsIterator.HasNext() {
		response, err := resultsIterator.Next()
		if err != nil {
			return nil, err
		}

		var asset Asset
		if len(response.Value) > 0 {
			err = json.Unmarshal(response.Value, &asset)
			if err != nil {
				return nil, err
			}
		} else {
			asset = Asset{
				ID: assetID,
			}
		}

		record := HistoryQueryResult{
			TxId:      response.TxId,
			Timestamp: response.Timestamp.AsTime(),
			Record:    &asset,
			IsDelete:  response.IsDelete,
		}
		records = append(records, record)
	}

	return records, nil
}

// AssetExists returns true when asset with given ID exists in the ledger.
func (t *SimpleChaincode) AssetExists(ctx contractapi.TransactionContextInterface, assetID string) (bool, error) {
	assetBytes, err := ctx.GetStub().GetState(assetID)
	if err != nil {
		return false, fmt.Errorf("failed to read asset %s from world state. %v", assetID, err)
	}

	return assetBytes != nil, nil
}

// InitLedger creates the initial set of assets in the ledger.
func (t *SimpleChaincode) InitLedger(ctx contractapi.TransactionContextInterface) error {
	assets := []Asset{
		{DocType: "asset", ID: "asset1", Color: "blue", Size: 5, Owner: "Tomoko", AppraisedValue: 300},
		{DocType: "asset", ID: "asset2", Color: "red", Size: 5, Owner: "Brad", AppraisedValue: 400},
		{DocType: "asset", ID: "asset3", Color: "green", Size: 10, Owner: "Jin Soo", AppraisedValue: 500},
		{DocType: "asset", ID: "asset4", Color: "yellow", Size: 10, Owner: "Max", AppraisedValue: 600},
		{DocType: "asset", ID: "asset5", Color: "black", Size: 15, Owner: "Adriana", AppraisedValue: 700},
		{DocType: "asset", ID: "asset6", Color: "white", Size: 15, Owner: "Michel", AppraisedValue: 800},
	}

	for _, asset := range assets {
		err := t.CreateAsset(ctx, asset.ID, asset.Color, asset.Size, asset.Owner, asset.AppraisedValue)
		if err != nil {
			return err
		}
	}

	return nil
}

func main() {
	chaincode, err := contractapi.NewChaincode(&SimpleChaincode{})
	if err != nil {
		log.Panicf("Error creating asset chaincode: %v", err)
	}

	if err := chaincode.Start(); err != nil {
		log.Panicf("Error starting asset chaincode: %v", err)
	}
}


Signed-off-by: Sarsilmaz <recepsara710@gmail.com>
2024-12-27 00:21:19 +03:00
Mark S. Lewis
e1a64665db
Update fabric-contract-api-go to v2.2.0 (#1283)
Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-12-25 18:06:01 +09:00
leo
898d333efb
docs: Quotation marks are used incorrectly. (#1282)
Signed-off-by: RiceChuan <lc582041246@gmail.com>
2024-12-24 09:52:40 +00:00
Arne Rutjes
5e0e5a1550 make version regex posix compliant so that it works on mac
Signed-off-by: Arne Rutjes <arne123@gmail.com>
2024-12-16 16:06:42 -05:00
Mark S. Lewis
8538e32437
Update Gradle version and shadow plugin (#1278)
The shadow plugin is now maintained by the GradleUp organization. Change
to use the current plugin ID and latest version.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-12-11 08:04:56 -05:00
Andi
b71a4587dc
chore: use errors.New to replace fmt.Errorf with no parameters (#1277)
Also remove repetitive words.

Signed-off-by: ChengenH <hce19970702@gmail.com>
2024-12-10 11:15:02 +00:00
Mark S. Lewis
15ab2e5da8
Fix invoke CLI commands in full-stack guide (#1276)
A behaviour change in microfab means that the orderer endpoint needs to
be explicitly specified when using the peer CLI to submit transactions.
Ideally the microfab environment would not require this but the
documented commands do not currently work without this.

This change updates the full-stack-asset-transfer-guide documentation so
that CLI commands include the orderer endpoint explicitly.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-12-07 15:05:30 -05:00
Mark S. Lewis
b11239aac0
Update fabric-contract-api-go to v2.1.0 (#1275)
Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-12-07 08:36:56 -05:00
Mark S. Lewis
1aa3822788 Fix build with new microfab release
The new microfab release seems to start slower than the previous
release. This might be due to a change from solo to raft consensus. This
causes failures in the full-stack-asset-transfer appdev tests. Chaincode
deployment fails since the channel is not yet available.

Instead of increasing the sleep time after launching microfab, this
change attempts to wait however long is required by looking for the
"Microfab started" message in the container log before proceeding.

The test script is also updated to correctly stop the external chaincode
process when the script exits. Previously the process ID of the npm
command used to lauch the chaincode was captured rather than the actual
chaincode process.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-11-27 21:20:37 -05:00
David Enyeart
30b6186440 Update maintainers
Update maintainers to reflect activty from the past year.
- Retire Josh Kneubuhl, Matthew White, Arnaud Le Hors, Nikhil Gupta.
- Add Mark Lewis

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2024-11-12 09:07:30 -05:00
Tatsuya Sato
dd94aae3d5 Update chaincode container versions in k8s samples
This patch updates chaincode container versions to 2.5 in the following
samples:
- test-network-k8s
- full-stack-asset-transfer-guide

Signed-off-by: Tatsuya Sato <tatsuya.sato.so@hitachi.com>
2024-11-07 17:13:06 -05:00
Mark S. Lewis
8136eb4f5e Update test-network chaincode container versions
The test-network peer configuration specifies $(TWO_DIGIT_VERSION) as
the tag for the Node and Java chaincode containers. For Fabric v3.0,
this requests fabric-nodeenv:3.0 and fabric-javaenv:3.0 Docker images to
host Node and Java chaincode respectively. These images do not exist,
which causes deployment of Node and Java chaincode to fail when using
Fabric v3.0. Fabric v3.0 continues to use fabric-nodeenv:2.5 and
fabric-javaenv:2.5.

This change updates the test-network peer configuration to explicitly
specify `2.5` as the Node and Java chaincode Docker image tags. This is
(currently) the correct version for both Fabric v2.5 and Fabric v3.0.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-11-06 19:38:53 +09:00
Stanislav Jakuschevskij
9b199d4e0b Add private data go application
Created project directory, app.go and connect.go files. Reused the logic for
connect.go from the events application and added second organization setup.

Implemented private data transaction example in go as described in the main
documentation in "Tutorials/Using Private Data in Fabric".

Updated README.md with the command to run the go application and the script
which runs the application in the Github Actions workflow.

Fixed typos and punctuation in the private data typescript application.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2024-10-31 16:30:25 -04:00
Mark S. Lewis
e23bc6714e Simplify Java client error-handling example
The latest fabric-gateway client API release (v1.7.0) includes the gRPC error
details in the GatewayExcetion stack trace so it is not necessary to
programmatically access them to demonstrate that they are present.

This change updates the asset-transfer-basic/application-gateway-java
sample to simplify the updateNonExistentAsset example method. It also:

- Updates all samples to use the latest fabric-gateway release.
- Adds equivalent Maven POM files for fabric-gateway application samples.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-10-24 23:45:04 -04:00
Stanislav Jakuschevskij
51e3a533dc Remove cli from podman compose file
Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2024-10-22 16:50:08 -04:00
Mark S. Lewis
f16e9e6de5 Consistent Go version in go.mod and go.work files
The repository currently uses Go 1.22 to test samples in the automated
build. This change sets the Go version in all go.mod (and go.work) files
to Go 1.22.0, and removes any Go toolchain entries.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-10-14 10:25:34 -04:00
Mark S. Lewis
b931df3a5f Explicitly specify hash in client applications
For some signing implementations, such as ed25519, a non-default hash
implementation must be specified when creating the Gateway connection in
client applications. Rather than relying on the default hash algorithm,
it is probably good practice in general to specify an algorithm that is
compatible with your signing implementation.

This change explicitly specifies the hash algorithm to raise visibility
of the option to select the hash algorithm.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-10-07 12:25:40 -04:00
Mark S. Lewis
e37e991c4c Update applications to use fabric-gateway v1.6.0
Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-09-25 13:18:45 +09:00
David Enyeart
137f365ec9 Bump ubuntu to 22.04 in CI
Since Fabric v3.0 builds on ubuntu 22.04,
it is necessary for samples CI to run on ubuntu 22.04.

Both Fabric v2.5 components (ubuntu 20.04) and
Fabric v3.0 components (ubuntu 22.04) work on
ubuntu 22.04 runtime.

The update also requires shell script updates to pass linting.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2024-09-19 10:27:26 +09:00
Tatsuya Sato
ce5aa883ee test-network-k8s: Improve prereqs logic
This patch improves prereqs logic in test-network-k8s.
- Use the newer install script instead of bootstrap.sh
- Download binaries matching the Docker image versions, instead of the latest version
- Add checks for Fabric versions to ensure consistency between images and binaries

Signed-off-by: Tatsuya Sato <tatsuya.sato.so@hitachi.com>
2024-08-21 12:29:22 -04:00
Tatsuya Sato
5c5e98bb3d Fix the default chaincode version to "1.0" in test-network
Signed-off-by: Tatsuya Sato <tatsuya.sato.so@hitachi.com>
2024-08-20 13:15:11 -04:00
Mark S. Lewis
3826626d00 Configure dependabot updates to GitHub Actions
Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-07-29 15:50:33 -04:00
takayuki-nagai
50b69f6157
Add document about how to benchmark the performance using Hyperledger Caliper (#1238)
Add document about how to benchmark the performance using Hyperledger Caliper

Signed-off-by: takayuki-nagai <takayuki.nagai.nu@hitachi.com>
Co-authored-by: Tatsuya Sato <tatsuya.sato.so@hitachi.com>
2024-07-17 17:46:23 +09:00
chinmayi
604a0a561b Fix directory path for chaincode-external
Signed-off-by: chinmayi <chinmayishaan2316@gmail.com>
2024-06-24 16:27:16 -04:00
Mark S. Lewis
110e732259 Update Go chaincode to fabric-contract-api-go/v2
Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-06-21 15:18:12 -04:00
Mark S. Lewis
7258b4f4ab Add JavaScript asset-transfer-basic application
While the TypeScript application sample is essentially identical (with
the addition of some type declarations), there seems to be sufficient
uncertainty amongst JavaScript developers not familiar with TypeScript
on how best to implement a JavaScript application that it is worthwhile
having one plain JavaScript sample using the current client API.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-06-21 12:16:31 -04:00
Mark S. Lewis
76088d0273 Remove legacy sample applications
The removed samples make use of deprecated legacy client SDKs. They all
have equivalent samples implemented using the currently supported Fabric
Gateway client API, and are therefore redundant.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-06-19 10:38:52 -04:00
David Enyeart
e334b7527a Bump fabric to v2.5.9
Bump fabric to v2.5.9.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2024-06-19 11:59:47 +09:00
Mark S. Lewis
c077dae79c Update TypeScript implementations
- Dependency updates
- ESLint flat configuration format, replacing deprecated configuration
- Minor fixes to compile and lint issues
- Consistent TypeScript formatting with .editorconfig

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-06-18 06:51:58 -04:00
Chris Elder
a4f0a2c5b2 Change CA ports in test-network-nano-bash
Signed-off-by: Chris Elder <celder@Chriss-MacBook-Pro.local>
2024-06-15 16:43:43 -04:00
Chris Elder
3622a5e383 Add chaincode logging for binary chaincode in test-network-nano-bash
- Correct sh compability in ca_utils.sh
- Correct linux compatibility in external builder

Signed-off-by: Chris Elder <celder628@gmail.com>
Signed-off-by: Chris Elder <celder@Chriss-MacBook-Pro.local>
2024-06-14 13:10:53 -04:00
Mark S. Lewis
29e695187a Use more specific chaincode package versions
This demonstrates good practice in restricting the chaincode package
versions to those applicable for the specific Fabric (major/minor)
version targeted for deployment.

Also some corrections to the repository README. Particularly referring
to other branches for samples targeted at earlier Fabric versions, since
samples in the main branch may exploit features not available in older
Fabric releases, which can cause confusion for end users.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-06-14 00:24:08 -04:00
Chris Elder
179bc96846 Add external builders for golang and node chaincode to test-network-nano-bash
The external builders will build and launch binary chaincode instead of docker containers.

Signed-off-by: Chris Elder <celder628@gmail.com>
2024-06-06 17:51:34 -04:00
Tatsuya Sato
e4af8fe198 test-network-k8s: bump k8s-builder and couchdb
Signed-off-by: Tatsuya Sato <tatsuya.sato.so@hitachi.com>
2024-06-04 12:56:19 -04:00
Mark S. Lewis
0ed34585e1 Update Node chaincode for v2.5.5 release
Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-06-03 15:27:51 -04:00
Chris Elder
3c63eac4e3 Add CA capability to test-network-nano-bash
This change adds:
- shell scripts to start CAs for each org
- optional flag (-c) to network.sh to start CAs
- generate crypto material in the same format as cryptogen using the CAs
- describe how to start the CAs using terminals

Signed-off-by: Chris Elder <celder@chriss-mbp.raleigh.ibm.com>
2024-05-28 23:31:18 -04:00
David Enyeart
92f028c08d Bump dependencies
Go to 1.22
CouchDB to 3.3.3
Fabric to 2.5.8
Fabric-CA to 1.5.11

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2024-05-28 11:38:28 +09:00
James Taylor
1058f9ffe1 Update test-network-k8s
Add required permissions for upcoming k8s builder release

Also adds ttl to install jobs and configures the k8s builder prefix

Signed-off-by: James Taylor <jamest@uk.ibm.com>
2024-05-27 13:49:37 +09:00
Mark S. Lewis
d3e2a90ad5 Update test dependencies for Java chaincode
This resolves mocking errors using the latest Java chaincode shim and
very old versions of Mockito.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-05-21 22:19:39 -04:00
David Enyeart
bf61094231 Remove double quotes for env variables
Double quotes have caused issues in some environments,
e.g. see https://github.com/hyperledger/fabric/issues/4358

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2024-05-07 01:06:09 +09:00
Dave Enyeart
effe8ff980
Switch microfab to hyperledger-labs version (#1203)
full-stack-asset-transfer points to an old image
that no longer exists.
Point to the hyperledger-labs microfab image instead.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2024-05-03 10:03:27 +01:00
David Enyeart
2fa83c957a GHA: Use ubuntu-20.04 for local forks
GHA: Use ubuntu-20.04 for local forks
since local forks don't have access to fabric-ubuntu-20.04.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2024-04-30 12:35:31 -04:00
David Enyeart
4763bcae8d test-network error message if jq not installed
With removal of fabric-tools image, test-network
now depends on jq being installed locally.

This commit logs an error message if jq commands
fail due to jq not being installed locally.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2024-04-30 14:48:25 +09:00
James Taylor
0db64487e5 Update nano test network
Fix regression in network.sh and update peer scripts to allow
chaincodeListenAddress and chaincodeAddress to be overridden if
required

Also updates the nano test network readme to describe the new
environment variables for the k8s builder

Fixes #1198

Signed-off-by: James Taylor <jamest@uk.ibm.com>
2024-04-29 10:42:41 -04:00
Mark S. Lewis
42b9b60ebc Update Go gRPC dependency
grpc.Dial() is (soon to be) deprecated in current gRPC versions. Use grpc.NewClient() instead.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-04-24 16:24:37 +09:00
Tatsuya Sato
c691cf94a9 Refactor test-network post-decoupling fabric-tools image
This patch aims to refactor the test-network in several aspects,
following the decoupling of the fabric-tools image from fabric-samples.

- Rename 'test_network_home' env var to 'TEST_NETWORK_HOME'
- Dedicate the intermediate artifacts related to configtx to
channel-artifacts
- Refer to core.yaml in fabric-samples/config, similar to org1 and 2,
  instead of adding a new core file
- Remove unnecessary functions and comments for CLI container
- Other minor modifications

Signed-off-by: Tatsuya Sato <tatsuya.sato.so@hitachi.com>
2024-04-18 13:41:28 -04:00
David Enyeart
820368571d test-network envVar.sh script improvement
Change shell script to use single equals.

In my shell environment single bracket with double equals did not work.
It caused failure when running the chaincode-external tutorial README.

It looks like for maximum portability, it is best to use single bracket with single equals.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2024-04-12 12:55:48 +09:00
Mark S. Lewis
d4ce4cfadc Update asset-transfer-sbe/chaincode-java
Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-04-11 22:57:57 -04:00
Tatsuya Sato
02bcb44ad4 Fix docs and scripts for asset-transfer-basic as an external service
Signed-off-by: Tatsuya Sato <tatsuya.sato.so@hitachi.com>
2024-04-11 15:24:37 -04:00
Sam Yuan
ebbc419933
Decouple fabric tools image from fabric sample (#1186)
* Decouple fabric tools image from fabric sample
* update with review comments

Signed-off-by: Sam Yuan <yy19902439@126.com>
2024-04-06 19:07:18 +09:00