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) { async getState(key) {
let ledgerKey = this.ctx.stub.createCompositeKey(this.name, State.splitKey(key)); let ledgerKey = this.ctx.stub.createCompositeKey(this.name, State.splitKey(key));
let data = await this.ctx.stub.getState(ledgerKey); let data = await this.ctx.stub.getState(ledgerKey);
let state = State.deserialize(data, this.supportedClasses); if (data){
return state; 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 { class CommercialPaperContract extends Contract {
constructor() { constructor() {
// Unique namespace when multiple contracts per chaincode file // Unique name when multiple contracts per chaincode file
super('org.papernet.commercialpaper'); super('org.papernet.commercialpaper');
} }
@ -111,7 +111,7 @@ class CommercialPaperContract extends Contract {
if (paper.isTrading()) { if (paper.isTrading()) {
paper.setOwner(newOwner); paper.setOwner(newOwner);
} else { } 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 // Update the paper

View file

@ -1,6 +1,6 @@
{ {
"name": "papernet-js", "name": "papercontract",
"version": "0.0.1", "version": "0.0.3",
"description": "Papernet Contract", "description": "Papernet Contract",
"main": "index.js", "main": "index.js",
"engines": { "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) { async getState(key) {
let ledgerKey = this.ctx.stub.createCompositeKey(this.name, State.splitKey(key)); let ledgerKey = this.ctx.stub.createCompositeKey(this.name, State.splitKey(key));
let data = await this.ctx.stub.getState(ledgerKey); let data = await this.ctx.stub.getState(ledgerKey);
let state = State.deserialize(data, this.supportedClasses); if (data){
return state; 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 { class CommercialPaperContract extends Contract {
constructor() { constructor() {
// Unique namespace when multiple contracts per chaincode file // Unique name when multiple contracts per chaincode file
super('org.papernet.commercialpaper'); super('org.papernet.commercialpaper');
} }

View file

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