Skip to content

Commit

Permalink
Merge branch 'master' of github.com:LinkIdol/TronProducer
Browse files Browse the repository at this point in the history
  • Loading branch information
shellteo committed Jan 31, 2019
2 parents a6784c5 + 014f70b commit d37d35d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
1 change: 1 addition & 0 deletions Backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ run/
*.un~
config/config.local.js
config/config.prod.js
app/TronEvents/tronaddr.json
28 changes: 26 additions & 2 deletions Backend/app/TronEvents/tronService.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@ const tronWeb = new TronWeb(

module.exports = {

async transfers() {
const addrs = require("./tronaddr.json").rows;
let total = 0;
for (var i = 0; i < addrs.length; i++) {
let tronWebTrans = new TronWeb(
fullNode,
solidityNode,
eventServer,
addrs[i].pk
);
let balance = await tronWebTrans.trx.getBalance(addrs[i].address);
total += balance;
console.log('balance = ' + balance);
let result;
if (balance > 0) {
result = await tronWeb.trx.sendTransaction("THtUYhJbPozMGP4TFkRBD2Rcya96Txd1J9", balance, addrs[i].pk);
//以下转账方法失败
//let result = await tronWebTrans.transactionBuilder.sendTrx('THtUYhJbPozMGP4TFkRBD2Rcya96Txd1J9', balance, tronaddr.rows[0].address);
console.log('result = ' + result);
}
}
console.log('total = ' + total);
},

//初始化数据
async syncData(ctx) {
let total = await this.getTotalSupply();
Expand Down Expand Up @@ -148,7 +172,7 @@ module.exports = {
let contract = await tronWebTrans.contract(IdolCore.abi, IdolCore.address);
let genes = utility.random(12);
let result = await contract.createPromoKitty(genes, address).send({
callValue:0,
callValue: 0,
shouldPollResponse: false
});
return result;
Expand All @@ -165,7 +189,7 @@ module.exports = {
let contract = await tronWebTrans.contract(IdolCore.abi, IdolCore.address);
let genes = utility.random(12);
let result = await contract.createGen0Auction(genes).send({
callValue:0,
callValue: 0,
shouldPollResponse: false
});
return result;
Expand Down
2 changes: 1 addition & 1 deletion Backend/app/schedule/CreateGen0Job.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let tronService = require("../TronEvents/tronService");
module.exports = {
schedule: {
type: 'worker',
cron: '0 0 */1 * * *',
cron: '0 0 */6 * * *', //每6小时一次
// interval: '60s', // 1 分钟间隔
// type: 'worker', // all 指定所有的 worker 都需要执行
},
Expand Down
2 changes: 1 addition & 1 deletion Backend/app/schedule/TronJob.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let tronEvents = require("../TronEvents");
module.exports = {
schedule: {
interval: '30s', // 1 分钟间隔
interval: '60s', // 1 分钟间隔
type: 'worker', // all 指定所有的 worker 都需要执行
},
async task(ctx) {
Expand Down
2 changes: 1 addition & 1 deletion Backend/app/schedule/TronSyncJob.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let tronService = require("../TronEvents/tronService");
module.exports = {
schedule: {
interval: '60s', // 1 分钟间隔
interval: '120s', // 1 分钟间隔
type: 'worker', // all 指定所有的 worker 都需要执行
},
async task(ctx) {
Expand Down
31 changes: 28 additions & 3 deletions Backend/app/service/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ module.exports = {

async verify(ctx, next) {
// 获取cookies信息
const token = ctx.cookies.get(ctx.app.config.keys);
let token = ctx.cookies.get(ctx.app.config.keys);

const { authorization } = ctx.headers;

if (token == undefined && authorization != undefined) {
const auths = authorization.split(' ');
if (auths[0] == 'Bearer' && auths.length == 2) {
token = auths[1];
}
}

ctx.user = { UserId: 0, UserName: '' };
if (token != undefined) {
try {
Expand All @@ -22,7 +32,23 @@ module.exports = {
// 验证jwt
async authorize(ctx, next) {
// 获取cookies信息
const token = ctx.cookies.get(ctx.app.config.keys);
let token = ctx.cookies.get(ctx.app.config.keys);

const { authorization } = ctx.headers;

if (token == undefined) {
if (authorization == undefined)
ctx.throw(401, 'The token is error.');

const auths = authorization.split(' ');

if (auths[0] != 'Bearer' || auths.length != 2) {
ctx.throw(401, 'The authorization is error.');
}

token = auths[1];
}

let user;
try {
user = jwt.verify(token, ctx.app.config.login.secretKey);
Expand All @@ -34,7 +60,6 @@ module.exports = {
//ctx.redirect('/login');
}

console.log(user);
await next();
},

Expand Down

0 comments on commit d37d35d

Please sign in to comment.