mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-20 16:45:09 +00:00
Merge "[FAB-13823] Commercial Paper fixes" into release-1.4
This commit is contained in:
commit
ec9eb7fa73
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) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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": {
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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": {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue