Tools, FAQ, Tutorials:
papercontract.js - PaperNet Chaincode (Smart Contract)
What is the PaperNet Chaincode (Smart Contract), papercontract.js?
✍: FYIcenter.com
papercontract.js is the chaincode (or smart contract) for the PaperNet
written in Node.js language.
1. View papercontract.js source code:
(magnetocorp admin)$ cd ~/hyperledger-binaries/fabric-samples
(magnetocorp admin)$ cd commercial-paper/organization/magnetocorp/contract
(magnetocorp admin)$ more lib/papercontract.js
/* SPDX-License-Identifier: Apache-2.0
*/
'use strict';
// Fabric smart contract classes
const { Contract, Context } = require('fabric-contract-api');
// PaperNet specific classes
const CommercialPaper = require('./paper.js');
const PaperList = require('./paperlist.js');
/** A custom context provides easy access to list of all commercial papers
*/
class CommercialPaperContext extends Context {
constructor() {
super();
// All papers are held in a list of papers
this.paperList = new PaperList(this);
}
}
/** Define commercial paper smart contract by extending Fabric Contract class
*
*/
class CommercialPaperContract extends Contract {
constructor() {
// Unique namespace when multiple contracts per chaincode file
super('org.papernet.commercialpaper');
}
createContext() {
return new CommercialPaperContext();
}
/** Instantiate to perform any setup of the ledger that might be required.
* @param {Context} ctx the transaction context
*/
async instantiate(ctx) {
// No implementation required with this example
// It could be where data migration is performed, if necessary
console.log('Instantiate the contract');
}
/** Issue commercial paper
*
* @param {Context} ctx the transaction context
* @param {String} issuer commercial paper issuer
* @param {Integer} paperNumber paper number for this issuer
* @param {String} issueDateTime paper issue date
* @param {String} maturityDateTime paper maturity date
* @param {Integer} faceValue face value of paper
*/
async issue(ctx, issuer, paperNumber, issueDateTime, maturityDateTime, faceValue) {
...
return paper.toBuffer();
}
/** Buy commercial paper
*
* @param {Context} ctx the transaction context
* @param {String} issuer commercial paper issuer
* @param {Integer} paperNumber paper number for this issuer
* @param {String} currentOwner current owner of paper
* @param {String} newOwner new owner of paper
* @param {Integer} price price paid for this paper
* @param {String} purchaseDateTime time paper was purchased (i.e. traded)
*/
async buy(ctx, issuer, paperNumber, currentOwner, newOwner, price, purchaseDateTime) {
...
return paper.toBuffer();
}
/** Redeem commercial paper
*
* @param {Context} ctx the transaction context
* @param {String} issuer commercial paper issuer
* @param {Integer} paperNumber paper number for this issuer
* @param {String} redeemingOwner redeeming owner of paper
* @param {String} redeemDateTime time paper was redeemed
*/
async redeem(ctx, issuer, paperNumber, redeemingOwner, redeemDateTime) {
...
return paper.toBuffer();
}
}
module.exports = CommercialPaperContract;
As you can see, papercontract.js offers 3 functions: issue, buy and redeem for the PaperNet chaincode. Client applications can submit transactions correspondingly to issue, buy and redeem commercial paper on the ledger.
⇒ Install PaperNet Chaincode (Smart Contract)
⇐ Start CLI Container for MagnetoCorp Admin
2019-12-02, ∼1449🔥, 0💬
Popular Posts:
How to use "xsl-transform" Azure API Policy Statement? The "xsl-transform" Policy Statement allows y...
Where to find tutorials on EPUB file format? I want to know how to create EPUB books. Here is a larg...
Where to find tutorials on OpenID? Here is a large collection of tutorials to answer many frequently...
How to add a new operation to an API on the Publisher Dashboard of an Azure API Management Service? ...
How To Create an Array with a Sequence of Integers or Characters in PHP? The quickest way to create ...