Skip to content

Commit

Permalink
Fix fees typecast to bigint via migration, and fixes rollback migrati…
Browse files Browse the repository at this point in the history
…ons to properly restore
  • Loading branch information
rhyslbw committed Jul 3, 2020
1 parent 37b23bf commit 571628a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 10 deletions.
@@ -1,2 +1,2 @@
DROP VIEW IF EXISTS "Block", "Cardano", "Epoch", "Transaction", "Utxo", "TransactionInput", "TransactionOutput" CASCADE;
DROP FUNCTION IF EXISTS utxo_set_at_block CASCADE;
drop view if exists "Block", "Cardano", "Epoch", "Transaction", "Utxo", "TransactionInput", "TransactionOutput" cascade;
drop function if exists utxo_set_at_block cascade;
@@ -1,6 +1,6 @@
create view "Block" as
select
CAST(COALESCE((select sum(tx.fee) from tx where tx.block = block.id), 0) as integer) as "fees",
cast(coalesce((select sum(tx.fee) from tx where tx.block = block.id), 0) as integer) as "fees",
block.hash as hash,
block.merkel_root as "merkelRoot",
block.block_no as number,
Expand Down Expand Up @@ -47,7 +47,7 @@ from epoch;
create view "Transaction" as
select
block.hash as "blockHash",
COALESCE(tx.fee, 0) as fee,
coalesce(tx.fee, 0) as fee,
tx.hash as hash,
cast((select sum("value") from tx_out where tx_id = tx.id) as bigint) as "totalOutput",
tx.size,
Expand Down Expand Up @@ -97,8 +97,8 @@ from tx
join tx_out
on tx.id = tx_out.tx_id;

CREATE FUNCTION utxo_set_at_block("hash" hash32type)
RETURNS SETOF "TransactionOutput" AS $$
create function utxo_set_at_block("hash" hash32type)
returns setof "TransactionOutput" AS $$
select
"TransactionOutput".address,
"TransactionOutput".value,
Expand All @@ -114,4 +114,4 @@ RETURNS SETOF "TransactionOutput" AS $$
and tx_out.index = tx_in.tx_out_index
where tx_in.tx_in_id is null
and tx.block <= (select id from block where hash = "hash")
$$ LANGUAGE sql STABLE;
$$ language sql stable;
@@ -1 +1,13 @@
DROP VIEW IF EXISTS "Transaction" CASCADE;
drop view if exists "Transaction" cascade;
create view "Transaction" as
select
block.hash as "blockHash",
coalesce(tx.fee, 0) as fee,
tx.hash as hash,
cast((select sum("value") from tx_out where tx_id = tx.id) as bigint) as "totalOutput",
tx.size,
block.time as "includedAt"
from
tx
inner join block
on block.id = tx.block;
@@ -1,7 +1,8 @@
create or replace view "Transaction" as
drop view "Transaction";
create view "Transaction" as
select
block.hash as "blockHash",
COALESCE(tx.fee, 0) as fee,
coalesce(tx.fee, 0) as fee,
tx.hash as hash,
cast((select sum("value") from tx_out where tx_id = tx.id) as bigint) as "totalOutput",
tx.size,
Expand Down
@@ -0,0 +1,23 @@
drop view if exists "Block" cascade;
create view "Block" as
select
cast(coalesce((select sum(tx.fee) from tx where tx.block = block.id), 0) as integer) as "fees",
block.hash as hash,
block.merkel_root as "merkelRoot",
block.block_no as number,
previous_block."hash" as "previousBlockHash",
next_block."hash" as "nextBlockHash",
slot_leader."description" as "createdBy",
block.size as size,
block.tx_count as "transactionsCount",
block.epoch_no as "epochNo",
block.slot_no as "slotNo",
block.slot_no - (block.epoch_no * (10 * (select protocol_const from meta))) as "slotWithinEpoch",
block.time as "createdAt"
from block
left outer join block as previous_block
on block.previous = previous_block.id
left outer join block as next_block
on next_block.previous = block.id
left outer join slot_leader
on block.slot_leader = slot_leader.id;
@@ -0,0 +1,36 @@
drop view "Block" cascade;
create view "Block" as
select
cast(coalesce((select sum(tx.fee) from tx where tx.block = block.id), 0) as bigint) as "fees",
block.hash as hash,
block.merkel_root as "merkelRoot",
block.block_no as number,
previous_block."hash" as "previousBlockHash",
next_block."hash" as "nextBlockHash",
slot_leader."description" as "createdBy",
block.size as size,
block.tx_count as "transactionsCount",
block.epoch_no as "epochNo",
block.slot_no as "slotNo",
block.slot_no - (block.epoch_no * (10 * (select protocol_const from meta))) as "slotWithinEpoch",
block.time as "createdAt"
from block
left outer join block as previous_block
on block.previous = previous_block.id
left outer join block as next_block
on next_block.previous = block.id
left outer join slot_leader
on block.slot_leader = slot_leader.id;

create view "Cardano" as
select
number as "blockHeight",
"epochNo" as "currentEpochNo",
(select slot_duration from meta) as "slotDuration",
(select start_time from meta) as "startTime",
(select protocol_const from meta) as "protocolConst",
(select network_name from meta) as "networkName"
from "Block"
where number is not null
order by number desc
limit 1;

0 comments on commit 571628a

Please sign in to comment.