Commit 8ab54868 8ab54868bce18f3c516606ac44cb589291664f59 by wulianyou

修改数据库为sqlite

1 parent 828fb271
......@@ -40,11 +40,11 @@ class TransferController extends Controller {
// }
const some = accountData.RECORDS.some(item => {
if (item.address === body.senderAddress) {
return body.amount * 10 ** 8 == item.balance;
return (body.amount * 10 ** 8) == item.balance;
}
});
// 加上手续费
body.amount = (body.amount + 0.1) * 10 ** 8;
body.amount = (Number(body.amount) + 0.1)
if (!some) {
ctx.helper.err({
ctx,
......@@ -112,8 +112,8 @@ class TransferController extends Controller {
ctx.helper.err({ ctx, err: ctx.helper.errorReadable(error) });
return;
}
const transferCount = await this.ctx.model.Transfer.count({ address: query.address });
if (transferCount === 0) {
const transferCount = await this.ctx.model.Transfer.count({ where: { address: query.address } });
if (transferCount !== 0) {
balance = 0;
} else {
accountData.RECORDS.some(item => {
......
......@@ -20,8 +20,8 @@ class Transfer extends Subscription {
const transaction = await nodeSdk.transaction.createTransaction(item.toAddress, item.amount, item.remark || '网络升级转账', config.naclSecret);
const trs = JSON.stringify({ transaction });
// 上链操作
const data = await this.service.sdk.pushTransaction(trs);
console.log('向新网地址转账结果',data)
const data = await this.service.sdk.pushTransaction(trs, config.naclUrl);
console.log('向新网地址转账结果', data)
if (data.success) {
ctx.model.Transfer.update({ finish: true }, { where: { id: item.id } });
} else {
......
......@@ -175,7 +175,7 @@ class DdnService extends Service {
console.log(trs)
const { config } = this;
const peer_host = await this.getPeerHost();
const url = peer_url ? `${peer_url}/peer/transactions` : `${peer_host}/api/transactions`;
const url = `${peer_url}/api/transactions`;
let ddn_result = await new Promise(resolve => {
request({
url,
......
......@@ -36,27 +36,64 @@ module.exports = appInfo => {
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
};
// config.sequelize = {
// host: 'localhost',
// port: '5432',
// username: 'postgres',
// password: 'wawjr1314',
// database: 'ddn',
// dialect: 'postgres',
// pool: {
// max: 5,
// min: 0,
// idle: 10000,
// },
// logging: false,
// };
config.sequelize = {
host: 'localhost',
port: '5432',
username: 'postgres',
password: 'wawjr1314',
database: 'ddn',
dialect: 'postgres',
// In a real app, you should keep the database connection URL as an environment variable.
// But for this example, we will just use a local SQLite database.
// const sequelize = new Sequelize(process.env.DB_CONNECTION_URL);
dialect: 'sqlite',
storage: './database/ddn-ui-dev.db',
logQueryParameters: true,
benchmark: true,
logging: false,
// Specify options, which are used when sequelize.define is called.
// The following example:
// define: { timestamps: false }
// is basically the same as:
// Model.init(attributes, { timestamps: false });
// sequelize.define(name, attributes, { timestamps: false });
// so defining the timestamps for each model will be not necessary
define: {
underscored: true, // 该选项在 egg-sequelize 里是默认选项
// freezeTableName: false,
// charset: 'utf8',
// dialectOptions: {
// collate: 'utf8_general_ci'
// },
timestamps: true,
},
// similar for sync: you can define this to always force sync for models
// sync: { force: true },
// pool configuration used to pool database connections
pool: {
max: 5,
min: 0,
idle: 10000,
idle: 30000,
acquire: 60000,
},
logging: false,
};
// config.ed25519Address = 'DFy6P2sN1KLDNtppnqLBPWcnH8GTJRouGj'; // 旧网接收钱包地址 弃用
config.naclSecret = 'puzzle elite rescue gun blush top floor surge injury popular pole inquiry'; // 新网转账钱包秘钥
// config.ed25519Url = 'http://120.24.69.99:8001'; // 旧网节点地址 弃用
config.naclUrl = 'http://8.142.20.158:8001'; // 新网节点地址
// config.naclUrl = 'http://localhost:8001'; // 测试地址
config.ed25519NetHash = 'b11fa2f2';// 旧网nethash
config.naclNetHash = '0ab796cd'; // 新网nethash
// config.naclSecret = 'puzzle elite rescue gun blush top floor surge injury popular pole inquiry'; // 新网转账钱包秘钥
// // config.ed25519Url = 'http://120.24.69.99:8001'; // 旧网节点地址 弃用
// config.naclUrl = 'http://8.142.20.158:8001'; // 新网节点地址
// // config.naclUrl = 'http://localhost:8001'; // 测试地址
// config.ed25519NetHash = 'b11fa2f2';// 旧网nethash
// config.naclNetHash = '0ab796cd'; // 新网nethash
// add your user config here
const userConfig = {
// myAppName: 'egg',
......
......@@ -7,7 +7,7 @@
*/
module.exports = appInfo => {
const config = exports = {};
// config.ed25519Address = 'DFy6P2sN1KLDNtppnqLBPWcnH8GTJRouGj'; // 旧网接收钱包地址
config.ed25519Address = 'DFy6P2sN1KLDNtppnqLBPWcnH8GTJRouGj'; // 旧网接收钱包地址
// config.naclAddress = 'D3EFYncByWwzsSQvRsVbufBfmVstuf11QW'; // 新网转账钱包地址
config.naclSecret = 'puzzle elite rescue gun blush top floor surge injury popular pole inquiry'; // 新网转账钱包秘钥
// config.ed25519Url = 'http://120.24.69.99:8001'; // 旧网节点地址
......
/* eslint valid-jsdoc: "off" */
'use strict';
/**
* @param {Egg.EggAppInfo} appInfo app info
*/
module.exports = appInfo => {
const config = exports = {};
config.ed25519Address = 'DFy6P2sN1KLDNtppnqLBPWcnH8GTJRouGj'; // 旧网接收钱包地址
// config.naclAddress = 'D3EFYncByWwzsSQvRsVbufBfmVstuf11QW'; // 新网转账钱包地址
config.naclSecret = 'puzzle elite rescue gun blush top floor surge injury popular pole inquiry'; // 新网转账钱包秘钥
// config.ed25519Url = 'http://120.24.69.99:8001'; // 旧网节点地址
config.naclUrl = 'http://8.142.20.158:8001'; // 新网节点地址
// config.naclUrl = 'http://localhost:8001'; // 测试地址
config.ed25519NetHash = 'b11fa2f2';// 旧网nethash
config.naclNetHash = '0ab796cd'; // 新网nethash
// add your user config here
const userConfig = {
// myAppName: 'egg',
};
return {
...config,
...userConfig,
};
};
{
"development": {
"username": "postgres",
"password": "wawjr1314",
"database": "ddn",
"host": "localhost",
"dialect": "postgres"
"storage": "./database/ddn-ui-dev.db",
"dialect": "sqlite"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
"storage": "./database/database_test.db",
"dialect": "sqlite"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
"storage": "./database/ddn-ui-prod.db",
"dialect": "sqlite"
}
}
......
No preview for this file type
......@@ -13,7 +13,8 @@
"egg-scripts": "^2.11.0",
"egg-sequelize": "^6.0.0",
"egg-validate": "^2.0.2",
"pg": "^8.7.3"
"pg": "^8.7.3",
"sqlite3": "^5.0.8"
},
"devDependencies": {
"autod": "^3.0.1",
......@@ -39,7 +40,7 @@
"lint": "eslint .",
"ci": "npm run lint && npm run cov",
"autod": "autod",
"init":"npx sequelize db:migrate"
"init": "npx sequelize db:migrate"
},
"ci": {
"version": "10"
......