mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
Correct index location (#443)
Signed-off-by: Matthew B White <whitemat@uk.ibm.com>
This commit is contained in:
parent
9db8164f04
commit
ce5186008b
2 changed files with 10 additions and 6 deletions
|
|
@ -181,7 +181,7 @@ class Chaincode extends Contract {
|
||||||
async GetAssetsByRange(ctx, startKey, endKey) {
|
async GetAssetsByRange(ctx, startKey, endKey) {
|
||||||
|
|
||||||
let resultsIterator = await ctx.stub.getStateByRange(startKey, endKey);
|
let resultsIterator = await ctx.stub.getStateByRange(startKey, endKey);
|
||||||
let results = await this.GetAllResults(resultsIterator, false);
|
let results = await this._GetAllResults(resultsIterator, false);
|
||||||
|
|
||||||
return JSON.stringify(results);
|
return JSON.stringify(results);
|
||||||
}
|
}
|
||||||
|
|
@ -249,7 +249,7 @@ class Chaincode extends Contract {
|
||||||
async GetQueryResultForQueryString(ctx, queryString) {
|
async GetQueryResultForQueryString(ctx, queryString) {
|
||||||
|
|
||||||
let resultsIterator = await ctx.stub.getQueryResult(queryString);
|
let resultsIterator = await ctx.stub.getQueryResult(queryString);
|
||||||
let results = await this.GetAllResults(resultsIterator, false);
|
let results = await this._GetAllResults(resultsIterator, false);
|
||||||
|
|
||||||
return JSON.stringify(results);
|
return JSON.stringify(results);
|
||||||
}
|
}
|
||||||
|
|
@ -262,7 +262,7 @@ class Chaincode extends Contract {
|
||||||
async GetAssetsByRangeWithPagination(ctx, startKey, endKey, pageSize, bookmark) {
|
async GetAssetsByRangeWithPagination(ctx, startKey, endKey, pageSize, bookmark) {
|
||||||
|
|
||||||
const {iterator, metadata} = await ctx.stub.getStateByRangeWithPagination(startKey, endKey, pageSize, bookmark);
|
const {iterator, metadata} = await ctx.stub.getStateByRangeWithPagination(startKey, endKey, pageSize, bookmark);
|
||||||
const results = await this.GetAllResults(iterator, false);
|
const results = await this._GetAllResults(iterator, false);
|
||||||
|
|
||||||
results.ResponseMetadata = {
|
results.ResponseMetadata = {
|
||||||
RecordsCount: metadata.fetched_records_count,
|
RecordsCount: metadata.fetched_records_count,
|
||||||
|
|
@ -282,7 +282,7 @@ class Chaincode extends Contract {
|
||||||
async QueryAssetsWithPagination(ctx, queryString, pageSize, bookmark) {
|
async QueryAssetsWithPagination(ctx, queryString, pageSize, bookmark) {
|
||||||
|
|
||||||
const {iterator, metadata} = await ctx.stub.getQueryResultWithPagination(queryString, pageSize, bookmark);
|
const {iterator, metadata} = await ctx.stub.getQueryResultWithPagination(queryString, pageSize, bookmark);
|
||||||
const results = await this.GetAllResults(iterator, false);
|
const results = await this._GetAllResults(iterator, false);
|
||||||
|
|
||||||
results.ResponseMetadata = {
|
results.ResponseMetadata = {
|
||||||
RecordsCount: metadata.fetched_records_count,
|
RecordsCount: metadata.fetched_records_count,
|
||||||
|
|
@ -296,7 +296,7 @@ class Chaincode extends Contract {
|
||||||
async GetAssetHistory(ctx, assetName) {
|
async GetAssetHistory(ctx, assetName) {
|
||||||
|
|
||||||
let resultsIterator = await ctx.stub.getHistoryForKey(assetName);
|
let resultsIterator = await ctx.stub.getHistoryForKey(assetName);
|
||||||
let results = await this.GetAllResults(resultsIterator, true);
|
let results = await this._GetAllResults(resultsIterator, true);
|
||||||
|
|
||||||
return JSON.stringify(results);
|
return JSON.stringify(results);
|
||||||
}
|
}
|
||||||
|
|
@ -308,7 +308,11 @@ class Chaincode extends Contract {
|
||||||
return assetState && assetState.length > 0;
|
return assetState && assetState.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
async GetAllResults(iterator, isHistory) {
|
// This is JavaScript so without Funcation Decorators, all functions are assumed
|
||||||
|
// to be transaction functions
|
||||||
|
//
|
||||||
|
// For internal functions... prefix them with _
|
||||||
|
async _GetAllResults(iterator, isHistory) {
|
||||||
let allResults = [];
|
let allResults = [];
|
||||||
let res = await iterator.next();
|
let res = await iterator.next();
|
||||||
while (!res.done) {
|
while (!res.done) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue