Commit 8ab54868 8ab54868bce18f3c516606ac44cb589291664f59 by wulianyou

修改数据库为sqlite

1 parent 828fb271
...@@ -40,11 +40,11 @@ class TransferController extends Controller { ...@@ -40,11 +40,11 @@ class TransferController extends Controller {
40 // } 40 // }
41 const some = accountData.RECORDS.some(item => { 41 const some = accountData.RECORDS.some(item => {
42 if (item.address === body.senderAddress) { 42 if (item.address === body.senderAddress) {
43 return body.amount * 10 ** 8 == item.balance; 43 return (body.amount * 10 ** 8) == item.balance;
44 } 44 }
45 }); 45 });
46 // 加上手续费 46 // 加上手续费
47 body.amount = (body.amount + 0.1) * 10 ** 8; 47 body.amount = (Number(body.amount) + 0.1)
48 if (!some) { 48 if (!some) {
49 ctx.helper.err({ 49 ctx.helper.err({
50 ctx, 50 ctx,
...@@ -112,8 +112,8 @@ class TransferController extends Controller { ...@@ -112,8 +112,8 @@ class TransferController extends Controller {
112 ctx.helper.err({ ctx, err: ctx.helper.errorReadable(error) }); 112 ctx.helper.err({ ctx, err: ctx.helper.errorReadable(error) });
113 return; 113 return;
114 } 114 }
115 const transferCount = await this.ctx.model.Transfer.count({ address: query.address }); 115 const transferCount = await this.ctx.model.Transfer.count({ where: { address: query.address } });
116 if (transferCount === 0) { 116 if (transferCount !== 0) {
117 balance = 0; 117 balance = 0;
118 } else { 118 } else {
119 accountData.RECORDS.some(item => { 119 accountData.RECORDS.some(item => {
......
...@@ -20,8 +20,8 @@ class Transfer extends Subscription { ...@@ -20,8 +20,8 @@ class Transfer extends Subscription {
20 const transaction = await nodeSdk.transaction.createTransaction(item.toAddress, item.amount, item.remark || '网络升级转账', config.naclSecret); 20 const transaction = await nodeSdk.transaction.createTransaction(item.toAddress, item.amount, item.remark || '网络升级转账', config.naclSecret);
21 const trs = JSON.stringify({ transaction }); 21 const trs = JSON.stringify({ transaction });
22 // 上链操作 22 // 上链操作
23 const data = await this.service.sdk.pushTransaction(trs); 23 const data = await this.service.sdk.pushTransaction(trs, config.naclUrl);
24 console.log('向新网地址转账结果',data) 24 console.log('向新网地址转账结果', data)
25 if (data.success) { 25 if (data.success) {
26 ctx.model.Transfer.update({ finish: true }, { where: { id: item.id } }); 26 ctx.model.Transfer.update({ finish: true }, { where: { id: item.id } });
27 } else { 27 } else {
......
...@@ -175,7 +175,7 @@ class DdnService extends Service { ...@@ -175,7 +175,7 @@ class DdnService extends Service {
175 console.log(trs) 175 console.log(trs)
176 const { config } = this; 176 const { config } = this;
177 const peer_host = await this.getPeerHost(); 177 const peer_host = await this.getPeerHost();
178 const url = peer_url ? `${peer_url}/peer/transactions` : `${peer_host}/api/transactions`; 178 const url = `${peer_url}/api/transactions`;
179 let ddn_result = await new Promise(resolve => { 179 let ddn_result = await new Promise(resolve => {
180 request({ 180 request({
181 url, 181 url,
......
...@@ -36,27 +36,64 @@ module.exports = appInfo => { ...@@ -36,27 +36,64 @@ module.exports = appInfo => {
36 allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH', 36 allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
37 }; 37 };
38 38
39 // config.sequelize = {
40 // host: 'localhost',
41 // port: '5432',
42 // username: 'postgres',
43 // password: 'wawjr1314',
44 // database: 'ddn',
45 // dialect: 'postgres',
46 // pool: {
47 // max: 5,
48 // min: 0,
49 // idle: 10000,
50 // },
51 // logging: false,
52 // };
39 config.sequelize = { 53 config.sequelize = {
40 host: 'localhost', 54 // In a real app, you should keep the database connection URL as an environment variable.
41 port: '5432', 55 // But for this example, we will just use a local SQLite database.
42 username: 'postgres', 56 // const sequelize = new Sequelize(process.env.DB_CONNECTION_URL);
43 password: 'wawjr1314', 57 dialect: 'sqlite',
44 database: 'ddn', 58 storage: './database/ddn-ui-dev.db',
45 dialect: 'postgres', 59 logQueryParameters: true,
60 benchmark: true,
61 logging: false,
62
63 // Specify options, which are used when sequelize.define is called.
64 // The following example:
65 // define: { timestamps: false }
66 // is basically the same as:
67 // Model.init(attributes, { timestamps: false });
68 // sequelize.define(name, attributes, { timestamps: false });
69 // so defining the timestamps for each model will be not necessary
70 define: {
71 underscored: true, // 该选项在 egg-sequelize 里是默认选项
72 // freezeTableName: false,
73 // charset: 'utf8',
74 // dialectOptions: {
75 // collate: 'utf8_general_ci'
76 // },
77 timestamps: true,
78 },
79
80 // similar for sync: you can define this to always force sync for models
81 // sync: { force: true },
82
83 // pool configuration used to pool database connections
46 pool: { 84 pool: {
47 max: 5, 85 max: 5,
48 min: 0, 86 idle: 30000,
49 idle: 10000, 87 acquire: 60000,
50 }, 88 },
51 logging: false,
52 }; 89 };
53 // config.ed25519Address = 'DFy6P2sN1KLDNtppnqLBPWcnH8GTJRouGj'; // 旧网接收钱包地址 弃用 90 // config.ed25519Address = 'DFy6P2sN1KLDNtppnqLBPWcnH8GTJRouGj'; // 旧网接收钱包地址 弃用
54 config.naclSecret = 'puzzle elite rescue gun blush top floor surge injury popular pole inquiry'; // 新网转账钱包秘钥 91 // config.naclSecret = 'puzzle elite rescue gun blush top floor surge injury popular pole inquiry'; // 新网转账钱包秘钥
55 // config.ed25519Url = 'http://120.24.69.99:8001'; // 旧网节点地址 弃用 92 // // config.ed25519Url = 'http://120.24.69.99:8001'; // 旧网节点地址 弃用
56 config.naclUrl = 'http://8.142.20.158:8001'; // 新网节点地址 93 // config.naclUrl = 'http://8.142.20.158:8001'; // 新网节点地址
57 // config.naclUrl = 'http://localhost:8001'; // 测试地址 94 // // config.naclUrl = 'http://localhost:8001'; // 测试地址
58 config.ed25519NetHash = 'b11fa2f2';// 旧网nethash 95 // config.ed25519NetHash = 'b11fa2f2';// 旧网nethash
59 config.naclNetHash = '0ab796cd'; // 新网nethash 96 // config.naclNetHash = '0ab796cd'; // 新网nethash
60 // add your user config here 97 // add your user config here
61 const userConfig = { 98 const userConfig = {
62 // myAppName: 'egg', 99 // myAppName: 'egg',
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 */ 7 */
8 module.exports = appInfo => { 8 module.exports = appInfo => {
9 const config = exports = {}; 9 const config = exports = {};
10 // config.ed25519Address = 'DFy6P2sN1KLDNtppnqLBPWcnH8GTJRouGj'; // 旧网接收钱包地址 10 config.ed25519Address = 'DFy6P2sN1KLDNtppnqLBPWcnH8GTJRouGj'; // 旧网接收钱包地址
11 // config.naclAddress = 'D3EFYncByWwzsSQvRsVbufBfmVstuf11QW'; // 新网转账钱包地址 11 // config.naclAddress = 'D3EFYncByWwzsSQvRsVbufBfmVstuf11QW'; // 新网转账钱包地址
12 config.naclSecret = 'puzzle elite rescue gun blush top floor surge injury popular pole inquiry'; // 新网转账钱包秘钥 12 config.naclSecret = 'puzzle elite rescue gun blush top floor surge injury popular pole inquiry'; // 新网转账钱包秘钥
13 // config.ed25519Url = 'http://120.24.69.99:8001'; // 旧网节点地址 13 // config.ed25519Url = 'http://120.24.69.99:8001'; // 旧网节点地址
......
1 /* eslint valid-jsdoc: "off" */
2
3 'use strict';
4
5 /**
6 * @param {Egg.EggAppInfo} appInfo app info
7 */
8 module.exports = appInfo => {
9 const config = exports = {};
10 config.ed25519Address = 'DFy6P2sN1KLDNtppnqLBPWcnH8GTJRouGj'; // 旧网接收钱包地址
11 // config.naclAddress = 'D3EFYncByWwzsSQvRsVbufBfmVstuf11QW'; // 新网转账钱包地址
12 config.naclSecret = 'puzzle elite rescue gun blush top floor surge injury popular pole inquiry'; // 新网转账钱包秘钥
13 // config.ed25519Url = 'http://120.24.69.99:8001'; // 旧网节点地址
14 config.naclUrl = 'http://8.142.20.158:8001'; // 新网节点地址
15 // config.naclUrl = 'http://localhost:8001'; // 测试地址
16 config.ed25519NetHash = 'b11fa2f2';// 旧网nethash
17 config.naclNetHash = '0ab796cd'; // 新网nethash
18 // add your user config here
19 const userConfig = {
20 // myAppName: 'egg',
21 };
22
23 return {
24 ...config,
25 ...userConfig,
26 };
27 };
1 { 1 {
2 "development": { 2 "development": {
3 "username": "postgres", 3 "storage": "./database/ddn-ui-dev.db",
4 "password": "wawjr1314", 4 "dialect": "sqlite"
5 "database": "ddn",
6 "host": "localhost",
7 "dialect": "postgres"
8
9 }, 5 },
10 "test": { 6 "test": {
11 "username": "root", 7 "storage": "./database/database_test.db",
12 "password": null, 8 "dialect": "sqlite"
13 "database": "database_test",
14 "host": "127.0.0.1",
15 "dialect": "mysql"
16 }, 9 },
17 "production": { 10 "production": {
18 "username": "root", 11 "storage": "./database/ddn-ui-prod.db",
19 "password": null, 12 "dialect": "sqlite"
20 "database": "database_production",
21 "host": "127.0.0.1",
22 "dialect": "mysql"
23 } 13 }
24 } 14 }
......
No preview for this file type
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
13 "egg-scripts": "^2.11.0", 13 "egg-scripts": "^2.11.0",
14 "egg-sequelize": "^6.0.0", 14 "egg-sequelize": "^6.0.0",
15 "egg-validate": "^2.0.2", 15 "egg-validate": "^2.0.2",
16 "pg": "^8.7.3" 16 "pg": "^8.7.3",
17 "sqlite3": "^5.0.8"
17 }, 18 },
18 "devDependencies": { 19 "devDependencies": {
19 "autod": "^3.0.1", 20 "autod": "^3.0.1",
...@@ -39,7 +40,7 @@ ...@@ -39,7 +40,7 @@
39 "lint": "eslint .", 40 "lint": "eslint .",
40 "ci": "npm run lint && npm run cov", 41 "ci": "npm run lint && npm run cov",
41 "autod": "autod", 42 "autod": "autod",
42 "init":"npx sequelize db:migrate" 43 "init": "npx sequelize db:migrate"
43 }, 44 },
44 "ci": { 45 "ci": {
45 "version": "10" 46 "version": "10"
......