forked from gcarq/rusty-blockparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.sql
46 lines (35 loc) · 864 Bytes
/
views.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
CREATE OR REPLACE VIEW view_blocks AS
SELECT
height,
LOWER(HEX(hash)) AS hash,
version,
LOWER(HEX(hashPrev)) AS hashPrev,
LOWER(HEX(hashMerkleRoot)) AS hashMerkleRoot,
nTime,
nBits,
nNonce
FROM blocks
ORDER BY height ASC;
SELECT * FROM view_blocks;
CREATE OR REPLACE VIEW view_transactions AS
SELECT
LOWER(HEX(txid)) as txid,
LOWER(HEX(hashBlock)) as hashBlock,
version,
lockTime
FROM transactions;
SELECT * FROM view_transactions;
CREATE OR REPLACE VIEW view_balances AS
SELECT
address,
CAST(SUM(value) / 100000000 AS DECIMAL (16 , 8 )) AS balance
FROM
tx_out
WHERE
unspent = TRUE
GROUP BY address
ORDER BY balance DESC;
SELECT * FROM view_balances;
CREATE FUNCTION target (bits float)
RETURNS REAL DETERMINISTIC
RETURN mod(bits, 0x1000000) * pow(256, bits div 0x1000000 - 3);