mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
chore: use errors.New to replace fmt.Errorf with no parameters
Signed-off-by: ChengenH <hce19970702@gmail.com>
This commit is contained in:
parent
a2400500be
commit
9ec84d1efd
5 changed files with 14 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package auction
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"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)
|
||||
}
|
||||
if auctionJSON == nil {
|
||||
return nil, fmt.Errorf("auction does not exist")
|
||||
return nil, errors.New("auction does not exist")
|
||||
}
|
||||
|
||||
var auction *Auction
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ import (
|
|||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/hyperledger/fabric-contract-api-go/v2/contractapi"
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package auction
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"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)
|
||||
}
|
||||
if auctionJSON == nil {
|
||||
return nil, fmt.Errorf("auction does not exist")
|
||||
return nil, errors.New("auction does not exist")
|
||||
}
|
||||
|
||||
var auction *Auction
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
}
|
||||
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()
|
||||
|
|
@ -149,7 +149,7 @@ func (s *SmartContract) Burn(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
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue