Skip to content

Commit 3854310

Browse files
authored
Merge pull request #99 from UniqueNetwork/release/v1.6.3
Release/v1.6.3
2 parents 992f5b4 + 548c07c commit 3854310

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

lib/blockDB.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ async function save({
4848
'total_issuance',
4949
'timestamp',
5050
'need_rescan',
51+
'total_extrinsics',
5152
],
5253
transaction = null,
5354
}) {
@@ -78,6 +79,7 @@ async function save({
7879
new_accounts: block.newAccounts,
7980
total_issuance: block.totalIssuance,
8081
timestamp: block.timestamp,
82+
total_extrinsics: block.extrinsics?.length,
8183
need_rescan: false,
8284
},
8385
transaction,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
module.exports = {
4+
async up (queryInterface, Sequelize) {
5+
await queryInterface.addColumn('block', 'total_extrinsics', {
6+
type: Sequelize.DataTypes.INTEGER,
7+
allowNull: true,
8+
});
9+
},
10+
11+
async down (queryInterface, Sequelize) {
12+
await queryInterface.removeColumn('block', 'total_extrinsics');
13+
},
14+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
module.exports = {
4+
async up (queryInterface, Sequelize) {
5+
const transaction = await queryInterface.sequelize.transaction();
6+
7+
try {
8+
await queryInterface.sequelize.query(
9+
`update block b
10+
set total_extrinsics = (select count(*) from extrinsic e where e.block_number = b.block_number);
11+
`,
12+
{ transaction },
13+
);
14+
15+
await queryInterface.changeColumn(
16+
'block',
17+
'total_extrinsics',
18+
{
19+
type: Sequelize.DataTypes.INTEGER,
20+
defaultValue: 0,
21+
},
22+
{
23+
transaction,
24+
},
25+
);
26+
27+
await transaction.commit();
28+
} catch (err) {
29+
console.error(err);
30+
await transaction.rollback();
31+
throw err;
32+
}
33+
},
34+
35+
async down (queryInterface, Sequelize) {},
36+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
module.exports = {
4+
async up (queryInterface, Sequelize) {
5+
const transaction = await queryInterface.sequelize.transaction();
6+
7+
try {
8+
await queryInterface.sequelize.query(`DROP VIEW public.view_last_block;`, { transaction });
9+
10+
await queryInterface.sequelize.query(`
11+
CREATE OR REPLACE VIEW public.view_last_block
12+
AS SELECT block.block_number,
13+
block.total_events AS event_count,
14+
block.total_extrinsics AS extrinsic_count,
15+
block."timestamp"
16+
FROM block
17+
ORDER BY block.block_number DESC;
18+
`, { transaction });
19+
20+
await transaction.commit();
21+
} catch (err) {
22+
console.error(err);
23+
await transaction.rollback();
24+
throw err;
25+
}
26+
},
27+
28+
async down(queryInterface, Sequelize) {
29+
const transaction = await queryInterface.sequelize.transaction();
30+
31+
try {
32+
await queryInterface.sequelize.query(`DROP VIEW public.view_last_block;`, { transaction });
33+
34+
await queryInterface.sequelize.query(`
35+
CREATE OR REPLACE VIEW public.view_last_block
36+
AS SELECT block.block_number,
37+
vceb.count_block_number AS event_count,
38+
v.count_extrinsic AS extrinsic_count,
39+
block."timestamp"
40+
FROM block
41+
LEFT JOIN view_count_event_block vceb ON block.block_number = vceb.block_number
42+
LEFT JOIN view_count_extrinsic_block v ON block.block_number = v.block_number
43+
ORDER BY block.block_number DESC;
44+
`, { transaction });
45+
46+
await transaction.commit();
47+
} catch (err) {
48+
console.error(err);
49+
await transaction.rollback();
50+
throw err;
51+
}
52+
},
53+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
module.exports = {
4+
async up (queryInterface, Sequelize) {
5+
const transaction = await queryInterface.sequelize.transaction();
6+
7+
try {
8+
await queryInterface.sequelize.query(`DROP VIEW public.view_last_block;`, { transaction });
9+
10+
await queryInterface.sequelize.query(`
11+
CREATE OR REPLACE VIEW public.view_last_block
12+
AS SELECT block.block_number,
13+
block.total_events AS event_count,
14+
block.total_extrinsics AS extrinsic_count,
15+
block."timestamp"
16+
FROM block;
17+
`, { transaction });
18+
19+
await transaction.commit();
20+
} catch (err) {
21+
console.error(err);
22+
await transaction.rollback();
23+
throw err;
24+
}
25+
},
26+
27+
async down (queryInterface, Sequelize) {
28+
const transaction = await queryInterface.sequelize.transaction();
29+
30+
try {
31+
await queryInterface.sequelize.query(`DROP VIEW public.view_last_block;`, { transaction });
32+
33+
await queryInterface.sequelize.query(`
34+
CREATE OR REPLACE VIEW public.view_last_block
35+
AS SELECT block.block_number,
36+
block.total_events AS event_count,
37+
block.total_extrinsics AS extrinsic_count,
38+
block."timestamp"
39+
FROM block
40+
ORDER BY block.block_number DESC;
41+
`, { transaction });
42+
43+
await transaction.commit();
44+
} catch (err) {
45+
console.error(err);
46+
await transaction.rollback();
47+
throw err;
48+
}
49+
}
50+
};

0 commit comments

Comments
 (0)