diff --git a/db/sql/migrations/updates/20180205000003_create_rounds_rewards_table.sql b/db/sql/migrations/updates/20180205000003_create_rounds_rewards_table.sql index 8cde4abfca3..057d2ebe671 100644 --- a/db/sql/migrations/updates/20180205000003_create_rounds_rewards_table.sql +++ b/db/sql/migrations/updates/20180205000003_create_rounds_rewards_table.sql @@ -72,23 +72,23 @@ DO $$ -- Calculating total fees of round fees AS (SELECT sum(fees) AS total, floor(sum(fees) / 101) AS single FROM round), -- Get last delegate and timestamp of round's last block - last AS (SELECT "publicKey", timestamp FROM filtered_round ORDER BY height DESC LIMIT 1) + last AS (SELECT "publicKey", timestamp FROM round ORDER BY height DESC LIMIT 1) INSERT INTO rounds_rewards SELECT -- Timestamp of last round's block last.timestamp, -- Calculating real fee reward for delegate: -- Rounded fee per delegate + remaining fees if block is last one of round - (fees.single + (CASE WHEN last."publicKey" = filtered_round."publicKey" AND last.timestamp = filtered_round.timestamp THEN (fees.total - fees.single * 101) ELSE 0 END)) AS fees, + (fees.single + (CASE WHEN last."publicKey" = round."publicKey" AND last.timestamp = round.timestamp THEN (fees.total - fees.single * 101) ELSE 0 END)) AS fees, -- Block reward - filtered_round.reward, + round.reward, -- Round - ceil(filtered_round.height / 101::float)::int, + ceil(round.height / 101::float)::int, -- Delegate public key - filtered_round."publicKey" - FROM last, fees, filtered_round + round."publicKey" + FROM last, fees, round -- Sort fees by block height - ORDER BY filtered_round.height ASC; + ORDER BY round.height ASC; END LOOP; RETURN; END $$;