mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-21 09:05:10 +00:00
Update with Java Contract Change-Id: I1a70473f038576d741c8c9ac83e527b5e51e88ca Signed-off-by: Matthew B. White <whitemat@uk.ibm.com> [FAB-15213] Update Commercial Paper for Java Change-Id: Ie116962a6c3952e52269323492f5f292e9b65e95 Signed-off-by: Matthew B. White <whitemat@uk.ibm.com>
102 lines
2.1 KiB
JavaScript
102 lines
2.1 KiB
JavaScript
/*
|
|
SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
// Utility class for ledger state
|
|
const State = require('./../ledger-api/state.js');
|
|
|
|
// Enumerate commercial paper state values
|
|
const cpState = {
|
|
ISSUED: 1,
|
|
TRADING: 2,
|
|
REDEEMED: 3
|
|
};
|
|
|
|
/**
|
|
* CommercialPaper class extends State class
|
|
* Class will be used by application and smart contract to define a paper
|
|
*/
|
|
class CommercialPaper extends State {
|
|
|
|
constructor(obj) {
|
|
super(CommercialPaper.getClass(), [obj.issuer, obj.paperNumber]);
|
|
Object.assign(this, obj);
|
|
}
|
|
|
|
/**
|
|
* Basic getters and setters
|
|
*/
|
|
getIssuer() {
|
|
return this.issuer;
|
|
}
|
|
|
|
setIssuer(newIssuer) {
|
|
this.issuer = newIssuer;
|
|
}
|
|
|
|
getOwner() {
|
|
return this.owner;
|
|
}
|
|
|
|
setOwner(newOwner) {
|
|
this.owner = newOwner;
|
|
}
|
|
|
|
/**
|
|
* Useful methods to encapsulate commercial paper states
|
|
*/
|
|
setIssued() {
|
|
this.currentState = cpState.ISSUED;
|
|
}
|
|
|
|
setTrading() {
|
|
this.currentState = cpState.TRADING;
|
|
}
|
|
|
|
setRedeemed() {
|
|
this.currentState = cpState.REDEEMED;
|
|
}
|
|
|
|
isIssued() {
|
|
return this.currentState === cpState.ISSUED;
|
|
}
|
|
|
|
isTrading() {
|
|
return this.currentState === cpState.TRADING;
|
|
}
|
|
|
|
isRedeemed() {
|
|
return this.currentState === cpState.REDEEMED;
|
|
}
|
|
|
|
static fromBuffer(buffer) {
|
|
return CommercialPaper.deserialize(buffer);
|
|
}
|
|
|
|
toBuffer() {
|
|
return Buffer.from(JSON.stringify(this));
|
|
}
|
|
|
|
/**
|
|
* Deserialize a state data to commercial paper
|
|
* @param {Buffer} data to form back into the object
|
|
*/
|
|
static deserialize(data) {
|
|
return State.deserializeClass(data, CommercialPaper);
|
|
}
|
|
|
|
/**
|
|
* Factory method to create a commercial paper object
|
|
*/
|
|
static createInstance(issuer, paperNumber, issueDateTime, maturityDateTime, faceValue) {
|
|
return new CommercialPaper({ issuer, paperNumber, issueDateTime, maturityDateTime, faceValue });
|
|
}
|
|
|
|
static getClass() {
|
|
return 'org.papernet.commercialpaper';
|
|
}
|
|
}
|
|
|
|
module.exports = CommercialPaper;
|