mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-20 08: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"]
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/hyperledger/fabric-contract-api-go/v2/contractapi"
|
"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"]
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue