mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-18 16:05:10 +00:00
modify query number in fabcar for golang
default query number for fabcar in other programming language is 1000 cars Signed-off-by: zhuzeyu <zhuzeyu0409@gmail.com>
This commit is contained in:
parent
7b2dcbf2ed
commit
6c29fa0118
6 changed files with 22 additions and 22 deletions
24
chaincode/fabcar/external/fabcar.go
vendored
24
chaincode/fabcar/external/fabcar.go
vendored
|
|
@ -7,16 +7,16 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/hyperledger/fabric-chaincode-go/shim"
|
||||
"github.com/hyperledger/fabric-contract-api-go/contractapi"
|
||||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
CCID string
|
||||
Address string
|
||||
CCID string
|
||||
Address string
|
||||
}
|
||||
|
||||
// SmartContract provides functions for managing a car
|
||||
|
|
@ -99,8 +99,8 @@ func (s *SmartContract) QueryCar(ctx contractapi.TransactionContextInterface, ca
|
|||
|
||||
// QueryAllCars returns all cars found in world state
|
||||
func (s *SmartContract) QueryAllCars(ctx contractapi.TransactionContextInterface) ([]QueryResult, error) {
|
||||
startKey := "CAR0"
|
||||
endKey := "CAR99"
|
||||
startKey := ""
|
||||
endKey := ""
|
||||
|
||||
resultsIterator, err := ctx.GetStub().GetStateByRange(startKey, endKey)
|
||||
|
||||
|
|
@ -158,13 +158,13 @@ func main() {
|
|||
}
|
||||
|
||||
server := &shim.ChaincodeServer{
|
||||
CCID: config.CCID,
|
||||
Address: config.Address,
|
||||
CC: chaincode,
|
||||
TLSProps: shim.TLSProperties{
|
||||
Disabled: true,
|
||||
},
|
||||
}
|
||||
CCID: config.CCID,
|
||||
Address: config.Address,
|
||||
CC: chaincode,
|
||||
TLSProps: shim.TLSProperties{
|
||||
Disabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
if err := server.Start(); err != nil {
|
||||
fmt.Printf("Error starting fabcar chaincode: %s", err.Error())
|
||||
|
|
|
|||
|
|
@ -92,8 +92,8 @@ func (s *SmartContract) QueryCar(ctx contractapi.TransactionContextInterface, ca
|
|||
|
||||
// QueryAllCars returns all cars found in world state
|
||||
func (s *SmartContract) QueryAllCars(ctx contractapi.TransactionContextInterface) ([]QueryResult, error) {
|
||||
startKey := "CAR0"
|
||||
endKey := "CAR99"
|
||||
startKey := ""
|
||||
endKey := ""
|
||||
|
||||
resultsIterator, err := ctx.GetStub().GetStateByRange(startKey, endKey)
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ public final class FabCar implements ContractInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieves every car between CAR0 and CAR999 from the ledger.
|
||||
* Retrieves all cars from the ledger.
|
||||
*
|
||||
* @param ctx the transaction context
|
||||
* @return array of Cars found on the ledger
|
||||
|
|
@ -143,8 +143,8 @@ public final class FabCar implements ContractInterface {
|
|||
public CarQueryResult[] queryAllCars(final Context ctx) {
|
||||
ChaincodeStub stub = ctx.getStub();
|
||||
|
||||
final String startKey = "CAR0";
|
||||
final String endKey = "CAR999";
|
||||
final String startKey = "";
|
||||
final String endKey = "";
|
||||
List<CarQueryResult> queryResults = new ArrayList<CarQueryResult>();
|
||||
|
||||
QueryResultsIterator<KeyValue> results = stub.getStateByRange(startKey, endKey);
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ public final class FabCarTest {
|
|||
Context ctx = mock(Context.class);
|
||||
ChaincodeStub stub = mock(ChaincodeStub.class);
|
||||
when(ctx.getStub()).thenReturn(stub);
|
||||
when(stub.getStateByRange("CAR0", "CAR999")).thenReturn(new MockCarResultsIterator());
|
||||
when(stub.getStateByRange("", "")).thenReturn(new MockCarResultsIterator());
|
||||
|
||||
CarQueryResult[] cars = contract.queryAllCars(ctx);
|
||||
|
||||
|
|
|
|||
|
|
@ -108,8 +108,8 @@ class FabCar extends Contract {
|
|||
}
|
||||
|
||||
async queryAllCars(ctx) {
|
||||
const startKey = 'CAR0';
|
||||
const endKey = 'CAR999';
|
||||
const startKey = '';
|
||||
const endKey = '';
|
||||
const allResults = [];
|
||||
for await (const {key, value} of ctx.stub.getStateByRange(startKey, endKey)) {
|
||||
const strValue = Buffer.from(value).toString('utf8');
|
||||
|
|
|
|||
|
|
@ -105,8 +105,8 @@ export class FabCar extends Contract {
|
|||
}
|
||||
|
||||
public async queryAllCars(ctx: Context): Promise<string> {
|
||||
const startKey = 'CAR0';
|
||||
const endKey = 'CAR999';
|
||||
const startKey = '';
|
||||
const endKey = '';
|
||||
const allResults = [];
|
||||
for await (const {key, value} of ctx.stub.getStateByRange(startKey, endKey)) {
|
||||
const strValue = Buffer.from(value).toString('utf8');
|
||||
|
|
|
|||
Loading…
Reference in a new issue