基于NAS智能合约的去中心化PasteBin服务,构建永久保存、不可篡改的PasteBin服务系统
本网站旨在用作各方之间短期交流的粘贴信息(特别是程序代码)。 所有提交的数据都被视为公开信息。 与大多数PasteBin网站不同,本站提交的数据保证是永久的,并且记录在星云区块链上不可篡改。
NasPasteBin解决了传统PasteBin服务中无法承诺永久保存,无法承诺不可篡改代码的弊端。
'use strict';
var Item = function (text) {
if (text) {
var o = JSON.parse(text);
this.id = o.id;
this.hash = o.hash;
this.createTime = o.createTime;
this.createAddr = o.createAddr;
this.nickname = o.nickname;
this.type = o.type;
this.content = o.content;
} else {
this.id = '';
this.hash = '';
this.createTime = 0;
this.createAddr = '';
this.nickname = '';
this.type = '';
this.content = '';
}
};
Item.prototype = {
toString: function () {
return JSON.stringify(this);
},
};
var NasFloater = function () {
LocalContractStorage.defineMapProperty(this, "repo", {
parse: function (text) {
return new Item(text);
},
stringify: function (o) {
return o.toString();
}
});
LocalContractStorage.defineProperty(this, "counter", {
stringify: function (obj) {
return obj.toString();
},
parse: function (str) {
return new BigNumber(str);
}
});
};
NasFloater.prototype = {
init: function () {
this.counter = new BigNumber(1);
},
addItem: function (nickname, type, content) {
var item = new Item();
item.id = this.counter.toString();
item.hash = Blockchain.transaction.hash;
item.createTime = Blockchain.transaction.timestamp * 1000;
item.createAddr = Blockchain.transaction.from;
item.nickname = nickname;
item.type = type;
item.content = content;
this.repo.put(item.hash, item);
this.counter = this.counter.plus(1);
return item;
},
getItem: function (hash) {
var item = this.repo.get(hash);
if (!item) {
throw new Error("not exist.");
}
return item;
}
};
module.exports = NasFloater;
使用文档
使用:
- 启动调试服务:
npm start
- 构建 dist:
npm run build
目录结构:
- react-router @4.x 默认采用 hashHistory 的单页应用
- 入口文件:
src/index.js
- 导航配置:
src/menuConfig.js
- 路由配置:
src/routerConfig.js
- 路由入口:
src/router.jsx
- 布局文件:
src/layouts
- 通用组件:
src/components
- 页面文件:
src/pages