Added new lines at the bottom of index.js and asset_transfer_ledger_chaincode.js. Modified node version in package.json. Modified error messages in the chaincode to all begin uppercase.

Signed-off-by: r2roC <arturo@IBM.com>
This commit is contained in:
r2roC 2020-07-10 09:34:17 -04:00 committed by denyeart
parent 666e61ec6e
commit 1c5cf4383c
3 changed files with 9 additions and 9 deletions

View file

@ -75,7 +75,7 @@ class Chaincode extends Contract{
async createAsset(ctx, assetID, color, owner, size, appraisedValue) {
const exists = await this.assetExists(ctx, assetID)
if (exists) {
throw new Error('asset exists')
throw new Error(`The asset ${assetID} already exists`)
}
// ==== Create asset object and marshal to JSON ====
@ -101,7 +101,7 @@ class Chaincode extends Contract{
async readAsset(ctx, id) {
const assetJSON = await ctx.stub.getState(id); // get the asset from chaincode state
if (!assetJSON || assetJSON.length === 0) {
throw new Error(`The asset ${id} does not exist`);
throw new Error(`Asset ${id} does not exist`);
}
return assetJSON.toString();
@ -110,19 +110,19 @@ class Chaincode extends Contract{
// delete - remove a asset key/value pair from state
async deleteAsset(ctx, id) {
if (!id) {
throw new Error('asset name must not be empty');
throw new Error('Asset name must not be empty');
}
var exists = await this.assetExists(ctx, id)
if (!exists) {
throw new Error('')
throw new Error(`Asset ${id} does not exist`)
}
// to maintain the color~name index, we need to read the asset first and get its color
let valAsbytes = await ctx.stub.getState(id); // get the asset from chaincode state
let jsonResp = {};
if (!valAsbytes) {
jsonResp.error = 'asset does not exist: ' + name;
jsonResp.error = 'Asset does not exist: ' + name;
throw new Error(jsonResp);
}
let assetJSON = {};
@ -150,7 +150,7 @@ class Chaincode extends Contract{
let assetAsBytes = await ctx.stub.getState(assetName);
if (!assetAsBytes || !assetAsBytes.toString()) {
throw new Error('asset does not exist');
throw new Error(`Asset ${assetName} does not exist`);
}
let assetToTransfer = {};
try {

View file

@ -4,7 +4,7 @@
"description": "asset chaincode implemented in node.js",
"main": "index.js",
"engines": {
"node": ">=8.4.0",
"node": ">=12",
"npm": ">=5.3.0"
},
"scripts": {