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

Also remove repetitive words.

Signed-off-by: ChengenH <hce19970702@gmail.com>
This commit is contained in:
Andi 2024-12-10 19:15:02 +08:00 committed by GitHub
parent 15ab2e5da8
commit b71a4587dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 23 additions and 20 deletions

View file

@ -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 // 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 // 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 // using a composite key
func (s *SmartContract) AgreeToTransfer(ctx contractapi.TransactionContextInterface) error { func (s *SmartContract) AgreeToTransfer(ctx contractapi.TransactionContextInterface) error {

View file

@ -339,7 +339,7 @@ public final class AssetTransfer implements ContractInterface {
/** /**
* AgreeToTransfer is used by the potential buyer of the asset to agree to the * 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 * 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 * using a composite key
* Uses transient map with key asset_value * Uses transient map with key asset_value
* *

View file

@ -61,7 +61,7 @@ export class AssetTransfer extends Contract {
// AgreeToTransfer is used by the potential buyer of the asset to agree to the // 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 // 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 // using a composite key
@Transaction() @Transaction()
public async AgreeToTransfer(ctx: Context): Promise<void> { public async AgreeToTransfer(ctx: Context): Promise<void> {

View file

@ -148,7 +148,7 @@ func (s *SmartContract) RevealBid(ctx contractapi.TransactionContextInterface, a
transientBidJSON, ok := transientMap["bid"] transientBidJSON, ok := transientMap["bid"]
if !ok { 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 // get implicit collection name of organization ID

View file

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

View file

@ -8,6 +8,7 @@ import (
"bytes" "bytes"
"crypto/sha256" "crypto/sha256"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"sort" "sort"
@ -129,7 +130,7 @@ func (s *SmartContract) Bid(ctx contractapi.TransactionContextInterface, auction
bidJSON, ok := transientMap["bid"] bidJSON, ok := transientMap["bid"]
if !ok { 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 // get the implicit collection name using the bidder's organization ID

View file

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

View file

@ -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 `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. - 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. 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.
@ -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. 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 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` We can define the address to be a template in the `connection.json`

View file

@ -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. 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 export PATH=${PWD}/../bin:${PWD}:$PATH

View file

@ -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) return fmt.Errorf("failed to check if contract is already initialized: %v", err)
} }
if !initialized { 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 // Check minter authorization - this sample assumes Org1 is the central banker with privilege to mint new tokens
@ -52,7 +52,7 @@ func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount
return fmt.Errorf("failed to get MSPID: %v", err) return fmt.Errorf("failed to get MSPID: %v", err)
} }
if clientMSPID != "Org1MSP" { 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 // Get ID of submitting client identity
@ -62,7 +62,7 @@ func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount
} }
if amount <= 0 { 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) currentBalanceBytes, err := ctx.GetStub().GetState(minter)
@ -141,7 +141,7 @@ func (s *SmartContract) Burn(ctx contractapi.TransactionContextInterface, amount
return fmt.Errorf("failed to check if contract is already initialized: %v", err) return fmt.Errorf("failed to check if contract is already initialized: %v", err)
} }
if !initialized { 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 // Check minter authorization - this sample assumes Org1 is the central banker with privilege to burn new tokens
clientMSPID, err := ctx.GetClientIdentity().GetMSPID() clientMSPID, err := ctx.GetClientIdentity().GetMSPID()
@ -149,7 +149,7 @@ func (s *SmartContract) Burn(ctx contractapi.TransactionContextInterface, amount
return fmt.Errorf("failed to get MSPID: %v", err) return fmt.Errorf("failed to get MSPID: %v", err)
} }
if clientMSPID != "Org1MSP" { 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 // Get ID of submitting client identity
@ -719,7 +719,7 @@ func checkInitialized(ctx contractapi.TransactionContextInterface) (bool, error)
// sub two number checking for overflow // sub two number checking for overflow
func sub(b int, q int) (int, error) { func sub(b int, q int) (int, error) {
// sub two number checking // sub two number checking
if q <= 0 { if q <= 0 {
return 0, fmt.Errorf("Error: the subtraction number is %d, it should be greater than 0", q) return 0, fmt.Errorf("Error: the subtraction number is %d, it should be greater than 0", q)
} }

View file

@ -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. 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 export PATH=${PWD}/../bin:${PWD}:$PATH
@ -304,7 +304,7 @@ And then request the approval for the operator to transfer the token.
``` ```
# Issue a new 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 # 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" 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"

View file

@ -445,7 +445,7 @@ public class ERC721TokenContract implements ContractInterface {
} }
/** /**
* Get the the NFT details by token id. * Get the NFT details by token id.
* *
* @param ctx the transaction context * @param ctx the transaction context
* @param tokenId Unique ID of a non-fungible token * @param tokenId Unique ID of a non-fungible token

View file

@ -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. 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 PATH=${PWD}/../bin:${PWD}:$PATH
export FABRIC_CFG_PATH=$PWD/../config/ export FABRIC_CFG_PATH=$PWD/../config/