Skip to content

Commit

Permalink
Merge "[FAB-16607] Update FabCar to reflect CC updates"
Browse files Browse the repository at this point in the history
  • Loading branch information
mbwhite authored and Gerrit Code Review committed Sep 19, 2019
2 parents c13a5ec + 521a7ff commit 7010c50
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 50 deletions.
4 changes: 2 additions & 2 deletions chaincode/fabcar/java/config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
-->

<property name="fileExtensions" value="java, properties, xml"/>

<module name="SuppressionFilter">
<property name="file" value="config/checkstyle/suppressions.xml"/>
<property name="file" value="${config_loc}/suppressions.xml"/>
<property name="optional" value="false"/>
</module>

Expand Down
35 changes: 11 additions & 24 deletions chaincode/fabcar/javascript/lib/fabcar.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,33 +108,20 @@ class FabCar extends Contract {
async queryAllCars(ctx) {
const startKey = 'CAR0';
const endKey = 'CAR999';

const iterator = await ctx.stub.getStateByRange(startKey, endKey);

const allResults = [];
while (true) {
const res = await iterator.next();

if (res.value && res.value.value.toString()) {
console.log(res.value.value.toString('utf8'));

const Key = res.value.key;
let Record;
try {
Record = JSON.parse(res.value.value.toString('utf8'));
} catch (err) {
console.log(err);
Record = res.value.value.toString('utf8');
}
allResults.push({ Key, Record });
}
if (res.done) {
console.log('end of data');
await iterator.close();
console.info(allResults);
return JSON.stringify(allResults);
for await (const {key, value} of ctx.stub.getStateByRange(startKey, endKey)) {
const strValue = Buffer.from(value).toString('utf8');
let record;
try {
record = JSON.parse(strValue);
} catch (err) {
console.log(err);
record = strValue;
}
allResults.push({ Key: key, Record: record });
}
console.info(allResults);
return JSON.stringify(allResults);
}

async changeCarOwner(ctx, carNumber, newOwner) {
Expand Down
35 changes: 11 additions & 24 deletions chaincode/fabcar/typescript/src/fabcar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,33 +107,20 @@ export class FabCar extends Contract {
public async queryAllCars(ctx: Context): Promise<string> {
const startKey = 'CAR0';
const endKey = 'CAR999';

const iterator = await ctx.stub.getStateByRange(startKey, endKey);

const allResults = [];
while (true) {
const res = await iterator.next();

if (res.value && res.value.value.toString()) {
console.log(res.value.value.toString('utf8'));

const Key = res.value.key;
let Record;
try {
Record = JSON.parse(res.value.value.toString('utf8'));
} catch (err) {
console.log(err);
Record = res.value.value.toString('utf8');
}
allResults.push({ Key, Record });
}
if (res.done) {
console.log('end of data');
await iterator.close();
console.info(allResults);
return JSON.stringify(allResults);
for await (const {key, value} of ctx.stub.getStateByRange(startKey, endKey)) {
const strValue = Buffer.from(value).toString('utf8');
let record;
try {
record = JSON.parse(strValue);
} catch (err) {
console.log(err);
record = strValue;
}
allResults.push({ Key: key, Record: record });
}
console.info(allResults);
return JSON.stringify(allResults);
}

public async changeCarOwner(ctx: Context, carNumber: string, newOwner: string) {
Expand Down

0 comments on commit 7010c50

Please sign in to comment.