mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
[FAB-13823] Commercial Paper fixes
Change-Id: I35e3e02fe9672ea79bd96e4d49926c900dfa627d Signed-off-by: Matthew B. White <whitemat@uk.ibm.com>
This commit is contained in:
parent
026aa9ec01
commit
6c28eca339
8 changed files with 293 additions and 11 deletions
|
|
@ -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": {}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "papernet-js",
|
||||
"version": "0.0.1",
|
||||
"name": "papercontract",
|
||||
"version": "0.0.3",
|
||||
"description": "Papernet Contract",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
|
|
|
|||
|
|
@ -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": {}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "papernet-js",
|
||||
"version": "0.0.1",
|
||||
"name": "papercontract",
|
||||
"version": "0.0.3",
|
||||
"description": "Papernet Contract",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue