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

chore: use errors.New to replace fmt.Errorf with no parameters #1277

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface)

// AgreeToTransfer is used by the potential buyer of the asset to agree to the
// asset value. The agreed to appraisal value is stored in the buying orgs
// org specifc collection, while the the buyer client ID is stored in the asset collection
// org specifc collection, while the buyer client ID is stored in the asset collection
// using a composite key
func (s *SmartContract) AgreeToTransfer(ctx contractapi.TransactionContextInterface) error {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public Asset CreateAsset(final Context ctx) {
/**
* AgreeToTransfer is used by the potential buyer of the asset to agree to the
* asset value. The agreed to appraisal value is stored in the buying orgs
* org specifc collection, while the the buyer client ID is stored in the asset collection
* org specifc collection, while the buyer client ID is stored in the asset collection
* using a composite key
* Uses transient map with key asset_value
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class AssetTransfer extends Contract {

// AgreeToTransfer is used by the potential buyer of the asset to agree to the
// asset value. The agreed to appraisal value is stored in the buying orgs
// org specifc collection, while the the buyer client ID is stored in the asset collection
// org specifc collection, while the buyer client ID is stored in the asset collection
// using a composite key
@Transaction()
public async AgreeToTransfer(ctx: Context): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (s *SmartContract) RevealBid(ctx contractapi.TransactionContextInterface, a

transientBidJSON, ok := transientMap["bid"]
if !ok {
return fmt.Errorf("bid key not found in the transient map")
return errors.New("bid key not found in the transient map")
}

// get implicit collection name of organization ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package auction

import (
"encoding/json"
"errors"
"fmt"

"github.com/hyperledger/fabric-chaincode-go/v2/shim"
Expand All @@ -20,7 +21,7 @@ func (s *SmartContract) QueryAuction(ctx contractapi.TransactionContextInterface
return nil, fmt.Errorf("failed to get auction object %v: %v", auctionID, err)
}
if auctionJSON == nil {
return nil, fmt.Errorf("auction does not exist")
return nil, errors.New("auction does not exist")
}

var auction *Auction
Expand Down
3 changes: 2 additions & 1 deletion auction-dutch/chaincode-go/smart-contract/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
"sort"

Expand Down Expand Up @@ -129,7 +130,7 @@ func (s *SmartContract) Bid(ctx contractapi.TransactionContextInterface, auction

bidJSON, ok := transientMap["bid"]
if !ok {
return "", fmt.Errorf("bid key not found in the transient map")
return "", errors.New("bid key not found in the transient map")
}

// get the implicit collection name using the bidder's organization ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package auction

import (
"encoding/json"
"errors"
"fmt"

"github.com/hyperledger/fabric-chaincode-go/v2/shim"
Expand All @@ -20,7 +21,7 @@ func (s *SmartContract) QueryAuction(ctx contractapi.TransactionContextInterface
return nil, fmt.Errorf("failed to get auction object %v: %v", auctionID, err)
}
if auctionJSON == nil {
return nil, fmt.Errorf("auction does not exist")
return nil, errors.New("auction does not exist")
}

var auction *Auction
Expand Down
4 changes: 2 additions & 2 deletions test-network/CHAINCODE_AS_A_SERVICE_TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ We need to use the latest 2.4.1 release as this contains some improvements to ma
- The `ccaasbuilder` applications are included in the binary tgz archive download for use in other circumstances. The `sampleconfig/core.yaml` is updated as well to refer to 'ccaasbuilder'
- The 2.4.1 Java Chaincode release has been updated to remove the need to write a custom bootstrap main class, similar to the Node.js Chaincode. It is intended that this will be added to the go chaincode as well.

## End-to-end with the the test-network
## End-to-end with the test-network

The `test-network` and some of the chaincodes have been updated to support running chaincode-as-a-service. The commands below assume that you've got the latest fabric-samples cloned, along with the latest Fabric docker images.

Expand Down Expand Up @@ -181,7 +181,7 @@ For Java please note:
In the traditional approach, each peer that the chaincode is approved on will have a container running the chaincode. With the '-as-a-service' approach we need to achieve the same architecture.

As the `connection.json` contains the address of the running chaincode container, it can be updated to ensure that each peer connects to a different container. However the as the `connection.json` in the chaincode package, Fabric mandates that the package id is consistent amongst all peers in an organization. To achieve that
the the external builder supports a template capability. The context from this template is taken from an environment variable set on each Peer. `CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG`
the external builder supports a template capability. The context from this template is taken from an environment variable set on each Peer. `CHAINCODE_AS_A_SERVICE_BUILDER_CONFIG`

We can define the address to be a template in the `connection.json`

Expand Down
2 changes: 1 addition & 1 deletion token-erc-20/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ cp "${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml" "${

The minter intends to approve 500 tokens to be transferred by the spender, but first the spender needs to provide their own client ID as the payment address.

Open a 3rd terminal to represent the spender in Org1 and navigate to fabric-samples/test-network. Set the the environment variables for the Org1 spender user.
Open a 3rd terminal to represent the spender in Org1 and navigate to fabric-samples/test-network. Set the environment variables for the Org1 spender user.

```
export PATH=${PWD}/../bin:${PWD}:$PATH
Expand Down
12 changes: 6 additions & 6 deletions token-erc-20/chaincode-go/chaincode/token_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount
return fmt.Errorf("failed to check if contract is already initialized: %v", err)
}
if !initialized {
return fmt.Errorf("Contract options need to be set before calling any function, call Initialize() to initialize contract")
return errors.New("Contract options need to be set before calling any function, call Initialize() to initialize contract")
}

// Check minter authorization - this sample assumes Org1 is the central banker with privilege to mint new tokens
Expand All @@ -52,7 +52,7 @@ func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount
return fmt.Errorf("failed to get MSPID: %v", err)
}
if clientMSPID != "Org1MSP" {
return fmt.Errorf("client is not authorized to mint new tokens")
return errors.New("client is not authorized to mint new tokens")
}

// Get ID of submitting client identity
Expand All @@ -62,7 +62,7 @@ func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount
}

if amount <= 0 {
return fmt.Errorf("mint amount must be a positive integer")
return errors.New("mint amount must be a positive integer")
}

currentBalanceBytes, err := ctx.GetStub().GetState(minter)
Expand Down Expand Up @@ -141,15 +141,15 @@ func (s *SmartContract) Burn(ctx contractapi.TransactionContextInterface, amount
return fmt.Errorf("failed to check if contract is already initialized: %v", err)
}
if !initialized {
return fmt.Errorf("Contract options need to be set before calling any function, call Initialize() to initialize contract")
return errors.New("Contract options need to be set before calling any function, call Initialize() to initialize contract")
}
// Check minter authorization - this sample assumes Org1 is the central banker with privilege to burn new tokens
clientMSPID, err := ctx.GetClientIdentity().GetMSPID()
if err != nil {
return fmt.Errorf("failed to get MSPID: %v", err)
}
if clientMSPID != "Org1MSP" {
return fmt.Errorf("client is not authorized to mint new tokens")
return errors.New("client is not authorized to mint new tokens")
}

// Get ID of submitting client identity
Expand Down Expand Up @@ -719,7 +719,7 @@ func checkInitialized(ctx contractapi.TransactionContextInterface) (bool, error)
// sub two number checking for overflow
func sub(b int, q int) (int, error) {

// sub two number checking
// sub two number checking
if q <= 0 {
return 0, fmt.Errorf("Error: the subtraction number is %d, it should be greater than 0", q)
}
Expand Down
4 changes: 2 additions & 2 deletions token-erc-721/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ cp ${PWD}/organizations/peerOrganizations/org1.example.com/msp/config.yaml ${PWD

The minter intends to approve a non-fungible token to be transferred by the operator, but first the operator needs to provide their own client ID as the payment address.

Open a 3rd terminal to represent the operator in Org1 and navigate to fabric-samples/test-network. Set the the environment variables for the Org1 operator user.
Open a 3rd terminal to represent the operator in Org1 and navigate to fabric-samples/test-network. Set the environment variables for the Org1 operator user.

```
export PATH=${PWD}/../bin:${PWD}:$PATH
Expand Down Expand Up @@ -304,7 +304,7 @@ And then request the approval for the operator to transfer the token.

```
# Issue a new token
peer chaincode invoke $TARGET_TLS_OPTIONS -C mychannel -n token_erc721 -c '{"function":"MintWithTokenURI","Args":["102", "https://example.com/nft102.json"]}' --waitForEvent
peer chaincode invoke $TARGET_TLS_OPTIONS -C mychannel -n token_erc721 -c '{"function":"MintWithTokenURI","Args":["102", "https://example.com/nft102.json"]}' --waitForEvent

# The owner approves
export OPERATOR="x509::/C=US/ST=North Carolina/O=Hyperledger/OU=client/CN=operator::/C=US/ST=North Carolina/L=Durham/O=org1.example.com/CN=ca.org1.example.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public String ClientAccountID(final Context ctx) {
}

/**
* Get the the NFT details by token id.
* Get the NFT details by token id.
*
* @param ctx the transaction context
* @param tokenId Unique ID of a non-fungible token
Expand Down
2 changes: 1 addition & 1 deletion token-utxo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Now you are ready to call the deployed smart contract via peer CLI calls. But le

The smart contract supports UTXO ownership based on individual client identities from organizations that are members of the channel. In our scenario, the minter of the tokens will be a member of Org1, while the recipient will belong to Org2. To highlight the connection between the `GetClientIdentity().GetID()` API and the information within a user's certificate, we will register two new identities using the Org1 and Org2 Certificate Authorities (CA's), and then use the CA's to generate each identity's certificate and private key.

First, we need to set the following environment variables to use the the Fabric CA client (and subsequent commands)
First, we need to set the following environment variables to use the Fabric CA client (and subsequent commands)
```
export PATH=${PWD}/../bin:${PWD}:$PATH
export FABRIC_CFG_PATH=$PWD/../config/
Expand Down
Loading