Skip to content
Snippets Groups Projects
Commit 9eabad23 authored by 赵易's avatar 赵易
Browse files

first commit

parents
Branches master
No related tags found
No related merge requests found
#
# SPDX-License-Identifier: Apache-2.0
#
.idea
.vscode
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless
.npmrc 0 → 100644
registry = http://registry.npmmirror.com
\ No newline at end of file
index.js 0 → 100644
/**
* Create with cscec_contract
* Author: ChrisChiu
* Date: 2024/4/15
* Desc
*/
'use strict';
const PEC_task = require('./lib/PEC_task');
module.exports.PEC_task = PEC_task;
module.exports.contracts = [ PEC_task ];
\ No newline at end of file
/**
* Create with cscec_contract
* Author: ChrisChiu
* Date: 2024/4/15
* Desc
*/
'use strict';
const {Contract} = require('fabric-contract-api');
const {Shim} = require('fabric-shim');
const {Task} = require('./model');
class PECTASK extends Contract {
async saveTask(ctx, task) {
let obj = {};
try {
obj = JSON.parse(task);
} catch (err) {
return Shim.error('The parameter is not a valid json format');
}
const _task = new Task(obj);
if (!_task.taskId) {
return Shim.error('taskId is not included in JSON format parameters');
}
/* 获得TxID */
const txId = ctx.stub.getTxID();
/* 组装stateId */
const stateId = ctx.stub.createCompositeKey('Task', [_task.taskId]) || 'Task' + _task.taskId;
/* 交易发起者数字身份 */
const msp = ctx.clientIdentity.getMSPID();
Object.assign(_task, {txId, msp});
const buffer = Buffer.from(JSON.stringify(_task));
await ctx.stub.putState(stateId, buffer);
return Shim.success(JSON.stringify({txId}));
};
async getTask(ctx, taskId) {
const stateId = ctx.stub.createCompositeKey('Task', [taskId]) || 'Task' + taskId;
const buffer = await ctx.stub.getState(stateId);
if (!!buffer && buffer.length > 0) {
return Shim.success(JSON.parse(buffer.toString()));
} else {
return Shim.error(`TaskId: ${taskId} is not exists`);
}
}
}
module.exports = PECTASK;
\ No newline at end of file
/**
* Create with cscec_contract
* Author: ChrisChiu
* Date: 2024/4/15
* Desc
*/
'use strict';
class Task {
constructor(task) {
this.taskId = task.taskId;
this.taskIdName = task.taskIdName;
this.ascription = task.ascription;
this.ownOrganId = task.ownOrganId;
this.ownOrganName = task.ownOrganName;
this.otherOrganId = task.otherOrganId;
this.otherOrganName = task.otherOrganName;
this.taskResultHash = task.taskResultHash;
}
}
module.exports = {Task}
\ No newline at end of file
{
"name": "cscec_contract",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "fabric-chaincode-node start"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"fabric-contract-api": "1.4.5",
"fabric-shim": "1.4.5"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment