Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/3.0.0-milestone3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bigomby committed Jun 12, 2020
2 parents 55821c8 + 703fb7b commit f2e5de2
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 140 deletions.
2 changes: 1 addition & 1 deletion docker/polkastats-backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
- '30333:30333'
- '9933:9933'
- '9944:9944'
command: -d /data --unsafe-ws-external --rpc-cors all --pruning=archive --name 'Polkastats 🤖 v3'
command: -d /data --unsafe-ws-external --rpc-cors all --pruning=archive --name 'Polkastats 🤖 v3' --chain kusama
restart: on-failure
#
# SQL data base
Expand Down
4 changes: 3 additions & 1 deletion docker/polkastats-backend/sql/polkastats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CREATE TABLE IF NOT EXISTS rewards (
stake_info TEXT,
estimated_payout BIGINT NOT NULL,
timestamp BIGINT NOT NULL,
PRIMARY KEY ( block_number, era_index, stash_id )
PRIMARY KEY ( era_index, stash_id )
);

CREATE TABLE IF NOT EXISTS validator_slashes_era (
Expand Down Expand Up @@ -170,10 +170,12 @@ CREATE TABLE IF NOT EXISTS account (
account_id VARCHAR(47) NOT NULL,
identity TEXT NOT NULL,
identity_display VARCHAR(100) NOT NULL,
identity_display_parent VARCHAR(100) NOT NULL,
balances TEXT NOT NULL,
available_balance BIGINT NOT NULL,
free_balance BIGINT NOT NULL,
locked_balance BIGINT NOT NULL,
nonce BIGINT NOT NULL,
timestamp BIGINT NOT NULL,
block_height BIGINT NOT NULL,
is_staking BOOLEAN NOT NULL,
Expand Down
2 changes: 1 addition & 1 deletion docker/polkastats-backend/substrate-client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM phusion/baseimage:0.11
LABEL maintainer "@ColmenaLabs_svq"
LABEL description="Small image with the Substrate binary."

ARG VERSION=v0.7.33
ARG VERSION=v0.8.7

RUN apt-get update && apt-get install wget curl jq -y

Expand Down
28 changes: 15 additions & 13 deletions lib/crawlers/activeAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,22 @@ const makeQuery = (state, block, timestamp) => {
const freeBalance = balances.freeBalance.toString();
const lockedBalance = balances.lockedBalance.toString();
const identityDisplay = identity.display ? identity.display.toString() : ``;
const identityDisplayParent = identity.displayParent ? identity.displayParent.toString() : ``;
const JSONIdentity = identity.display ? JSON.stringify(identity) : ``;
const JSONbalances = JSON.stringify(balances);
const query = ` \
INSERT INTO account (account_id, identity, identity_display, balances, available_balance, free_balance, locked_balance, timestamp, block_height, is_staking) \
VALUES ('${id}', '${JSONIdentity}', '${identityDisplay}', '${JSONbalances}', '${availableBalance}', '${freeBalance}', '${lockedBalance}', '${timestamp}', '${block}', ${isStaking}) \
ON CONFLICT (account_id) \
DO UPDATE \
SET identity = EXCLUDED.identity, \
balances = EXCLUDED.balances, \
available_balance = EXCLUDED.available_balance, \
free_balance = EXCLUDED.free_balance, \
timestamp = EXCLUDED.timestamp, \
is_staking = EXCLUDED.is_staking, \
block_height = EXCLUDED.block_height; \
const JSONbalances = JSON.stringify(balances);
const nonce = balances.accountNonce.toString();
const query = ` \
INSERT INTO account (account_id, identity, identity_display, identity_display_parent, balances, available_balance, free_balance, locked_balance, nonce, timestamp, block_height, is_staking) \
VALUES ('${id}', '${JSONIdentity}', '${identityDisplay}', '${identityDisplayParent}', '${JSONbalances}', '${availableBalance}', '${freeBalance}', '${lockedBalance}', '${nonce}', '${timestamp}', '${block}', ${isStaking}) \
ON CONFLICT (account_id) \
DO UPDATE \
SET identity = EXCLUDED.identity, \
balances = EXCLUDED.balances, \
available_balance = EXCLUDED.available_balance, \
free_balance = EXCLUDED.free_balance, \
timestamp = EXCLUDED.timestamp, \
is_staking = EXCLUDED.is_staking, \
block_height = EXCLUDED.block_height; \
`;

return { ...state, query };
Expand Down
12 changes: 11 additions & 1 deletion lib/crawlers/blockHarvester.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,17 @@ module.exports = {

// Get block author identity display name
const blockAuthorIdentity = await api.derive.accounts.info(blockAuthor);
const blockAuthorName = blockAuthorIdentity.identity.display || ``;
let blockAuthorName;
if (
blockAuthorIdentity.identity.displayParent &&
blockAuthorIdentity.identity.displayParent !== `` &&
blockAuthorIdentity.identity.display &&
blockAuthorIdentity.identity.display !== ``
) {
blockAuthorName = `${blockAuthorIdentity.identity.displayParent} / ${blockAuthorIdentity.identity.display}`;
} else {
blockAuthorName = blockAuthorIdentity.identity.display || ``;
}

// Get runtime spec name and version
const runtimeVersion = await api.rpc.state.getRuntimeVersion(blockHash);
Expand Down
12 changes: 11 additions & 1 deletion lib/crawlers/blockListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ module.exports = {

// Get block author identity display name
const blockAuthorIdentity = await api.derive.accounts.info(blockAuthor);
const blockAuthorName = blockAuthorIdentity.identity.display || ``;
let blockAuthorName;
if (
blockAuthorIdentity.identity.displayParent &&
blockAuthorIdentity.identity.displayParent !== `` &&
blockAuthorIdentity.identity.display &&
blockAuthorIdentity.identity.display !== ``
) {
blockAuthorName = `${blockAuthorIdentity.identity.displayParent} / ${blockAuthorIdentity.identity.display}`;
} else {
blockAuthorName = blockAuthorIdentity.identity.display || ``;
}

// Get runtime spec name and version
const runtimeVersion = await api.rpc.state.getRuntimeVersion(blockHash);
Expand Down
5 changes: 4 additions & 1 deletion lib/crawlers/rewardsSlashes.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ module.exports = {
const estimatedPayoutKSM = estimatedPayout.dividedBy(1e12).toNumber().toFixed(3);

const sql = `INSERT INTO rewards (block_number, era_index, stash_id, commission, era_rewards, era_points, stake_info, estimated_payout, timestamp)
VALUES ('${blockNumber}', '${lastEraIndex}', '${validator}', '${eraValidatorCommission[index].commission}', '${poolRewardWithCommission.toString(10)}', '${eraPoints}', '${JSON.stringify(exposure)}', '${estimatedPayout.toFixed(0)}', extract(epoch from now()));`;
VALUES ('${blockNumber}', '${lastEraIndex}', '${validator}', '${eraValidatorCommission[index].commission}', '${poolRewardWithCommission.toString(10)}', '${eraPoints}', '${JSON.stringify(exposure)}', '${estimatedPayout.toFixed(0)}', extract(epoch from now()))
ON CONFLICT ON CONSTRAINT rewards_pkey
DO NOTHING
`;
try {
logger.info(`Adding reward for validator ${validator}, era: ${lastEraIndex}, commission: ${commission}%, points: ${eraPoints} (${eraPointsPercent}%), exposure: ${totalExposure} KSM, reward: ${poolRewardWithCommissionKSM} KSM (without ${commission}% = ${poolRewardWithoutCommissionKSM} KSM), estimated era profit for 1000 KSM: ${estimatedPayoutKSM} KSM`);
await pool.query(sql);
Expand Down
Loading

0 comments on commit f2e5de2

Please sign in to comment.