Merge "[FAB-13823] Commercial Paper fixes" into release-1.4

This commit is contained in:
Simon Stone 2019-04-24 18:01:05 +00:00 committed by Gerrit Code Review
commit ec9eb7fa73
8 changed files with 293 additions and 11 deletions

View file

@ -0,0 +1,137 @@
{
"$schema": "http://fabric-shim.github.io/contract-schema.json",
"info": {
"title": "papercontract",
"version": "1.4.1",
"description": "Commercial Paper example",
"termsOfService": "https://github.com/hyperledger/fabric-samples/",
"contact": {
"name": "Hyperledger Fabric",
"url": "https://chat.hyperledger.org/channel/fabric-samples",
"email": "fabric@lists.hyperledger.org"
},
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"contracts": {
"org.papernet.commercialpaper": {
"name": "org.papernet.commercialpaper",
"transactions": [
{
"name": "issue",
"parameters": [
{
"name": "issuer",
"schema": {
"type":"string"
}
},
{
"name": "paperNumber",
"schema": {
"type":"integer"
}
},
{
"name": "issueDateTime",
"schema": {
"type":"string"
}
},
{
"name": "maturityDateTime",
"schema": {
"type":"string"
}
},
{
"name": "faceValue",
"schema": {
"type":"integer"
}
}
]
},
{
"name": "buy",
"parameters": [
{
"name": "issuer",
"schema": {
"type":"string"
}
},
{
"name": "paperNumber",
"schema": {
"type":"integer"
}
},
{
"name": "currentOwner",
"schema": {
"type":"string"
}
},
{
"name": "newOwner",
"schema": {
"type":"string"
}
},
{
"name": "price",
"schema": {
"type":"integer"
}
},
{
"name": "purchaseDateTime",
"schema": {
"type":"string"
}
}
]
},
{
"name": "redeem",
"parameters": [
{
"name": "issuer",
"schema": {
"type":"string"
}
},
{
"name": "paperNumber",
"schema": {
"type":"integer"
}
},
{
"name": "redeemingOwner",
"schema": {
"type":"string"
}
},
{
"name": "redeemDateTime",
"schema": {
"type":"string"
}
}
]
}
],
"info": {
"title": "",
"version": "1.4.1"
}
}
},
"components": {
"schemas": {}
}
}

View file

@ -42,8 +42,12 @@ class StateList {
async getState(key) {
let ledgerKey = this.ctx.stub.createCompositeKey(this.name, State.splitKey(key));
let data = await this.ctx.stub.getState(ledgerKey);
let state = State.deserialize(data, this.supportedClasses);
return state;
if (data){
let state = State.deserialize(data, this.supportedClasses);
return state;
} else {
return null;
}
}
/**

View file

@ -31,7 +31,7 @@ class CommercialPaperContext extends Context {
class CommercialPaperContract extends Contract {
constructor() {
// Unique namespace when multiple contracts per chaincode file
// Unique name when multiple contracts per chaincode file
super('org.papernet.commercialpaper');
}
@ -111,7 +111,7 @@ class CommercialPaperContract extends Contract {
if (paper.isTrading()) {
paper.setOwner(newOwner);
} else {
throw new Error('Paper ' + issuer + paperNumber + ' is not trading. Current state = ' + cp.getCurrentState());
throw new Error('Paper ' + issuer + paperNumber + ' is not trading. Current state = ' +paper.getCurrentState());
}
// Update the paper

View file

@ -1,6 +1,6 @@
{
"name": "papernet-js",
"version": "0.0.1",
"name": "papercontract",
"version": "0.0.3",
"description": "Papernet Contract",
"main": "index.js",
"engines": {

View file

@ -0,0 +1,137 @@
{
"$schema": "http://fabric-shim.github.io/contract-schema.json",
"info": {
"title": "papercontract",
"version": "1.4.1",
"description": "Commercial Paper example",
"termsOfService": "https://github.com/hyperledger/fabric-samples/",
"contact": {
"name": "Hyperledger Fabric",
"url": "https://chat.hyperledger.org/channel/fabric-samples",
"email": "fabric@lists.hyperledger.org"
},
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"contracts": {
"org.papernet.commercialpaper": {
"name": "org.papernet.commercialpaper",
"transactions": [
{
"name": "issue",
"parameters": [
{
"name": "issuer",
"schema": {
"type":"string"
}
},
{
"name": "paperNumber",
"schema": {
"type":"integer"
}
},
{
"name": "issueDateTime",
"schema": {
"type":"string"
}
},
{
"name": "maturityDateTime",
"schema": {
"type":"string"
}
},
{
"name": "faceValue",
"schema": {
"type":"integer"
}
}
]
},
{
"name": "buy",
"parameters": [
{
"name": "issuer",
"schema": {
"type":"string"
}
},
{
"name": "paperNumber",
"schema": {
"type":"integer"
}
},
{
"name": "currentOwner",
"schema": {
"type":"string"
}
},
{
"name": "newOwner",
"schema": {
"type":"string"
}
},
{
"name": "price",
"schema": {
"type":"integer"
}
},
{
"name": "purchaseDateTime",
"schema": {
"type":"string"
}
}
]
},
{
"name": "redeem",
"parameters": [
{
"name": "issuer",
"schema": {
"type":"string"
}
},
{
"name": "paperNumber",
"schema": {
"type":"integer"
}
},
{
"name": "redeemingOwner",
"schema": {
"type":"string"
}
},
{
"name": "redeemDateTime",
"schema": {
"type":"string"
}
}
]
}
],
"info": {
"title": "",
"version": "1.4.1"
}
}
},
"components": {
"schemas": {}
}
}

View file

@ -42,8 +42,12 @@ class StateList {
async getState(key) {
let ledgerKey = this.ctx.stub.createCompositeKey(this.name, State.splitKey(key));
let data = await this.ctx.stub.getState(ledgerKey);
let state = State.deserialize(data, this.supportedClasses);
return state;
if (data){
let state = State.deserialize(data, this.supportedClasses);
return state;
} else {
return null;
}
}
/**

View file

@ -31,7 +31,7 @@ class CommercialPaperContext extends Context {
class CommercialPaperContract extends Contract {
constructor() {
// Unique namespace when multiple contracts per chaincode file
// Unique name when multiple contracts per chaincode file
super('org.papernet.commercialpaper');
}

View file

@ -1,6 +1,6 @@
{
"name": "papernet-js",
"version": "0.0.1",
"name": "papercontract",
"version": "0.0.3",
"description": "Papernet Contract",
"main": "index.js",
"engines": {